params['keyword']) && $this->params['keyword']){ $where[] = ['name','like','%'.$this->params['keyword'].'%']; } if(isset($this->params['category_id']) && $this->params['category_id']){ $shopIds = ShopCategoryIndex::where(['category_id'=>$this->params['category_id']])->column('shop_id'); empty($shopIds) && $shopIds = []; $where[] = ['id','in',$shopIds]; } if(isset($this->params['city_id']) && $this->params['city_id']){ $where[] = ['city_id','=',$this->params['city_id']]; } $where[] = ['audit_status','=',ShopEnum::AUDIT_STATUS_PASS]; $where[] = ['server_status','=',ShopEnum::SERVERSTATUSOPEN]; return $where; } /** * @notes 广告列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/3/25 9:54 上午 */ public function lists(): array { $field = 'id,name,good_comment,logo,work_status,0 as distance'; if (!empty($params['longitude']) && !empty($params['latitude'])) { $field = 'id,name,good_comment,logo,work_status,round(st_distance_sphere(point('.$this->params['longitude'].','.$this->params['latitude'].'),point(longitude, latitude))/1000,2) as distance'; } $lists = Shop::where($this->where()) ->append(['distance_desc','categoryIds','work_status_desc']) ->order('distance asc') ->field($field) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); $categoryLists = GoodsCategory::where(['is_show'=>1])->column('name','id'); $consumptionLists = Order::where(['pay_status'=>PayEnum::ISPAID]) ->where('shop_id','>',0) ->group('shop_id') ->column('round(sum(order_amount)/count(id),2) as consumption,shop_id'); $consumptionLists = array_column($consumptionLists,null,'shop_id'); foreach ($lists as $key => $shop) { $categoryNameLists = []; foreach ($shop['categoryIds'] as $category){ $categoryNameLists[] = $categoryLists[$category['category_id']] ?? ''; } $lists[$key]['consumption'] = $consumptionLists[$shop['id']]['consumption'] ?? 0; $lists[$key]['category_name'] = $categoryNameLists; } return $lists; } /** * @notes 广告数量 * @return int * @author ljj * @date 2022/3/25 9:55 上午 */ public function count(): int { return Shop::where($this->where()) ->count(); } }