diff --git a/app/api/controller/Shop.php b/app/api/controller/Shop.php index ea64b2fc..9abdacaf 100644 --- a/app/api/controller/Shop.php +++ b/app/api/controller/Shop.php @@ -35,18 +35,29 @@ class Shop extends Api { if($this->request->isGet()) { $shopId = $this->request->get('shop_id', '', 'trim'); - $city_id = $this->request->get('city_id', 0); $validate = Validate::rule('shop_id', 'require|integer|gt:0'); if(!$validate->check(['shop_id'=>$shopId])) { return JsonServer::error($validate->getError()); } - $data = ShopLogic::getShopInfo($city_id,$shopId, $this->user_id, input()); + $data = ShopLogic::getShopInfo($shopId, $this->user_id, input()); + return JsonServer::success('获取店铺信息成功', $data); + }else{ + return JsonServer::error('请求类型错误'); + } + } + /** + * 店铺列表信息 + */ + public function getShopCityInfo() + { + if($this->request->isGet()) { + $city_id = $this->request->get('city_id', 0); + $data = ShopLogic::getShopCityInfo($city_id, $this->user_id, input()); return JsonServer::success('获取店铺信息成功', $data); }else{ return JsonServer::error('请求类型错误'); } } - /** * 店铺列表 */ diff --git a/app/api/logic/ShopLogic.php b/app/api/logic/ShopLogic.php index f6c11801..0b74e66b 100644 --- a/app/api/logic/ShopLogic.php +++ b/app/api/logic/ShopLogic.php @@ -120,6 +120,95 @@ class ShopLogic extends Logic return $shop; } + public static function getShopCityInfo($city_id,$userId, $params = []) + { + // 记录统计信息(访问商铺用户量) + Event::listen('ShopStat', 'app\common\listener\ShopStat'); + + $shop_msg = Shop::where("city_id",$city_id) + ->where("is_run",1) + ->where("is_freeze",0) + ->where("del",0) + ->find(); + $c = ""; + if($shop_msg == null){ + $c = "id = 1"; + }else{ + $c = "city_id = ".$city_id.""; + } + + $field = [ + 'id', 'create_time', 'name', 'logo', 'background', + 'type', 'score', 'star', 'intro', + 'visited_num', 'cover', 'banner', 'is_freeze', + 'is_run', 'expire_time', + 'province_id', 'city_id', 'district_id', 'address', + 'run_start_time', 'run_end_time', 'weekdays', + ]; + $shop = Shop::field($field) + ->where($c) + ->append([ 'type_desc', 'is_expire' ]) + ->find(); + // + $shop['logo'] = UrlServer::getFileUrl($shop['logo'] ? : ShopEnum::DEFAULT_LOGO); + $shop['background'] = UrlServer::getFileUrl($shop['background'] ? : ShopEnum::DEFAULT_BG); + $shop['cover'] = UrlServer::getFileUrl($shop['cover'] ? :ShopEnum::DEFAULT_COVER); + $shop['banner'] = UrlServer::getFileUrl($shop['banner'] ? : ShopEnum::DEFAULT_BANNER); + $shop['run_start_time'] = $shop['run_start_time'] ? date('H:i:s', $shop['run_start_time']) : ''; + $shop['run_end_time'] = $shop['run_end_time'] ? date('H:i:s', $shop['run_end_time']) : ''; + $shop['province'] = DevRegion::getAreaName($shop['province_id']); + $shop['city'] = DevRegion::getAreaName($shop['city_id']); + $shop['district'] = DevRegion::getAreaName($shop['district_id']); + + $shop['qr_code'] = (new QrCodeLogic)->shopQrCode($shop['id'], $params['terminal'] ?? ''); + + // 在售商品 + // 销售中商品:未删除/审核通过/已上架 + $onSaleWhere = [ + ['del', '=', GoodsEnum::DEL_NORMAL], // 未删除 + ['status', '=', GoodsEnum::STATUS_SHELVES], // 上架中 + ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK], // 审核通过 + ]; + $shop['on_sale_count'] = Goods::where($onSaleWhere)->where('shop_id', $shopId)->count(); + + // 店铺推荐商品 + $shop['goods_list'] = Goods::field('id,image,name,min_price,market_price') + ->where($onSaleWhere) + ->where([ + 'shop_id' => $shop['id'], + 'is_recommend' => 1, // 推荐商品 + ]) + ->limit(9) + ->select() + ->toArray(); + + // 用户是否关注店铺 + $shop['shop_follow_status'] = 0; + if($userId) { // 用户已登录 + $shopFollow = ShopFollow::where(['user_id'=>$userId, 'shop_id'=>$shopId])->findOrEmpty(); + if(!$shopFollow->isEmpty()) { + $shop['shop_follow_status'] = $shopFollow['status']; + } + } + $shop['follow_num'] = ShopFollow::where(['shop_id' => $shopId,'status' => 1])->count('id'); + $image = ConfigServer::get('shop_customer_service', 'image', '', $shopId); + $shop['customer_image'] = $image ? UrlServer::getFileUrl($image) : ''; + $shop['customer_wechat'] = ConfigServer::get('shop_customer_service', 'wechat', '', $shopId); + $shop['customer_phone'] = ConfigServer::get('shop_customer_service', 'phone', '', $shopId); + + // 店铺广告 + $adWhere = [ + [ 'shop_id', '=', $shopId ], + [ 'status', '=', 1 ], + ]; + $shop['ad'] = [ + 'pc' => ShopAd::where($adWhere)->where('terminal', ShopAdEnum::TERMINAL_PC)->append([ 'link_path', 'link_query' ])->order('sort desc,id desc')->select()->toArray(), + 'mobile' => ShopAd::where($adWhere)->where('terminal', ShopAdEnum::TERMINAL_MOBILE)->append([ 'link_path', 'link_query' ])->order('sort desc,id desc')->select()->toArray(), + ]; + + return $shop; + } + /** * 店铺列表 */