diff --git a/app/Jobs/Module/SendModuleEarningsJob.php b/app/Jobs/Module/SendModuleEarningsJob.php index 7fcc442..da688bd 100644 --- a/app/Jobs/Module/SendModuleEarningsJob.php +++ b/app/Jobs/Module/SendModuleEarningsJob.php @@ -4,7 +4,8 @@ use App\Jobs\Job; use App\Models\Module; -use App\Notifications\Modules\ModuleEarnings; +use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; class SendModuleEarningsJob extends Job { @@ -27,10 +28,61 @@ public function handle(): void { (new Module)->chunk(100, function ($modules) { foreach ($modules as $module) { - (new ModuleEarnings($module)) - ->toGroup($module->calculate()); + $this->send($module); } }); } + + private function send(Module $module): void + { + $data = $module->calculate(); + + if (!$data) { + return; + } + + // make wecom_key visible + $wecom_key = $module->wecom_key ?? config('settings.wecom.robot_hook.billing'); + + + $text = "# $module->name 收益"; + foreach ($data as $year => $months) { + // 排序 months 从小到大 + ksort($months); + + $total = 0; + $total_should = 0; + + foreach ($months as $month => $m) { + $total += round($m['balance'], 2); + $total_should += round($m['should_balance'], 2); + $text .= << 'markdown', + 'markdown' => [ + 'content' => $text, + ], + ]); + + + if ($resp->failed()) { + Log::error('发送模块盈利到企业微信时失败', [ + 'module' => $module->id, + 'data' => $data, + 'resp' => $resp->json(), + ]); + } + } } diff --git a/app/Notifications/Modules/ModuleEarnings.php b/app/Notifications/Modules/ModuleEarnings.php deleted file mode 100644 index 1927cef..0000000 --- a/app/Notifications/Modules/ModuleEarnings.php +++ /dev/null @@ -1,81 +0,0 @@ -module = $module; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * - * @return void - */ - public function toGroup(mixed $notifiable): void - { - $module = $this->module; - - // make wecom_key visible - $wecom_key = $module->wecom_key ?? config('settings.wecom.robot_hook.billing'); - - - $text = "# $module->name 收益"; - foreach ($notifiable as $year => $months) { - // 排序 months 从小到大 - ksort($months); - - $total = 0; - $total_should = 0; - - foreach ($months as $month => $m) { - $total += round($m['balance'], 2); - $total_should += round($m['should_balance'], 2); - $text .= << 'markdown', - 'markdown' => [ - 'content' => $text, - ], - ]); - - - if ($resp->failed()) { - Log::error('发送模块盈利到企业微信时失败', [ - 'module' => $module->id, - 'data' => $notifiable, - 'resp' => $resp->json(), - ]); - } - } -}