Goods.php 2.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/6
 * Time: 15:27
 */

namespace app\index\model;


use think\Model;

class Goods extends Model
{
    public function getPropertyAttr($value){
        $data = [];
        if(!empty($value)){
            $data = explode(',',$value);
        }
        return $data;
    }
    public function getThumbnailAttr($value){
        return cdnurl($value);
    }
    public function selectData($where){
        $where['g.status'] = ['eq','1'];
        $data = $this
            ->alias('g')
            ->field('g.*,t.name as goodstype_name,s.name as store_name,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
            ->join('sto_goodstype t','t.id = g.goodstype_id')
            ->join('sto_store s','s.id = g.store_id')
            ->where($where)
            ->order('weigh desc')
            ->select();
        $storeModel = new Store();
        foreach($data as $key => $vo){
            $store = $storeModel->findData(['id'=>$vo['store_id']]);
            $data[$key]['store_is_vip'] = $store['is_vip'];
            $data[$key]['store_is_svip'] = $store['is_svip'];
        }
        return $data;
    }
    public function selectPageData($where,$pageNum){
        $where['g.status'] = ['eq','1'];
        $data = $this
            ->alias('g')
            ->field('g.*,t.name as goodstype_name,s.name as store_name,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
            ->join('sto_goodstype t','t.id = g.goodstype_id')
            ->join('sto_store s','s.id = g.store_id')
            ->where($where)
            ->order('weigh desc')
            ->paginate($pageNum);
        $storeModel = new Store();
        foreach($data as $key => $vo){
            $store = $storeModel->findData(['id'=>$vo['store_id']]);
            $data[$key]['store_is_vip'] = $store['is_vip'];
            $data[$key]['store_is_svip'] = $store['is_svip'];
        }
        return $data;
    }
    public function findData($where){
        $data = $this
            ->alias('g')
            ->field('g.*,t.name as goodstype_name,s.lng,s.lat,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
            ->join('sto_goodstype t','t.id = g.goodstype_id')
            ->join('sto_store s','s.id = g.store_id')
            ->where($where)
            ->find();
        $storeModel = new Store();
        $store = $storeModel->findData(['id'=>$data['store_id']]);
        $data['store_is_vip'] = $store['is_vip'];
        $data['store_is_svip'] = $store['is_svip'];
        return $data;
    }
}