JoinLogController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace addons\Recommen\backend\controllers;
  3. use addons\Recommen\common\models\Recommen;
  4. use addons\Recommen\common\models\RecommenLog;
  5. use common\enums\StatusEnum;
  6. use common\models\user\User;
  7. use Yii;
  8. use common\controllers\AddonsController;
  9. use yii\db\Exception;
  10. use yii\helpers\Json;
  11. /**
  12. * 默认控制器
  13. *
  14. * Class DefaultController
  15. * @package addons\CardSecret\backend\controllers
  16. */
  17. class JoinLogController extends BaseController
  18. {
  19. public $enableCsrfValidation = false;
  20. /**
  21. * 首页
  22. *
  23. * @return string
  24. */
  25. public function actionIndex()
  26. {
  27. $retuest = Yii::$app->request;
  28. if ($retuest->isAjax) {
  29. if ($retuest->isGet) {
  30. $get = Yii::$app->request->get();
  31. // 检查提交的参数
  32. $res = Yii::$app->services->validate->validate($get,[
  33. [['user_id','mobile','user_keyword','name','create_time'], 'safe'],
  34. [['limit'],'default','value' => '15'],
  35. ]);
  36. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  37. $where = [];
  38. if (!empty($get['user_keyword'])) {
  39. $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $get['user_keyword'] . '%', false])->asArray()->column();
  40. $user_name = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $get['user_keyword'] . '%', false])->asArray()->column();
  41. $user_ids = $user_ids + $user_name;
  42. if (empty($user_ids)) $this->success('查无此用户');
  43. $where[] = ['in', 'user_id', $user_ids];
  44. }
  45. if($get['create_time']) $where[] = ['between', 'created_at', strtotime($get['create_time'][0]),strtotime($get['create_time'][1])];
  46. $with = ['user'];
  47. if(!empty($get['user_id'])) $where[] = ['=', 'user_id', $get['user_id']];
  48. //筛选出正在进行的活动
  49. $active = Recommen::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['>', 'start_time', time()])->andWhere(['<', 'end_time', time()])->asArray()->column();
  50. if($active) { $where[] = ['in', 'active_id', $active]; }
  51. $where[] = ['=', 'mall_id', $this->mall_id];
  52. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  53. $order = 'new_num desc';
  54. $params = array('where' => $where,'with' => $with,'group'=>'user_id','order'=>$order, 'limit' => $get['limit']);
  55. $params['select'] = 'user_id,max(new_num) as new_num';
  56. $list = RecommenLog::listPage($params, false, true);
  57. $this->success('获取成功', $list);
  58. }
  59. } else {
  60. return $this->render($this->action->id);
  61. }
  62. }
  63. }