AccordingToOwnersManualBack.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\OracleDOCOrderHeader;
  4. use App\Owner;
  5. use App\ValueStore;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  9. class AccordingToOwnersManualBack extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'AccordingToOwnersManualBack';
  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. public function handle()
  36. {
  37. $ownerCodes=Owner::query()->where('is_manual_back',1)->pluck('code');
  38. $last_order_manual_back_at=$this->getOrderManualBackAt();
  39. $now=Carbon::now()->toDateTimeString();
  40. OracleDOCOrderHeader::query()
  41. ->whereIn('sostatus',['40','50','60','61'])
  42. ->where('edittime','>=',$last_order_manual_back_at)
  43. ->where('edittime','<=',$now)
  44. ->whereNotNull('soreference5')
  45. ->where('manualflag','N')
  46. ->whereIn('customerid',$ownerCodes) //指定货主
  47. ->where('releasestatus','!=','H')
  48. ->update(['manualflag'=>'Y','edittime'=>$now]);
  49. $this->setOrderManualBackAt();
  50. }
  51. /**
  52. * @return HigherOrderBuilderProxy|mixed|null
  53. * 获取订单上次自动回传时间
  54. */
  55. private function getOrderManualBackAt()
  56. {
  57. $val = ValueStore::query()
  58. ->select("value")
  59. ->where("name", "last_order_manual_back_at")
  60. ->lockForUpdate()
  61. ->first();
  62. if (!$val) $val = ValueStore::query()
  63. ->create(["name" => "last_order_manual_back_at",'value'=>Carbon::now()->toDateTimeString()]);
  64. return $val->value ?? null;
  65. }
  66. /**
  67. * 设置订单上次自动回传时间
  68. */
  69. private function setOrderManualBackAt()
  70. {
  71. ValueStore::query()
  72. ->select("value")
  73. ->where("name", "last_order_manual_back_at")
  74. ->update(["value" => Carbon::now()->toDateTimeString()]);
  75. }
  76. }