فهرست منبع

Merge branch 'master' of http://git.9026.com/swdz-WangHaijun/BaoMa

whj 4 سال پیش
والد
کامیت
25b6c81586

+ 3 - 2
app/Admin/Actions/backstage/Refund/RefundCompleteAction.php

xqd
@@ -15,12 +15,13 @@ class RefundCompleteAction extends RowAction
 
     public function handle(Model $model)
     {
+        $money = Order::where('id',$this->row->order_id)->value('payment_amount');
         Order::where('id',$this->row->order_id)->update(['payment_status'=> 4]);
         RefundApplication::where('id',$this->row->id)->update([ 'end_time'=>date('Y-m-d H:i:s',time()),
                                                                 'financial_auditor'=>\Admin::user()->id,
-                                                                'status'=>2]);
+                                                                'status'=>2,
+                                                                'refund_amount'=> $money]);
         $user_id = Order::where('id',$this->row->order_id)->value('user_id');
-        $money = Order::where('id',$this->row->order_id)->value('payment_amount');
         $balance = User::where('id',$user_id)->value('balance');
         $new_balance = $balance+$money;
         User::where('id',$user_id)->update(['balance'=>$new_balance]);

+ 58 - 0
app/Admin/Actions/backstage/Refund/RefundPartCompleteAction.php

xqd
@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Admin\Actions\backstage\Refund;
+
+use App\Models\Order;
+use App\Models\RefundApplication;
+use App\Models\UserBalanceLog;
+use App\User;
+use Encore\Admin\Actions\RowAction;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Http\Request;
+
+class RefundPartCompleteAction extends RowAction
+{
+    public $name = '部分退款完成';
+
+    public function handle(Model $model,Request $request)
+    {
+        $num = request('num');
+        $num = $num*100;
+        $total =  Order::where('id',$this->row->order_id)->value('payment_amount');
+        if ($num>=$total)
+        {
+            return $this->response()->error('部分退款金额不得大于订单金额')->refresh();
+        }
+        if ($num<0)
+        {
+            return $this->response()->error('部分退款金额不得小于0')->refresh();
+        }
+        Order::where('id',$this->row->order_id)->update(['payment_status'=> 4]);
+        RefundApplication::where('id',$this->row->id)->update([ 'end_time'=>date('Y-m-d H:i:s',time()),
+            'financial_auditor'=>\Admin::user()->id,
+            'status'=>2,
+            'refund_amount'=> $num
+        ]);
+        $user_id = Order::where('id',$this->row->order_id)->value('user_id');
+        $balance = User::where('id',$user_id)->value('balance');
+        $new_balance = $balance+$num;
+        User::where('id',$user_id)->update(['balance'=>$new_balance]);
+        $balance_log = [
+            'user_id' => $user_id,
+            'admin_user_id' => \Admin::user()->id,
+            'type' => 4,
+            'relation_id' => $this->row->order_id,
+            'before_balance' => $balance,
+            'change_balance' => '+'.$num,
+            'after_balance' => $new_balance,
+            'remark'=>'订单部分退款'
+        ];
+        UserBalanceLog::create($balance_log);
+        return $this->response()->success('退款成功')->refresh();
+    }
+    public function form(){
+        $total =  Order::where('id',$this->row->order_id)->value('payment_amount');
+        $this->text('total','当前订单金额')->value($total/100)->disable();
+        $this->text('num','部分退款金额')->help('部分退款金额应小于订单金额');
+    }
+}

+ 22 - 1
app/Admin/Controllers/OrdersManagement/BookingOrderController.php

xqd xqd
@@ -3,6 +3,8 @@
 namespace App\Admin\Controllers\OrdersManagement;
 
 use App\Admin\Actions\backstage\Orders\Evaluate;
+use App\Admin\Actions\backstage\Orders\RefundApplicationAction;
+use App\Admin\Actions\backstage\Refund\RefundCompleteAction;
 use App\Models\Order;
 use App\Admin\Actions\backstage\Orders\OrderDetails;
 use App\Models\OrderPack;
@@ -69,7 +71,26 @@ class BookingOrderController extends AdminController
             });
         });
 
-        $grid->disableActions();
+        $grid->actions(function ($actions){
+            // 1.门诊预约和儿保预约有退款操作
+            $actions->disableView();
+            $actions->disableEdit();
+            $actions->disableDelete();
+            if ($actions->row->product_type == 3 || $actions->row->product_type == 5)
+            {
+                if (
+                    //已取消 待退款
+                    ($actions->row->order_status == 5 && $actions->row->payment_status == 5)||
+                    //已超时 已支付
+                    ($actions->row->order_status == 6 && $actions->row->payment_status == 2)){
+                    $actions->add(new RefundApplicationAction());
+                }
+            }
+            //有问题 未支付是订单状态,这里冲突了
+//            if ($actions->row->product_type == 5 && $actions->row->order_status == 5 && $actions->row->payment_status == 2){
+//
+//            }
+        });
         $grid->model()->orderBy('id','desc');
         $grid->column('id', __('Id'))->sortable();
         $grid->column('user.nickname', __('用户姓名'));

+ 3 - 7
app/Admin/Controllers/OrdersManagement/ConsultingOrdersController.php

xqd xqd xqd
@@ -79,10 +79,6 @@ class ConsultingOrdersController extends AdminController
             $actions->disableView();
             $actions->disableEdit();
             $actions->disableDelete();
-           if ($actions->row->order_status == 6 && $actions->row->payment_status !=3 &&$actions->row->payment_status !=4)
-           {
-               $actions->add(new RefundApplicationAction());
-           }
         });
         $grid->model()->orderBy('id','desc');
         $grid->column('id', __('Id'))->sortable();
@@ -91,7 +87,7 @@ class ConsultingOrdersController extends AdminController
         $grid->column('orderPatient.name', __('患者姓名'));
         $grid->column('orderPatient.patient_phone', __('患者电话'));
         $grid->column('orderPatient.symptoms', __('患者描述'));
-        $grid->column('product_type', __('产品类型'))->using([1=>'电话咨询',2=>'图文咨询']);
+        $grid->column('product_type', __('产品类型'))->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值',8=>'快速预约']);
         $grid->column('payment_type', __('支付方式'))->display(function ($payment_type){
             if ($payment_type == 1)
             {
@@ -106,8 +102,8 @@ class ConsultingOrdersController extends AdminController
                 return '服务包支付('.$name[0].')';
             }
         });
-        $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消',6=>'已超时']);
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款']);
+        $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消',6=>'已超时',7=>'已预约']);
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款']);
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });

+ 9 - 14
app/Admin/Controllers/OrdersManagement/RefundApplicationController.php

xqd xqd xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Admin\Controllers\OrdersManagement;
 
 use App\Admin\Actions\backstage\Refund\RefundCompleteAction;
+use App\Admin\Actions\backstage\Refund\RefundPartCompleteAction;
 use App\Models\Organization;
 use App\Models\Patient;
 use App\Models\RefundApplication;
@@ -41,6 +42,7 @@ class RefundApplicationController extends AdminController
            {
                if (\Admin::user()->isRole('financial_staff')){
                    $actions->add(new RefundCompleteAction());
+                   $actions->add(new RefundPartCompleteAction());
                }
            }
         });
@@ -55,21 +57,16 @@ class RefundApplicationController extends AdminController
             $name = Patient::where('id',$id)->value('name');
             return $name;
         });
-        $grid->column('orders.organization_id', __('机构名'))->display(function ($id){
-            if ($id == 0 )
-            {
-                return '';
-            }
-            else
-            {
-                $name = Organization::where('id',$id)->value('name');
-                return $name;
-            }
+        $grid->column('orders.product_type','产品类型')->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值',8=>'快速预约']);
+        $grid->column('orders.order_notes','取消备注');
+        $grid->column('orders.order_status','订单状态')->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
+        $grid->column('status', __('退款状态'))->using([1=>'退款中',2=>'已退款']);
+        $grid->column('orders.payment_amount', __('订单金额'))->display(function ($money){
+            return $money/100;
         });
-        $grid->column('orders.payment_amount', __('退款金额'))->display(function ($money){
+        $grid->column('refund_amount', __('退款金额'))->display(function ($money){
             return $money/100;
         });
-        $grid->column('status', __('退款状态'))->using([1=>'退款中',2=>'退款完成']);
         $grid->column('refund_applicant', __('退款申请人员'))->display(function ($id){
             $name = Administrator::where('id',$id)->value('name');
             return $name;
@@ -89,8 +86,6 @@ class RefundApplicationController extends AdminController
                 return $time;
             }
         });
-        $grid->column('updated_at', __('更新时间'));
-
         return $grid;
     }
 

+ 72 - 0
app/Admin/Controllers/ServicePacksManagment/InsuranceAgreementController.php

xqd
@@ -0,0 +1,72 @@
+<?php
+
+namespace App\Admin\Controllers\ServicePacksManagment;
+
+use App\Models\InsuranceAgreement;
+use Encore\Admin\Controllers\AdminController;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Show;
+
+class InsuranceAgreementController extends AdminController
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title = '保险协议列表';
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new InsuranceAgreement());
+        $grid->disableBatchActions();
+        $grid->actions(function ($actions){
+           $actions->disableView();
+        });
+        $grid->column('id', __('Id'));
+        $grid->column('name', __('协议名称'));
+        $grid->column('content', __('协议内容'))->limit(20,'...');
+        $status = [
+            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
+            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
+        ];
+        $grid->column('status', __('状态'))->switch($status);
+        $grid->column('created_at', __('创建时间'));
+        $grid->column('updated_at', __('更新时间'));
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new InsuranceAgreement());
+
+        $form->text('name', __('协议名称'));
+        $form->editor('content', __('协议内容'));
+        $status = [
+            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
+            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
+        ];
+        $form->switch('status', __('状态'))->states($status)->default(1);
+
+        return $form;
+    }
+}

+ 5 - 1
app/Admin/Controllers/ServicePacksManagment/ServicePacksController.php

xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\ServicePacksManagment;
 
+use App\Models\InsuranceAgreement;
 use App\Models\Nurse;
 use App\Models\ServicePack;
 use App\Models\Team;
@@ -69,6 +70,7 @@ class ServicePacksController extends AdminController
 
         $grid->column('image','图片')->lightbox(['width' =>'', 'height' => 30]);
         $grid->column('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
+        $grid->column('insuranceagreement.name', __('保险协议名称'));
         $grid->column('phone_minutes', __('电话次数'));
         $grid->column('chat_num', __('图文次数'));
         $grid->column('appoint_num', __('门诊次数'));
@@ -99,7 +101,9 @@ class ServicePacksController extends AdminController
         $form->radio('is_need_insure', __('服务包是否包含保险'))->options([
             0=>'否',
             1=>'是'
-        ])->rules('required',['required'=>'请选择是否包含保险']);
+        ])->when(1,function (Form $form){
+            $form->select('agreement_id','协议名称')->options(InsuranceAgreement::pluck('name','id'))->rules('required',['required'=>'请选择协议名称']);
+        })->rules('required',['required'=>'请选择是否包含保险']);
         $form->radio('is_need_team', __('是否包含团队'))->options([
             0=>'否',
             1=>'是'

+ 1 - 1
app/Admin/Controllers/WeChatProgram/UserManagement/IconsUserController.php

xqd
@@ -77,7 +77,7 @@ class IconsUserController extends AdminController
 
         $form->text('name', __('名称'))->rules('required' ,['required'=>'请填写名称!']);
         $form->image('image', __('图片'))->rules('required' ,['required'=>'请选择图片!']);
-        $form->text('url', __('点击地址'))->rules('required',['requried'=>'请填写点击地址']);
+        $form->text('url', __('点击地址'));
         $form->hidden('type_cl')->default(1);
         $form->select('type', __('分类'))->options(Icons::$_post_type)->default(1);
         $form->number('laval', __('顺序'));

+ 2 - 0
app/Admin/routes.php

xqd
@@ -67,6 +67,8 @@ Route::group([
     //开通记录
     $router->resource('open_pack', ServicePacksManagment\OpenPackController::class);
 
+    $router->resource('insurance_agreements', ServicePacksManagment\InsuranceAgreementController::class);
+
     $router->resource('/setting', 'Config\ConfigController');
     $router->get('/setting_form', 'Config\FormController@form');
     $router->post('/setting_form_save', 'Config\FormController@setting_form_save');

+ 18 - 0
app/Helpers/functions.php

xqd
@@ -558,3 +558,21 @@ if (!function_exists('send_wechat_message')) {
         return $ret ?? false;
     }
 }
+
+// 医生端发送公众号模板消息方法
+if (!function_exists('send_wechatSubscription_message')) {
+    function send_wechatSubscription_message($type, $arr)
+    {
+        try {
+            $app = Factory::officialAccount(config('config.docter_wechat_officialAccount'));
+            $data = config('config.wechatSubscription_template')[$type];
+            $json = json_encode($data, JSON_UNESCAPED_UNICODE);
+            $json = vsprintf($json, $arr);
+            $data = json_decode($json, true);
+            $result = $app->template_message->send($data);
+        } catch (Exception $e) {
+            trace(['发送微信模板消息失败' => $e->getMessage(), '请求参数' => $data ?? '', '返回数据' => $result ?? ''], 'error');
+        }
+        return $result ?? false;
+    }
+}

+ 6 - 0
app/Http/Controllers/Api/V2/CommonController.php

xqd xqd
@@ -1108,6 +1108,8 @@ class CommonController extends Controller
                     $newList[$k] = $v['messageId'];
                 }
             }
+            $reminderController = new PatientController();
+
             $list = [];
             if($data){
                 foreach ($data as $k=>$v){
@@ -1120,6 +1122,10 @@ class CommonController extends Controller
                         $list[$k]['payload'] = $v['payload'];
                         $list[$k]['text'] = $req['content'];
                         $list[$k]['create_time'] = time();
+                        if (substr($v['senderId'],0,6)!='doctor'){
+                            // 说明是用户给医生发的
+                            $reminderController->ReplyReminder(substr($v['receiverId'],7),substr($v['senderId'],7));
+                        }
                     }
                 }
                 ImMessage::insert($list);

+ 12 - 0
app/Http/Controllers/Api/V2/DoctorController.php

xqd xqd xqd xqd xqd
@@ -885,6 +885,12 @@ class DoctorController extends AuthController
             $is_del = true;
         }
         $org_list = [];
+        $Reminder = new PatientController();
+        // 医院
+        $orgs = Organization::where('id',$work[0]['hospital'])->first('name');
+        $offs = Office::where('id',$work[0]['department'])->first('name');
+        $quals = Qualification::where('id',$work[0]['qualifications'])->first('name');
+        $Reminder->ThenReminder($doctor_id,$orgs['name'].'社区 - '.$offs['name'].'科室 - '.$quals['name'].'主任',date('Y-m-d H:i:s',time()));
         foreach ($work as $k => $v) {
             if ($v['hospital']) {
                 $org_list[$k]['docter_id'] = $doctor_id;
@@ -1994,6 +2000,7 @@ class DoctorController extends AuthController
         $Wheres[] = ['schedule_date','>=',date('Y-m-d',time())];
         $meSureList = SchedulePeriod::where($Wheres)->get();
         $moth_date = $this->date_bool();
+        $Reminder = new PatientController();
         $delDate = [];
         $delDate2 = [];
         $schedule_ids = [];
@@ -2112,6 +2119,8 @@ class DoctorController extends AuthController
             }
             SchedulePeriod::insert($scheduleLists);
             WeekSchedule::insert($weekList);
+            $Reminder->ScheduleReminder($doctor_id,0);
+
             DB::commit();
             return out();
         } catch (\Exception $e) {
@@ -2148,6 +2157,7 @@ class DoctorController extends AuthController
             $flag = true;
             $req = $data;
         }
+        $Reminder = new PatientController();
         $user = $this->user;
         $doctor_id = $user['id'];
         $save_data = [];
@@ -2237,10 +2247,12 @@ class DoctorController extends AuthController
                 }
             }
 
+
             DB::commit();
             if ($flag) {
                 return true;
             } else {
+                $Reminder->ScheduleReminder($doctor_id,1);
                 return out();
             }
         } catch (\Exception $e) {

+ 461 - 224
app/Http/Controllers/Api/V2/PatientController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -16,15 +16,15 @@ use App\Models\OrderPatient;
 use App\Models\DocterOrganization;
 use App\Models\SchedulePeriod;
 use App\Models\Suggest;
-use App\Models\SystemConfig;
 use App\Models\User;
 use App\Models\UserMessages;
 use App\Models\Organization;
 use App\Http\Controllers\Api\V2\CommonController as Commons;
 use Illuminate\Support\Facades\DB;
 use App\Models\Axb;
+use App\Models\SystemConfig;
 use App\Models\CallPhone;
-
+use EasyWeChat\Factory;
 /**
  * 咨询订单用户类
  * Class PatientController
@@ -34,6 +34,7 @@ class PatientController extends AuthController
 {
     protected $relationSearch = true;
 
+
     /**
      * @return mixed
      * 患者咨询列表
@@ -46,58 +47,58 @@ class PatientController extends AuthController
             'curPage' => 'required|integer',
             'pageSize' => 'required|integer',
         ]);
-        $pageSize = ($req['curPage']-1)*$req['pageSize'];
+        $pageSize = ($req['curPage'] - 1) * $req['pageSize'];
         $user = $this->user;
         $doctor_id = $user['id'];
         $where = [];
-        $order=['created_at','desc'];
+        $order = ['created_at', 'desc'];
 
         $where['docter_id'] = $doctor_id;
-        if (isset($req['appointment']) && $req['appointment']==1){
+        if (isset($req['appointment']) && $req['appointment'] == 1) {
             // 门诊预约
             $where['product_type'] = 3;
-            if (isset($req['timeSort']) && $req['timeSort']=='0') {
-                $order = ['order_patients.appoint_start_time','asc']; //预约时间正序
+            if (isset($req['timeSort']) && $req['timeSort'] == '0') {
+                $order = ['order_patients.appoint_start_time', 'asc']; //预约时间正序
             }
-            if (isset($req['timeSort']) && $req['timeSort']=='1') {
-                $order= ['order_patients.appoint_start_time','desc']; //预约时间倒叙
+            if (isset($req['timeSort']) && $req['timeSort'] == '1') {
+                $order = ['order_patients.appoint_start_time', 'desc']; //预约时间倒叙
             }
-            if (isset($req['timeSort']) && $req['timeSort']=='2') {
-                $order = ['created_at','asc']; //下单时间正序
+            if (isset($req['timeSort']) && $req['timeSort'] == '2') {
+                $order = ['created_at', 'asc']; //下单时间正序
             }
-            if (isset($req['timeSort']) && $req['timeSort']=='3') {
-                $order = ['created_at','desc']; //下单时间倒叙
+            if (isset($req['timeSort']) && $req['timeSort'] == '3') {
+                $order = ['created_at', 'desc']; //下单时间倒叙
             }
 
-            if (isset($req['comStatus']) && $req['comStatus']=='0') {
-                $comstatus = [1,2,3];
-                $where[] = [function($query) use ($comstatus){
+            if (isset($req['comStatus']) && $req['comStatus'] == '0') {
+                $comstatus = [1, 2, 3];
+                $where[] = [function ($query) use ($comstatus) {
                     $query->whereIn('order_status', $comstatus);//处理中
                 }];
             }
-            if (isset($req['comStatus']) && $req['comStatus']=='1') {
+            if (isset($req['comStatus']) && $req['comStatus'] == '1') {
                 $where['order_status'] = 4; //已完成
 
             }
-        }else{
+        } else {
             // 图文和电话的
-            $ids = [1,2];
-            $where[] = [function($query) use ($ids){
+            $ids = [1, 2];
+            $where[] = [function ($query) use ($ids) {
                 $query->whereIn('product_type', $ids);
             }];
-            if(isset($req['typeAll']) && $req['typeAll']==1){
-                $where['product_type']=2;//图文咨询
+            if (isset($req['typeAll']) && $req['typeAll'] == 1) {
+                $where['product_type'] = 2;//图文咨询
             }
-            if(isset($req['typeAll']) && $req['typeAll']==2){
-                $where['product_type']=1;//电话咨询
+            if (isset($req['typeAll']) && $req['typeAll'] == 2) {
+                $where['product_type'] = 1;//电话咨询
             }
-            if(isset($req['processing']) && $req['processing']==0){
-                $status = [1,2,3];
-                $where[] = [function($query) use ($status){
+            if (isset($req['processing']) && $req['processing'] == 0) {
+                $status = [1, 2, 3];
+                $where[] = [function ($query) use ($status) {
                     $query->whereIn('order_status', $status);//处理中
                 }];
             }
-            if(isset($req['processing']) && $req['processing']==1){
+            if (isset($req['processing']) && $req['processing'] == 1) {
                 $where['order_status'] = 4; //历史记录,已完成订单
             }
         }
@@ -107,31 +108,31 @@ class PatientController extends AuthController
 //            $query->orderBy($orders[0],$orders[1]);
 //        }])->where($where)->orderBy($order[0],$order[1])->skip($pageSize)->take($req['pageSize'])->groupBy('id')->get()->toArray();
         $data = DB::table('orders')
-                ->leftJoin('order_patients','order_patients.order_id','=','orders.id')
-                ->select(['orders.*','order_patients.birthday as obirthday','order_patients.appoint_start_time','order_patients.name as oanme'])
-                ->where($where)->orderBy($order[0],$order[1])
-                ->skip($pageSize)->take($req['pageSize'])
-                ->groupBy('id')
-                ->get()->toArray();
+            ->leftJoin('order_patients', 'order_patients.order_id', '=', 'orders.id')
+            ->select(['orders.*', 'order_patients.birthday as obirthday', 'order_patients.appoint_start_time', 'order_patients.name as oanme'])
+            ->where($where)->orderBy($order[0], $order[1])
+            ->skip($pageSize)->take($req['pageSize'])
+            ->groupBy('id')
+            ->get()->toArray();
 
 //        $data = Order::with('orderPatient')->where($where)->skip($pageSize)->take($req['pageSize'])->groupBy('id')->toSql();
 //        $data = OrderPatient::with("order")->where('id', $user['id'])->orderBy('id', 'desc')->limit($pageSize,$req['pageSize'])->get()->toarray();
         $list = [];
         try {
 
-            foreach ($data as $k=>$v){
+            foreach ($data as $k => $v) {
                 $v = get_object_vars($v);
-                if (!$v['obirthday']){
+                if (!$v['obirthday']) {
                     unset($list[$k]);
-                }else{
+                } else {
                     $list[$k]['id'] = $v['id'];
                     $list[$k]['user_id'] = $v['user_id'];
                     $list[$k]['order_sn'] = $v['order_sn'];
                     $list[$k]['zl'] = $v['product_type'];
                     $list[$k]['zt'] = $v['order_status'];
-                    unset($list[$k]['order_status'],$list[$k]['product_type']);
+                    unset($list[$k]['order_status'], $list[$k]['product_type']);
                     $list[$k]['created_at'] = $v['created_at'];
-                    $list[$k]['appoint_time'] = empty($v['appoint_start_time'])?'---':date('Y-m-d H:i:s',$v['appoint_start_time']);
+                    $list[$k]['appoint_time'] = empty($v['appoint_start_time']) ? '---' : date('Y-m-d H:i:s', $v['appoint_start_time']);
                     $list[$k]['name'] = $v['oanme'];
                     $list[$k]['birthday'] = numBirthday($v['obirthday']);
                 }
@@ -139,16 +140,18 @@ class PatientController extends AuthController
             }
 
             return out($list);
-        }catch (\Exception $e){
-            return out($e->getFile().'中第 '.$e->getLine().'行发生了 '.$e->getMessage().'错误');
+        } catch (\Exception $e) {
+            return out($e->getFile() . '中第 ' . $e->getLine() . '行发生了 ' . $e->getMessage() . '错误');
         }
         return out($list);
     }
 
 
-    public function mzPutOrder(){
+    public function mzPutOrder()
+    {
 
     }
+
     /**
      * @return mixed
      * 完成订单
@@ -165,16 +168,16 @@ class PatientController extends AuthController
 
         ]);
         $user = $this->user;
-        $find = Order::where('id','=',$req['order_id'])->first()->toArray();
-        if (!$find){
-            return out('',500,'订单错误!');
+        $find = Order::where('id', '=', $req['order_id'])->first()->toArray();
+        if (!$find) {
+            return out('', 500, '订单错误!');
         }
-        if ($find['order_status']>3){
-            return out('',500,'此订单不可操作!');
+        if ($find['order_status'] > 3) {
+            return out('', 500, '此订单不可操作!');
 
         }
         $lable = '';
-        switch ($find['product_type']){
+        switch ($find['product_type']) {
             case 1:
                 $lable = '电话咨询';
                 break;
@@ -200,28 +203,28 @@ class PatientController extends AuthController
         if ($find['product_type'] == 1 || $find['product_type'] == 2) {
             // 需要有意见单的
             $suggests = Suggest::create([
-                'order_id'=> $find['id'],
-                'user_id'=> $find['user_id'],
-                'symptoms'=> $req['symptoms'],
-                'pathogen'=> $req['pathogen'],
-                'suggest'=> $req['suggest'],
-                'patient_id'=> $req['patient_id']
+                'order_id' => $find['id'],
+                'user_id' => $find['user_id'],
+                'symptoms' => $req['symptoms'],
+                'pathogen' => $req['pathogen'],
+                'suggest' => $req['suggest'],
+                'patient_id' => $req['patient_id']
             ]);
             $suggests = $suggests->toArray();
-            $relation_id= $suggests['id'];
-        }else{
-            $relation_id= 0;
+            $relation_id = $suggests['id'];
+        } else {
+            $relation_id = 0;
         }
 
 
         $status = $find['product_type'];
-        $lab='';
+        $lab = '';
         $mesid = $relation_id;
-        if ($status==1){
+        if ($status == 1) {
             $lab = '电话咨询';
-        }else if ($status==2){
+        } else if ($status == 2) {
             $lab = '图文咨询';
-        }else if($status==3){
+        } else if ($status == 3) {
             $mesid = $find['id'];
             $lab = '门诊预约';
         }
@@ -235,29 +238,29 @@ class PatientController extends AuthController
             Docter::where('id', '=', $user['id'])->increment('service_persons');
             // 添加到用户记录中!
             UserMessages::create([
-                'user_id'=>$find['user_id'],
-                'docter_id'=>$user['id'],
-                'status'=>1,
-                'type'=>2,
-                'relation_id'=>$mesid,
-                'content'=>"您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认完成(点击查看意见单)",
+                'user_id' => $find['user_id'],
+                'docter_id' => $user['id'],
+                'status' => 1,
+                'type' => 2,
+                'relation_id' => $mesid,
+                'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认完成(点击查看意见单)",
             ]);
             DB::commit();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             DB::rollBack();
-            return out('',500,$e->getMessage());
-        }catch (\PDOException $e){
+            return out('', 500, $e->getMessage());
+        } catch (\PDOException $e) {
             DB::rollBack();
-            return out('',500,$e->getMessage());
+            return out('', 500, $e->getMessage());
         }
 
         $axbwhere['docter_id'] = $user['id'];
         $axbwhere['user_id'] = $req['user_id'];
-        $finds = Axb::where($axbwhere)->orderBy('id','desc')->first();
+        $finds = Axb::where($axbwhere)->orderBy('id', 'desc')->first();
 
-        if ($status==1 && $finds){
-            $unlok = (new Commons())->unLokPhone($finds['xphone'],$finds['subs_id']);
-            Axb::where(['subs_id'=>$finds['subs_id']])->delete();
+        if ($status == 1 && $finds) {
+            $unlok = (new Commons())->unLokPhone($finds['xphone'], $finds['subs_id']);
+            Axb::where(['subs_id' => $finds['subs_id']])->delete();
         }
 
         return out();
@@ -277,16 +280,16 @@ class PatientController extends AuthController
             'order_id|订单id' => 'required|integer',
         ]);
         $user = $this->user;
-        $find = Order::where('id','=',$req['order_id'])->first()->toArray();
-        if (!$find){
-            return out('',500,'订单错误!');
+        $find = Order::where('id', '=', $req['order_id'])->first()->toArray();
+        if (!$find) {
+            return out('', 500, '订单错误!');
         }
-        if ($find['order_status']>3){
-            return out('',500,'此订单不可操作!');
+        if ($find['order_status'] > 3) {
+            return out('', 500, '此订单不可操作!');
 
         }
         $lable = '';
-        switch ($find['product_type']){
+        switch ($find['product_type']) {
             case 1:
                 $lable = '电话咨询';
                 break;
@@ -306,17 +309,17 @@ class PatientController extends AuthController
                 $lable = '服务包';
                 break;
             default:
-                $lable ='参数错误!';
+                $lable = '参数错误!';
         }
-        $relation_id= 0;
+        $relation_id = 0;
         $status = $find['product_type'];
-        $lab='';
+        $lab = '';
         $mesid = $relation_id;
-        if ($status==1){
+        if ($status == 1) {
             $lab = '电话咨询';
-        }else if ($status==2){
+        } else if ($status == 2) {
             $lab = '图文咨询';
-        }else if($status==3){
+        } else if ($status == 3) {
             $mesid = $find['id'];
             $lab = '门诊预约';
         }
@@ -324,24 +327,24 @@ class PatientController extends AuthController
         $doctername = $user['name'];
         DB::beginTransaction();
         try {
-            Order::where('id','=',$req['order_id'])->update(['order_status'=>4,'updated_at'=>date('Y-m-d H:i:s',time()),'end_time'=>time()]);
-            Docter::where('id','=',$user['id'])->increment('service_persons');
+            Order::where('id', '=', $req['order_id'])->update(['order_status' => 4, 'updated_at' => date('Y-m-d H:i:s', time()), 'end_time' => time()]);
+            Docter::where('id', '=', $user['id'])->increment('service_persons');
             // 添加到用户记录中!
             UserMessages::create([
-                'user_id'=>$find['user_id'],
-                'docter_id'=>$user['id'],
-                'status'=>1,
-                'type'=>2,
-                'relation_id'=>$mesid,
-                'content'=>"您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认完成(点击查看订单)",
+                'user_id' => $find['user_id'],
+                'docter_id' => $user['id'],
+                'status' => 1,
+                'type' => 2,
+                'relation_id' => $mesid,
+                'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认完成(点击查看订单)",
             ]);
             DB::commit();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             DB::rollBack();
-            return out('',500,$e->getMessage());
-        }catch (\PDOException $e){
+            return out('', 500, $e->getMessage());
+        } catch (\PDOException $e) {
             DB::rollBack();
-            return out('',500,$e->getMessage());
+            return out('', 500, $e->getMessage());
         }
 
         return out();
@@ -352,59 +355,59 @@ class PatientController extends AuthController
      * 接单
      * @author Yuanhang Liu & Xiaoyun Liu
      */
-    public function putOrderPatient(){
+    public function putOrderPatient()
+    {
         $req = request()->post();
         $this->validate(request(), [
             'order_id|订单id' => 'required|integer',
         ]);
         $user = $this->user;
 
-        $find = Order::where('id','=',$req['order_id'])->first()->toArray();
+        $find = Order::where('id', '=', $req['order_id'])->first()->toArray();
         $status = $find['product_type'];
-        $lab='';
-        if ($status==1){
+        $lab = '';
+        if ($status == 1) {
             $lab = '电话咨询';
-        }else if ($status==2){
+        } else if ($status == 2) {
             $lab = '图文咨询';
-        }else if($status==3){
+        } else if ($status == 3) {
             $lab = '门诊预约';
         }
         $order_sn = $find['order_sn'];
         $order_id = $find['id'];
         $doctername = $user['name'];
-//        1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值
-
-        if (!$find){
-            return out('',500,'订单错误!');
+        if (!$find) {
+            return out('', 500, '订单错误!');
         }
-        if ($find['order_status']!=2){
-            return out('',500,'此订单已被接单或未付款!');
+        if ($find['order_status'] != 2) {
+            return out('', 500, '此订单已被接单或未付款!');
         }
-        if ($find['payment_status']>=4){
-            return out('',500,'此订单可能已完成!');
+        if ($find['payment_status'] >= 4) {
+            return out('', 500, '此订单可能已完成!');
         }
         DB::beginTransaction();
         try {
-            Order::where('id','=',$req['order_id'])->update(['order_status'=>3,'updated_at'=>date('Y-m-d H:i:s',time()),'receiving_time'=>time()]);
+            Order::where('id', '=', $req['order_id'])->update(['order_status' => 3, 'updated_at' => date('Y-m-d H:i:s', time()), 'receiving_time' => time()]);
             // 添加到用户记录中!
             UserMessages::create([
-                'user_id'=>$find['user_id'],
-                'docter_id'=>$user['id'],
-                'status'=>1,
-                'type'=>1,
-                'relation_id'=>$order_id,
-                'content'=> "您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认接单(点击查看订单详情)",
+                'user_id' => $find['user_id'],
+                'docter_id' => $user['id'],
+                'status' => 1,
+                'type' => 1,
+                'relation_id' => $order_id,
+                'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认接单(点击查看订单详情)",
             ]);
             DB::commit();
+            $this->ReceivingReminder($req['order_id']);
             return out();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
 
             DB::rollBack();
-            return out('',500,$e->getMessage());
-        }catch (\PDOException $e){
+            return out('', 500, $e->getMessage());
+        } catch (\PDOException $e) {
 
             DB::rollBack();
-            return out('',500,$e->getMessage());
+            return out('', 500, $e->getMessage());
         }
     }
 
@@ -421,7 +424,7 @@ class PatientController extends AuthController
         ]);
         $data = [];
         // 订单查询
-        $data = Order::with(['orderPatient','user','calllog'])->where('id', $req['patient_id'])->first()->toArray();
+        $data = Order::with(['orderPatient', 'user', 'calllog'])->where('id', $req['patient_id'])->first()->toArray();
 
         // 通话记录查询
         $datas = CallLog::where('order_id', $req['patient_id'])->get();
@@ -431,39 +434,40 @@ class PatientController extends AuthController
         $doctor_id = (new Commons)->getUserIdByDoctorId($user['phone']);
         // 返回数组
         $res_patient = [];
+
         //电话咨询
 
-        if($data['product_type']==1){
+        if ($data['product_type'] == 1) {
 
             $res_patient['patient_id'] = $data['order_patient']['id'];
             $res_patient['user_id'] = $data['user_id'];
             $res_patient['order_sn'] = $data['order_sn'];
             $res_patient['patient_id'] = $data['patient_id'];
             $res_patient['product_type'] = $data['product_type'];
-            $res_patient['name']=$data['order_patient']['name'];//患者姓名
-            $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']);//年龄
-            $res_patient['card_number']=$data['order_patient']['card_number'];//身份证号
-            $res_patient['created_at']=$data['created_at'];//下单时间
-            $res_patient['nickname']=$data['user']['nickname'];//下单用户
-            $res_patient['receiving_time']=!empty($data['receiving_time'])?date('Y-m-d H:i:s',$data['receiving_time']):'---';//接单时间
-            $res_patient['order_status']=$data['order_status'];//订单状态
-            $res_patient['call_list']=[];//通话记录
+            $res_patient['name'] = $data['order_patient']['name'];//患者姓名
+            $res_patient['numbirthday'] = numBirthday($data['order_patient']['birthday']);//年龄
+            $res_patient['card_number'] = $data['order_patient']['card_number'];//身份证号
+            $res_patient['created_at'] = $data['created_at'];//下单时间
+            $res_patient['nickname'] = $data['user']['nickname'];//下单用户
+            $res_patient['receiving_time'] = !empty($data['receiving_time']) ? date('Y-m-d H:i:s', $data['receiving_time']) : '---';//接单时间
+            $res_patient['order_status'] = $data['order_status'];//订单状态
+            $res_patient['call_list'] = [];//通话记录
             $res_patient['one_call'] = '';
-            if ($data['calllog']){
+            if ($data['calllog']) {
                 $res_patient['one_call'] = $data['calllog'][0]['call_time'];
-                $res_patient['secret_no']=$data['calllog'][count($data['calllog'])-1]['secret_no'];//X号码
-                foreach ($data['calllog'] as $ks=>$vs){
-                    $res_patient['call_list'][$ks]['frequency']='通话'.($ks+=1);//拨打电话开始时间
-                    $res_patient['call_list'][$ks]['start']=$vs['call_time'];//拨打电话开始时间
-                    $res_patient['call_list'][$ks]['end']=$vs['ring_time'];//拨打电话结束时间
-                    $res_patient['call_list'][$ks]['duration']=gmdate('i:s',$vs['talk_time']);//拨打电话结束时间
+                $res_patient['secret_no'] = $data['calllog'][count($data['calllog']) - 1]['secret_no'];//X号码
+                foreach ($data['calllog'] as $ks => $vs) {
+                    $res_patient['call_list'][$ks]['frequency'] = '通话' . ($ks += 1);//拨打电话开始时间
+                    $res_patient['call_list'][$ks]['start'] = $vs['call_time'];//拨打电话开始时间
+                    $res_patient['call_list'][$ks]['end'] = $vs['ring_time'];//拨打电话结束时间
+                    $res_patient['call_list'][$ks]['duration'] = gmdate('i:s', $vs['talk_time']);//拨打电话结束时间
 
                 }
             }
         }
 
         //图文咨询
-        if($data['product_type']==2){
+        if ($data['product_type'] == 2) {
             $res_patient['order_sn'] = $data['order_sn'];
             $res_patient['patient_id'] = $data['patient_id'];
             $res_patient['user_id'] = $data['user_id'];
@@ -471,38 +475,38 @@ class PatientController extends AuthController
             $res_patient['user_avatar'] = $data['user']['avatar'];
             $res_patient['sex'] = $data['order_patient']['sex'];
             $res_patient['product_type'] = $data['product_type'];
-            $res_patient['name']=$data['order_patient']['name'];
-            $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']);
-            $res_patient['card_number']=$data['order_patient']['card_number'];
-            $res_patient['symptoms']=$data['order_patient']['symptoms'];//病情描述
-            $res_patient['medical_imgs']=json_decode($data['order_patient']['medical_imgs'],true);//病情照片
-            $res_patient['created_at']=$data['created_at'];//下单时间
-            $res_patient['nickname']=$data['user']['nickname'];//下单用户
-            $res_patient['receiving_time']=!empty($data['receiving_time'])?date('Y-m-d H:i:s',$data['receiving_time']):'---'; //接单时间
-            $res_patient['order_status']=$data['order_status'];//接单时间
+            $res_patient['name'] = $data['order_patient']['name'];
+            $res_patient['numbirthday'] = numBirthday($data['order_patient']['birthday']);
+            $res_patient['card_number'] = $data['order_patient']['card_number'];
+            $res_patient['symptoms'] = $data['order_patient']['symptoms'];//病情描述
+            $res_patient['medical_imgs'] = json_decode($data['order_patient']['medical_imgs'], true);//病情照片
+            $res_patient['created_at'] = $data['created_at'];//下单时间
+            $res_patient['nickname'] = $data['user']['nickname'];//下单用户
+            $res_patient['receiving_time'] = !empty($data['receiving_time']) ? date('Y-m-d H:i:s', $data['receiving_time']) : '---'; //接单时间
+            $res_patient['order_status'] = $data['order_status'];//接单时间
         }
 
         //门诊预约
-        if($data['product_type']==3){
+        if ($data['product_type'] == 3) {
             $res_patient['order_sn'] = $data['order_sn'];
             $res_patient['patient_id'] = $data['patient_id'];
-            $res_patient['product_type'] =$data['product_type'];
-            $res_patient['name']=$data['order_patient']['name']; // 患者
-            $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']); //年龄
-            $res_patient['card_number']=$data['order_patient']['card_number']; // 证件号
-            $res_patient['appoint_time'] = date('Y年m月d日 H:i',$data['order_patient']['appoint_start_time']);// 预约时间
+            $res_patient['product_type'] = $data['product_type'];
+            $res_patient['name'] = $data['order_patient']['name']; // 患者
+            $res_patient['numbirthday'] = numBirthday($data['order_patient']['birthday']); //年龄
+            $res_patient['card_number'] = $data['order_patient']['card_number']; // 证件号
+            $res_patient['appoint_time'] = date('Y年m月d日 H:i', $data['order_patient']['appoint_start_time']);// 预约时间
             $res_patient['order_status'] = $data['order_status'];// 订单状态
-            $organization = Organization::where('id','=',$data['organization_id'])->first();
-            if($organization){
+            $organization = Organization::where('id', '=', $data['organization_id'])->first();
+            if ($organization) {
                 $organization = $organization->toArray();
-                $res_patient['organization']= $organization['name']; // 门诊机构
-            }else{
-                $res_patient['organization']= ''; // 门诊机构
+                $res_patient['organization'] = $organization['name']; // 门诊机构
+            } else {
+                $res_patient['organization'] = ''; // 门诊机构
 
             }
-            $res_patient['order_sn']=$data['order_sn'];//订单号
-            $res_patient['created_at']=$data['created_at'];//下单时间
-            $res_patient['nickname']=$data['user']['nickname'];//下单用户
+            $res_patient['order_sn'] = $data['order_sn'];//订单号
+            $res_patient['created_at'] = $data['created_at'];//下单时间
+            $res_patient['nickname'] = $data['user']['nickname'];//下单用户
         }
 
         return out($res_patient);
@@ -515,7 +519,8 @@ class PatientController extends AuthController
      * @author Liu-Yh
      * Create By 2020/11/24 19:19
      */
-    public function callPhones(){
+    public function callPhones()
+    {
         $req = request()->post();
         $user = $this->user;
         $this->validate(request(), [
@@ -524,62 +529,62 @@ class PatientController extends AuthController
         ]);
         $docter_id = $user['id'];
         $docter_phone = $user['phone'];
-        if(!$docter_phone){
-            return out('',500,'医生电话不存在!');
+        if (!$docter_phone) {
+            return out('', 500, '医生电话不存在!');
         }
-        $find = Order::with('orderPatient')->where('order_sn',$req['order_id'])->first()->toArray();
-        if (empty($find['order_patient'])){
-            return out('',500,'患者电话不存在');
+        $find = Order::with('orderPatient')->where('order_sn', $req['order_id'])->first()->toArray();
+        if (empty($find['order_patient'])) {
+            return out('', 500, '患者电话不存在');
         }
         $phone = $find['order_patient']['phone'];
-        if($docter_phone==$phone){
-            return out('',500,'医生和患者电话号不能一样!');
+        if ($docter_phone == $phone) {
+            return out('', 500, '医生和患者电话号不能一样!');
         }
         $wheres['docter_id'] = $docter_id;
         $wheres['user_id'] = $req['user_id'];
         $commons = new Commons();
-        $finds = Axb::where($wheres)->orderBy('id','desc')->first();
-        if ($finds){
+        $finds = Axb::where($wheres)->orderBy('id', 'desc')->first();
+        if ($finds) {
             $querylok = $commons->QuerySubsId($finds['xphone']);
-            if ($querylok['Code']=='OK'){
+            if ($querylok['Code'] == 'OK') {
                 // 可能是数组
-                $new_arr = explode(',',$querylok['SubsId']);
-                foreach ($new_arr as $v){
-                    $queryCallStatus = $commons->QuerySubscriptionDetail($finds['xphone'],$v);
-                    if ($queryCallStatus['Code']=="OK"){
-                        if ($queryCallStatus['SecretBindDetailDTO']['PhoneNoA']==$docter_phone&&$queryCallStatus['SecretBindDetailDTO']['PhoneNoB']==$phone){
+                $new_arr = explode(',', $querylok['SubsId']);
+                foreach ($new_arr as $v) {
+                    $queryCallStatus = $commons->QuerySubscriptionDetail($finds['xphone'], $v);
+                    if ($queryCallStatus['Code'] == "OK") {
+                        if ($queryCallStatus['SecretBindDetailDTO']['PhoneNoA'] == $docter_phone && $queryCallStatus['SecretBindDetailDTO']['PhoneNoB'] == $phone) {
                             return out($finds['xphone']);
-                        }else{
-                            if ($phone){
-                                Axb::where('id',$finds['id'])->delete();
-                                return $this->createCall($phone,$docter_phone,$docter_id,$req['user_id']);
-                            }else{
-                                return out('',500,'患者电话不存在');
+                        } else {
+                            if ($phone) {
+                                Axb::where('id', $finds['id'])->delete();
+                                return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']);
+                            } else {
+                                return out('', 500, '患者电话不存在');
                             }
                         }
-                    }else{
-                        if ($phone){
-                            Axb::where('id',$finds['id'])->delete();
-                            return $this->createCall($phone,$docter_phone,$docter_id,$req['user_id']);
-                        }else{
-                            return out('',500,'患者电话不存在');
+                    } else {
+                        if ($phone) {
+                            Axb::where('id', $finds['id'])->delete();
+                            return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']);
+                        } else {
+                            return out('', 500, '患者电话不存在');
                         }
                     }
                 }
-            }else{
-                if ($phone){
-                    Axb::where('id',$finds['id'])->delete();
-                    return $this->createCall($phone,$docter_phone,$docter_id,$req['user_id']);
-                }else{
-                    return out('',500,'患者电话不存在');
+            } else {
+                if ($phone) {
+                    Axb::where('id', $finds['id'])->delete();
+                    return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']);
+                } else {
+                    return out('', 500, '患者电话不存在');
                 }
             }
 
-        }else{
-            if ($phone){
-                return $this->createCall($phone,$docter_phone,$docter_id,$req['user_id']);
-            }else{
-                return out('',500,'患者电话不存在');
+        } else {
+            if ($phone) {
+                return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']);
+            } else {
+                return out('', 500, '患者电话不存在');
             }
         }
 
@@ -593,33 +598,34 @@ class PatientController extends AuthController
      * @param $user_id
      * @return \Illuminate\Http\JsonResponse
      */
-    protected function createCall($phone,$docter_phone,$docter_id,$user_id){
+    protected function createCall($phone, $docter_phone, $docter_id, $user_id)
+    {
         $commons = new Commons();
-        $callModel = $commons->BindAxb($docter_phone,$phone);
-        if ($callModel['Code']=="OK"){
+        $callModel = $commons->BindAxb($docter_phone, $phone);
+        if ($callModel['Code'] == "OK") {
             Axb::create([
-                'docter_id'=>$docter_id,
-                'user_id'=>$user_id,
-                'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
-                'subs_id'=>$callModel['SecretBindDTO']['SubsId'],
-                'createtime'=>time(),
+                'docter_id' => $docter_id,
+                'user_id' => $user_id,
+                'xphone' => $callModel['SecretBindDTO']['SecretNo'],
+                'subs_id' => $callModel['SecretBindDTO']['SubsId'],
+                'createtime' => time(),
             ]);
             return out($callModel['SecretBindDTO']['SecretNo']);
-        }else{
+        } else {
             return out($callModel);
         }
 
     }
 
 
-
     /**
      * 电话随访
      * @return \Illuminate\Http\JsonResponse
      * @author Liu-Yh
      * Create By 2020/11/24 19:19
      */
-    public function callPhoneSure(){
+    public function callPhoneSure()
+    {
         $req = request()->post();
         $user = $this->user;
         $this->validate(request(), [
@@ -627,16 +633,16 @@ class PatientController extends AuthController
         ]);
         $docter_id = $user['id'];
         $docter_phone = $user['phone'];
-        if(!$docter_phone){
-            return out('',500,'医生电话不存在!');
+        if (!$docter_phone) {
+            return out('', 500, '医生电话不存在!');
         }
-        $find = User::where('id',$req['user_id'])->first()->toArray();
+        $find = User::where('id', $req['user_id'])->first()->toArray();
         $phone = $find['phone'];
         $wheres['docter_id'] = $docter_id;
         $wheres['user_id'] = $find['id'];
         $commons = new Commons();
-        $finds = Axb::where($wheres)->orderBy('id','desc')->first();
-        if ($finds){
+        $finds = Axb::where($wheres)->orderBy('id', 'desc')->first();
+        if ($finds) {
             $querylok = $commons->QuerySubsId($finds['xphone']);
             if ($querylok['Code'] == 'OK') {
                 $queryCallStatus = $commons->QueryCallStatus($phone, $querylok['SubsId']);
@@ -679,7 +685,6 @@ class PatientController extends AuthController
 
 
 
-
     /**
      * 取消订单接口
      * @throws \Illuminate\Validation\ValidationException
@@ -704,6 +709,7 @@ class PatientController extends AuthController
                     Order::where('id', $req['order_id'])->update(['order_status' => 5, 'order_notes' => '医生拒绝接单', 'payment_status' => 4]);
                 }
                 DB::commit();
+                $this->CancelReminder($req['order_id']);
                 return out('', 200, '订单取消成功');
             } catch (\Exception $e) {
                 DB::rollBack();
@@ -722,8 +728,8 @@ class PatientController extends AuthController
      * 订单超时自动完成(定时)
      */
     public function overTimeOrers(){
-        $user = $this->user;
-        $docter_id = $user['id'];
+//        $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');
 
@@ -731,7 +737,7 @@ class PatientController extends AuthController
         $config_chat = $config_chat*60;
         $config_phone = $config_phone*60;
 
-        $inOrder = Order::with('orderPatient')->where(['docter_id'=>$docter_id,'order_status'=>3,'payment_status'=>2])->get();
+        $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
         $catNewIds = [];
         $menNewIds = [];
         foreach ($inOrder as $k=>$v){
@@ -818,4 +824,235 @@ class PatientController extends AuthController
     }
 
 
+    /**
+     * 修改关闭状态
+     * $type 1=开启小程序,2=关闭小程序
+     * @return \Illuminate\Http\JsonResponse
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function docter_open(){
+        $req = request()->post();
+        $this->validate(request(), [
+            'type' => 'required|integer|in:1,2',
+        ]);
+        $user = $this->user;
+        $docter_id = $user['id'];
+        Docter::where('id',$docter_id)->update(['is_open'=>$req['type']]);
+        return out();
+    }
+    /**
+     * 	确认超时提醒 当天的预约订单,医生还未点击完成的订单,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'],"https://easywechat.org",$v['order_sn'],$v['user']['nickname'],$v['user']['phone'],$v['created_at']]);
+                }
+            }
+        }
+    }
+
+    /**
+     * 取消订单提醒
+     * @param $order_id
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function CancelReminder($order_id){
+        $Order = Order::with(['orderPatient','docter','user'])->where(['id'=>$order_id])->first();
+
+        $type = '';
+        if ($Order['product_type']==1){
+            $type = '电话咨询';
+        }elseif ($Order['product_type']==2){
+            $type = '图文咨询 ';
+        }elseif ($Order['product_type']==3){
+            $type = '门诊预约';
+        }
+        if ($Order){
+            if ($Order['docter']['openid']){
+                $send = send_wechatSubscription_message('cancel_reminder',[
+                    $Order['docter']['openid'],
+                    "https://easywechat.org",
+                    $Order['docter']['name'],
+                    $Order['order_sn'],
+                    $type,
+                    $Order['total_amount'],
+                    $Order['created_at'],
+                    '',
+                ]);
+                var_dump($send);
+            }
+        }
+    }
+
+
+    /**
+     * 咨询订单接单提醒
+     * @param $order_id
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function ReceivingReminder($order_id){
+        $Order = Order::with(['orderPatient','user'])->where(['id'=>$order_id])->first();
+        $type = '';
+        if ($Order['product_type']==1){
+            $type = '电话咨询';
+        }elseif ($Order['product_type']==2){
+            $type = '图文咨询 ';
+        }elseif ($Order['product_type']==3){
+            $type = '门诊预约';
+        }
+        if ($Order){
+            if ($Order['user']['openid']){
+                $send = send_wechatSubscription_message('receiving_reminder',[
+                    $Order['user']['openid'],
+                    "https://easywechat.org",
+                    $Order['order_sn'],
+                    $type,
+                    date('Y-m-d H:i',$Order['receiving_time']),
+                    $Order['order_patient']['phone'],
+                ]);
+            }
+        }
+    }
+
+
+    /**
+     * 消息回复提醒(医生)
+     * @param $order_id
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function ReplyReminder($docter_id,$user_id){
+        $list = DocterOrganization::with(['docter','organization'])->where(['docter_id'=>$docter_id,'is_open'=>2])->first();
+        $user = User::where('id',$user_id)->first();
+        if ($list){
+            if ($user['openid']){
+                $send = send_wechatSubscription_message('reply_reminder',[
+                    $user['openid'],
+                    "https://easywechat.org",
+                    $list['organization']['name'],
+                    $list['docter']['name'],
+                    $user['nickname'],
+                ]);
+            }
+        }
+    }
+
+
+    /**
+     * 排班变更提醒
+     * @param $docter_id 医生id
+     * @param int $type 类型0=周排班 1=月排班
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function ScheduleReminder($docter_id=81,$type=0){
+        $list = Docter::where(['id'=>$docter_id])->first();
+        $type = '';
+        $openid = $list['openid'];
+        if ($type==0){
+            $type = '周排班变动';
+        }elseif ($type==1){
+            $type = '月排班变动 ';
+        }
+        if ($list){
+            if ($openid){
+                $send = send_wechatSubscription_message('schedule_reminder',[$openid, "https://easywechat.org", $type, 'A社区']);
+            }
+        }
+    }
+
+    /**
+     * 审核认证提醒
+     * @param $docter_id 医生id
+     * @param int $msg 消息
+     * @param $time 时间
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function ThenReminder($docter_id,$msg='',$time){
+        $list = Docter::where(['id'=>$docter_id])->first();
+        $openid = $list['openid'];
+        if ($list){
+            if ($openid){
+                $send = send_wechatSubscription_message('then_reminder',[$openid, "https://easywechat.org", $list['name'],$msg,$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'], "https://easywechat.org", $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'], "https://easywechat.org", $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 TodayReminder(){
+        $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('schedule_reminder', [
+                        '医生id',
+                        "https://easywechat.org",
+                        '小刘',
+                        '类型',
+                        '人数',
+                        '医院',
+                    ]);
+
+                }
+            }
+        }
+    }
+
+
 }

+ 11 - 0
app/Models/InsuranceAgreement.php

xqd
@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class InsuranceAgreement extends Model
+{
+    //
+    protected $table = 'insurance_agreement';
+}

+ 3 - 0
app/Models/ServicePack.php

xqd
@@ -29,4 +29,7 @@ class ServicePack extends BaseModel
 
         return $data;
     }
+    public function insuranceagreement(){
+        return $this->hasOne(InsuranceAgreement::class,'id','agreement_id');
+    }
 }

+ 212 - 47
config/config.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -88,7 +88,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -118,7 +118,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -148,7 +148,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -184,7 +184,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -220,7 +220,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -256,7 +256,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
@@ -286,7 +286,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '%s',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
@@ -319,7 +319,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '%s',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
@@ -349,7 +349,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '%s',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
@@ -385,7 +385,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '%s',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
@@ -415,7 +415,7 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '%s',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
@@ -436,42 +436,6 @@ return [
                 ],
             ],
         ],
-        //测试
-        12 => [
-            'touser' => '%s',
-            'mp_template_msg' => [
-                'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => 'Xu7Ar0Ov3_8xJSeQgjtJwGuMiaS6qyRg5xGtZMLy03k',
-                'url' => '',
-                'miniprogram' => [
-                    'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'pagepath' => '',
-                ],
-                'data' => [
-                    'first' => [
-                        'value' => '%s',
-                    ],
-                    'keyword1' => [
-                        'value' => '%s',
-                    ],
-                    'keyword2' => [
-                        'value' => '%s',
-                    ],
-                    'keyword3' => [
-                        'value' => '%s',
-                    ],
-                    'keyword4' => [
-                        'value' => '%s',
-                    ],
-                    'keyword5' => [
-                        'value' => '%s',
-                    ],
-                    'remark' => [
-                        'value' => '%s',
-                    ],
-                ],
-            ],
-        ],
     ],
 
     //小程序订阅消息
@@ -727,4 +691,205 @@ return [
             ],
         ],
     ],
+
+    // 线上公众号
+    'docter_wechat_officialAccount' =>[
+        'app_id' => 'wx6df68b725662f8a3',
+        'secret' => '4f91ff06530833577eedcb0c0e111a57',
+    ],
+    'wechatSubscription_template' => [
+        // 订单超时提醒
+        'appoint_reminder'=>[
+            'template_id' => '7K3l4BAe013gGhCepf0kK53L11jsVLZznBe53D8Y0lo',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '您的订单即将过期',
+                ],
+                'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '%s',
+                ],
+                'keyword4' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序进行操作,有疑问请联系客服',
+                ],
+            ]
+        ],
+
+        // 取消订单提醒
+        'cancel_reminder'=>[
+            'template_id' => 'jpFpsVmsGTvpbagoMTAe31Qvq73f6EdW7vET7_niUCo',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '尊敬的%s你有一个订单已被取消',
+                ]
+                ,'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '%s',
+                ],
+                'keyword4' => [
+                    'value' => '%s',
+                ],
+                'keyword5' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看详情',
+                ],
+            ]
+        ],
+
+        // 认证审核提醒
+        'then_reminder'=>[
+            'template_id' => 'tTpVBoLbyJZVRQ6KKXOrS5MuWuQ-xhpVaEtN1vSWls8',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '您有一条医生认证申请已提交成功!',
+                ]
+                ,'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '你的认证申请已提交,请耐心等待结果',
+                ],
+            ]
+        ],
+        // 排班变更提醒
+        'schedule_reminder'=>[
+            'template_id' => 'OmNx3Tiu83KwMriLeYsWRbuLfIk1O5JZM1S_K8hdwN4',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '您好,你的排班情况有所变动,请及时查看',
+                ]
+                ,'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看详情,有疑问请联系客服',
+                ],
+            ]
+        ],
+        // 医生认证到期提醒
+        'out_then_reminder'=>[
+            'template_id' => 'RhvT7gFJcFpUDAImkXIovBTOWZUYA7DirkMrwL0EzE0',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '你在%s社区的认证还有一天到期,请及时续签!',
+                ]
+                ,'keyword1' => [
+                    'value' => '签约到期提醒',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看详情,有疑问请联系管理员!',
+                ],
+            ]
+        ],
+        // 医生接单提醒
+        'receiving_reminder'=>[
+            'template_id' => 'grtzjXaIQNMTI-UoxY8cakzVna4q65s6qqZFbW67rIk',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '尊敬的用户,你的咨询订单已被医生接单!',
+                ]
+                ,'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '%s',
+                ],
+                'keyword4' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看详情!',
+                ],
+            ]
+        ],
+        // 消息回复提醒
+        'reply_reminder'=>[
+            'template_id' => '0T33vX4zLYSUbFH4NxEe_6Yt4b6m1AoanjpwvBbsRgE',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '你的咨询订单已被医生回复,请及时查看!',
+                ]
+                ,'keyword1' => [
+                    'value' => '%s',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '%s',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看详情!',
+                ],
+            ]
+        ],
+        // 明日预约提醒
+        'today_reminder'=>[
+            'template_id' => 'sqRXeqYDHyzxQMu_mO7EroNPhVWUCs2wpbZMRdrrIYc',
+            'touser' => '%s',
+            'url' => '%s',
+            'data' => [
+                'first' => [
+                    'value' => '尊敬的%s,您明天有新的门诊预约订单待处理!',
+                ]
+                ,'keyword1' => [
+                    'value' => '签约失效提醒',
+                ],
+                'keyword2' => [
+                    'value' => '%s',
+                ],
+                'keyword3' => [
+                    'value' => '就诊人数:%s个,就诊地点:%s医院',
+                ],
+                'remark' => [
+                    'value' => '点击进入小程序查看相关详情',
+                ],
+            ]
+        ],
+
+    ],
 ];

+ 3 - 3
upgrade.md

xqd
@@ -2,6 +2,6 @@
 - 执行以下sql:
     ALTER TABLE `bm_orders` 
     ADD COLUMN `cancel_time` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '取消订单时间' AFTER `receiving_time`;
-- .env添加如下配置
-    OFFICIAL_WECHAT_APPID=xxx
-    OFFICIAL_WECHAT_APPSECRET=yyy
+- 线上.env添加如下配置
+    OFFICIAL_WECHAT_APPID=wx6df68b725662f8a3
+    OFFICIAL_WECHAT_APPSECRET=4f91ff06530833577eedcb0c0e111a57