store_id; $cat_id = $this->cat_id; $goods_name = $this->goods_name; $goods_id = $this->goods_id; $time = time(); $where = ['p.is_delete' => 0, 's.is_delete' => 0]; if ($store_id <= 0) { $where = array_merge($where, ['p.is_platform' => 1]); } else { $where = array_merge($where, ['p.store_id' => $store_id, 'p.is_platform' => 0]); } $query = PtActivity::find()->alias('p')->where($where) ->leftJoin(['s' => Store::tableName()], 's.id = p.store_id') ->andWhere(['AND', ['<', 'p.start_time', $time], ['>', 'p.end_time', $time]])->select('p.id'); //只有平台运营的商城或者单店铺的无独立小程序才展示商盟的营销活动 if (\Yii::$app->prod_is_dandianpu()) { $store_id = Option::find()->where(['group' => 'store', 'name' => 'self_mini'])->select('store_id')->column(); $query->andWhere(['NOT IN', 's.store_id', $store_id]); } else { $query->andWhere(['s.business_model' => [1, 2]]); } $pt_activity_id = $query->column(); if (!empty($pt_activity_id)) { $query = PtActivityGoods::find()->alias('pag')->where(['pag.is_delete' => 0, 'g.status' => 1, 'g.is_delete' => 0]) ->andWhere(['pag.activity_id' => $pt_activity_id]) ->leftJoin(['g' => Goods::tableName()], 'pag.goods_id = g.id') ->select('g.id, g.name, g.cover_pic, g.price, pag.pt_price, pag.use_attr, pag.sale_num, pag.virtual_sales, pag.activity_id, pag.cat_id, pag.attr, g.store_id'); if ($cat_id && (int)$cat_id !== -1) { $query->andWhere(['pag.cat_id' => $cat_id]); } if ($goods_name) { $query->andWhere(['LIKE', 'g.name', $goods_name]); } if ($goods_id) { if(is_string($goods_id)){ $goods_id = explode(',', $goods_id); } $query->andWhere(['g.id' => $goods_id]); } $query->orderBy('pag.created_at desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $attr = json_decode($item['attr'], true); $attr = array_column($attr, 'pt_price'); $attr = array_filter($attr); $attr = array_merge($attr, [$item['price']]); $item['pt_price'] = sprintf('%.2f', min($attr)); $item['sale_num'] += $item['virtual_sales']; $pt_activity = PtActivity::findOne($item['activity_id']); $item['party_size'] = $pt_activity->party_size ?? 0; $item['party_type'] = $pt_activity->party_type ?? 0; $item['party_goods_count'] = $pt_activity->party_goods_count ?? 0; $diff_price = sprintf('%.2f', ($item['price'] - $item['pt_price'])); if (strpos($diff_price, '.00') !== false) { $diff_price = str_replace('.00', '', $diff_price); } $item['diff_price'] = $diff_price; } } return [ 'code' => 0, 'msg' => '', 'data' => [ 'list' => $list['list'] ?? [], 'pageNo' => $list['pageNo'] ?? 0, 'totalCount' => $list['totalCount'] ?? 0 ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getBanner() { try { $store_id = $this->store_id; $banner_list = PtActivityBanner::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'status' => 1]) ->orderBy('sort asc')->select('name, url, cover_pic')->asArray()->all(); foreach ($banner_list as &$item) { $item['url'] = !empty($item['url']) ? json_decode($item['url'], true) : [ 'name' => '', 'link' => '', 'open_type' => '' ]; } return [ 'code' => 0, 'msg' => "获取成功", 'data' => [ 'list' => $banner_list ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getPtGoodsCat() { try { $store_id = $this->store_id; $goods_cat_list = PtActivityGoodsCat::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'status' => 1]) ->orderBy('created_at desc')->select('id, name')->asArray()->all(); $goods_cat_list = array_values(array_merge([ [ 'id' => '-1', 'name' => '全部' ], ], $goods_cat_list)); return [ 'code' => 0, 'msg' => "获取成功", 'data' => [ 'list' => $goods_cat_list ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取拼团广场数据 public function getPtSquare() { try { //开团人员 $query = PtActivityOrderDetail::find()->alias('pod')->where(['p.is_platform' => 1, 'p.is_platform_audit' => 1]) ->leftJoin(['po' => PtActivityOrder::tableName()], 'pod.order_id = po.id') ->leftJoin(['p' => PtActivity::tableName()], 'pod.activity_id = p.id') ->andWhere(['po.pt_number' => 0, 'po.is_pay' => 1, 'po.is_pt_finish' => 0]) ->select('po.id, pod.goods_id, pod.goods_name, pod.pic, pod.total_price pt_price, po.pay_time, pod.activity_id, po.user_id') ->andWhere(['po.pt_number' => 0]); $query->orderBy('num desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $pt_activity = PtActivity::findOne($item['activity_id']); $item['end_time'] = 0; if (($item['pay_time'] + ($pt_activity->split_time * 60 * 60)) > time()) { $item['end_time'] = ($item['pay_time'] + ($pt_activity->split_time * 60 * 60)) - time(); } $saas_user = SaasUser::findOne(get_saas_user_id()); $item['avatar'] = $saas_user->avatar; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list['list'] ?? [], 'pageNo' => $list['pageNo'] ?? 0, 'totalCount' => $list['totalCount'] ?? 0 ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }