model = new ShopSite(); } /** * 获取站点列表 * @param array $where * @return array * @throws DbException */ public function getPage(array $where = []) { $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id, district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id'; $condition = [ [ 'app_type', '<>', 'admin' ], [ 'status', '=', 1 ] ]; $search_model = $this->model->where($condition)->withSearch(['keyword', 'group_id', 'category_id', 'is_self' ], $where) ->withJoin( [ 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName']) ->field($field)->order('create_time desc'); return $this->pageQuery($search_model); } /** * 获取站点列表 * @param array $where * @return array * @throws DbException */ public function getAll(int $limit = 0) { $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id, district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id'; $condition = [ [ 'app_type', '<>', 'admin' ], [ 'status', '=', 1 ] ]; $search_model = $this->model->where($condition)->withJoin( [ 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName']) ->field($field)->order('create_time desc')->limit($limit); return $search_model->select()->toArray(); } /** * 站点信息 * @param int $site_id * @return array */ public function getInfo(int $site_id) { $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id, district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id'; $condition = [ [ 'shop_site.site_id', '=', $site_id ] ]; $modelResult = $this->model->where($condition) ->withJoin( [ 'shop'=> ['site_id', 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName']) ->field($field)->findOrEmpty()->toArray(); if (!empty($this->member_id)) { $member_info = (new ShopMember())->field('is_follow')->where([['member_id', '=', $this->member_id], ['site_id', '=', $site_id]])->findOrEmpty()->toArray(); $modelResult['member_info'] = $member_info ? ['is_follow' => $member_info['is_follow']] : ['is_follow' => 0]; } else { $modelResult['member_info'] = ['is_follow' => 0]; } return $modelResult; } /** * 更新店铺关注数 * @param int $site_id * @param int $is_follow * @return void */ public function editFollowNumber(int $site_id, int $is_follow) { $shop_model = new Shop(); if ($is_follow == 1) { $shop_model->where(['site_id' => $site_id])->setInc('follow_number'); } else if ($is_follow == 0) { $shop_model->where(['site_id' => $site_id])->setDec('follow_number'); } } }