overTimeOrder.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DocterOrganization;
  4. use App\Models\Order;
  5. use App\Models\SystemConfig;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Log;
  8. class overTimeOrder extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'order {type}';
  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. $type = $this->argument('type');
  39. if(!in_array($type,['orderOut','appiontOut','thenOut','thenLose'])){
  40. dd('请输入正确的参数');
  41. }
  42. if($type == 'orderOut'){
  43. //订单超时
  44. $this->overTimeOrers();
  45. dd('订单超时'.date('Y-m-d H:i:s'));
  46. } else if($type == 'appiontOut'){
  47. //预约超时
  48. $this->AppointReminder();
  49. }else if($type == 'thenOut'){
  50. //认证到期
  51. $this->OutThenReminder();
  52. }else if($type == 'thenLose'){
  53. //认证失效
  54. $this->InvalidThenReminder();
  55. }
  56. dd('ok');
  57. }
  58. /**
  59. * 确认超时提醒 当天的预约订单,医生还未点击完成的订单,23:00给医生发送提醒
  60. */
  61. public function AppointReminder(){
  62. $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
  63. $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  64. $Order = Order::with(['orderPatient','docter','user'])->where(['order_status'=>3,'payment_status'=>2,'product_type'=>3])->whereBetween('receiving_time',[$beginToday,$endToday])->get();
  65. foreach ($Order as $k=>$v){
  66. if ($v['docter']){
  67. if ($v['docter']['openid']){
  68. $send = send_wechatSubscription_message('appoint_reminder',[$v['docter']['openid'], "pages/index/index",$v['order_sn'],$v['user']['nickname'],$v['user']['phone'],$v['created_at']]);
  69. }
  70. }
  71. }
  72. }
  73. /**
  74. * 签约失效提醒
  75. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  76. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  77. * @throws \GuzzleHttp\Exception\GuzzleException
  78. */
  79. public function InvalidThenReminder(){
  80. $list = DocterOrganization::with('docter','organization')->get();
  81. if($list){
  82. foreach ($list as $k=>$v){
  83. if ($v['docter']['openid']&& time()>=strtotime($v['authentication_end_time'])){
  84. $send = send_wechatSubscription_message('out_then_reminder',[$v['docter']['openid'], "pages/index/index", $v['organization']['name'],date('Y-m-d',strtotime($v['authentication_end_time']))]);
  85. }
  86. }
  87. }
  88. }
  89. /**
  90. * 认证到期提醒
  91. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  92. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  93. * @throws \GuzzleHttp\Exception\GuzzleException
  94. */
  95. public function OutThenReminder(){
  96. $list = DocterOrganization::with('docter','organization')->get();
  97. if($list){
  98. foreach ($list as $k=>$v){
  99. if ($v['docter']['openid']&& (strtotime($v['authentication_end_time'])-strtotime($v['authentication_time']))<=(1*60*60*24)){
  100. $send = send_wechatSubscription_message('out_then_reminder',[$v['docter']['openid'], "pages/index/index", $v['organization']['name'],date('Y-m-d',strtotime($v['authentication_end_time']))]);
  101. }
  102. }
  103. }
  104. }
  105. /**
  106. * 订单超时自动完成(定时)
  107. */
  108. public function overTimeOrers(){
  109. $config_chat = SystemConfig::get('docter_config','chat_complete_time');
  110. $config_phone = SystemConfig::get('docter_config','phone_complete_time');
  111. // 换算为秒
  112. $config_chat = intval($config_chat)*60;
  113. $config_phone = intval($config_phone)*60;
  114. $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
  115. $catNewIds = [];
  116. $menNewIds = [];
  117. foreach ($inOrder as $k=>$v){
  118. if ($v['product_type']==1){
  119. if ((time()-$v['receiving_time'])>=$config_chat){
  120. $catNewIds[$k] = $v['id'];
  121. }
  122. }else if($v['product_type']==2){
  123. if ((time()-$v['receiving_time'])>=$config_phone){
  124. $catNewIds[$k] = $v['id'];
  125. }
  126. }else if($v['product_type']==3){
  127. if ((time()-$v['receiving_time'])>=(1*60*60*24)){
  128. $menNewIds[$k] = $v['id'];
  129. }
  130. }
  131. }
  132. if ($catNewIds || $menNewIds){
  133. // 操作图文和电话订单为已完成
  134. Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
  135. // 操作门诊订单为已超时
  136. Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
  137. }
  138. }
  139. }