统计模块收益
This commit is contained in:
parent
c435ee2db9
commit
e3f8ef6a34
@ -19,6 +19,7 @@
|
|||||||
use App\Jobs\ClearTasks;
|
use App\Jobs\ClearTasks;
|
||||||
use App\Jobs\DeleteHost;
|
use App\Jobs\DeleteHost;
|
||||||
use App\Jobs\Remote;
|
use App\Jobs\Remote;
|
||||||
|
use App\Jobs\SendThisMonthModuleEarnings;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@ -56,8 +57,6 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
|
|
||||||
// dispatch HostCost job
|
// dispatch HostCost job
|
||||||
$schedule->job(new HostCost())->everyFiveMinutes();
|
$schedule->job(new HostCost())->everyFiveMinutes();
|
||||||
// $schedule->job(new UserSave())->everyTenMinutes();
|
// $schedule->job(new UserSave())->everyTenMinutes();
|
||||||
@ -74,5 +73,8 @@ protected function schedule(Schedule $schedule)
|
|||||||
$schedule->job(new AutoCloseWorkOrder())->everyFiveMinutes();
|
$schedule->job(new AutoCloseWorkOrder())->everyFiveMinutes();
|
||||||
|
|
||||||
$schedule->job(new JobsCalcModule())->everyFiveMinutes();
|
$schedule->job(new JobsCalcModule())->everyFiveMinutes();
|
||||||
|
|
||||||
|
// 每天晚上 20 点,发送模块收益
|
||||||
|
$schedule->job(new SendThisMonthModuleEarnings())->dailyAt('20:00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
app/Jobs/SendThisMonthModuleEarnings.php
Normal file
56
app/Jobs/SendThisMonthModuleEarnings.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Module\Module;
|
||||||
|
use App\Notifications\ModuleEarnings;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class SendThisMonthModuleEarnings extends Job
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
$default = [
|
||||||
|
'balance' => 0,
|
||||||
|
'drops' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$rate = config('drops.module_rate');
|
||||||
|
|
||||||
|
Module::chunk(
|
||||||
|
100,
|
||||||
|
function ($modules) use ($default, $rate) {
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$data = [
|
||||||
|
'transactions' => [
|
||||||
|
'this_month' => Cache::get('this_month_balance_and_drops_' . $module->id, $default),
|
||||||
|
'last_month' => Cache::get('last_month_balance_and_drops_' . $module->id, $default),
|
||||||
|
],
|
||||||
|
'rate' => $rate,
|
||||||
|
];
|
||||||
|
|
||||||
|
return (new ModuleEarnings($module))
|
||||||
|
->toGroup($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
66
app/Notifications/ModuleEarnings.php
Normal file
66
app/Notifications/ModuleEarnings.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use App\Models\Module\Module;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class ModuleEarnings extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
protected Module $module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Module $module)
|
||||||
|
{
|
||||||
|
$this->module = $module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toGroup($notifiable)
|
||||||
|
{
|
||||||
|
if (!isset($notifiable['transactions'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$module = $this->module;
|
||||||
|
|
||||||
|
$view = 'notifications.module.earnings';
|
||||||
|
|
||||||
|
// make wecom_key visible
|
||||||
|
$wecom_key = $module->wecom_key ?? config('settings.wecom.robot_hook.billing');
|
||||||
|
|
||||||
|
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [
|
||||||
|
'msgtype' => 'markdown',
|
||||||
|
'markdown' => [
|
||||||
|
'content' => view($view, [
|
||||||
|
'module' => $module,
|
||||||
|
'data' => $notifiable,
|
||||||
|
])->render(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($resp->failed()) {
|
||||||
|
Log::error('发送模块盈利到企业微信时失败', [
|
||||||
|
'module' => $module->id,
|
||||||
|
'data' => $notifiable,
|
||||||
|
'resp' => $resp->json(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
resources/views/notifications/module/earnings.blade.php
Normal file
38
resources/views/notifications/module/earnings.blade.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
## 收益汇报
|
||||||
|
# {{ $module->name }}
|
||||||
|
==================================
|
||||||
|
## 本月
|
||||||
|
#### 现金 {{ round($data['transactions']['this_month']['balance'], 2) }} 元
|
||||||
|
#### Drops {{ round($data['transactions']['this_month']['drops'], 4) }}
|
||||||
|
==================================
|
||||||
|
## 上个月
|
||||||
|
#### 现金 {{ round($data['transactions']['last_month']['balance'], 2) }} 元
|
||||||
|
#### Drops {{ round($data['transactions']['last_month']['drops'], 4) }}
|
||||||
|
|
||||||
|
|
||||||
|
{{--
|
||||||
|
$module = $this->http->get('modules')->json()['data'];
|
||||||
|
|
||||||
|
$total = $module['transactions']['this_month']['balance'];
|
||||||
|
|
||||||
|
$drops = $module['transactions']['this_month']['drops'] / $module['rate'];
|
||||||
|
|
||||||
|
if ($drops < 0) { $drops=0; } $total +=$drops; $total=round($total, 2); $module=[ 'balance'=>
|
||||||
|
$module['transactions']['this_month']['balance'],
|
||||||
|
'drops' => $module['transactions']['this_month']['drops'],
|
||||||
|
'total' => $total,
|
||||||
|
];
|
||||||
|
|
||||||
|
<h4>收益</h4>
|
||||||
|
<div>
|
||||||
|
<h3>
|
||||||
|
本月收益
|
||||||
|
</h3>
|
||||||
|
<p>
|
||||||
|
直接扣费金额: {{ $module['balance'] }} 元
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Drops: {{ $module['drops'] }}
|
||||||
|
</p>
|
||||||
|
<p>本月总计收入 CNY: {{ $module['total'] }} </p>
|
||||||
|
</div> --}}
|
Loading…
Reference in New Issue
Block a user