52 lines
1.6 KiB
PHP
Executable File
52 lines
1.6 KiB
PHP
Executable File
<?php
|
|
namespace app\coachapi\lists;
|
|
use app\common\enum\coach\CoachEnum;
|
|
use app\common\enum\GoodsEnum;
|
|
use app\common\model\coach\Coach;
|
|
use app\common\model\coach\CoachGoodsIndex;
|
|
use app\common\model\goods\Goods;
|
|
use app\common\model\goods\GoodsSkillIndex;
|
|
|
|
class GoodsLists extends BaseCoachApiDataLists
|
|
{
|
|
public function setWhere(){
|
|
$where = [];
|
|
$where[] = ['status','=',1];
|
|
$id = $this->params['id'] ?? 0;
|
|
$isCoach = $this->params['is_coach'] ?? 0;
|
|
$where[] = ['audit_status','=',GoodsEnum::AUDIT_STATUS_PASS];
|
|
$shopId = Coach::where(['id'=>$this->coachId])->value('shop_id');
|
|
if($shopId){
|
|
$where[] = ['shop_id','in',[$shopId,0]];
|
|
}else{
|
|
$where[] = ['shop_id','=',0];
|
|
}
|
|
if($id){
|
|
$goodsIds = GoodsSkillIndex::where(['skill_id'=>$id])->column('goods_id');
|
|
empty($goodsIds) && $goodsIds = [];
|
|
$where[] = ['id','in',implode(',',$goodsIds)];
|
|
}
|
|
if($isCoach){
|
|
$goodsIds = CoachGoodsIndex::where(['coach_id'=>$this->coachId])->column('goods_id');
|
|
empty($goodsIds) && $goodsIds = [];
|
|
$where[] = ['id','in',implode(',',$goodsIds)];
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
$lists = Goods::where($this->setWhere())
|
|
->field('id,name,image,price')
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()->toArray();
|
|
return $lists;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return Goods::where(['status'=>1])
|
|
->where($this->setWhere())
|
|
->count();
|
|
}
|
|
} |