示例#1
0
 private function createSelectQueryForUpdateEntireWeapons()
 {
     $ruleNawabari = Rule::findOne(['key' => 'nawabari'])->id;
     $query = BattlePlayer::find()->innerJoinWith(['battle' => function ($q) {
         return $q->orderBy(null);
     }, 'battle.lobby', 'weapon'])->andWhere(['{{battle}}.[[is_automated]]' => true])->andWhere(['<>', '{{lobby}}.[[key]]', 'private'])->andWhere(['not', ['{{battle}}.[[is_win]]' => null]])->andWhere(['not', ['{{battle_player}}.[[kill]]' => null]])->andWhere(['not', ['{{battle_player}}.[[death]]' => null]])->andWhere(['{{battle_player}}.[[is_me]]' => false])->groupBy('{{battle}}.[[rule_id]], {{battle_player}}.[[weapon_id]]');
     // ルール別の処理を記述
     $query->andWhere(['or', ['and', ['{{battle}}.[[rule_id]]' => $ruleNawabari], ['not', ['{{battle_player}}.[[point]]' => null]], ['or', ['{{lobby}}.[[key]]' => 'standard'], ['{{lobby}}.[[key]]' => 'fest', '{{battle_player}}.[[is_my_team]]' => false]], ['or', ['and', ['=', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 300]], ['and', ['<>', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 0]]]], ['and', ['<>', '{{battle}}.[[rule_id]]', $ruleNawabari], ['not like', '{{lobby}}.[[key]]', 'squad_%', false]]]);
     $query->select(['rule_id' => '{{battle}}.[[rule_id]]', 'weapon_id' => '{{battle_player}}.[[weapon_id]]', 'players' => 'COUNT(*)', 'total_kill' => 'SUM({{battle_player}}.[[kill]])', 'total_death' => 'SUM({{battle_player}}.[[death]])', 'win_count' => sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle}}.[[is_win]] = TRUE AND {{battle_player}}.[[is_my_team]] = TRUE THEN 1', 'WHEN {{battle}}.[[is_win]] = FALSE AND {{battle_player}}.[[is_my_team]] = FALSE THEN 1', 'ELSE 0'])), 'total_point' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'WHEN {{battle}}.[[is_win]] = {{battle_player}}.[[is_my_team]] THEN battle_player.point - 300', 'ELSE {{battle_player}}.[[point]]']))), 'point_available' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'ELSE 1'])))]);
     return $query;
 }
示例#2
0
 public function beforeDelete()
 {
     if (!parent::beforeDelete()) {
         return false;
     }
     foreach ($this->battleImages as $img) {
         if (!$img->delete()) {
             return false;
         }
     }
     BattleDeathReason::deleteAll(['battle_id' => $this->id]);
     BattlePlayer::deleteAll(['battle_id' => $this->id]);
     if ($this->weapon_id) {
         $userWeapon = UserWeapon::findOne(['user_id' => $this->user_id, 'weapon_id' => $this->weapon_id]);
         if ($userWeapon) {
             if ($userWeapon->count <= 1) {
                 if (!$userWeapon->delete()) {
                     return false;
                 }
             } else {
                 $userWeapon->count--;
                 if (!$userWeapon->save()) {
                     return false;
                 }
             }
         }
     }
     return true;
 }