V2boardStatistics.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\StatServerJob;
  4. use Illuminate\Console\Command;
  5. use App\Models\Order;
  6. use Illuminate\Support\Facades\DB;
  7. class V2BoardStatistics extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'v2board:statistics';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '统计任务';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->statOrder();
  38. // $this->statServer();
  39. }
  40. private function statOrder()
  41. {
  42. $endAt = strtotime(date('Y-m-d'));
  43. $startAt = strtotime('-1 day', $endAt);
  44. $builder = Order::where('updated_at', '>=', $startAt)
  45. ->where('updated_at', '<', $endAt)
  46. ->whereIn('status', [3, 4]);
  47. $orderCount = $builder->count();
  48. $orderAmount = $builder->sum('total_amount');
  49. $builder = $builder->where('commission_balance', '!=', NULL)
  50. ->whereIn('commission_status', [1, 2]);
  51. $commissionCount = $builder->count();
  52. $commissionAmount = $builder->sum('commission_balance');
  53. dd([
  54. $orderCount,
  55. $orderAmount,
  56. $commissionCount,
  57. $commissionAmount
  58. ]);
  59. }
  60. private function statServer()
  61. {
  62. $endAt = strtotime(date('Y-m-d'));
  63. $startAt = strtotime('-1 day', $endAt);
  64. $statistics = ServerLog::select([
  65. 'server_id',
  66. 'method as server_type',
  67. DB::raw("sum(u) as u"),
  68. DB::raw("sum(d) as d"),
  69. ])
  70. ->where('log_at', '>=', $startAt)
  71. ->where('log_at', '<', $endAt)
  72. ->groupBy('server_id', 'method')
  73. ->get()
  74. ->toArray();
  75. foreach ($statistics as $statistic) {
  76. $statistic['record_type'] = 'm';
  77. $statistic['record_at'] = $startAt;
  78. StatServerJob::dispatch($statistic);
  79. }
  80. }
  81. }