overTimeOrder.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Order;
  4. use App\Models\SystemConfig;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Log;
  7. class overTimeOrder extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'overOrder';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '超时';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. Log::info('超时命令'.date('Y-m-d H:is',time()).PHP_EOL);
  38. $config_chat = SystemConfig::get('docter_config','chat_complete_time');
  39. $config_phone = SystemConfig::get('docter_config','phone_complete_time');
  40. // 换算为秒
  41. $config_chat = intval($config_chat)*60;
  42. $config_phone = intval($config_phone)*60;
  43. $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
  44. $catNewIds = [];
  45. $menNewIds = [];
  46. foreach ($inOrder as $k=>$v){
  47. if ($v['product_type']==1){
  48. if ((time()-$v['receiving_time'])>=$config_chat){
  49. $catNewIds[$k] = $v['id'];
  50. }
  51. }else if($v['product_type']==2){
  52. if ((time()-$v['receiving_time'])>=$config_phone){
  53. $catNewIds[$k] = $v['id'];
  54. }
  55. }else if($v['product_type']==3){
  56. if ((time()-$v['receiving_time'])>=(1*60*60*24)){
  57. $menNewIds[$k] = $v['id'];
  58. }
  59. }
  60. }
  61. if ($catNewIds || $menNewIds){
  62. // 操作图文和电话订单为已完成
  63. Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
  64. // 操作门诊订单为已超时
  65. Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
  66. }
  67. }
  68. }