UpdateStatisticBody.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Bike;
  4. use App\Models\Statistic;
  5. use App\Models\WorkOrder;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. class updateStatisticBody extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'update:statistic_body';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '更新统计表';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. //
  39. $sta = Statistic::query()->where('slug',Statistic::SLUG_PROFIT_STATIC)->whereIn('area_id',[9999,9])
  40. ->where('date','>',Carbon::today()->subDays(30))->get();
  41. $bikes = Bike::query()->where('put_area_id',9)->where('put_status',Bike::PUT_STATUS_YES)->count();
  42. $bar = $this->output->createProgressBar(count($sta));
  43. $bar->start();
  44. foreach ($sta as $v){
  45. $body = json_decode($v->body,true);
  46. $body['put_bikes'] = $bikes;
  47. $v->body = json_encode($body);
  48. $v->save();
  49. $bar->advance();
  50. }
  51. $bar->finish();
  52. }
  53. public function getWorkOrder($offset,$limit){
  54. $workOrder = WorkOrder::query()
  55. ->offset($offset)
  56. ->limit($limit)
  57. ->get();
  58. foreach ($workOrder as $v){
  59. $v->warning_type = WorkOrder::$typeWarningMaps[$v->type];
  60. $v->save();
  61. }
  62. $this->line($offset);
  63. }
  64. }