overTimeOrder.php 5.1 KB

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