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); } /** * 获取甄选好店列表(web端) * @return array * @throws DbException */ public function getSelectShopLists() { $config = (new CoreWebConfigService())->getWebConfig(); $site_ids = $config['site_ids'] ?? []; $field = 'site_id,site_name,front_end_name,front_end_logo,icon'; $condition = [ [ 'app_type', '<>', 'admin' ], [ 'status', '=', 1 ], [ 'site_id', 'in', $site_ids ] ]; $list = []; if ($config['is_show_shop']) { $list = $this->model->where($condition)->with( [ 'shop' => function($query) { $query->field('site_id,is_self'); }])->field($field)->order('create_time desc')->select()->toArray(); foreach ($list as &$v) { $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 2 ])))[0] ?? []; $v['goods_list'] = $goods_list; } } return [ 'list' => $list, 'config' => $config ]; } /** * 获取站点列表(wap端) * @param array $where * @return array * @throws DbException */ public function getShopPage(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'); $res = $this->pageQuery($search_model); foreach ($res['data'] as &$v) { $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 3 ])))[0] ?? []; $v['goods'] = $goods_list; } return $res; } /** * 获取站点列表 * @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', 'business_license'] ])->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'); } } /** * 获取商品列表供组件调用 * @param array $where * @return array */ public function getShopComponents(array $where = []) { $field = 'site_id,site_name,front_end_logo,front_end_name,icon'; $condition = [ [ 'app_type', '<>', 'admin' ], [ 'status', '=', SiteDict::ON ] ]; if (!empty($where[ 'site_ids' ])) { $condition[] = [ 'shop_site.site_id', 'in', $where[ 'site_ids' ] ]; } // 参数过滤 if (!empty($where[ 'order' ]) && in_array($where[ 'order' ], [ 'follow_number' ])) { $order = $where[ 'order' ] . ' desc'; } else { $order = 'follow_number desc,create_time desc'; } $list = $this->model ->where($condition)->withSearch([ 'category_id' ], $where) ->field($field) ->withJoin([ 'shop' => function($query) { $query->field('category_id')->with(['categoryName']); } ]) ->order($order) ->limit($where[ 'num' ]) ->select()->toArray(); foreach ($list as $k => &$v) { $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 3 ])))[0] ?? []; $v[ 'goods_list' ] = $goods_list; if (empty($goods_list)) unset($list[$k]); } return $list; } /** * 获取店铺二维码 */ public function getQrcode(int $site_id){ $url = ( new CoreSysConfigService() )->getSceneDomain($site_id)[ 'wap_url' ]; $page = 'app/pages/site/index'; $data = [ [ 'key' => 'sid', 'value' => $site_id ] ]; $dir = 'upload/qrcode/' . $site_id . '/shop'; $channel = 'weapp'; return qrcode($url, $page, $data, $site_id, $dir, $channel); } }