request->get(); $mch_id = $params['mch_id']; if (empty($mch_id)) return $this->error('参数错误'); $mall_id = $this->mall_id; $store = Mch::getOne([['id' => $mch_id], ['mall_id' => $mall_id]]); if (empty($store)) return $this->error('店铺打烊了'); $data['store_status'] =$store['shop_status']==1?'正在营业': '休息中'; $data['mch_id'] = $store['id']; $data['logo_img'] = $store['logo_img']; $data['store_name'] = $store['store_name']; $data['store_background'] = $store['store_background']; $data['store_style'] = $store['store_style']; $data['sales_volume'] = $store['sales_volume']; $data['praise'] = $store['praise'];//好评 $intra_city_distribution = json_decode($store['intra_city_distribution'], true); $data['distribution_fee'] = $intra_city_distribution['distribution_fee'] ?? 0;//配送费 $comment_where = [['mch_id' => $mch_id], ['mall_id' => $mall_id], ['status' => StatusEnum::ENABLED]]; $order_comment_count = OrderComments::listCount(['where' => $comment_where,]); $data['order_comment_count'] = $order_comment_count??0;//评论条数 $goods_cate_list = GoodsCate::lists([ 'where' => [ ['mall_id' => $mall_id], ['status' => StatusEnum::ENABLED], ['is_show' => 1], ], 'select' => 'id,name' ]); $data['goods_cate_list'] = $goods_cate_list; return $this->success('成功', $data); } //商户列表 public function actionStoreList() { $params = Yii::$app->request->get(); $sort = $params['sort'] ?? ''; $mall_id = $this->mall_id; $status = StatusEnum::ENABLED; $shop_status = 1; $check_status = 1; $where[] = ['mall_id' => $mall_id]; $where[] = ['status' => $status]; $where[] = ['shop_status' => $shop_status]; $where[] = ['check_status' => $check_status]; if (!empty($params['keyword'])) $where[] = ['like', 'store_name', trim($params['keyword']) . '%', false]; if (!empty($params['cate_id'])) $where[] = ['c_id' => $params['cate_id']]; if (in_array($sort, ['sales_volume', 'praise'])) $params['order'] = "{$sort} desc"; $params['where'] = $where; $list_page = Mch::listPage($params); return $this->success('成功', $list_page); } public function actionStoreCate() { $list = GoodsCate::lists(['where' => ['mall_id' => $this->mall_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED], 'select' => 'id,parent_id,name']); $list = GoodsCate::getTreeCate($list, 0); return $this->success('ok', compact('list')); } public function actionCate() { $params = \Yii::$app->request->get(); $cate_id = empty($params['cate_id']) ? 0 : $params['cate_id']; $params['where'] = [['mall_id' => $this->mall_id, 'parent_id' => $cate_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED]]; $params['select'] = 'id,name,pic,advert_pic,advert_url'; $params['order'] = 'sort desc'; $cate_list = MchCate::listPage($params); if (false === $cate_list) { return $this->error(MchCate::getStaticError()); } if (!empty($cate_list['list'])) { foreach ($cate_list['list'] as &$lv) { if (!empty($lv['advert_pic'])) { $lv['advert_pic'] = json_decode($lv['advert_pic'], true); if(!empty($lv['advert_pic'])){ $temp = []; foreach ($lv['advert_pic'] as $value){ $temp[] = ['pic_url'=>$value]; } $lv['advert_pic'] = $temp; } } if (!empty($lv['advert_url'])) { $lv['advert_url'] = json_decode($lv['advert_url'], true); } } } $cate = MchCate::find() ->select('id,name,pic,advert_pic,advert_url') ->where(['mall_id' => $this->mall_id, 'id' => $cate_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED]) ->asArray() ->one(); if (!empty($cate['advert_pic'])) { $cate['advert_pic'] = json_decode($cate['advert_pic'], true); if(!empty( $cate['advert_pic'] )){ $temp = []; foreach ($cate['advert_pic'] as $value){ $temp[] = ['pic_url'=>$value]; } $cate['advert_pic'] = $temp; } } if (!empty($cate['advert_url'])) { $cate['pic_url'] = json_decode($cate['advert_url'], true); } $cate_list['cate_info'] = $cate; return $this->success('操作成功', $cate_list); } /** * @name: * @msg: 添加门店聚合页--为你优选商品列表接口 * @return {*} */ public function actionOptimizationGoodsList() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $longitude = \Yii::$app->request->get('longitude'); $latitude = \Yii::$app->request->get('latitude'); if (empty($longitude) || empty($latitude)) { return $this->error('参数错误'); } $wheres = ['mall_id' => $this->mall_id, 'addons_name' => StoreEnum::ADDONS_NAME, 'status' => StatusEnum::ENABLED]; $res = AddonsMarketingSetting::findOne($wheres); if ($res == false) return $this->success('success', []); $data = $res->toArray(); $content = json_decode($data['content'], true); // dd($content); if (empty($content[4]['data']['goods'])) { return $this->success('success', []); } $good_ids = []; foreach ($content[4]['data']['goods'] as $good) { $good_ids[] = $good['params']['id'] ?? 0; } $good_ids = array_unique($good_ids); $goods = Goods::find() ->alias('sg') ->select('sg.*') ->join('INNER JOIN', Mch::tableName() . ' as s', 'sg.mch_id = s.id') ->with(['attr']) ->where(['sg.mall_id' => $this->mall_id, 'sg.status' => StatusEnum::ENABLED, 'sg.id' => $good_ids, 'sg.check_status' => StoreEnum::CHECK_ADOPT, 'sg.is_on_sale' => 1, 's.status' => StatusEnum::ENABLED, 's.check_status' => StoreEnum::CHECK_ADOPT]) ->andWhere(['or', ['>', 'expire_time', time()], ['expire_time' => 0]]) ->asArray() ->all(); if (!empty($goods)) { $mch_ids = array_column($goods, 'mch_id'); $comment_scores = OrderComments::find() ->select('goods_id,score') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'mch_id' => $mch_ids, 'goods_id' => $good_ids]) ->asArray() ->all(); // dd($comment_scores); $good_comment_rate_map = []; if (!empty($comment_scores)) { foreach ($comment_scores as $val) { if (empty($scores[$val['goods_id']])) { $scores[$val['goods_id']] = [ 'all' => 0, 'good_comment' => 0, ]; } $scores[$val['goods_id']]['all'] += 1; if ($val['score'] >= 4) { $scores[$val['goods_id']]['good_comment'] += 1; } } foreach ($scores as $goods_id => $score) { if ($score['all'] > 0) { $good_comment_rate_map[$goods_id] = bcdiv($score['good_comment'], $score['all'], 2); } else { $good_comment_rate_map[$goods_id] = 0; } } } foreach ($goods as $gk => &$good) { $good['good_comment_rate'] = ($good_comment_rate_map[$good['id']] ?? 0) * 100; } } return $this->success('success', $goods); } public function actionOptimizationStoresList() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $wheres = ['mall_id' => $this->mall_id, 'addons_name' => AddonsEnum::ADDONS_NAME_MCH, 'status' => StatusEnum::ENABLED]; $res = AddonsMarketingSetting::findOne($wheres); if ($res == false) return $this->success('success', []); $data = $res->toArray(); $content = json_decode($data['content'], true); if (empty($content[3]['data']['goods'])) { return $this->success('success', []); } $mch_ids = []; foreach ($content[3]['data']['goods'] as $good) { $mch_ids[] = $good['params']['id'] ?? 0; } $mch_ids = array_unique($mch_ids); $mch_list = Mch::find() ->select('id,store_name,logo_img,praise') ->where( ['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED, 'check_status' => StoreEnum::CHECK_ADOPT, 'id' => $mch_ids]) ->andWhere(['or', ['>', 'expire_time', time()], ['expire_time' => 0]]) ->asArray() ->all(); if (!empty($mch_list)) { $good_sales = Goods::find() ->select('mch_id,sum(sales_num) as sales_num,sum(virtual_sales) as virtual_sales') ->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED, 'check_status' => StoreEnum::CHECK_ADOPT, 'mch_id' => $mch_ids]) ->groupBy('mch_id') ->asArray() ->indexBy('mch_id') ->all(); foreach ($mch_list as &$mch) { $sales = $good_sales[$mch['id']] ?? []; $mch['sales_volume'] = $sales['sales_num'] + $sales['virtual_sales']; } } return $this->success('success', $mch_list); } //开屏优惠券列表 public function actionOpenScreenCouponList() { $where[] = ['mall_id' => $this->mall_id]; $where[] = ['coupon_status' => 2]; $where[] = ['is_open_screen' => 1]; $where[] = ['status' => StatusEnum::ENABLED]; $where[] = ['<>', 'mch_id', 0]; $params['order'] = 'id desc'; $params['where'] = $where; $params['select'] = 'id,mch_id,name as coupon_name,discount,discount_limit,min_price,sub_price,type,mall_id,store_id,expire_type,expire_day,begin_at,end_at'; $platform_coupon_list = AddonsCoupon::lists($params); $params['select'] = 'id,name as coupon_name,discount,discount_limit,min_price,sub_price,type,mall_id,store_id,expire_type, expire_day,begin_at,end_at,first_frame,video_url,watch_times'; $platform_coupon_list = $this->formatCouponList($platform_coupon_list, 1); $store_coupon_list = [];//预留 $list = array_merge($platform_coupon_list, $store_coupon_list); return $this->success('success', $list); } protected function formatCouponList($coupon_list, $from_type) { $coupon_ids = array_column($coupon_list, 'id'); $relate_list = AddonsCouponUserRelate::lists([ 'where' => [ ['coupon_id' => $coupon_ids], ['user_id' => $this->user_id] ], 'index' => 'coupon_id' ]); foreach ($coupon_list as &$item) { $item['coupon_id'] = $item['id']; $item['from_type'] = $from_type; $item['from_type_text'] = $from_type == 1 ? '平台券' : '商户券'; $item['is_receive'] = $item['is_use'] = $item['user_coupon_id'] = 0; if (isset($relate_list[$item['id']])) { $item['is_receive'] = 1; $item['is_use'] = $relate_list[$item['id']]['is_use']; $item['user_coupon_id'] = $relate_list[$item['id']]['id']; } } return $coupon_list; } }