request->isAjax) { return $this->render($this->action->id); } try { $params = \Yii::$app->request->get(); $rules = [ [['title', 'start_time', 'end_time'], 'string'], [['venue_user_id', 'merchants_user_id', 'page', 'pagesize'], 'integer'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $service = new ActivityService(); return $this->success('操作成功', $service->page($this->mall_id, $params, $this->mall)); } catch (\Exception $e) { return $this->success($e->getMessage()); } } public function actionEdit() { if (!\Yii::$app->request->isAjax) { return $this->render($this->action->id); } try { if (\Yii::$app->request->isGet) { $params = \Yii::$app->request->get(); $id = $params['id']; $service = new ActivityService(); return $this->success('成功', $service->detail($this->mall_id, $id)); } if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $rules = [ [['name', 'start_at', 'end_at'], 'string'], [['id', 'commission_type', 'is_alone_commission'], 'integer'], [['goods_info', 'merchants', 'venue'], 'safe'] ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $service = new ActivityService(); $params['mall_id'] = $this->mall_id; if (empty($params['venue'])) throw new Exception("场地负责人不能为空"); if (empty($params['merchants'])) throw new Exception("招商负责人不能为空"); if (!$service->write($params)) throw new Exception($service->getError()); return $this->success('保存成功'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionGoodsSearch() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { //商品列表筛选 $get = Yii::$app->request->get(); $rules = [ [['keyword'], 'string'], [['activity_id'], 'integer'] ]; $res = Yii::$app->services->validate->validate($get, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'is_on_sale' => 1, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; // 筛选 $where[] = ['!=', 'goods_name', '代客下单插件商品']; isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]]; $service = new ActivityService(); $goods_ids = $service->getGoodsIds(['mall_id' => $this->mall_id, 'activity_id' => $get['activity_id']]); if ($goods_ids) $where[] = ['NOT IN', 'id', $goods_ids]; $sort = !empty($sort) ? $sort . ',sort ASC,id DESC' : 'sort ASC,id DESC'; $params = ['where' => $where, 'with' => ['attr'], 'limit' => 10, 'order' => $sort, 'group' => 'id']; $page_data = Goods::listPage($params, false, true); if ($page_data === false) return $this->error(Goods::getStaticError()); return $this->success('操作成功', $page_data); } } } public function actionSwitch() { try { if (!\Yii::$app->request->isPost) throw new Exception('不支持该请求方式'); $params = \Yii::$app->request->post(); $rules = [ [['id', 'status'], 'integer'], [['id', 'status'], 'required'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $service = new ActivityService(); if (!$service->switch($this->mall_id, $params['id'], $params['status'])) throw new Exception($service->getError()); return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionDel() { try { if (!\Yii::$app->request->isPost) throw new Exception('不支持该请求方式'); $params = \Yii::$app->request->post(); $rules = [ [['id'], 'integer'], [['id'], 'required'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $service = new ActivityService(); if (!$service->del($this->mall_id, $params['id'])) throw new Exception($service->getError()); return $this->success('删除成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionSigninList() { try { $params = \Yii::$app->request->get(); $rules = [ [['activity_id', 'page', 'user_id', 'limit'], 'integer'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $service = new ActivityService(); $params['mall_id'] = $this->mall_id; $list = $service->getSigninList($params); return $this->success('请求成功', $list); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 获取海报二维码 * @return mixed|null */ public function actionPosterQrcode() { try { $params = \Yii::$app->request->get(); $rules = [ [['id'], 'integer'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $ret = (new ActivityService())->getPosterQrCodeUrl($this->mall, $params['id']); return $this->success('获取成功', $ret); } catch (Exception $e) { return $this->error($e->getMessage()); } } public function actionGetCanBindInviter() { if (\Yii::$app->request->isAjax) { $params = \Yii::$app->request->get(); $where = []; $where[] = ['mall_id' => $this->mall_id]; if (!empty($params['inviter_id'])) $where[] = ['id' => $params['inviter_id']]; if (!empty($params['keyword'])) { $where[] = ['or', ['like', 'mobile', $params['keyword']], ['like', 'nickname', $params['keyword']]]; } $user_list = User::listPage(['where' => $where]); if (!empty($user_list['list'])) { $user_level_arr = UserLevel::getUserLevelArr($params['mall_id']); foreach ($user_list['list'] as &$v) { $v['level_name'] = !empty($user_level_arr[$v['level']]) ? $user_level_arr[$v['level']] : MallSetting::getDefaultLevelName($this->mall_id); } } return $this->success('操作成功', ['list' => $user_list]); } } }