49 lines
1.5 KiB
PHP
Executable File
49 lines
1.5 KiB
PHP
Executable File
<?php
|
|
namespace app\shopapi\lists;
|
|
use app\coachapi\lists\BaseCoachApiDataLists;
|
|
use app\common\enum\GoodsEnum;
|
|
use app\common\model\goods\Goods;
|
|
use app\common\model\goods\GoodsCategory;
|
|
|
|
/**
|
|
* 服务列表
|
|
* Class GoodsLists
|
|
* @package app\shopapi\lists
|
|
*/
|
|
class GoodsLists extends BaseShopApiDataLists
|
|
{
|
|
public function setWhere()
|
|
{
|
|
$where = [];
|
|
$where[] = ['status','=',1];
|
|
$where[] = ['audit_status','=',GoodsEnum::AUDIT_STATUS_PASS];
|
|
$where[] = ['shop_id','=',0];
|
|
|
|
if(isset($this->params['category_id']) && $this->params['category_id']){
|
|
if(is_array(explode(',',$this->params['category_id']))) {
|
|
$categoryIds = explode(',',$this->params['category_id']);
|
|
}else{
|
|
$categoryIds[] = $this->params['category_id'];
|
|
}
|
|
$categoryId = GoodsCategory::where(['pid'=>$categoryIds])->column('id');
|
|
$categoryIds = array_merge($categoryId,$categoryIds);
|
|
$where[] = ['category_id','in',$categoryIds];
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
$lists = Goods::where($this->setWhere())
|
|
->field('id,name,image,status,price,audit_status,virtual_order_num+order_num as order_num')
|
|
->append(['audit_status_desc','status_desc'])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()->toArray();
|
|
return $lists;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return Goods::where($this->setWhere())->count();
|
|
}
|
|
} |