RewardController.php 3.1 KB

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