ChargeTemplateStat.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands;
  9. use App\Modules\Trade\Services\OrderService;
  10. use DB;
  11. use Illuminate\Console\Command;
  12. use Log;
  13. class ChargeTemplateStat extends Command
  14. {
  15. /**
  16. * 执行命令 php artisan bill_task
  17. *
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'charge_template_stat';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '充值模板数据统计';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $book_id = '1148';
  37. $distribution_channel_id = 123;
  38. $book_name = '婚情告急:总裁请别撩';
  39. $users = DB::table('user_first_visit_pay_page')->limit(12000)->get();
  40. foreach ($users as $userItem) {
  41. $uid = $userItem->uid;
  42. $created_at = $userItem->created_at;
  43. $created_at_timestamp = strtotime($created_at);
  44. $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400)];
  45. $recharge_amount_in_24h = OrderService::getAmount($params);
  46. $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 3)];
  47. $recharge_amount_in_72h = OrderService::getAmount($params);
  48. $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 7)];
  49. $recharge_amount_in_7d = OrderService::getAmount($params);
  50. $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 30)];
  51. $recharge_amount_in_30d = OrderService::getAmount($params);
  52. $params = ['uid' => $uid];
  53. $recharge_amount = OrderService::getAmount($params);
  54. $template_type = $userItem->template_type;
  55. $data = ['uid' => $uid, 'book_id' => $book_id, 'book_name' => $book_name, 'template_tye' => $template_type,
  56. 'distribution_channel_id' => $distribution_channel_id, 'recharge_amount_in_24h' => $recharge_amount_in_24h,
  57. 'recharge_amount_in_72h' => $recharge_amount_in_72h, 'recharge_amount_in_7d' => $recharge_amount_in_7d,
  58. 'recharge_amount_in_30d' => $recharge_amount_in_30d, 'recharge_amount' => $recharge_amount,
  59. 'created_at' => $created_at];
  60. DB::table('charge_template_stat')->insert($data);
  61. }
  62. DB::update("UPDATE charge_template_stat a join users b on a.uid=b.id set a.distribution_channel_id=b.distribution_channel_id");
  63. }
  64. }