Ejemplo n.º 1
0
 public function sendMailToModerator($news, $subject)
 {
     $subquery = (new \yii\db\Query())->select('user_id')->from('relation_categories')->where(['category_id' => $news->category_id]);
     $users = Users::findAll(['id' => $subquery]);
     foreach ($users as $user) {
         $emails[] = $user->email;
     }
     $body = sprintf('%s <br />
         Ссылка на новость - %s', $subject['moderator'], $this->urlToNews($news->id));
     $this->sendMail($emails, $subject['moderator'], $body);
 }
 /**
  * Creates a new MessagesUsers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new MessagesUsers();
     $type = Yii::$app->request->get('type');
     if (Yii::$app->request->isPost) {
         $param = Yii::$app->request->post();
         if ($param['user_type'] == 'user_name') {
             $userId = Users::getIdByName($param['MessagesUsers']['users_id']);
             if (empty($userId)) {
                 throw new ServerErrorHttpException('不存在的用户姓名!');
             }
             $model->messages_id = $param['MessagesUsers']['messages_id'];
             $model->type = $param['MessagesUsers']['type'];
             $model->users_id = $userId;
             $model->content = $param['MessagesUsers']['content'];
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } elseif ($param['user_type'] == 'user_level') {
             $levelId = Level::getIdByName($param['MessagesUsers']['users_id']);
             if (empty($levelId)) {
                 throw new ServerErrorHttpException('不存在的级别名称!');
             }
             $usersList = Users::findAll(['level_id' => $levelId, 'status' => 1]);
             if (!empty($usersList)) {
                 foreach ($usersList as $key => $val) {
                     $messagesUsersInfo['messages_id'] = $param['MessagesUsers']['messages_id'];
                     $messagesUsersInfo['type'] = $param['MessagesUsers']['type'];
                     $messagesUsersInfo['users_id'] = $val['id'];
                     $messagesUsersInfo['content'] = $param['MessagesUsers']['content'];
                     $messagesUsersInfo['create_time'] = date('Y-m-d H:i:s', time());
                     $messagesUsersInfo['create_user'] = '******';
                     $messagesUsersInfo['update_time'] = date('Y-m-d H:i:s', time());
                     $messagesUsersInfo['update_user'] = '******';
                     MessagesUsers::addInfo($messagesUsersInfo);
                 }
                 return $this->redirect('index');
             }
         } elseif ($param['user_type'] == 'all_user') {
             $usersList = Users::getAll();
             if (!empty($usersList)) {
                 foreach ($usersList as $key => $val) {
                     $messagesUsersInfo['messages_id'] = $param['MessagesUsers']['messages_id'];
                     $messagesUsersInfo['type'] = $param['MessagesUsers']['type'];
                     $messagesUsersInfo['users_id'] = $val['id'];
                     $messagesUsersInfo['content'] = $param['MessagesUsers']['content'];
                     $messagesUsersInfo['create_time'] = date('Y-m-d H:i:s', time());
                     $messagesUsersInfo['create_user'] = admin;
                     $messagesUsersInfo['update_time'] = date('Y-m-d H:i:s', time());
                     $messagesUsersInfo['update_user'] = '******';
                     MessagesUsers::addInfo($messagesUsersInfo);
                     return $this->redirect('index');
                 }
             }
         } else {
             throw new ServerErrorHttpException('参数错误!');
         }
     } else {
         return $this->render('create', ['model' => $model, 'type' => empty($type) ? '1' : $type]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Delete multiple existing Users model.
  * For ajax request will return json object
  * and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBulkDelete()
 {
     $request = Yii::$app->request;
     $pks = $request->post('pks');
     // Array or selected records primary keys
     foreach (Users::findAll(json_decode($pks)) as $model) {
         $model->delete();
     }
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ['forceClose' => true, 'forceReload' => true];
     } else {
         /*
          *   Process for non-ajax request
          */
         return $this->redirect(['index']);
     }
 }