| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\ShareRedpack\backend\controllers;
- use addons\ShareRedpack\common\models\ShareRedpackInvate;
- use addons\ShareRedpack\common\models\ShareRedpackInvateLog;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use yii\helpers\Json;
- use Yii;
- use common\controllers\AddonsController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\ShareRedpack\backend\controllers
- */
- class InvateController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->Post();
- $res = Yii::$app->services->validate->validate($params, [
- [['nickname','invite_code'], 'string'],
- [['page', 'limit', 'user_id'], 'integer'],
- [[ 'page', 'limit'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- if(!empty($params['nickname'])){
- $userQuery = User::find()->where(['mall_id'=>$this->mall_id]);
- $search_user_ids = $userQuery->andWhere(['like', 'nickname', $params['nickname']])->select(['id'])->asArray()->all();
- $search_user_ids = array_column($search_user_ids, 'id');
- if ($search_user_ids) {
- $where[] = ['user_id' => $search_user_ids];
- } else {
- $where[] = ['user_id' => []];
- }
- }
- // 关键字搜索
- !empty($params['invite_code']) && $where[] = [
- 'or',
- ['like', 'invite_code', $params['invite_code']],
- ];
- !empty($params['user_id']) && $where[] = [
- 'or',
- ['=', 'user_id', $params['user_id']],
- ];
- $order = 'id desc';
- $select = ['id', 'mall_id', 'user_id', 'invite_code', 'num', 'created_at'];
- $with = ['user'];
- $params = ['select' => $select, 'where' => $where, 'order' => $order, 'with'=>$with];
- $data = ShareRedpackInvate::listPage($params, false, true);
- $this->success('获取成功', $data);
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 海报修改
- * @return mixed|string|null
- */
- public function actionEdit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = $request->Get();
- $res = Yii::$app->services->validate->validate($params, [
- [['id'], 'required'],
- [['id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $detail = ShareRedpackInvate::getOne([['mall_id' => $this->mall_id], ['id' => $params['id']]],true, ['user']);
- //查找它邀请过的成员
- $where[] = ['invate_id'=>$detail['id']];
- $where[] = ['mall_id'=>$this->mall_id];
- $order = 'id desc';
- $select = ['id', 'mall_id', 'user_id', 'invate_id', 'created_at'];
- $with = ['user'];
- $params = ['select' => $select, 'where' => $where, 'order' => $order, 'with'=>$with];
- $list = ShareRedpackInvateLog::listPage($params, false, true);
- $data = [];
- $data['detail'] = $detail;
- $data['list'] = $list;
- $this->success('获取成功', $data);
- }
- }
- return $this->render($this->action->id);
- }
- }
|