| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace addons\Recommen\backend\controllers;
- use addons\Recommen\common\models\RecommenReward;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use common\controllers\AddonsController;
- use yii\db\Exception;
- use yii\helpers\Json;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\CardSecret\backend\controllers
- */
- class RewardController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','mobile','user_keyword','active_id','name','create_time'], 'safe'],
- [['limit'],'default','value' => '15'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- if (!empty($get['user_keyword'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $get['user_keyword'] . '%', false])->asArray()->column();
- $user_name = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $get['user_keyword'] . '%', false])->asArray()->column();
- $user_ids = $user_ids + $user_name;
- if (empty($user_ids)) $this->success('查无此用户');
- $where[] = ['in', 'user_id', $user_ids];
- }
- if($get['create_time']) $where[] = ['between', 'created_at', strtotime($get['create_time'][0]),strtotime($get['create_time'][1])];
- $with = ['user','recommen'];
- if(!empty($get['user_id'])) $where[] = ['=', 'user_id', $get['user_id']];
- if(!empty($get['active_id'])) $where[] = ['=', 'active_id', $get['active_id']];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $order = 'id desc';
- $params = array('where' => $where,'with' => $with, 'order'=>$order, 'limit' => $get['limit']);
- $list = RecommenReward::listPage($params, false, true);
- if($list['list']){
- foreach($list['list'] as $k => $v){
- //var_dump($v['reward']);
- if($v['reward'] && $v['reward'] != "null" && $v['reward'] != null){
- $list['list'][$k]['reward'] = implode(',',json_decode($v['reward'],true));
- }else{
- $list['list'][$k]['reward'] = '--';
- }
- }
- }
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- }
|