Explorar el Código

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

zilong hace 4 años
padre
commit
77d2651586

+ 4 - 2
app/Admin/Controllers/Chart/OrderChart.php

xqd xqd
@@ -81,7 +81,9 @@ class OrderChart
     {
 
         //type 1默认选择当前月份 2根据时间+
-        $month >10??$month = '0'.$month;
+        if(intval($month) < 10){
+           $month  = '0'.$month;
+        }
 
         if($type == 1){
             //查找天
@@ -115,7 +117,7 @@ class OrderChart
             $data = Order::query()
                 ->selectRaw('DATE_FORMAT(created_at,"%m-%d") as day')
                 ->selectRaw('COUNT(*) as count')
-                ->where('created_at', '>', $year.'-'.$month)
+                ->where('created_at', '>=', $year.'-'.$month)
                 ->where('created_at', '<', $year.'-'.($month+1))
                 ->groupBy('day')
                 ->get()->toArray();

+ 93 - 0
app/Admin/Controllers/DocterTypeController.php

xqd
@@ -0,0 +1,93 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Models\DocterType;
+use Encore\Admin\Controllers\AdminController;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Show;
+
+class DocterTypeController extends AdminController
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title = '医生类型';
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new DocterType());
+
+        $grid->column('id', __('ID'));
+        $grid->column('name', __('名称'));
+        $states = [
+            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
+            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
+        ];
+
+        $grid->column('status', __('状态'))->switch($states);
+        $grid->column('created_at', __('创建时间'));
+        $grid->column('updated_at', __('更新时间'));
+        $grid->actions(function($actions){
+            $actions->disableDelete();
+        });
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(DocterType::findOrFail($id));
+
+        $show->field('id', __('Id'));
+        $show->field('name', __('名称'));
+        $show->field('status', __('启用禁用'));
+
+        $show->field('created_at', __('创建时间'));
+        $show->field('updated_at', __('更新时间'));
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new DocterType());
+
+        $form->text('name', __('名称'));
+        $states = [
+            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
+            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
+        ];
+        $form->switch('status', __('名称'))->states($states);
+
+        $form->tools(function (Form\Tools $tools) {
+            $tools->disableDelete();
+            $tools->disableView();
+        });
+
+        $form->disableEditingCheck();
+        $form->disableCreatingCheck();
+        $form->disableViewCheck();
+
+        return $form;
+    }
+}

+ 10 - 10
app/Admin/Controllers/HomeController.php

xqd
@@ -25,43 +25,43 @@ class HomeController extends Controller
             ->row(function (Row $row) {
                 // 产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('新增电话咨询订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(1)));
+                    $column->append(infoBox('新增电话咨询订单', 'dropbox', '/admin/consulting_orders?product_type=1', 'green', Sta::getOrderCount(1)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增图文咨询订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(2)));
+                    $column->append(\App\Admin\Controllers\infoBox('新增图文咨询订单', 'dropbox', '/admin/consulting_orders?product_type=2', 'green', Sta::getOrderCount(2)));
                 });
 
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('新增门诊预约订单', 'user-plus', '/admin/withdraw?status=0', 'green',Sta::getOrderCount(3)));
+                    $column->append(infoBox('新增门诊预约订单', 'user-plus', '/admin/booking_order?product_type=3', 'green',Sta::getOrderCount(3)));
                 });
 
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增计免预约订单', 'user-plus', '/admin/withdraw?status=0', 'green', Sta::getOrderCount(4)));
+                    $column->append(\App\Admin\Controllers\infoBox('新增计免预约订单', 'user-plus', '/admin/booking_order?product_type=4', 'green', Sta::getOrderCount(4)));
                 });
             })
             ->row(function (Row $row) {
                 //产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增儿保订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(5)));
+                    $column->append(\App\Admin\Controllers\infoBox('新增儿保订单', 'dropbox', '/admin/booking_order?product_type=5', 'green', Sta::getOrderCount(5)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('历史总订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(0)));
+                    $column->append(\App\Admin\Controllers\infoBox('历史总订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(0)));
                 });
             })
             ->row('<h1 text-align="center">订单走势</h1>')
             ->row(function (Row $row) {
                 //产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('今日订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(7,1)));
+                    $column->append(\App\Admin\Controllers\infoBox('今日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,1)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('昨日订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(7,-1)));
+                    $column->append(\App\Admin\Controllers\infoBox('昨日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,-1)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('进七日订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(7,7)));
+                    $column->append(\App\Admin\Controllers\infoBox('进七日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,7)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('近三十日订单', 'dropbox', '/admin/deliver?status=1', 'green', Sta::getOrderCount(7,30)));
+                    $column->append(\App\Admin\Controllers\infoBox('近三十日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,30)));
                 });
 //                1=>'今日订单总数(单)',
 //                        1=>'昨日订单总数(单)',

+ 2 - 1
app/Admin/routes.php

xqd
@@ -18,7 +18,8 @@ Route::group([
     $router->resource('/cdms_user', CdmsController::class);
     $router->resource('/organizations', OrganizationController::class);
     $router->resource('/docters', DocterController::class);
-
+    //医生类型
+    $router->resource('docter_types', DocterTypeController::class);
 
     //文章管理
     $router->resource('articles', ArticleManagement\ArticleController::class);

+ 4 - 2
app/Community/Actions/Docter/ChangeType.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Community\Actions\Docter;
 
 use App\Models\Docter;
+use App\Models\DocterType;
 use Encore\Admin\Actions\RowAction;
 use Illuminate\Database\Eloquent\Model;
 
@@ -20,9 +21,10 @@ class ChangeType extends RowAction
     }
 
     public function form(){
-//        1.问诊医生 2.疫苗医生 3.儿保医生)
+        //1.问诊医生 2.疫苗医生 3.儿保医生)
         $type = $this->row->docter->type;
-        $this->select('type','类型')->options([1=>'门诊医生',2=>'计免医生',3=>'儿保医生'])->value(intval($type));
+        $docterType = DocterType::where(['status'=>1])->pluck('name','id')->toArray();
+        $this->select('type','类型')->options($docterType)->value(intval($type));
     }
 
 }

+ 1 - 0
app/Community/Actions/Vaccine/FasteOrder.php

xqd
@@ -39,6 +39,7 @@ class FasteOrder extends Action
                 'order_sn'=>$patientInfo['user_id'],
                 'product_type'=>4,
                 'total_amount'=>$orgVaccine['price'],
+                'is_faster'=>1,
                 'order_status'=>2,
                 'payment_status'=>2,
             ];

+ 2 - 2
app/Community/Controllers/StatController.php

xqd
@@ -93,10 +93,10 @@ class StatController extends  Controller
         })->whereNotIn('order_status',[1,5,6])->count();
 
         $data['today'] = $today;
-        $data['tomorrow '] = $tomorrow;
+        $data['tomorrow'] = $tomorrow;
         $data['people'] = $people;
         $data['yesterday'] = $yesterday;
-
+        return $data;
     }
 
     //疫苗统计

+ 105 - 108
app/Http/Controllers/Api/V2/CommonController.php

xqd xqd xqd
@@ -49,58 +49,79 @@ class CommonController extends Controller
 
         $data = $app->auth->session($req['wechat_code']);
 
-        if (empty($data['openid'])){
+        if (empty($data['openid'])) {
             return out(null, 10001, '微信登录code错误');
         }
 
         $session_key = !empty($data['session_key']) ? $data['session_key'] : '';
 
-        $user = User::select(['id', 'status', 'phone', 'nickname', 'avatar'])->where('openid', $data['openid'])->first();
-        if (empty($user)){
-            $user = User::create([
+
+//        $user = User::select(['id', 'status', 'phone', 'nickname', 'avatar'])->where('openid', $data['openid'])->first();
+        $user = Docter::select(['id', 'status', 'phone', 'name', 'avatar'])->where('openid', $data['openid'])->first();
+        if (empty($user)) {
+
+            $docter_list = [
+                'type' => 1,
                 'openid' => $data['openid'],
-                'nickname' => $req['nickname'] ?? '',
+                'session_key' => $session_key,
+                'name' => $req['nickname'] ?? '',
+                'phone' => '',
+                'sex' => 0,
+                'birthday' => 0,
                 'avatar' => $req['avatar'] ?? '',
+                'status' => 1,
+                'label' => '无',
+                'sign' => '无',
+                'intro' => 0,
+                'office_id' => 0,
+                'qualification_id' => 0,
+                'score' => 0,
+                'service_persons' => 0,
+                'eva_num' => 0,
+                'service_days' => 0,
+                'phone_minutes' => 0,
+                'chat_price' => 0,
+                'phone_price' => 0,
+                'appoint_price' => 0,
+                'is_chat' => 0,
+                'is_phone' => 0,
+                'is_appoint' => 0,
                 'latitude' => $req['latitude'] ?? 0,
                 'longitude' => $req['longitude'] ?? 0,
-                'session_key' => $session_key,
-                'is_docter' => 1
-            ]);
-        }
-        else {
+                'is_then' => 0,
+                'practice' => 0,
+                'card_photo' => 0,
+                'is_quail' => 0,
+                'card_id' => 0,
+            ];
+            $user = Docter::create($docter_list);
+        } else {
             if ($user['status'] == 0) {
                 return out(null, 10002, '该账号已被冻结');
             }
-
-            User::where('id', $user['id'])->update([
-                'nickname' => $req['nickname'] ?? '',
-                'avatar' => $req['avatar'] ?? '',
+            Docter::where('id', $user['id'])->update([
                 'latitude' => $req['latitude'] ?? 0,
                 'longitude' => $req['longitude'] ?? 0,
                 'session_key' => $session_key
             ]);
         }
-        // 查询医生表有没有记录
-        $doct = User::where('openid',$data['openid'])->orderBy('id','desc')->first();
 
-        if ($doct['phone']!=''){
-            $list = Docter::where('phone',$doct['phone'])->orderBy('id','desc')->first();
-            if ($list){
-                if ($list['status'] == 0) {
-                    return out(null, 10002, '该账号已被冻结');
-                }
-                $datas = [
-                    'avatar' => $list['avatar'],
-                    'name' => $list['name'],
-                    'flag' => 'doctor_'.$list['id'],
-                ];
-                $token = aes_encrypt(['doctor_id' => $list['id'], 'time' => time()]);
-                return out(['token' => $token,'data'=>$datas]);
-            }else{
-                return out(['session_key'=>$session_key,'openid'=>$data['openid']]);
+
+        if ($user['phone'] != '') {
+
+
+            if ($user['status'] == 0) {
+                return out(null, 10002, '该账号已被冻结');
             }
-        }else{
-            return out(['session_key'=>$session_key,'openid'=>$data['openid']]);
+            $datas = [
+                'avatar' => $user['avatar'],
+                'name' => $user['name'],
+                'flag' => 'doctor_' . $user['id'],
+            ];
+            $token = aes_encrypt(['doctor_id' => $user['id'], 'time' => time()]);
+            return out(['token' => $token, 'data' => $datas]);
+        } else {
+            return out(['session_key' => $session_key, 'openid' => $data['openid']]);
         }
     }
 
@@ -110,7 +131,8 @@ class CommonController extends Controller
      * Date:2020/10/18 17:17 *
      * @return \Illuminate\Http\JsonResponse
      */
-    public function getPhoneNumber(){
+    public function getPhoneNumber()
+    {
         $req = request()->post();
         $this->validate(request(), [
             'iv' => 'required',
@@ -126,93 +148,68 @@ class CommonController extends Controller
 //            return out(null, 10001, '微信登录code错误');
 //        }
         $session_key = !empty($req['session_key']) ? $req['session_key'] : '';
-        $user = User::select(['id','sex', 'status', 'phone', 'birthday','nickname', 'avatar','status'])->where('openid', $req['openid'])->first();
-        if (!$user){
-            return out(['status'=>false,'msg' => '用户不存在!']);
+//        $user = User::select(['id','sex', 'status', 'phone', 'birthday','nickname', 'avatar','status'])->where('openid', $req['openid'])->first();
+        $user = Docter::select(['id', 'sex', 'status', 'phone', 'birthday', 'name', 'avatar'])->where('openid', $req['openid'])->first();
+
+        if (!$user) {
+            return out(['status' => false, 'msg' => '用户不存在!']);
         }
 
 
         $decryptedData = $app->encryptor->decryptData($session_key, $req['iv'], $req['encryptedData']);
-        if (!isset($decryptedData['phoneNumber']) || empty($decryptedData['phoneNumber'])){
-            return out(['status'=>false,'msg' => '手机号解密失败!']);
+        if (!isset($decryptedData['phoneNumber']) || empty($decryptedData['phoneNumber'])) {
+            return out(['status' => false, 'msg' => '手机号解密失败!']);
         }
 
 
-        $docter_list = [
-            'type' => 1,
-            'name' => $user['nickname'],
-            'phone' => $decryptedData['phoneNumber'],
-            'sex' => $user['sex'],
-            'birthday' => $user['birthday'],
-            'avatar' => $user['avatar'],
-            'status' => 1,
-            'label' => '无',
-            'sign' => '无',
-            'intro' => 0,
-            'office_id' => 0,
-            'qualification_id' => 0,
-            'score' => 0,
-            'service_persons' => 0,
-            'eva_num' => 0,
-            'service_days' => 0,
-            'phone_minutes' => 0,
-            'chat_price' => 0,
-            'phone_price' => 0,
-            'appoint_price' => 0,
-            'is_chat' => 0,
-            'is_phone' => 0,
-            'is_appoint' => 0,
-            'latitude' => 0,
-            'longitude' => 0,
-            'is_then' => 0,
-            'practice' => 0,
-            'card_photo' => 0,
-            'is_quail' => 0,
-            'card_id' => 0,
-        ];
+//        $docter_list = [
+//            'type' => 1,
+//            'name' => $user['nickname'],
+//            'phone' => $decryptedData['phoneNumber'],
+//            'sex' => $user['sex'],
+//            'birthday' => $user['birthday'],
+//            'avatar' => $user['avatar'],
+//            'status' => 1,
+//            'label' => '无',
+//            'sign' => '无',
+//            'intro' => 0,
+//            'office_id' => 0,
+//            'qualification_id' => 0,
+//            'score' => 0,
+//            'service_persons' => 0,
+//            'eva_num' => 0,
+//            'service_days' => 0,
+//            'phone_minutes' => 0,
+//            'chat_price' => 0,
+//            'phone_price' => 0,
+//            'appoint_price' => 0,
+//            'is_chat' => 0,
+//            'is_phone' => 0,
+//            'is_appoint' => 0,
+//            'latitude' => 0,
+//            'longitude' => 0,
+//            'is_then' => 0,
+//            'practice' => 0,
+//            'card_photo' => 0,
+//            'is_quail' => 0,
+//            'card_id' => 0,
+//        ];
         // 查询医生表有没有记录
-        $doct = Docter::where('phone',$decryptedData['phoneNumber'])->orderBy('id','desc')->first();
-
-        if ($doct){
-            if ($doct['status'] == 0) {
+        $save = Docter::where('id', $user['id'])->update(['phone' => $decryptedData['phoneNumber']]);
+        if ($save) {
+            if ($user['status'] == 0) {
                 return out(null, 10002, '该账号已被冻结');
             }
             $datas = [
-                'avatar' => $doct['avatar'],
-                'name' => $doct['name'],
-                'flag' => 'doctor_'.$doct['id'],
+                'avatar' => $user['avatar'],
+                'name' => $user['name'],
+                'flag' => 'doctor_' . $user['id'],
             ];
-            $token = aes_encrypt(['doctor_id' => $doct['id'], 'time' => time()]);
-            return out(['token' => $token,'data'=>$datas]);
+            $token = aes_encrypt(['doctor_id' => $user['id'], 'time' => time()]);
+            return out(['token' => $token, 'data' => $datas]);
+        } else {
+            return out(null, 10003, '账户不存在请重新登陆');
         }
-        $list=[];
-        if ($user){
-            DB::beginTransaction();
-            try {
-                User::where('openid', $req['openid'])->update([
-                    'phone' => $decryptedData['phoneNumber'] ?? '',
-                    'unionid' => $decryptedData['unionId'] ?? '',
-                    'is_docter'=>1,
-                ]);
-                // 注册医生
-                $list = Docter::create($docter_list);
-                DB::commit();
-            }catch (\Exception $e){
-                DB::rollback();
-                return out(null, 500, $e->getMessage());
-            }catch (\PDOException $e){
-                DB::rollback();
-                return out(null, 500, $e->getMessage());
-            }
-        }
-
-        $datas = [
-            'avatar' => $list['avatar'],
-            'name' => $list['name'],
-            'flag' => 'doctor_'.$list['id'],
-        ];
-        $token = aes_encrypt(['doctor_id' => $list['id'], 'time' => time()]);
-        return out(['token' => $token,'data'=>$datas]);
 
     }
 

+ 3 - 2
app/Http/Controllers/Api/V2/DoctorController.php

xqd xqd
@@ -64,7 +64,7 @@ class DoctorController extends AuthController
     public function doctorInfor()
     {
         $req = $this->user;
-        $data = Docter::where('phone', $req['phone'])->first(['id', 'name', 'avatar', 'label', 'sign', 'intro', 'service_days', 'service_persons','password', 'eva_num', 'score', 'is_then', 'created_at']);
+        $data = Docter::where('phone', $req['phone'])->orderBy('id','desc')->first(['id', 'name', 'avatar', 'label', 'sign', 'intro', 'service_days', 'service_persons','password', 'eva_num', 'score', 'is_then', 'created_at']);
 
         if (!empty($data)) {
 
@@ -139,7 +139,8 @@ class DoctorController extends AuthController
             }
         } else {
             // get提交哈
-            $list = Docter::where('id', '=', $doctor_id)->first()->toArray();
+            $list = Docter::where('id', '=', $doctor_id)->orderBy('id','desc')->first()->toArray();
+
             // 头像,个人标签,服务简介展示
             $data = [
                 'avatar' => !empty($list['avatar'])?$list['avatar']:'',

+ 173 - 27
app/Http/Controllers/Api/V2/PatientController.php

xqd xqd xqd xqd xqd xqd xqd xqd
@@ -14,7 +14,9 @@ use App\Models\Patient;
 use App\Models\CallLog;
 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;
@@ -31,6 +33,7 @@ use App\Models\CallPhone;
 class PatientController extends AuthController
 {
     protected $relationSearch = true;
+
     /**
      * @return mixed
      * 患者咨询列表
@@ -151,7 +154,8 @@ class PatientController extends AuthController
      * 完成订单
      * @author Yuanhang Liu & Xiaoyun Liu
      */
-    public function orderPatientok(){
+    public function orderPatientok()
+    {
         $req = request()->post();
         $this->validate(request(), [
             'order_id|订单id' => 'required|integer',
@@ -190,10 +194,10 @@ class PatientController extends AuthController
                 $lable = '服务包';
                 break;
             default:
-                $lable ='参数错误!';
+                $lable = '参数错误!';
         }
         $relation_id = '';
-        if ($find['product_type']==1 || $find['product_type']==2){
+        if ($find['product_type'] == 1 || $find['product_type'] == 2) {
             // 需要有意见单的
             $suggests = Suggest::create([
                 'order_id'=> $find['id'],
@@ -227,8 +231,8 @@ class PatientController extends AuthController
 
         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'],
@@ -266,7 +270,8 @@ class PatientController extends AuthController
      * @return mixed
      * @throws \Exception
      */
-    public function mzPatientok(){
+    public function mzPatientok()
+    {
         $req = request()->post();
         $this->validate(request(), [
             'order_id|订单id' => 'required|integer',
@@ -464,6 +469,7 @@ class PatientController extends AuthController
             $res_patient['user_id'] = $data['user_id'];
             $res_patient['user_name'] = $data['user']['nickname'];
             $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']);
@@ -632,44 +638,184 @@ class PatientController extends AuthController
         $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']);
-                if ($queryCallStatus['Code']=='OK'){
-                    if ($queryCallStatus['SecretCallStatusDTO']!=4){
+            if ($querylok['Code'] == 'OK') {
+                $queryCallStatus = $commons->QueryCallStatus($phone, $querylok['SubsId']);
+                if ($queryCallStatus['Code'] == 'OK') {
+                    if ($queryCallStatus['SecretCallStatusDTO'] != 4) {
                         return out($finds['xphone']);
-                    }else{
-                        if ($phone){
-                            $callModel = $commons->BindAxb($docter_phone,$phone);
-                            if ($callModel['Code']=="OK"){
+                    } else {
+                        if ($phone) {
+                            $callModel = $commons->BindAxb($docter_phone, $phone);
+                            if ($callModel['Code'] == "OK") {
                                 return out($callModel['SecretBindDTO']['SecretNo']);
                             }
-                        }else{
-                            return out('',500,'患者电话不存在');
+                        } else {
+                            return out('', 500, '患者电话不存在');
                         }
                     }
                 }
             }
 
-        }else{
-            if ($phone){
-                $callModel = $commons->BindAxb($docter_phone,$phone);
-                if ($callModel['Code']=="OK"){
+        } else {
+            if ($phone) {
+                $callModel = $commons->BindAxb($docter_phone, $phone);
+                if ($callModel['Code'] == "OK") {
                     Axb::create([
-                        'docter_id'=>$docter_id,
-                        'user_id'=>$req['user_id'],
-                        'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
-                        'createtime'=>time(),
+                        'docter_id' => $docter_id,
+                        'user_id' => $req['user_id'],
+                        'xphone' => $callModel['SecretBindDTO']['SecretNo'],
+                        'createtime' => time(),
                     ]);
                     return out($callModel['SecretBindDTO']['SecretNo']);
-                }else{
+                } else {
                     return out($callModel);
                 }
-            }else{
-                return out('',500,'患者电话不存在');
+            } else {
+                return out('', 500, '患者电话不存在');
             }
         }
 
     }
 
 
+
+
+    /**
+     * 取消订单接口
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function cancelOrder()
+    {
+        $req = request()->post();
+        $this->validate(request(), [
+            'order_id' => 'required|integer',
+        ]);
+        $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first();
+        if ($order['order_status'] == 2 && $order['payment_status'] == 2) {
+            DB::beginTransaction();
+            try {
+                if ($order['product_type'] == 3) {
+                    Order::where('id',$req['order_id'])->update(['order_status'=>5,'payment_status'=>5,'order_notes'=>'医生拒绝接单']);
+                }else{
+                    //退钱到余额
+                    if (!empty($order['payment_amount'])) {
+                        User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '医生拒绝接单');
+                    }
+                    Order::where('id', $req['order_id'])->update(['order_status' => 5, 'order_notes' => '医生拒绝接单', 'payment_status' => 4]);
+                }
+                DB::commit();
+                return out('', 200, '订单取消成功');
+            } catch (\Exception $e) {
+                DB::rollBack();
+                return out('', 500, $e->getMessage());
+
+            } catch (\PDOException $e) {
+                DB::rollBack();
+                return out('', 500, $e->getMessage());
+            }
+        } else {
+            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(['docter_id'=>$docter_id,'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'];
+                }
+            }else if($v['product_type']==2){
+                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'];
+                }
+            }
+
+        }
+        if ($catNewIds || $menNewIds){
+            // 操作图文和电话订单为已完成
+            Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);
+            // 操作门诊订单为已超时
+            Order::whereIn('id',$menNewIds)->update(['order_status'=>6]);
+        }
+    }
+
+
+    /**
+     * 获取病例信息接口!
+     * @author  Liu
+     * @return \Illuminate\Http\JsonResponse
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function CaseAcquisition()
+    {
+        $req = request()->post();
+        $this->validate(request(), [
+            'user_id' => 'required|integer',
+            'order_id',
+            'is_showAll'=>'required|integer'
+        ]);
+        $user = $this->user;
+        $docter_id = $user['id'];
+
+        // 订单内点击
+        if (isset($req['order_id'])&&!empty($req['order_id'])){
+            $data = Order::with(['orderPatient','user'])->where('id',$req['order_id'])->first();
+        }else{
+            $data = Order::with(['orderPatient','user'])->where(['user_id'=>$req['user_id'],'docter_id'=>$docter_id,'product_type'=>2,'order_status'=>3])->orderBy('id','desc')->first();
+        }
+
+        // 返回数组
+        $res_patient = [];
+        if ($req['is_showAll']==1){
+            $list = Order::with(['orderPatient','user'])->where(['user_id'=>$req['user_id'],'docter_id'=>$docter_id,'product_type'=>2])->orderBy('id','asc')->get();
+            if ($list){
+                $list = $list->toArray();
+                foreach ($list as $k=>$v){
+                    $res_patient['list'][$k]['order_sn'] = $v['order_sn'];
+                    $res_patient['list'][$k]['user_id'] = $v['user_id'];
+                    $res_patient['list'][$k]['user_name'] = $v['user']['nickname'];
+                    $res_patient['list'][$k]['user_avatar'] = $v['user']['avatar'];
+                    $res_patient['list'][$k]['sex'] = $v['order_patient']['sex'];
+                    $res_patient['list'][$k]['name'] = $v['order_patient']['name'];
+                    $res_patient['list'][$k]['numbirthday'] = numBirthday($v['order_patient']['birthday']);
+                    $res_patient['list'][$k]['symptoms'] = $v['order_patient']['symptoms'];//病情描述
+                    $res_patient['list'][$k]['medical_imgs'] = json_decode($v['order_patient']['medical_imgs'], true);//病情照片
+                }
+            }
+        }
+        if ($data) {
+            $data = $data->toArray();
+            $res_patient['data']['order_sn'] = $data['order_sn'];
+            $res_patient['data']['user_id'] = $data['user_id'];
+            $res_patient['data']['user_name'] = $data['user']['nickname'];
+            $res_patient['data']['user_avatar'] = $data['user']['avatar'];
+            $res_patient['data']['sex'] = $data['order_patient']['sex'];
+            $res_patient['data']['name'] = $data['order_patient']['name'];
+            $res_patient['data']['numbirthday'] = numBirthday($data['order_patient']['birthday']);
+            $res_patient['data']['symptoms'] = $data['order_patient']['symptoms'];//病情描述
+            $res_patient['data']['medical_imgs'] = json_decode($data['order_patient']['medical_imgs'], true);//病情照片
+        }
+        return out($res_patient);
+    }
+
+
 }

+ 10 - 0
app/Models/DocterType.php

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