overTimeOrder.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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','orderCancel'])){
  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. } else if($type == 'orderCancel'){
  56. $this->orderCancel();
  57. dd('订单接单超时检查执行时间'.date('Y-m-d H:i:s'));
  58. }
  59. dd('ok');
  60. }
  61. /**
  62. * 确认超时提醒 当天的预约订单,医生还未点击完成的订单,23:00给医生发送提醒
  63. */
  64. public function AppointReminder(){
  65. $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
  66. $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  67. $Order = Order::with(['orderPatient','docter','user'])->where(['order_status'=>3,'payment_status'=>2,'product_type'=>3])->whereBetween('receiving_time',[$beginToday,$endToday])->get();
  68. foreach ($Order as $k=>$v){
  69. if ($v['docter']){
  70. if ($v['docter']['openid']){
  71. $send = send_wechatSubscription_message('appoint_reminder',[$v['docter']['openid'], "pages/index/index",$v['order_sn'],$v['user']['nickname'],$v['user']['phone'],$v['created_at']]);
  72. }
  73. }
  74. }
  75. }
  76. /**
  77. * 签约失效提醒
  78. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  79. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  80. * @throws \GuzzleHttp\Exception\GuzzleException
  81. */
  82. public function InvalidThenReminder(){
  83. $list = DocterOrganization::with('docter','organization')->get();
  84. if($list){
  85. foreach ($list as $k=>$v){
  86. if ($v['docter']['openid']&& time()>=strtotime($v['authentication_end_time'])){
  87. $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']))]);
  88. }
  89. }
  90. }
  91. }
  92. /**
  93. * 认证到期提醒
  94. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  95. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  96. * @throws \GuzzleHttp\Exception\GuzzleException
  97. */
  98. public function OutThenReminder(){
  99. $list = DocterOrganization::with('docter','organization')->get();
  100. if($list){
  101. foreach ($list as $k=>$v){
  102. if ($v['docter']['openid']&& (strtotime($v['authentication_end_time'])-strtotime($v['authentication_time']))<=(1*60*60*24)){
  103. $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']))]);
  104. }
  105. }
  106. }
  107. }
  108. /**
  109. * 订单超时自动完成(定时)
  110. */
  111. public function overTimeOrers(){
  112. $config_chat = SystemConfig::get('docter_config','chat_complete_time');
  113. $config_phone = SystemConfig::get('docter_config','phone_complete_time');
  114. // 换算为秒
  115. $config_chat = intval($config_chat)*60;
  116. $config_phone = intval($config_phone)*60;
  117. $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
  118. $catNewIds = [];
  119. $menNewIds = [];
  120. foreach ($inOrder as $k=>$v){
  121. if ($v['product_type']==1){
  122. if ((time()-intval($v['receiving_time']))>=$config_phone){
  123. $catNewIds[$k] = $v['id'];
  124. }
  125. }else if($v['product_type']==2){
  126. if ((time()-$v['receiving_time'])>=$config_chat){
  127. echo $v->order_sn.PHP_EOL;
  128. $catNewIds[$k] = $v['id'];
  129. }
  130. }else if($v['product_type']==3){
  131. if ((time()-$v['receiving_time'])>=(1*60*60*24)){
  132. $menNewIds[$k] = $v['id'];
  133. }
  134. }
  135. }
  136. // echo '图文订单'.count($catNewIds).'个 ---'.'门诊订单'.count($menNewIds).'个';
  137. if ($catNewIds || $menNewIds){
  138. // 操作图文和电话订单为已完成
  139. Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
  140. // 操作门诊订单为已超时
  141. Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
  142. }
  143. }
  144. /**
  145. * 订单接单超时自动取消(定时)
  146. */
  147. public function orderCancel(){
  148. $config_chat = SystemConfig::get('docter_config','chat_cancel_time');
  149. $config_phone = SystemConfig::get('docter_config','phone_cancel_time');
  150. // 换算为秒
  151. $config_chat = intval($config_chat)*60;
  152. $config_phone = intval($config_phone)*60;
  153. echo $config_phone.'---'.$config_chat;
  154. $inOrder = Order::with('orderPatient')->where('product_type','<',3)->where(['order_status'=>2,'payment_status'=>2])->get();
  155. foreach ($inOrder as $k=>$v){
  156. if ($v['product_type']==1){
  157. if ((time()-$v['receiving_time'])>=$config_phone){
  158. $catNewIds[$k] = $v['id'];
  159. Order::orderCancel($v['id'],'接单超时取消');
  160. }
  161. }else if($v['product_type']==2){
  162. if ((time()-$v['receiving_time'])>=$config_chat){
  163. Order::orderCancel($v['id'],'接单超时取消');
  164. $catNewIds[$k] = $v['id'];
  165. }
  166. }
  167. }
  168. }
  169. }