SendOrderBreakevenForceUser.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use DB;
  5. class SendOrderBreakevenForceUser extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'sendorderbreadforceuser';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '更新粉丝数';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $this->start();
  36. }
  37. public function start(){
  38. DB::table('send_order_breakeven_stats')->select('id','official_account_id','date')->where('date','=',date('Y-m-d',time()-86400))->orderBy('id')->chunk(1000,function ($res){
  39. foreach ($res as $v){
  40. $appid = DB::table('official_accounts')->where('id',$v->official_account_id)->select('appid')->first();
  41. if($appid && isset($appid->appid)){
  42. $total = DB::table('force_subscribe_users')->where('is_subscribed',1)->where('appid',$appid->appid)->count();
  43. $today = DB::table('force_subscribe_users')
  44. ->where('appid',$appid->appid)
  45. ->where('created_at','>=',$v->date)
  46. ->where('created_at','<=',$v->date.' 23:59:59')
  47. ->count();
  48. DB::table('send_order_breakeven_stats')->where('id',$v->id)->update(['total_force_user_num'=>$total,'force_user_num'=>$today]);
  49. }
  50. }
  51. });
  52. }
  53. }