| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace addons\BusinessActivity\backend\controllers;
- use addons\BusinessActivity\common\service\ActivityService;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- use common\enums\StatusEnum;
- use common\models\common\MallSetting;
- use common\models\goods\Goods;
- use Exception;
- /**
- *
- * Class ActivityController
- * @package addons\BusinessActivity\backend\controllers
- */
- class ActivityController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (!\Yii::$app->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]);
- }
- }
- }
|