FansCommand.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Console\Commands\Data;
  3. use Illuminate\Console\Command;
  4. class FansCommand extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'data:fans';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = '每月的统计数据';
  18. /**
  19. * Create a new command instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. /**
  28. * Execute the console command.
  29. *
  30. * @return mixed
  31. */
  32. public function handle()
  33. {
  34. //
  35. // $date = $this->ask("日期?");
  36. $headers = ["日期", "总人数", "手机号人数", "卡片人数", "报名人数", "普通会员人数"];
  37. $data = [];
  38. $dates = [
  39. '2018-07',
  40. '2018-08',
  41. '2018-09',
  42. '2018-10',
  43. '2018-11',
  44. '2018-12',
  45. '2019-01',
  46. '2019-02',
  47. '2019-03',
  48. '2019-04',
  49. '2019-05',
  50. '2019-06',
  51. '2019-07',
  52. ];
  53. // foreach ($dates as $date) {
  54. // $y = date("Y", strtotime($date));
  55. // $m = date("m", strtotime($date));
  56. // $begin = mktime(0, 0, 0, $m, 1, $y);
  57. // $end = mktime(0, 0, 0, $m + 1, 1, $y) - 1;
  58. $begin = 0;
  59. $end = time();
  60. // 总人数
  61. $total = \DB::table('kdgx_partner_charge_user as u')
  62. ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
  63. ->where('o.public_id', 'gh_b598cb7474d8')
  64. ->where('o.subscribe', 1)
  65. ->whereBetween('u.login_at', [$begin, $end])
  66. ->count();
  67. // 手机号人数
  68. $phone_total = \DB::table('kdgx_partner_charge_user as u')
  69. ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
  70. ->where('o.public_id', 'gh_b598cb7474d8')
  71. ->where('o.subscribe', 1)
  72. ->whereNotNull('u.phone')
  73. ->whereBetween('u.login_at', [$begin, $end])
  74. ->count();
  75. // 卡片人数
  76. $partner_total = \DB::table('kdgx_partner_charge_user as u')
  77. ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
  78. ->where('o.public_id', 'gh_b598cb7474d8')
  79. ->where('o.subscribe', 1)
  80. ->where('u.partner_id', '>', 0)
  81. ->whereBetween('u.login_at', [$begin, $end])
  82. ->count();
  83. // 报名人数
  84. $pair_total = \DB::table('kdgx_partner_charge_user as u')
  85. ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
  86. ->join('kdgx_partner_charge_pair as p', 'p.uid', '=', 'u.uid')
  87. ->where('o.public_id', 'gh_b598cb7474d8')
  88. ->where('o.subscribe', 1)
  89. ->whereBetween('u.login_at', [$begin, $end])
  90. ->distinct()
  91. ->count('u.uid');
  92. // 普通会员人数
  93. $vip_total = \DB::table('kdgx_partner_charge_user as u')
  94. ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
  95. ->where('o.public_id', 'gh_b598cb7474d8')
  96. ->where('o.subscribe', 1)
  97. ->whereBetween('u.be_vip_at', [$begin, $end])
  98. ->count();
  99. array_push($data, [
  100. // "date"=>$date,
  101. "date" => "全部",
  102. "total" => $total,
  103. "phone_total" => $phone_total,
  104. "partner_total" => $partner_total,
  105. "pair_total" => $pair_total,
  106. "vip_total" => $vip_total
  107. ]);
  108. // }
  109. $this->table($headers, $data);
  110. }
  111. }