$this->mall_id]); if (Yii::$app->request->isGet) { // $params = Yii::$app->request->get(); // $time = time(); // $where = []; // $where[] = ['=', 'mall_id', $this->mall_id]; // $where[] = ['<=', 'start_at', $time]; // $where[] = ['>=', 'end_at', $time]; // $where[] = ['=', 'status', StatusEnum::ENABLED]; // $order = 'created_at desc'; // $select = "id,item_id,created_at"; // $limit = $params['limit'] ?? 20; // $with = ['goods' => function($query){ // $query->select("id,goods_name,price,cover_pic"); // }]; // $params = compact('where','order','select','with','limit'); // $list = Rebate::listPage($params, false, true); //获取全部商品 $all_goods_list = Rebate::getRebateAllGoodsId($this->mall_id); //用商品ID进行分页 $goods_ids = array_column($all_goods_list, 'item_id'); $goods_ids = array_unique($goods_ids); $limit = $params['limit'] ?? 20; $order = ''; if ($goods_ids) { // 生成 FIELD() 排序条件 $order = new \yii\db\Expression("FIELD(id, " . implode(',', $goods_ids) . ")"); } $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['in', 'id', $goods_ids]; $select = "id,goods_name,price,cover_pic"; $params = compact('where','select', 'order','limit'); $list = Goods::listPage($params, false, true); foreach ($list['list'] as &$item) { $item['goods'] = $item; } // 获取广告 $ad = AdLogic::getList($this->mall_id, AddonsEnum::ADDONS_NAME_REBATE); // 获取插件名称 $addons_name = $settingService->getSetting()['addons_name']; return $this->success('获取成功', compact('list','ad', 'addons_name')); } } /** * @Author: lun * @Date: 2022-01-01 * @Time: 17:42 * @Note:我的活动接口 * @return \yii\web\Response */ public function actionMyActivity() { if (Yii::$app->request->isGet) { $params = Yii::$app->request->get(); $user_id = $this->user_id; $now_time = time(); $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'user_id', $user_id]; $where[] = ['=', 'status', StatusEnum::ENABLED]; $order = 'created_at desc'; $select = "id,r_id,share_num,pay_num"; $limit = $params['limit'] ?? 20; $with = ['activity' => function($query){ $query->select("id,title,start_at,end_at,item_type,item_id,item_info,status,is_freeze_first_reward"); }]; $params = compact('where','order','select','with','limit'); $list = RebateRecommendNum::listPage($params, false, true); if($list) { foreach($list['list'] as $key => &$item) { $item['goods'] = Json::decode($item['activity']['item_info'], true); $item['recommend_num'] = RebateBuy::GetRecommendNumCount($this->mall_id, $this->user_id, $item['r_id'], $item['order_no']); // 判断是否已结束 $activity = $item['activity']; if($activity['status'] == 1 && $activity['end_at'] <= $now_time) $item['activity']['status'] = 2; } } return $this->success('获取成功', compact('list','now_time')); } } /** * @Author: lun * @Date: 2022-01-01 * @Time: 17:42 * @Note:邀请人数列表接口 * @return \yii\web\Response */ public function actionInviteNum() { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); // 验证 $res = Yii::$app->services->validate->validate($params, [ [['r_id'], 'required'], [['r_id'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $user_id = $this->user_id; $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'r_id', $params['r_id']]; $where[] = ['=', 'pid', $user_id]; $where[] = ['=', 'status', StatusEnum::ENABLED]; $order = 'created_at desc'; $select = "id,user_id,created_at"; $limit = $params['limit'] ?? 20; // 关联查询用户 $with = ['user' => function($query){ $query->select("id,nickname,avatar_url"); }]; $params = compact('where','order','select','with','limit'); $list = RebateShare::listPage($params, false, true); return $this->success('获取成功', $list); } } /** * @Author: lun * @Date: 2022-01-01 * @Time: 17:42 * @Note:推广下单数量列表接口 * @return \yii\web\Response */ public function actionPayNum() { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); // 验证 $res = Yii::$app->services->validate->validate($params, [ [['r_id'], 'required'], [['r_id'], 'integer'], [['type'], 'string'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $user_id = $this->user_id; $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'r_id', $params['r_id']]; $where[] = ['=', 'pid', $user_id]; $where[] = ['=', 'status', StatusEnum::ENABLED]; $order = 'created_at desc'; $select = "id,user_id,order_no,pay_at,pay_money,goods_info,order_settlement_status,refund_id"; $limit = $params['limit'] ?? 20; if (!empty($params['type'])) { switch ($params['type']) { case self::SEARCH_TYPE_ACHIEVED: $order = sprintf('settlement_at desc, %s', $order); $where[] = ['=', 'order_settlement_status', StatusEnum::ENABLED]; break; case self::SEARCH_TYPE_UNACHIEVED: $where[] = ['=', 'order_settlement_status', StatusEnum::DISABLED]; $where[] = ['=', 'refund_id', StatusEnum::DISABLED]; break; case self::SEARCH_TYPE_EXPIRED: $order = sprintf('refund_at desc, %s', $order); $where[] = ['=', 'order_settlement_status', StatusEnum::DISABLED]; $where[] = ['>', 'refund_id', StatusEnum::DISABLED]; break; default: break; } } // 关联查询用户 $with = ['user' => function($query){ $query->select("id,nickname,avatar_url"); }]; $params = compact('where','order','select','with','limit'); $list = RebateBuy::listPage($params, false, true); $orderNoArr = array_column($list['list'], 'order_no'); $orderList = Order::find()->where(['order_no' => $orderNoArr])->select('id,order_no,order_status')->asArray()->indexBy('order_no')->all(); if($list['list']) { foreach ($list['list'] as $key => $item) { $list['list'][$key]['goods_info'] = Json::decode($item['goods_info'], true); // 兼容虚拟订单问题,虚拟订单状态当作已完成 $list['list'][$key]['order'] = $orderList[$item['order_no']] ?? ['id' => 0, 'order_no' => $item['order_no'], 'order_status' => OrderStatusEnum::ACCOMPLISH]; } } return $this->success('获取成功', $list); } } public function actionGetTabOption() { $rid = $this->request->get('rid', 0); if ($rid && is_numeric($rid)) { $select = "COUNT(*) AS order_total," . "COUNT(IF(order_settlement_status = 1, 1, NULL)) AS achieved_total," . "COUNT(IF(order_settlement_status = 0 AND refund_id = 0, 1, NULL)) AS unachieved_total," . "COUNT(IF(order_settlement_status = 0 AND refund_id > 0, 1, NULL)) AS expired_total"; $params = [ 'select' => new Expression($select), 'where' => [ [ 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'r_id' => $rid, 'pid' => $this->user_id ] ] ]; $find = RebateBuy::find(); RebateBuy::paramPack($params, $find); $statistics = $find->asArray()->one(); } $this->success('success', [ [ 'name' => sprintf('全部(%d)', $statistics['order_total'] ?? 0), 'search_type' => self::SEARCH_TYPE_ALL, ], [ 'name' => sprintf('已达标(%d)', $statistics['achieved_total'] ?? 0), 'search_type' => self::SEARCH_TYPE_ACHIEVED, ], [ 'name' => sprintf('未达标(%d)', $statistics['unachieved_total'] ?? 0), 'search_type' => self::SEARCH_TYPE_UNACHIEVED, ], [ 'name' => sprintf('已失效(%d)', $statistics['expired_total'] ?? 0), 'search_type' => self::SEARCH_TYPE_EXPIRED, ], ]); } /** * 商品详情 * @Author: lun * @DateTime: 2022/1/18 0018 19:20 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionDetail() { $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['goods_id','pid'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 判断是否是分享 $parent_id = $this->user['parent_id'] ?? 0; $headers = Yii::$app->request->headers; if (!empty($params['pid']) && $parent_id == $headers['x-parent-id']) { // 判断是否符合分享条件,并保存数据 RebateShare::checkShare($this->mall_id, $params['goods_id'], $this->user_id, $parent_id); } // 根据商品id获取商品详情信息 $goods = GoodsLogic::GetDetail($this->mall_id, $params, $this->user); if ($goods == false) return $this->error("获取失败," . GoodsLogic::getStaticError()); // 智能表单 $smart_form_template = GlobalInvoke::exec(GlobalInvoke::GOODS_NEED_SMARTFORM, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'goods_id' => $params['goods_id']]); if (!empty($smart_form_template)) $goods = array_merge($goods, $smart_form_template); // 商品详情公共调用 $invoke_data = GlobalInvoke::exec(GlobalInvoke::API_GOODS_DETAIL, $this->mall_id, ['mall_id' => $this->mall_id, 'goods' => $goods, 'user' => $this->user]); if (!empty($invoke_data['goods'])) $goods = $invoke_data['goods']; return $this->success('获取成功', $goods); } /** * 活动规则接口 * * @return void */ public function actionExplain() { $settingService = new SettingService(['mall_id' => $this->mall_id]); if (Yii::$app->request->isGet) { $explain = $settingService->getSetting()['explain']; return $this->success('获取成功', $explain); } } /** * 奖励明细列表 * * @return void */ public function actionRewardLog() { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['r_id'], 'required'], [['r_id'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $user_id = $this->user_id; $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'r_id', $params['r_id']]; $where[] = ['=', 'user_id', $user_id]; $where[] = ['=', 'status', StatusEnum::ENABLED]; $order = 'created_at desc'; $select = "reward_title,content,created_at,is_frozen"; $limit = $params['limit'] ?? 20; $params = compact('where','order','select','limit'); $list = RebateRewardLog::listPage($params, false, true); return $this->success('获取成功', $list); } } }