UpdateSendOrderPreSendDate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Console\Commands\SendOrder;
  3. use App\Modules\SendOrder\Services\SendOrderService;
  4. use App\Modules\SendOrder\Models\SendOrder;
  5. use App\Modules\Sys\Services\PromotionGroupConfigService;
  6. use Illuminate\Console\Command;
  7. use App\Modules\Util;
  8. use Log;
  9. class UpdateSendOrderPreSendDate extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'updateSendOrderPreSendDate{--pre_date=}{--id=*}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '更新派单预计发送时间';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. if($this->option('id'))
  40. {
  41. $distribution_channel_ids=$this->option('id');
  42. }else{
  43. $distribution_channel_ids = explode(',', PromotionGroupConfigService::CHANNEL_ID_LIST());
  44. $distribution_channel_ids = [2,14,13,188];
  45. }
  46. if($this->option('pre_date')){
  47. $pre_date=$this->option('pre_date');
  48. }
  49. $params = compact('distribution_channel_ids', 'show_agent','pre_date');
  50. // $params['promotion_type'] = 'EXTERNAL'; //只筛选外部
  51. $data = SendOrderService::searchForDaliy($params, true);
  52. $ids ='';
  53. $count=0;
  54. foreach ($data as $item) {
  55. $item->old_name = $item->name;
  56. if (strpos($item->name, "-")) {
  57. $strs = explode('-', $item->name);
  58. if (count($strs) == 4) {
  59. $date_str = $strs[2];
  60. // dump($item->name.' '.$item->id.' '.$date_str.' '.date('Y/m/d',strtotime($date_str)));
  61. if($date_str==date('Y/m/d',strtotime($date_str))){
  62. $item->real_pre_send_date = date('Y/m/d',strtotime($date_str));
  63. }
  64. }elseif (count($strs) == 6) {
  65. $date_str = $strs[2] .'-'.$strs[3] .'-'.$strs[4];
  66. // dump($item->name.' '.$item->id.' '.$date_str.' '.date('Y-m-d',strtotime($date_str)));
  67. if ($date_str == date('Y-m-d', strtotime($date_str))) {
  68. $item->real_pre_send_date = date('Y/m/d', strtotime($date_str));
  69. }
  70. }
  71. if(isset($item->real_pre_send_date)&&(date('Y-m-d',strtotime($item->real_pre_send_date))!=date('Y-m-d',strtotime($item->pre_send_date))||empty($item->pre_send_date))){
  72. // dump($item->id.' '.' : '.date('Y-m-d',strtotime($item->real_pre_send_date)).' '.date('Y-m-d',strtotime($item->pre_send_date)));
  73. $effect = SendOrder::where('id',$item->id)->update(['pre_send_date'=>date('Y-m-d',strtotime($item->real_pre_send_date))]);
  74. $ids =$ids.' '.$item->id;
  75. $count+=$effect;
  76. }
  77. }
  78. }
  79. if($count){
  80. dump("共修改了{$count} 项数据,id为{$ids}");
  81. Log::info("共修改了{$count}项数据,id为{$ids}");
  82. }
  83. }
  84. }