request->isAjax) { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['coupon_num', 'user_id_list'], 'required'], [['coupon_id'], 'required'], [['user_id_list'], 'safe'], [['all_send'], 'string'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if(!$params['user_id_list']&&$params['all_send']==2) throw new \Exception("请选择发送对象"); if($params['all_send'] == 1){ //发送给全部会员则走队列 $params['mall_id'] = $this->mall_id; \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $params, CouponSend::class, 'index'); }else{ $t = \Yii::$app->db->beginTransaction(); try { if($params['user_id_list']){ foreach ($params['user_id_list'] as $k=>$v){ $params['user_id'] = $v; $params['mall_id'] = $this->mall_id; $params['num'] = $params['coupon_num'];//数量 $params['extra'] = '操作后台发放';//额外信息 $params['from'] = "1"; $return = AddonsCouponUserRelate::setData($params); if($return!==true){ $t->rollBack(); return $this->error(AddonsCouponUserRelate::$static_error); } } } }catch (Exception $e) { $t->rollBack(); return $this->error($e->getMessage()); } $t->commit(); return $this->success('操作成功', $return); } }else{ $params = \Yii::$app->request->get(); $list = AddonsCoupon::getOne([['id' => $params['id']]]); $res = \Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } /** * 搜索用户 * @return \yii\web\Response */ public function actionSearchUser() { if (\Yii::$app->request->isAjax) { $params = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($params, [ [['keyword_name','keyword_id','keyword_mobile'], 'string','message' => '请输入发放对象搜索关键字'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if(!empty($params['keyword_name']))$where[] = ['like','nickname',$params['keyword_name']]; if(!empty($params['keyword_id']))$where[] = ['=','id',$params['keyword_id']]; if(!empty($params['keyword_mobile']))$where[] = ['=','mobile',$params['keyword_mobile']]; $cond = ['where' => $where, 'limit' => 10,'order'=>"id desc"]; $field = "nickname,id,avatar_url,mobile"; $list = User::listPage($cond); return $this->success('操作成功', $list); } } }