初始版本
This commit is contained in:
62
server/app/coachapi/lists/ShopLists.php
Executable file
62
server/app/coachapi/lists/ShopLists.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user