Пример #1
0
 public function actionChooseplayer()
 {
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         $all = Players::findAll(['status' => 0]);
         for ($i = 0; $i < count($all); $i++) {
             $all_[] = $all[$i]->nameofagiver;
         }
         $post['player_code'] = trim($post['player_code']);
         if (empty($post['player_code'])) {
             return json_encode(['error' => 'Код не может быть пустым']);
         }
         $findcode = Players::findOne(['token' => $post['player_code']]);
         if ($findcode) {
             if ($findcode->whogift == 0) {
                 $fdsfsdfsf = Yii::$app->ss->secretSanta($all_, Yii::$app->ss->conditions($findcode->nameofagiver));
                 $nameofagiver = Players::findOne(['nameofagiver' => $fdsfsdfsf]);
                 if ($nameofagiver) {
                     $findcode->whogift = $nameofagiver->id;
                     $findcode->save();
                     $nameofagiver->status = 1;
                     $nameofagiver->date = time();
                     $nameofagiver->save();
                 }
                 return json_encode(['result' => $fdsfsdfsf]);
             } else {
                 return json_encode(['error' => 'Вы уже выбрали']);
             }
         } else {
             return json_encode(['error' => 'Код неверен']);
         }
     } else {
         return json_encode(['error' => 'Wrong format']);
     }
 }
 public function listplayers($id)
 {
     $players = Players::find('all', array('order' => array('power' => 'ASC'), 'conditions' => array('alliance' => $id)));
     return compact('players');
 }