0, 'id' => $shopId ]; $shop = Shop::field('id,name,logo,background,type,score,star,intro,visited_num,cover,banner') ->where($where) ->append(['type_desc']) ->findOrEmpty(); if($shop->isEmpty()) { return []; }else{ $shop = $shop->toArray(); } // logo及背景图 $shop['logo'] = $shop['logo'] ? UrlServer::getFileUrl($shop['logo']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_LOGO); $shop['background'] = $shop['background'] ? UrlServer::getFileUrl($shop['background']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_BG); $shop['cover'] = $shop['cover'] ? UrlServer::getFileUrl($shop['cover']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_COVER); $shop['banner'] = UrlServer::getFileUrl(!empty($shop['banner']) ? $shop['banner'] : ShopEnum::DEFAULT_BANNER); // 在售商品 // 销售中商品:未删除/审核通过/已上架 $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(); // 店铺推荐商品 $onSaleWhere = [ ['del', '=', GoodsEnum::DEL_NORMAL], // 未删除 ['status', '=', GoodsEnum::STATUS_SHELVES], // 上架中 ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK], // 审核通过 ]; $set = null; $w = []; $settpye = 0; if($p_id != 0&&$set_id!=0){ $set = Procurementset::where("set_id",$set_id)->where("set_state",1)->find(); if($set['set_pro']!=0){ $w[] = ['purchase_price', '>', 0]; }else if($set['set_issued']!=0){ $w[] = ['issuing_price', '>', 0]; }else if($set['set_wholesale']!=0){ $w[] = ['wholesale_price', '>', 0]; } } if($p_id != 0&&$set_id==0){ $settpye = 1; $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find(); $w[] = ['purchase_price|issuing_price|wholesale_price', '>', 0]; } $shop['goods_list'] = Goods::field('id,image,name,min_price,market_price,purchase_price,issuing_price,wholesale_price') ->where($onSaleWhere) ->where($w) ->where([ 'shop_id' => $shop['id'], 'is_recommend' => 1, // 推荐商品 ]) ->limit(9) ->select() ->toArray(); $set_price_type = 0; if ($set != null&&$settpye!=1) { foreach ($shop['goods_list'] as $key => $value) { if($set['price_type']==1){ $set_price_type = 1; } if($set['price_type']==2){ $set_price_type = 2; } if($set['price_type']==3){ $set_price_type = 3; } if ($set['set_pro'] != 0) { // $set_price_type = 1; if ($set['set_pro_type'] == 1) { $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price'] * (100 + $set['set_pro']) / 100, 2); } if ($set['set_pro_type'] == 3) { $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price'] + $set['set_pro'], 2); } } if ($set['set_issued'] != 0) { // $set_price_type = 2; if ($set['set_issued_type'] == 1) { $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price'] * (100 + $set['set_issued']) / 100, 2); } if ($set['set_issued_type'] == 3) { $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price'] + $set['set_issued'], 2); } } if ($set['set_wholesale'] != 0) { // $set_price_type = 3; if ($set['set_wholesale_type'] == 1) { $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price'] * (100 + $set['set_wholesale']) / 100, 2); } if ($set['set_wholesale_type'] == 3) { $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price'] + $set['set_wholesale'], 2); } } } } $shop['set_price_type'] = $set_price_type; // 用户是否关注店铺 $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); return $shop; } /** * 店铺列表 */ public static function getShopList($get) { $where = [ ['is_freeze', '=', 0], // 未冻结 ['del', '=', 0], // 未删除 ['is_run', '=', 1], // 未暂停营业 ]; // 店铺名称 if(isset($get['name']) && !empty($get['name'])) { $where[] = ['name', 'like', '%'. trim($get['name']. '%')]; } // 主营类目 if(isset($get['shop_cate_id']) && !empty($get['shop_cate_id'])) { $where[] = ['cid', '=', $get['shop_cate_id']]; } $order = [ 'weight' => 'asc', 'score' => 'desc', 'id' => 'desc' ]; $set = null; $settpye = 0; if(isset($get['p_id'])){ $p_id = $get['p_id']; }else{ $p_id = 0; } if(isset($get['set'])){ $set_id = $get['set']; }else{ $set_id = 0; } $where1 = []; if($p_id != 0&&$set_id!=0){ $set = Procurementset::where("set_id",$set_id)->where("set_state",1)->find(); if($set != null){ if($set['set_pro']!=0){ $where1[] = ['purchase_price', '>', 0]; }else if($set['set_issued']!=0){ $where1[] = ['issuing_price', '>', 0]; }else if($set['set_wholesale']!=0){ $where1[] = ['wholesale_price', '>', 0]; } } } if($p_id != 0&&$set_id==0){ $settpye = 1; $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find(); if($set != null){ $where1[] = ['purchase_price|issuing_price|wholesale_price', '>', 0]; } } $set_price_type = 0; if($set != null){ if($set['price_type']==1){ $set_price_type = 1; } if($set['price_type']==2){ $set_price_type = 2; } if($set['price_type']==3){ $set_price_type = 3; } // if ($set['set_pro'] != 0) { // $set_price_type = 1; // } // if ($set['set_issued'] != 0) { // $set_price_type = 2; // } // if ($set['set_wholesale'] != 0) { // $set_price_type = 3; // } } $list = Shop::field('id,type,name,logo,background,visited_num,cover,banner') ->where($where) // 无限期 或 未到期 ->whereRaw('expire_time =0 OR expire_time > '. time()) ->order($order) ->page($get['page_no'], $get['page_size']) ->select() ->toArray(); $count = Shop::where($where) // 无限期 或 未到期 ->whereRaw('expire_time =0 OR expire_time > '. time()) ->count(); $onSaleWhere = [ ['del', '=', GoodsEnum::DEL_NORMAL], // 未删除 ['status', '=', GoodsEnum::STATUS_SHELVES], // 上架中 ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK], // 审核通过 ]; foreach($list as &$shop) { $shop['goods_list'] = Goods::field('id,image,name,min_price,market_price,purchase_price,issuing_price,wholesale_price') ->where($where1) ->where($onSaleWhere) ->where([ 'shop_id' => $shop['id'], ]) ->page(0, 5) ->select() ->toArray(); foreach($shop['goods_list'] as $key=>$value){ if($set != null&&$settpye!=1){ if($set['set_pro']!=0){ if($set['set_pro_type'] == 1){ $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price']*(100+$set['set_pro'])/100,2); } if($set['set_pro_type'] == 3){ if($value['purchase_price'] >0){ $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price']+$set['set_pro'],2); }else{ $shop['goods_list'][$key]['purchase_price'] = "0.00"; } } } if($set['set_issued']!=0){ if($set['set_issued_type'] == 1){ $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price']*(100+$set['set_issued'])/100,2); } if($set['set_issued_type'] == 3) { if ($value['issuing_price'] > 0) { $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price'] + $set['set_issued'], 2); }else{ $shop['goods_list'][$key]['issuing_price'] = "0.00"; } } } if($set['set_wholesale']!=0){ if($set['set_wholesale_type'] == 1){ $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price']*(100+$set['set_wholesale'])/100,2); } if($set['set_wholesale_type'] == 3) { if ($value['wholesale_price'] > 0) { $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price'] + $set['set_wholesale'], 2); }else{ $shop['goods_list'][$key]['wholesale_price'] = "0.00"; } } } } } $shop['on_sale_goods'] = count($shop['goods_list']); // logo及背景图 $shop['logo'] = $shop['logo'] ? UrlServer::getFileUrl($shop['logo']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_LOGO); $shop['background'] = $shop['background'] ? UrlServer::getFileUrl($shop['background']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_BG); $shop['cover'] = $shop['cover'] ? UrlServer::getFileUrl($shop['cover']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_COVER); $shop['banner'] = $shop['banner'] ? UrlServer::getFileUrl($shop['banner']) : ''; } $more = is_more($count, $get['page_no'], $get['page_size']); $data = [ 'list' => $list, 'set_price_type' => $set_price_type, 'count' => $count, 'more' => $more, 'page_no' => $get['page_no'], 'page_isze' => $get['page_size'] ]; return $data; } /** * @notes 附近店铺列表 * @param $get * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/9/20 4:29 下午 */ public static function getNearbyShops($get) { $where = [ ['is_freeze', '=', 0], // 未冻结 ['del', '=', 0], // 未删除 ['is_run', '=', 1], // 未暂停营业 ['city_id', '=', $get['city_id']], ]; // 店铺名称 if(isset($get['name']) && !empty($get['name'])) { $where[] = ['name', 'like', '%'. trim($get['name']. '%')]; } // 主营类目 if(isset($get['shop_cate_id']) && !empty($get['shop_cate_id'])) { $where[] = ['cid', '=', $get['shop_cate_id']]; } $city = DevRegion::where('id',$get['city_id'])->field('db09_lng,db09_lat')->findOrEmpty()->toArray(); $list = Shop::field('id,name,logo,background,visited_num,cover,banner,st_distance_sphere(point('.$city['db09_lng'].','.$city['db09_lat'].'),point(longitude, latitude)) as distance') ->where($where) // 无限期 或 未到期 ->whereRaw('expire_time =0 OR expire_time > '. time()) ->order('distance asc') ->page($get['page_no'], $get['page_size']) ->select() ->toArray(); $count = Shop::where($where) // 无限期 或 未到期 ->whereRaw('expire_time =0 OR expire_time > '. time()) ->count(); $onSaleWhere = [ ['del', '=', GoodsEnum::DEL_NORMAL], // 未删除 ['status', '=', GoodsEnum::STATUS_SHELVES], // 上架中 ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK], // 审核通过 ]; $set = null; $settpye = 0; if(isset($get['p_id'])){ $p_id = $get['p_id']; }else{ $p_id = 0; } if(isset($get['set'])){ $set_id = $get['set']; }else{ $set_id = 0; } $where1 = []; if($p_id != 0&&$set_id!=0){ $set = Procurementset::where("set_id",$set_id)->where("set_state",1)->find(); if($set != null){ if($set['set_pro']!=0){ $where1[] = ['purchase_price', '>', 0]; }else if($set['set_issued']!=0){ $where1[] = ['issuing_price', '>', 0]; }else if($set['set_wholesale']!=0){ $where1[] = ['wholesale_price', '>', 0]; } } } if($p_id != 0&&$set_id==0){ $settpye = 1; $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find(); if($set != null){ $where1[] = ['purchase_price|issuing_price|wholesale_price', '>', 0]; } } $set_price_type = 0; if($set != null){ if($set['price_type']==1){ $set_price_type = 1; } if($set['price_type']==2){ $set_price_type = 2; } if($set['price_type']==3){ $set_price_type = 3; } // if ($set['set_pro'] != 0) { // $set_price_type = 1; // } // if ($set['set_issued'] != 0) { // $set_price_type = 2; // } // if ($set['set_wholesale'] != 0) { // $set_price_type = 3; // } } foreach($list as &$shop) { $shop['goods_list'] = Goods::field('id,image,name,min_price,market_price,purchase_price,issuing_price,wholesale_price') ->where($where1) ->where($onSaleWhere) ->where([ 'shop_id' => $shop['id'], ]) ->select() ->toArray(); foreach($shop['goods_list'] as $key=>$value){ if($set != null&&$settpye!=1){ if($set['set_pro']!=0){ if($set['set_pro_type'] == 1){ $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price']*(100+$set['set_pro'])/100,2); } if($set['set_pro_type'] == 3){ if($value['purchase_price'] >0){ $shop['goods_list'][$key]['purchase_price'] = round($value['purchase_price']+$set['set_pro'],2); }else{ $shop['goods_list'][$key]['purchase_price'] = "0.00"; } } } if($set['set_issued']!=0){ if($set['set_issued_type'] == 1){ $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price']*(100+$set['set_issued'])/100,2); } if($set['set_issued_type'] == 3) { if ($value['issuing_price'] > 0) { $shop['goods_list'][$key]['issuing_price'] = round($value['issuing_price'] + $set['set_issued'], 2); }else{ $shop['goods_list'][$key]['issuing_price'] = "0.00"; } } } if($set['set_wholesale']!=0){ if($set['set_wholesale_type'] == 1){ $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price']*(100+$set['set_wholesale'])/100,2); } if($set['set_wholesale_type'] == 3) { if ($value['wholesale_price'] > 0) { $shop['goods_list'][$key]['wholesale_price'] = round($value['wholesale_price'] + $set['set_wholesale'], 2); }else{ $shop['goods_list'][$key]['wholesale_price'] = "0.00"; } } } } } $shop['on_sale_goods'] = count($shop['goods_list']); // logo及背景图 $shop['logo'] = $shop['logo'] ? UrlServer::getFileUrl($shop['logo']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_LOGO); $shop['background'] = $shop['background'] ? UrlServer::getFileUrl($shop['background']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_BG); $shop['cover'] = $shop['cover'] ? UrlServer::getFileUrl($shop['cover']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_COVER); $shop['banner'] = $shop['banner'] ? UrlServer::getFileUrl($shop['banner']) : ''; //转换距离单位 if ($shop['distance'] < 1000) { $shop['distance'] = round($shop['distance']).'m'; }else { $shop['distance'] = round($shop['distance'] / 1000,2).'km'; } } $more = is_more($count, $get['page_no'], $get['page_size']); $data = [ 'list' => $list, 'set_price_type'=>$set_price_type, 'count' => $count, 'more' => $more, 'page_no' => $get['page_no'], 'page_isze' => $get['page_size'] ]; return $data; } }