argument('type'); if(!in_array($type,['orderOut','appiontOut','thenOut','thenLose','orderCancel'])){ dd('请输入正确的参数'); } if($type == 'orderOut'){ //订单超时 $this->overTimeOrers(); dd('订单超时检查执行时间'.date('Y-m-d H:i:s')); } else if($type == 'appiontOut'){ //预约超时 $this->AppointReminder(); }else if($type == 'thenOut'){ //认证到期 $this->OutThenReminder(); }else if($type == 'thenLose'){ //认证失效 $this->InvalidThenReminder(); } else if($type == 'orderCancel'){ $this->orderCancel(); dd('订单接单超时检查执行时间'.date('Y-m-d H:i:s')); } dd('ok'); } /** * 确认超时提醒 当天的预约订单,医生还未点击完成的订单,23:00给医生发送提醒 */ public function AppointReminder(){ $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; $Order = Order::with(['orderPatient','docter','user'])->where(['order_status'=>3,'payment_status'=>2,'product_type'=>3])->whereBetween('receiving_time',[$beginToday,$endToday])->get(); foreach ($Order as $k=>$v){ if ($v['docter']){ if ($v['docter']['openid']){ $send = send_wechatSubscription_message('appoint_reminder',[$v['docter']['openid'], "pages/index/index",$v['order_sn'],$v['user']['nickname'],$v['user']['phone'],$v['created_at']]); } } } } /** * 签约失效提醒 * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function InvalidThenReminder(){ $list = DocterOrganization::with('docter','organization')->get(); if($list){ foreach ($list as $k=>$v){ if ($v['docter']['openid']&& time()>=strtotime($v['authentication_end_time'])){ $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']))]); } } } } /** * 认证到期提醒 * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function OutThenReminder(){ $list = DocterOrganization::with('docter','organization')->get(); if($list){ foreach ($list as $k=>$v){ if ($v['docter']['openid']&& (strtotime($v['authentication_end_time'])-strtotime($v['authentication_time']))<=(1*60*60*24)){ $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']))]); } } } } /** * 有医生接单的情况 * 订单超时自动完成 电话 图文 门诊(定时) */ public function overTimeOrers(){ $config_chat = SystemConfig::get('docter_config','chat_complete_time'); $config_phone = SystemConfig::get('docter_config','phone_complete_time'); // 换算为秒 $config_chat = intval($config_chat)*60; $config_phone = intval($config_phone)*60; $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get(); $catNewIds = []; $menNewIds = []; foreach ($inOrder as $k=>$v){ if ($v['product_type']==1){ if ((time()-intval($v['receiving_time']))>=$config_phone){ $catNewIds[$k] = $v['id']; } }else if($v['product_type']==2){ if ((time()-$v['receiving_time'])>=$config_chat){ echo $v->order_sn.PHP_EOL; $catNewIds[$k] = $v['id']; } }else if($v['product_type']==3){ if ((time()-$v['receiving_time'])>=(1*60*60*24)){ $menNewIds[$k] = $v['id']; } } } // echo '图文订单'.count($catNewIds).'个 ---'.'门诊订单'.count($menNewIds).'个'; if ($catNewIds || $menNewIds){ // 操作图文和电话订单为已完成 Order::whereIn('id',$catNewIds)->update(['order_status'=>4]); // 操作门诊订单为已超时 Order::whereIn('id',$menNewIds)->update(['order_status'=>6]); } } /** * 没有医生接单的情况 * 订单接单超时自动取消 电话 图文(定时) */ public function orderCancel(){ $config_chat = SystemConfig::get('docter_config','chat_cancel_time'); $config_phone = SystemConfig::get('docter_config','phone_cancel_time'); // 换算为秒 $config_chat = intval($config_chat)*60; $config_phone = intval($config_phone)*60; $inOrder = Order::with('orderPatient')->with('orderUser')->with('docter')->where('product_type','<',3)->where(['order_status'=>2,'payment_status'=>2])->get(); foreach ($inOrder as $k=>$v){ if ($v['product_type']==1){ if ((time()-intval($v['payment_time']))>=$config_phone){ $catNewIds[$k] = $v['id']; $res = Order::orderCancel($v['id'],'医生超时未接单自动取消'); //取消成功才发送消息 if($res){ $this->cancelUserMsg($v); $this->cancelDocterMsg($v); } } }else if($v['product_type']==2){ if ((time()-intval($v['payment_time']))>=$config_chat){ $res = Order::orderCancel($v['id'],'医生超时未接单自动取消'); //取消成功才发送消息 if($res){ $this->cancelUserMsg($v); $this->cancelDocterMsg($v); } } } } } public function cancelUserMsg($order) { $openid = $order->orderUser->openid; $pt = Order::getProductType(); $type = $pt[$order->product_type]; $msgArr = [ $openid, $order->order_sn, $type, ($order->payment_amount/100), // $order->created_at, date('Y-m-d H:i:s'), $order->orderPatient->name, $order->docter->name.'医生', '医生超时未接单自动取消', '订单状态:已退款 ', ]; $minArr = [$openid,$order->order_sn,$type,'医生超时未接单自动取消']; send_wechat_message(7,$msgArr,$minArr); } public function cancelDocterMsg($order) { $openid = $order->docter->openid; // $openid = 'oflME5eixHMij2TIVyy52WbfaQvA'; $pt = Order::getProductType(); $type = $pt[$order->product_type]; $msgArr = [ $openid, '', $order->docter->name, $order->order_sn, $type, ($order->payment_amount/100).'元', // $order->created_at, date('Y-m-d H:i:s'), '医生超时未接单自动取消', ]; $res = send_wechatSubscription_message('cancel_reminder',$msgArr); } }