123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace App\Console\Commands\Data;
- use Illuminate\Console\Command;
- class FansCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'data:fans';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '每月的统计数据';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //
- // $date = $this->ask("日期?");
- $headers = ["日期", "总人数", "手机号人数", "卡片人数", "报名人数", "普通会员人数"];
- $data = [];
- $dates = [
- '2018-07',
- '2018-08',
- '2018-09',
- '2018-10',
- '2018-11',
- '2018-12',
- '2019-01',
- '2019-02',
- '2019-03',
- '2019-04',
- '2019-05',
- '2019-06',
- '2019-07',
- ];
- // foreach ($dates as $date) {
- // $y = date("Y", strtotime($date));
- // $m = date("m", strtotime($date));
- // $begin = mktime(0, 0, 0, $m, 1, $y);
- // $end = mktime(0, 0, 0, $m + 1, 1, $y) - 1;
- $begin = 0;
- $end = time();
- // 总人数
- $total = \DB::table('kdgx_partner_charge_user as u')
- ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
- ->where('o.public_id', 'gh_b598cb7474d8')
- ->where('o.subscribe', 1)
- ->whereBetween('u.login_at', [$begin, $end])
- ->count();
- // 手机号人数
- $phone_total = \DB::table('kdgx_partner_charge_user as u')
- ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
- ->where('o.public_id', 'gh_b598cb7474d8')
- ->where('o.subscribe', 1)
- ->whereNotNull('u.phone')
- ->whereBetween('u.login_at', [$begin, $end])
- ->count();
- // 卡片人数
- $partner_total = \DB::table('kdgx_partner_charge_user as u')
- ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
- ->where('o.public_id', 'gh_b598cb7474d8')
- ->where('o.subscribe', 1)
- ->where('u.partner_id', '>', 0)
- ->whereBetween('u.login_at', [$begin, $end])
- ->count();
- // 报名人数
- $pair_total = \DB::table('kdgx_partner_charge_user as u')
- ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
- ->join('kdgx_partner_charge_pair as p', 'p.uid', '=', 'u.uid')
- ->where('o.public_id', 'gh_b598cb7474d8')
- ->where('o.subscribe', 1)
- ->whereBetween('u.login_at', [$begin, $end])
- ->distinct()
- ->count('u.uid');
- // 普通会员人数
- $vip_total = \DB::table('kdgx_partner_charge_user as u')
- ->join('kddx_user_openid as o', 'o.uid', '=', 'u.uid')
- ->where('o.public_id', 'gh_b598cb7474d8')
- ->where('o.subscribe', 1)
- ->whereBetween('u.be_vip_at', [$begin, $end])
- ->count();
- array_push($data, [
- // "date"=>$date,
- "date" => "全部",
- "total" => $total,
- "phone_total" => $phone_total,
- "partner_total" => $partner_total,
- "pair_total" => $pair_total,
- "vip_total" => $vip_total
- ]);
- // }
- $this->table($headers, $data);
- }
- }
|