From 9446f3624810daf434c7d45b42d88c66b40d531d Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Tue, 13 Jun 2023 00:25:06 +0800 Subject: [PATCH] yh --- app/Command/RebateCommand.php | 7 ++ app/Helper/RebateGiftItem/Game12.php | 105 +++++++++++++++++++++++++++ app/Model/RebateGift.php | 1 + app/Service/RebateService.php | 54 +++++++++++++- 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 app/Helper/RebateGiftItem/Game12.php diff --git a/app/Command/RebateCommand.php b/app/Command/RebateCommand.php index 68d72a0..85483fe 100644 --- a/app/Command/RebateCommand.php +++ b/app/Command/RebateCommand.php @@ -158,6 +158,13 @@ class RebateCommand extends HyperfCommand } } + private function generateRoleLevel() + { + foreach ($this->baseGames as $baseGame) { + $this->rebateService->generateRoleLevel($baseGame, $this->timeRange); + } + } + protected function getArguments() { return [ diff --git a/app/Helper/RebateGiftItem/Game12.php b/app/Helper/RebateGiftItem/Game12.php new file mode 100644 index 0000000..99a074a --- /dev/null +++ b/app/Helper/RebateGiftItem/Game12.php @@ -0,0 +1,105 @@ + $this->getAItems(), + 'C' => $this->getCItems(), + 'D' => $this->getDItems(), + 'G' => $this->getGItems(), + 'J' => $this->getJItems(), + ]; + } + + public function getAItems() + { + return [ + ['gift_key' => 'A-28', 'amount' => 28, 'gifts' => [['id' => 587, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '特权月卡*1'], + ['gift_key' => 'A-100', 'amount' => 100, 'gifts' => [['id' => 592, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '100000元宝|200000充值元宝'], + ['gift_key' => 'A-500', 'amount' => 500, 'gifts' => [['id' => 593, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '500000元宝|1000000充值元宝'], + ['gift_key' => 'A-1000', 'amount' => 1000, 'gifts' => [['id' => 594, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '1000000元宝|2000000充值元宝'], + ['gift_key' => 'A-1500', 'amount' => 1500, 'gifts' => [['id' => 595, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '1500000元宝|3000000充值元宝'], + ['gift_key' => 'A-2000', 'amount' => 2000, 'gifts' => [['id' => 596, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '2000000元宝|4000000充值元宝'], + ['gift_key' => 'A-3000', 'amount' => 3000, 'gifts' => [['id' => 597, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '3000000元宝|6000000充值元宝'], + ['gift_key' => 'A-5000', 'amount' => 5000, 'gifts' => [['id' => 598, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '5000000元宝|10000000充值元宝'], + ['gift_key' => 'A-10000', 'amount' => 10000, 'gifts' => [['id' => 599, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '10000000元宝|20000000充值元宝'], + ]; + } + + public function getCItems() + { + return [ + ['gift_key' => 'C-328', 'amount' => 328, 'gifts' => [['id' => 58706, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '328累充豪礼'], + ['gift_key' => 'C-500', 'amount' => 500, 'gifts' => [['id' => 58704, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '檀木充值豪礼·壹'], + ['gift_key' => 'C-1000', 'amount' => 1000, 'gifts' => [['id' => 58705, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '檀木充值豪礼·贰'], + ['gift_key' => 'C-2000', 'amount' => 2000, 'gifts' => [['id' => 29050, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '青铜充值豪礼·壹'], + ['gift_key' => 'C-5000', 'amount' => 5000, 'gifts' => [['id' => 29051, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '青铜充值豪礼·贰'], + ['gift_key' => 'C-10000', 'amount' => 10000, 'gifts' => [['id' => 29052, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '青铜充值豪礼·叁'], + ['gift_key' => 'C-20000', 'amount' => 20000, 'gifts' => [['id' => 29053, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '白银充值豪礼·壹'], + + ['gift_key' => 'C-30000', 'amount' => 30000, 'gifts' => [['id' => 29054, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '白银充值豪礼·贰'], + ['gift_key' => 'C-40000', 'amount' => 40000, 'gifts' => [['id' => 29055, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '白银充值豪礼·叁'], + ['gift_key' => 'C-50000', 'amount' => 50000, 'gifts' => [['id' => 29056, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '白银充值豪礼·肆'], + ['gift_key' => 'C-60000', 'amount' => 60000, 'gifts' => [['id' => 29057, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '黄金充值豪礼·壹'], + ['gift_key' => 'C-70000', 'amount' => 70000, 'gifts' => [['id' => 29058, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '黄金充值豪礼·贰'], + ['gift_key' => 'C-80000', 'amount' => 80000, 'gifts' => [['id' => 29059, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '黄金充值豪礼·叁'], + ['gift_key' => 'C-90000', 'amount' => 90000, 'gifts' => [['id' => 29060, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '黄金充值豪礼·肆'], + ['gift_key' => 'C-100000', 'amount' => 100000, 'gifts' => [['id' => 29061, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '黄金充值豪礼·伍'], + + ['gift_key' => 'C-120000', 'amount' => 120000, 'gifts' => [['id' => 29063, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '铂金充值豪礼·贰'], + ['gift_key' => 'C-150000', 'amount' => 150000, 'gifts' => [['id' => 29066, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '铂金充值豪礼·伍'], + ['gift_key' => 'C-170000', 'amount' => 170000, 'gifts' => [['id' => 29068, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '钻石充值豪礼·贰'], + ['gift_key' => 'C-200000', 'amount' => 200000, 'gifts' => [['id' => 29071, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '钻石充值豪礼·伍'], + + ['gift_key' => 'C-250000', 'amount' => 250000, 'gifts' => [['id' => 58017, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '荣耀充值豪礼·叁'], + ['gift_key' => 'C-300000', 'amount' => 300000, 'gifts' => [['id' => 58019, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '荣耀充值豪礼·伍'], + + ['gift_key' => 'C-350000', 'amount' => 350000, 'gifts' => [['id' => 58022, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '至尊充值豪礼·叁'], + ['gift_key' => 'C-400000', 'amount' => 400000, 'gifts' => [['id' => 58024, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '至尊充值豪礼·伍'], + ['gift_key' => 'C-450000', 'amount' => 450000, 'gifts' => [['id' => 58027, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '巅峰充值豪礼·叁'], + ['gift_key' => 'C-500000', 'amount' => 500000, 'gifts' => [['id' => 58029, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '巅峰充值豪礼·伍'], + + ['gift_key' => 'C-550000', 'amount' => 550000, 'gifts' => [['id' => 58128, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·壹'], + ['gift_key' => 'C-600000', 'amount' => 600000, 'gifts' => [['id' => 58129, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·贰'], + ['gift_key' => 'C-650000', 'amount' => 650000, 'gifts' => [['id' => 58130, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·叁'], + ['gift_key' => 'C-700000', 'amount' => 700000, 'gifts' => [['id' => 58131, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·肆'], + ['gift_key' => 'C-750000', 'amount' => 750000, 'gifts' => [['id' => 58132, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·伍'], + ['gift_key' => 'C-800000', 'amount' => 800000, 'gifts' => [['id' => 58133, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·陆'], + ['gift_key' => 'C-850000', 'amount' => 850000, 'gifts' => [['id' => 58134, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·柒'], + ['gift_key' => 'C-900000', 'amount' => 900000, 'gifts' => [['id' => 58135, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·捌'], + ['gift_key' => 'C-950000', 'amount' => 950000, 'gifts' => [['id' => 58136, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·玖'], + ['gift_key' => 'C-1000000', 'amount' => 1000000, 'gifts' => [['id' => 58137, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '无上充值豪礼·拾'], + + ]; + } + + public function getDItems() + { + return [ + ['gift_key' => 'D-0', 'amount' => 0, 'gifts' => [['id' => 58688, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '首充礼包'], + ]; + } + + public function getGItems() + { + return [ + ['gift_key' => 'D-0', 'amount' => 0, 'gifts' => [['id' => 58686, 'num' => 1], ['id' => 58687, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '豪华进游福利、仙盟礼包'], + ]; + } + + public function getJItems() + { + return [ + ['gift_key' => 'J-150', 'amount' => 150, 'gifts' => [['id' => 58689, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '150级等级福利礼包'], + ['gift_key' => 'J-220', 'amount' => 220, 'gifts' => [['id' => 58690, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '220级等级福利礼包'], + ['gift_key' => 'J-270', 'amount' => 270, 'gifts' => [['id' => 58691, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '270级等级福利礼包'], + ['gift_key' => 'J-320', 'amount' => 320, 'gifts' => [['id' => 58692, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '320级等级福利礼包'], + ['gift_key' => 'J-370', 'amount' => 370, 'gifts' => [['id' => 58693, 'num' => 1]], 'game_currency' => 0, 'gift_content' => '370级等级福利礼包'], + ]; + } +} \ No newline at end of file diff --git a/app/Model/RebateGift.php b/app/Model/RebateGift.php index 101074a..e45054e 100644 --- a/app/Model/RebateGift.php +++ b/app/Model/RebateGift.php @@ -22,5 +22,6 @@ class RebateGift extends Model 'G' => '首次进游福利', 'H' => '签到福利发放', 'I' => '充值返利发放', + 'J' => '等级福利发放', ]; } \ No newline at end of file diff --git a/app/Service/RebateService.php b/app/Service/RebateService.php index 838b579..7a5cc4b 100644 --- a/app/Service/RebateService.php +++ b/app/Service/RebateService.php @@ -746,13 +746,65 @@ class RebateService extends Service RebateOrder::insert($records); } + /** + * 等级福利生成 + */ + public function generateRoleLevel($baseGame, $timeRange) + { + $gifts = RebateGift::where('type', 'J') + ->where('base_game_id', $baseGame->id) + ->orderBy('amount', 'asc') + ->get(); + if (count($gifts) == 0) { + return; + } + $gameIds = [$baseGame->android_game_id, $baseGame->ios_game_id]; + $roleIds = PlayerRole::whereIn('game_id', $gameIds) + ->whereBetween('play_time', $timeRange) + ->get([DB::raw('DISTINCT role_id')]) + ->pluck('role_id') + ->toArray(); + + $existItems = RebateOrder::whereIn('role_id', $roleIds) + ->where('type', 'J') + ->where('base_game_id', $baseGame->id) + ->get(['gift_key', 'role_id']) + ->keyBy(function($item) { + return $item->role_id . '-' . $item->gift_key; + }); + + $roles = $this->getRolesByRoleIds($baseGame, $roleIds); + + $records = []; + foreach ($roleIds as $roleId) { + $role = $roles[$roleId] ?? null; + if (is_null($role)) { + continue; + } + foreach ($gifts as $gift) { + if ($role->role_level >= $gift->amount) { + $orderKey = $roleId . '-' . $gift->gift_key; + if (empty($existItems[$orderKey])) { + $record = $this->getCommonRecord($baseGame, $role, $gift); + $record = array_merge($record, [ + 'pay_amount' => $role->role_level, + 'order_number' => uniqid('total_').rand(100000, 999999) + ]); + $records[] = $record; + } + } + } + } + RebateOrder::insert($records); + } + private function getRolesByRoleIds($baseGame, $roleIds) { $gameIds = [$baseGame->android_game_id, $baseGame->ios_game_id]; return PlayerRole::whereIn('game_id', $gameIds) ->whereIn('role_id', $roleIds) ->orderBy('role_level', 'desc') - ->get(['user_id', 'role_name', 'role_id', 'server_id', 'server_name', 'user_account']) + ->get(['user_id', 'role_name', 'role_id', 'server_id', 'server_name', 'user_account', 'role_level']) ->keyBy('role_id'); }