瀏覽代碼

排班和订单优化

wanghaijun 4 年之前
父節點
當前提交
54accc4ebf
共有 2 個文件被更改,包括 41 次插入37 次删除
  1. 31 31
      app/Community/Controllers/ApiController.php
  2. 10 6
      app/Community/Controllers/DocterChatController.php

+ 31 - 31
app/Community/Controllers/ApiController.php

xqd xqd
@@ -731,43 +731,43 @@ class ApiController extends Controller
         }
 
         TimePeriod::where(['org_id' => $org_id, 'type' => $sType, 'docter_id' => $docter_id])->delete();
+        if($serviceTime['status']){
+            for ($i = 1; $i <= 3; $i++) {
+                $tType = $i;
+                DB::beginTransaction();
+                try {
+                    //1.删除旧时间段,并删除排班数据
 
-        for ($i = 1; $i <= 3; $i++) {
-            $tType = $i;
-            DB::beginTransaction();
-            try {
-                //1.删除旧时间段,并删除排班数据
-
-                //todo 暂时未删除周排班
-                self::deleteScheduleInfo($docter_id, $sType, $tType, $org_id);
-                $count = $countArr[$i];
-                //2.创建新时间段
-                self::makeTimePeriod($docter_id, $org_id, $sType, $c_r[$tType], $count, $serviceTime);
+                    //todo 暂时未删除周排班
+                    self::deleteScheduleInfo($docter_id, $sType, $tType, $org_id);
+                    $count = $countArr[$i];
+                    //2.创建新时间段
+                    self::makeTimePeriod($docter_id, $org_id, $sType, $c_r[$tType], $count, $serviceTime);
 
-                $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period', $times[$tType])->pluck('id')->toArray();
+                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period', $times[$tType])->pluck('id')->toArray();
 
 
-                if ($sType == 1) {
-                    $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType, 'schedule_type' => $sType]);
-                } else {
-                    $week_schedule = WeekSchedule::where(['organization_id' => $org_id, 'type' => $tType, 'schedule_type' => $sType]);
-                }
-                $week = $week_schedule->count();
+                    if ($sType == 1) {
+                        $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType, 'schedule_type' => $sType]);
+                    } else {
+                        $week_schedule = WeekSchedule::where(['organization_id' => $org_id, 'type' => $tType, 'schedule_type' => $sType]);
+                    }
+                    $week = $week_schedule->count();
 
-                if ($week != 0) {
-                    //3.以周模板添加2个月的数据
-                    self::makeSchedule($sType, $docter_id, $org_id, $tType, $time_periods);
-                    //TODO 删除周排班,插入新周排班
-                    self::changeWeekSchedule($docter_id, $org_id, $sType, $tType, $time_periods);
+                    if ($week != 0) {
+                        //3.以周模板添加2个月的数据
+                        self::makeSchedule($sType, $docter_id, $org_id, $tType, $time_periods);
+                        //TODO 删除周排班,插入新周排班
+                        self::changeWeekSchedule($docter_id, $org_id, $sType, $tType, $time_periods);
+                    }
+                    DB::commit();
+                } catch (\Exception $e) {
+                    dd($e->getMessage());
+                    DB::rollBack();
                 }
-                DB::commit();
-            } catch (\Exception $e) {
-                dd($e->getMessage());
-                DB::rollBack();
             }
         }
-
-
+        
         //{"1":{"amStartTime":"08:00","amEndTime":"12:00","amPerson":3},"2":{"pmStartTime":"14:00","pmEndTime":"18:00","pmPerson":5},"3":{"nightStartTime":"18:00","nightEndTime":"23:00","nightPerson":4}}
         $config = [
             1 => ['amStartTime' => $configData['amStartTime'], "amEndTime" => $configData['amEndTime'], 'amPerson' => $configData['amNum']],
@@ -870,9 +870,9 @@ class ApiController extends Controller
     public static function deleteScheduleInfo($docter_id, $sType, $timeType, $orgId = 0)
     {
         if ($docter_id != 0) {
-            SchedulePeriod::where(['docter_id' => $docter_id, 'type' => $timeType, 'me_sure' => 0])->where('organization_id', '=', $orgId)->delete();
+            SchedulePeriod::where(['docter_id' => $docter_id, 'schedule_type'=>$sType,'type' => $timeType, 'me_sure' => 0])->where('organization_id', '=', $orgId)->delete();
         } else {
-            SchedulePeriod::where(['organization_id' => $orgId, 'type' => $timeType, 'me_sure' => 0])->where('docter_id', 0)->delete();
+            SchedulePeriod::where(['organization_id' => $orgId, 'schedule_type'=>$sType,'type' => $timeType, 'me_sure' => 0])->where('docter_id', 0)->delete();
         }
         return true;
     }

+ 10 - 6
app/Community/Controllers/DocterChatController.php

xqd xqd
@@ -42,21 +42,20 @@ class DocterChatController extends AdminController
         $grid->batchActions(function ($batch) {
             $batch->add(new sendNotice());
         });
+        $where['product_type'] = 2;
         if(!$is_admin){
             $where['organization_id']=$org_id;
             if($docter_id){
                 $where['docter_id'] = $docter_id;
             }
-            $grid->model()->where($where);
-//            $grid->model()->whereHas('orders',function ($query) use ($org_id,$docter_id) {
-//                $query->where($where);
-//            });
         }
+        $grid->model()->where($where);
 
         $grid->column('order_sn', __('订单号'));
         $grid->column('docter.name', __('医生'));
         $grid->column('orderUser.nickname', __('咨询用户'));
         $grid->column('orderPatient.name', __('咨询患者'));
+        $grid->column('patient.phone', __('电话'));
         $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
             return birthday_to_age($w);
         });
@@ -69,9 +68,14 @@ class DocterChatController extends AdminController
            $actions->disableView();
            $actions->disableEdit();
         });
-        $grid->filter(function ($filter){
+        $grid->filter(function (Grid\Filter $filter){
             $filter->disableIdFilter();
-            $filter->equal('order_status','订单状态')->select(Order::$_order_status);
+            $filter->column(1/2, function ($filter) {
+                $filter->like('patient.phone','电话');
+                $filter->like('patient.name','患者名称');
+                $filter->equal('order_status','订单状态')->select(Order::$_order_status);
+                $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
+            });
         });
         $grid->column('order_status', __('订单状态'))->using(Order::$_order_status);
         $grid->column('created_at', __('下单时间'));