<?php
declare (strict_types = 1);

namespace app\model\system;

use library\traits\JwtAuthModelTrait;
use library\traits\ModelTrait;
use think\Exception;
use think\Model;

/**
 * @mixin \think\Model
 */
class SiteProduct extends Model
{

    use ModelTrait;
    use JwtAuthModelTrait;

    private $sassid;

    public function setSassid($sassid) {
        $this->sassid = $sassid;
    }


    /**
     * 获取列表数据
     * @param $page
     * @param $where
     * @param $pageCount
     * @param $desc
     */
    public function getList($page  = 1,$where = [],$pageCount = 20){
        $data =
            $this->field("sp.id,p.title,img,sp.price,p.commission,sp.status,sp.sales,sp.is_new,sp.is_host,sp.ver_bug_count,p.count")
                ->alias("sp")
                ->join("product p","p.id = sp.p_id","left")
                ->where('sp.sassid',$this->sassid)
                ->when(!empty($where),function ($query) use($where){
                    if(!empty($where['type'])) {
                        if($where['type'] == 'kc') {
                            $query->where('p.count','>',0);
                        }

                        if($where['type'] == 'nkc') {
                            $query->where('p.count','=',0);
                        }
                    }
                })
                ->paginate(['list_rows'=>$pageCount,'page'=>$page])
                ->toArray();
        return [$data['total'],$data['data']];
    }

}
