AdvertsCommand.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace App\Console\Commands\Data;
  3. use App\Exports\FormExport;
  4. use App\Models\Fpdx\ActivityModel;
  5. use App\Models\Fpdx\PairModel;
  6. use App\Models\OrderModel;
  7. use App\Models\User\UserModel;
  8. use Illuminate\Console\Command;
  9. use Maatwebsite\Excel\Facades\Excel;
  10. class AdvertsCommand extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'data:adverts';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '接单的数据';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. //
  41. $stage_id = $this->ask('选择期数?');
  42. $activity = ActivityModel::find($stage_id);
  43. $begin_at = $activity->signend_time - 66 * 3600;
  44. $end_at = $activity->signend_time;
  45. // $public_id = 'gh_c94c95866ca5';
  46. $public_id = 'gh_b598cb7474d8';
  47. $openids = \DB::table('kddx_user_openid')
  48. ->where('public_id', $public_id)
  49. ->whereBetween('subscribe_time', [$begin_at, $end_at])
  50. ->pluck('openid');
  51. $users = \DB::table('kddx_user_openid')
  52. ->whereIn('openid', $openids)
  53. ->where('uid', '>', 0)
  54. ->pluck('uid');
  55. // 用户数据
  56. $number = $openids->count();
  57. $subscribe_number = \DB::table('kddx_user_openid')
  58. ->whereIn('openid', $openids)
  59. ->where('subscribe', 1)->count();
  60. $reg_number = $users->count();
  61. $phone_number = UserModel::whereIn('uid', $users)->whereNotNull('phone')->count();
  62. // 活动数据
  63. $pair_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  64. 'state',
  65. '>',
  66. 100
  67. )->whereIn('uid', $users)->count();
  68. $pair_man_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  69. 'state',
  70. '>',
  71. 100
  72. )->whereIn('uid', $users)->where('sex', 1)->count();
  73. $pair_woman_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  74. 'state',
  75. '>',
  76. 100
  77. )->whereIn('uid', $users)->where('sex', 2)->count();
  78. $pair_order_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  79. 'state',
  80. '>',
  81. 100
  82. )->whereIn('uid', $users)->where('pay', '>', 0)->count();
  83. $pair_man_order_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  84. 'state',
  85. '>',
  86. 100
  87. )->whereIn('uid', $users)->where('pay', '>', 0)->where('sex', 1)->count();
  88. $pair_woman_order_number = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  89. 'state',
  90. '>',
  91. 100
  92. )->whereIn('uid', $users)->where('pay', '>', 0)->where('sex', 2)->count();
  93. $pair_order_amount = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  94. 'state',
  95. '>',
  96. 100
  97. )->whereIn('uid', $users)->where('pay', '>', 0)->sum('pay');
  98. $pair_man_order_amount = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  99. 'state',
  100. '>',
  101. 100
  102. )->whereIn('uid', $users)->where('pay', '>', 0)->where('sex', 1)->sum('pay');
  103. $pair_woman_order_amount = PairModel::whereBetween('create_time', [$begin_at, $end_at])->where(
  104. 'state',
  105. '>',
  106. 100
  107. )->whereIn('uid', $users)->where('pay', '>', 0)->where('sex', 2)->sum('pay');
  108. dump("全部人数:{$number}");
  109. dump("当前关注人数:{$subscribe_number}");
  110. dump("注册人数:{$reg_number}");
  111. dump("绑定手机号人数:{$phone_number}");
  112. dump("报名人数:{$pair_number}");
  113. dump("男生报名人数:{$pair_man_number}");
  114. dump("女生报名人数:{$pair_woman_number}");
  115. dump("付费报名人数:{$pair_order_number}");
  116. dump("男生付费报名人数:{$pair_man_order_number}");
  117. dump("女生付费报名人数:" . $pair_woman_order_number);
  118. dump("付费报名金额:" . sprintf("%.2f", $pair_order_amount));
  119. dump("男生付费报名金额:" . sprintf("%.2f", $pair_man_order_amount));
  120. dump("女生付费报名金额:" . sprintf("%.2f", $pair_woman_order_amount));
  121. // 消费数据
  122. $vip_order_amount = OrderModel::where('order_state', 1)->whereBetween(
  123. 'create_at',
  124. [$begin_at, $end_at]
  125. )->whereIn('uid', $users)->whereIn('type', [12, 13, 14])->sum('cash_fee');
  126. $pair_order_amount = OrderModel::where('order_state', 1)->whereBetween(
  127. 'create_at',
  128. [$begin_at, $end_at]
  129. )->whereIn('uid', $users)->whereIn('type', [3])->sum('cash_fee');
  130. dump("vip充值:" . sprintf("%.2f", $vip_order_amount / 100));
  131. dump("活动充值:" . sprintf("%.2f", $pair_order_amount / 100));
  132. // 粉丝数据
  133. $new_user = \DB::table('koudai.kddx_user_openid')->where('public_id', $public_id)
  134. ->selectRaw("from_unixtime(`subscribe_time`, '%Y-%m-%d') as date, count(*) as count")
  135. ->whereBetween('subscribe_time', [$begin_at, $end_at])
  136. ->groupBy("date")
  137. ->get()
  138. ->toArray();
  139. $increase_user = \DB::table('koudai.kddx_user_openid')
  140. ->where('public_id', $public_id)
  141. ->selectRaw("from_unixtime(`subscribe_time`, '%Y-%m-%d') as date, count(*) as count")
  142. ->whereBetween('subscribe_time', [$begin_at, $end_at])
  143. ->where('subscribe', 1)
  144. ->groupBy("date")
  145. ->get()
  146. ->toArray();
  147. dump("公众号新增用户:");
  148. dump($new_user);
  149. dump("公众号净增用户:");
  150. dump($increase_user);
  151. $new_user = \DB::select("SELECT from_unixtime(e.`subscribe_time`, '%Y-%m-%d') as date,
  152. count(*) as count
  153. FROM(
  154. SELECT `unionid`, `subscribe_time`
  155. FROM `pocket`.`kdgx_fans_5`
  156. WHERE `public_id`= 'gh_c94c95866ca5'
  157. AND `subscribe_time` between ?
  158. and ?) as e
  159. INNER JOIN(
  160. SELECT `unionid`
  161. FROM `pocket`.`kdgx_fans_8`
  162. WHERE `public_id`= 'gh_b598cb7474d8'
  163. AND `subscribe`= 1) as f on e.unionid= f.unionid
  164. GROUP BY date", [$begin_at, $end_at]);
  165. $increase_user = \DB::select("SELECT from_unixtime(e.`subscribe_time`, '%Y-%m-%d') as date,
  166. count(*) as count
  167. FROM(
  168. SELECT `unionid`, `subscribe_time`
  169. FROM `pocket`.`kdgx_fans_5`
  170. WHERE `public_id`= 'gh_c94c95866ca5'
  171. AND `subscribe_time` between ?
  172. and ?
  173. AND `subscribe`= 1) as e
  174. INNER JOIN(
  175. SELECT `unionid`
  176. FROM `pocket`.`kdgx_fans_8`
  177. WHERE `public_id`= 'gh_b598cb7474d8'
  178. AND `subscribe`= 1) as f on e.unionid= f.unionid
  179. GROUP BY date", [$begin_at, $end_at]);
  180. dump("时遇记新增用户&关注分配对象:");
  181. dump($new_user);
  182. dump("时遇记净增用户&关注分配对象:");
  183. dump($increase_user);
  184. // 小程序分享
  185. $share_number = \DB::table("koudai.kdgx_partner_charge_fpdx_invite")
  186. ->selectRaw("from_unixtime(`create_at`, '%Y-%m-%d') as date, count(distinct(invite_uid)) as count")
  187. ->whereBetween("create_at", [$begin_at, $end_at])
  188. ->whereIn("invite_uid", $users)
  189. ->groupBy('date')
  190. ->get()
  191. ->toArray();
  192. $share_count = \DB::table("koudai.kdgx_partner_charge_fpdx_invite")
  193. ->selectRaw("from_unixtime(`create_at`, '%Y-%m-%d') as date, count(*) as count")
  194. ->whereBetween("create_at", [$begin_at, $end_at])
  195. ->whereIn("invite_uid", $users)
  196. ->groupBy('date')
  197. ->get()
  198. ->toArray();
  199. dump("分享人数:");
  200. dump($share_number);
  201. dump("分享次数:");
  202. dump($share_count);
  203. }
  204. }