62 lines
2.0 KiB
PHP
Executable File
62 lines
2.0 KiB
PHP
Executable File
<?php
|
|
namespace app\coachapi\lists;
|
|
use app\common\enum\shop\ShopEnum;
|
|
use app\common\model\city\City;
|
|
use app\common\model\coach\Coach;
|
|
use app\common\model\goods\GoodsCategory;
|
|
use app\common\model\shop\Shop;
|
|
|
|
class ShopLists extends BaseCoachApiDataLists
|
|
{
|
|
|
|
public function setWhere()
|
|
{
|
|
$where[] = ['audit_status','=',ShopEnum::AUDIT_STATUS_PASS];
|
|
$where[] = ['server_status','=',ShopEnum::SERVERSTATUSOPEN];
|
|
if(isset($this->params['keyword']) && $this->params['keyword']){
|
|
$where[] = ['name|sn','like','%'.$this->params['keyword'].'%'];
|
|
}
|
|
else{
|
|
$coachInfo = Coach::where(['id'=>$this->coachId])->field('city_id')->findOrEmpty();
|
|
$where[] = ['city_id','=',$coachInfo['city_id']];
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
|
|
$shopLists = Shop::where($this->setWhere())
|
|
->field('id,logo,sn,name,synopsis,city_id')
|
|
->append(['category_ids'])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()->toArray();
|
|
$coach = Coach::where(['id'=>$this->coachId])->field('shop_id,city_id')->findOrEmpty();
|
|
$categoryLists = GoodsCategory::column('name','id');
|
|
foreach ($shopLists as $key => $shop){
|
|
$shopLists[$key]['category_name'] = '';
|
|
$isJoin = false;
|
|
if(0 == $coach['shop_id'] && $coach['city_id'] == $shop['city_id']){
|
|
$isJoin = true;
|
|
}
|
|
$shopLists[$key]['is_join'] = $isJoin;
|
|
$categoryIds = array_column($shop['category_ids']->toArray(),'id');
|
|
$categoryNameLists = [];
|
|
foreach ($categoryIds as $id){
|
|
$categoryNameLists[] = $categoryLists[$id] ??'';
|
|
}
|
|
|
|
$shopLists[$key]['category_name'] = implode(' ',$categoryNameLists);
|
|
|
|
|
|
}
|
|
return $shopLists;
|
|
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return Shop::where($this->setWhere())
|
|
->count();
|
|
}
|
|
} |