first(); if (!$spend) { throw new BusinessException('订单不存在'); } if ($spend->pay_status != 1) { throw new BusinessException('订单支付未成功'); } if ($spend->event_status == 1) { throw new BusinessException('该订单已处理'); } $this->saveUserPlayDataCountBySpend($spend); $this->addUserDataPayAmount($spend); $this->addGameDataPayAmount($spend); $spend->event_status = 1; $spend->save(); } private function saveUserPlayDataCountBySpend(Spend $spend) { $date = strtotime(date('Y-m-d 00:00:00', $spend->pay_time)); $record = UserPlayDataCount::where('user_id', $spend->user_id) ->where('game_id', $spend->game_id) ->where('server_id', $spend->server_id) ->where('role_id', $spend->game_player_id) ->where('create_time', $date) ->first(); if (!$record) { $record = new UserPlayDataCount(); $record->user_id = $spend->user_id; $record->promote_id = $spend->promote_id; $record->game_id = $spend->game_id; $record->server_id = $spend->server_id; $record->role_id = $spend->game_player_id; $record->create_time = $date; $record->recharge_cost = $spend->pay_amount; $record->recharge_count = 1; } else { $record->recharge_cost = Db::raw('recharge_cost+' . $spend->pay_amount); $record->recharge_count = Db::raw('recharge_count+1'); } $record->save(); } private function addUserDataPayAmount($spend) { UserData::updateOrCreate( ['user_id' => $spend->user_id], ['pay_amount' => Db::raw('pay_amount+' . $spend->pay_amount)] ); } private function addGameDataPayAmount($spend) { GameData::updateOrCreate( ['game_id' => $spend->game_id], ['pay_amount' => Db::raw('pay_amount+' . $spend->pay_amount)] ); } }