InvateController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace addons\ShareRedpack\backend\controllers;
  3. use addons\ShareRedpack\common\models\ShareRedpackInvate;
  4. use addons\ShareRedpack\common\models\ShareRedpackInvateLog;
  5. use common\enums\StatusEnum;
  6. use common\models\user\User;
  7. use yii\helpers\Json;
  8. use Yii;
  9. use common\controllers\AddonsController;
  10. /**
  11. * 默认控制器
  12. *
  13. * Class DefaultController
  14. * @package addons\ShareRedpack\backend\controllers
  15. */
  16. class InvateController extends BaseController
  17. {
  18. public $enableCsrfValidation = false;
  19. /**
  20. * 首页
  21. *
  22. * @return string
  23. */
  24. public function actionIndex()
  25. {
  26. if (Yii::$app->request->isAjax) {
  27. if (Yii::$app->request->isPost) {
  28. $params = Yii::$app->request->Post();
  29. $res = Yii::$app->services->validate->validate($params, [
  30. [['nickname','invite_code'], 'string'],
  31. [['page', 'limit', 'user_id'], 'integer'],
  32. [[ 'page', 'limit'], 'safe'],
  33. ]);
  34. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  35. $where = [];
  36. $where[] = ['=', 'mall_id', $this->mall_id];
  37. if(!empty($params['nickname'])){
  38. $userQuery = User::find()->where(['mall_id'=>$this->mall_id]);
  39. $search_user_ids = $userQuery->andWhere(['like', 'nickname', $params['nickname']])->select(['id'])->asArray()->all();
  40. $search_user_ids = array_column($search_user_ids, 'id');
  41. if ($search_user_ids) {
  42. $where[] = ['user_id' => $search_user_ids];
  43. } else {
  44. $where[] = ['user_id' => []];
  45. }
  46. }
  47. // 关键字搜索
  48. !empty($params['invite_code']) && $where[] = [
  49. 'or',
  50. ['like', 'invite_code', $params['invite_code']],
  51. ];
  52. !empty($params['user_id']) && $where[] = [
  53. 'or',
  54. ['=', 'user_id', $params['user_id']],
  55. ];
  56. $order = 'id desc';
  57. $select = ['id', 'mall_id', 'user_id', 'invite_code', 'num', 'created_at'];
  58. $with = ['user'];
  59. $params = ['select' => $select, 'where' => $where, 'order' => $order, 'with'=>$with];
  60. $data = ShareRedpackInvate::listPage($params, false, true);
  61. $this->success('获取成功', $data);
  62. }
  63. }
  64. return $this->render($this->action->id);
  65. }
  66. /**
  67. * 海报修改
  68. * @return mixed|string|null
  69. */
  70. public function actionEdit()
  71. {
  72. $request = Yii::$app->request;
  73. if ($request->isAjax) {
  74. if ($request->isGet) {
  75. $params = $request->Get();
  76. $res = Yii::$app->services->validate->validate($params, [
  77. [['id'], 'required'],
  78. [['id'], 'integer'],
  79. ]);
  80. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  81. $detail = ShareRedpackInvate::getOne([['mall_id' => $this->mall_id], ['id' => $params['id']]],true, ['user']);
  82. //查找它邀请过的成员
  83. $where[] = ['invate_id'=>$detail['id']];
  84. $where[] = ['mall_id'=>$this->mall_id];
  85. $order = 'id desc';
  86. $select = ['id', 'mall_id', 'user_id', 'invate_id', 'created_at'];
  87. $with = ['user'];
  88. $params = ['select' => $select, 'where' => $where, 'order' => $order, 'with'=>$with];
  89. $list = ShareRedpackInvateLog::listPage($params, false, true);
  90. $data = [];
  91. $data['detail'] = $detail;
  92. $data['list'] = $list;
  93. $this->success('获取成功', $data);
  94. }
  95. }
  96. return $this->render($this->action->id);
  97. }
  98. }