| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * 统计支付相关.
- */
- namespace App\Console\Commands\Statistics;
- use App\Jobs\Statistics\PayChannelJob;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use App\Models\Mysql\ChannelModel;
- class StatisticsPay extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'statistics:pay {--date=}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '统计支付相关, 可选参数--date=2021-03-04.';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $date = $this->getArgsDate();
- // 指派调度统计某1天的所有充值.
- dispatch(new PayChannelJob($date));
- $this->comment('['. Carbon::now()->toDateTimeString() .'][statistics:pay]['. $date .']所有每日支付统计,丢入队列');
- // 指派调度统计某1天的官方充值.
- dispatch(new PayChannelJob($date, ''));
- $this->comment('['. Carbon::now()->toDateTimeString() .'][statistics:pay]['. $date .']官方每日支付统计,丢入队列');
- // 分片处理.
- $chunkPer = 1000;
- ChannelModel::orderBy('id', 'ASC')->chunk($chunkPer, function ($res) use ($date) {
- foreach ($res as $item) {
- if (!empty($item->uid)) {
- dispatch(new PayChannelJob($date, $item->uid));
- }
- }
- });
- $this->comment('['. Carbon::now()->toDateTimeString() .'][statistics:pay]['. $date .']单独渠道代理每日支付统计,全部丢入队列');
- }
- /**
- * 获取日期参数.
- * @return string
- */
- private function getArgsDate()
- {
- $date = $this->option('date');
- if (empty($date)) {
- // 没有传参数,则默认使用执行脚本服务器环境昨天日期为准.
- $date = Carbon::now()->subDays(1)->toDateString();
- }
- return $date;
- }
- }
|