CompanyDayCharge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Console\Commands\Statistic;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class CompanyDayCharge extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'Statistic:CompanyDayCharge {--date= : 统计日期} {--company_uids= : 公司管理员ids}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '投放公司日充值';
  19. /**
  20. * Execute the console command.
  21. */
  22. public function handle(): void
  23. {
  24. $date = $this->option('date') ?? date('Y-m-d', strtotime('yesterday'));
  25. $company_uids = $this->option('company_uids');
  26. if($company_uids) {
  27. $companyUids = explode(',', $company_uids);
  28. } else {
  29. $companyUids = DB::table('user_has_roles')
  30. ->where(['role_id' => 1])
  31. ->select('user_id')
  32. ->get()->pluck('user_id');
  33. }
  34. $now = date('Y-m-d H:i:s');
  35. foreach ($companyUids as $companyUid) {
  36. $info = DB::table('orders')
  37. ->whereBetween('created_at', [$date, $date. ' 23:59:59'])
  38. ->where('puser_id', $companyUid)
  39. ->select(
  40. DB::raw("sum(if(status = 'unpaid', 0, price)) as pay_money"),
  41. DB::raw("sum(if(status <> 'unpaid' and order_type in ('coin', 'first_coin'), 1, 0)) as common_pay_count"),
  42. DB::raw("sum(if(status = 'unpaid' and order_type in ('coin', 'first_coin'), 1, 0)) as common_unpay_count"),
  43. DB::raw("sum(if(status <> 'unpaid' and order_type not in ('coin', 'first_coin'), 1, 0)) as vip_pay_count"),
  44. DB::raw("sum(if(status = 'unpaid' and order_type not in ('coin', 'first_coin'), 1, 0)) as vip_unpay_count"),
  45. )->first();
  46. if($info) {
  47. DB::table('tj_company_day_charge')
  48. ->insert([
  49. 'day_at' => $date,
  50. 'pay_money' => $info->pay_money,
  51. 'common_pay_count' => $info->common_pay_count,
  52. 'common_unpay_count' => $info->common_unpay_count,
  53. 'vip_pay_count' => $info->vip_pay_count,
  54. 'vip_unpay_count' => $info->vip_unpay_count,
  55. 'company_uid' => $companyUid,
  56. 'created_at' => $now,
  57. 'updated_at' => $now,
  58. ]);
  59. }
  60. }
  61. }
  62. }