瀏覽代碼

定时任务修改到console下

刘远航 4 年之前
父節點
當前提交
0be5ac3b2d

+ 96 - 38
app/Console/Commands/overTimeOrder.php

xqd xqd xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Console\Commands;
 
+use App\Http\Controllers\Api\V2\PatientController;
 use App\Models\DocterOrganization;
 use App\Models\Order;
 use App\Models\SystemConfig;
@@ -47,7 +48,7 @@ class overTimeOrder extends Command
         }
         if($type == 'orderOut'){
             //订单超时
-            $this->overTimeOrers();
+            $this->clinicOverTimeOrders();
             dd('订单超时检查执行时间'.date('Y-m-d H:i:s'));
         } else if($type == 'appiontOut'){
             //预约超时
@@ -61,32 +62,44 @@ class overTimeOrder extends Command
         } else if($type == 'orderCancel'){
             $this->orderCancel();
             dd('订单接单超时检查执行时间'.date('Y-m-d H:i:s'));
+        }else if ($type = 'orderComplete'){
+            // 图文||电话订单自动完成
+            $this->timeOrdersComplete();
+        }else if ($type = "todayReminder"){
+            // 明日预约提醒
+            $this->TodayReminder();
         }
         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']]);
+     * Notes:确认超时提醒 当天的预约订单,医生还未点击完成的订单,23:00给医生发送提醒
+     * Author: 白猫!
+     * DateTime: 2021/3/4 17:45
+     * @param array $params
+     */
+    public function AppointReminder($id=''){
+        if (!empty($id)){
+            $Order = Order::with(['orderPatient','docter','user'])->where(['id'=>$id,'order_status'=>3,'payment_status'=>2])->first();
+            $send = send_wechatSubscription_message('appoint_reminder',[$Order['docter']['openid'], "pages/index/index",$Order['order_sn'],$Order['user']['nickname'],$Order['user']['phone'],$Order['created_at']]);
+        }else{
+            $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
+     * Notes:签约失效提醒
+     * Author: 白猫!
+     * DateTime: 2021/3/4 17:59
      */
     public function InvalidThenReminder(){
         $list = DocterOrganization::with('docter','organization')->get();
@@ -102,10 +115,9 @@ class overTimeOrder extends Command
 
 
     /**
-     * 认证到期提醒
-     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
-     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
-     * @throws \GuzzleHttp\Exception\GuzzleException
+     * Notes: 认证到期提醒
+     * Author: 白猫!
+     * DateTime: 2021/3/4 18:00
      */
     public function OutThenReminder(){
         $list = DocterOrganization::with('docter','organization')->get();
@@ -119,42 +131,88 @@ class overTimeOrder extends Command
     }
 
     /**
-     * 有医生接单的情况
-     * 订单超时自动完成  电话 图文 门诊(定时)
+     * Notes:明日预约提醒 (定时)
+     * Author: 白猫!
+     * DateTime: 2021/3/4 17:54
+     */
+    public function TodayReminder(){
+        $list = Order::with('docter','orderPatient','organization')->get();
+        if($list){
+            foreach ($list as $k=>$v){
+                if ($v['docter']['openid']&& date('Y-m-d',$v['order_patient']['appoint_start_time'])==date("Y-m-d",strtotime("+1 day"))){
+                    $send = send_wechatSubscription_message('today_reminder', [
+                        $v['docter']['openid'],
+                        "pages/index/index",
+                        $v['docter']['name'],
+                        date("Y-m-d",strtotime("+1 day")),
+                        "门诊预约",
+                        count($list),
+                        !empty($v['organization']['name'])?$v['organization']['name']:'',
+                    ]);
+                }
+            }
+        }
+    }
+
+
+
+
+    /**
+     * Notes:图文电话超时自动完成!
+     * Author: 白猫!
+     * DateTime: 2021/3/4 17:44
      */
-    public function overTimeOrers(){
+    public function timeOrdersComplete(){
+//        $user = $this->user;
+//        $docter_id = $user['id'];
+        $patient = new PatientController();
         $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;
-
+        $config_chat = $config_chat*60;
+        $config_phone = $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){
+                if ((time()-$v['receiving_time'])>=$config_chat){
                     $catNewIds[$k] = $v['id'];
+                    $patient->ReceivingReminderOK($v['id']);
                 }
             }else if($v['product_type']==2){
-                if ((time()-$v['receiving_time'])>=$config_chat){
-                    echo $v->order_sn.PHP_EOL;
+                if ((time()-$v['receiving_time'])>=$config_phone){
                     $catNewIds[$k] = $v['id'];
-                }
-            }else if($v['product_type']==3){
-                if ((time()-$v['receiving_time'])>=(1*60*60*24)){
-                    $menNewIds[$k] = $v['id'];
+                    $patient->ReceivingReminderOK($v['id']);
                 }
             }
 
         }
-//        echo '图文订单'.count($catNewIds).'个  ---'.'门诊订单'.count($menNewIds).'个';
-        if ($catNewIds || $menNewIds){
+        if ($catNewIds){
             // 操作图文和电话订单为已完成
             Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
+        }
+    }
+
+
+    /**
+     * Notes:门诊24小时后未确认超时
+     * Author: 白猫!
+     * DateTime: 2021/3/4 17:48
+     */
+    public function clinicOverTimeOrders(){
+        $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
+        $menNewIds = [];
+
+        foreach ($inOrder as $k=>$v){
+            if($v['product_type']==3 || $v['product_type']==4 || $v['product_type']==5){
+//                if ((time()-$v['receiving_time'])>=(1*60*60*24)){
+                $menNewIds[$k] = $v['id'];
+                $this->AppointReminder($v['id']);
+//                }
+            }
+
+        }
+        if ($menNewIds){
             // 操作门诊订单为已超时
             Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
         }

+ 1 - 1
app/Http/Controllers/Api/V2/CommonController.php

xqd
@@ -987,7 +987,7 @@ class CommonController extends Controller
         // 开始json
         $req = request()->post();
         // 首先创建记录
-        if ($req) {
+        if ($req && (isset($req[0]['called_display_no'])&&!empty($req[0]['called_display_no'])) ) {
             try {
                 $data = [];
                 $data['call_time'] = $req[0]['call_time'];

+ 2 - 112
app/Http/Controllers/Api/V2/PatientController.php

xqd xqd
@@ -731,56 +731,7 @@ class PatientController extends AuthController
             return out('', 500, '订单不可取消');
         }
     }
-
-    /**
-     * 订单超时自动完成(定时)
-     */
-    public function overTimeOrers(){
-//        $user = $this->user;
-//        $docter_id = $user['id'];
-        $config_chat =  SystemConfig::get('docter_config','chat_complete_time');
-        $config_phone =  SystemConfig::get('docter_config','phone_complete_time');
-
-        // 换算为秒
-        $config_chat = $config_chat*60;
-        $config_phone = $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()-$v['receiving_time'])>=$config_chat){
-                    $catNewIds[$k] = $v['id'];
-                    Docter::where('id', '=', $v['docter_id'])->increment('service_persons');
-                    $this->ReceivingReminderOK($v['id']);
-                }
-            }else if($v['product_type']==2){
-                if ((time()-$v['receiving_time'])>=$config_phone){
-                    $catNewIds[$k] = $v['id'];
-                    Docter::where('id', '=', $v['docter_id'])->increment('service_persons');
-                    $this->ReceivingReminderOK($v['id']);
-                }
-            }else if($v['product_type']==3 || $v['product_type']==4 || $v['product_type']==5){
-//                if ((time()-$v['receiving_time'])>=(1*60*60*24)){
-                $menNewIds[$k] = $v['id'];
-                $this->AppointReminder($v['id']);
-//                }
-            }
-
-        }
-
-        // 自动完成订单加服务人数
-//        Docter::where('id', '=', $user['id'])->increment('service_persons');
-
-        if ($catNewIds || $menNewIds){
-            // 操作图文和电话订单为已完成
-            Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
-            // 操作门诊订单为已超时
-            Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
-        }
-    }
-
+    
 
     /**
      * 获取病例信息接口!
@@ -1014,68 +965,7 @@ class PatientController extends AuthController
         }
     }
 
-    /**
-     * 认证到期提醒
-     * @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']))]);
-                }
-            }
-        }
-
-    }
-
-    /**
-     * 签约失效提醒
-     * @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']))]);
-                }
-            }
-        }
-
-    }
-
-
-    /**
-     * 明日预约提醒  8点跑定时
-     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
-     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
-     * @throws \GuzzleHttp\Exception\GuzzleException
-     */
-    public function TodayReminder(){
-        $list = Order::with('docter','orderPatient','organization')->get();
-        if($list){
-            foreach ($list as $k=>$v){
-                if ($v['docter']['openid']&& date('Y-m-d',$v['order_patient']['appoint_start_time'])==date("Y-m-d",strtotime("+1 day"))){
-                    $send = send_wechatSubscription_message('today_reminder', [
-                        $v['docter']['openid'],
-                        "pages/index/index",
-                        $v['docter']['name'],
-                        date("Y-m-d",strtotime("+1 day")),
-                        "门诊预约",
-                        count($list),
-                        !empty($v['organization']['name'])?$v['organization']['name']:'',
-                    ]);
-                }
-            }
-        }
-    }
-
+    
     /**
      * 完成订单
      * @param $order_id