Sfoglia il codice sorgente

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

zilong 4 anni fa
parent
commit
35bec14e19

+ 2 - 2
app/Admin/Actions/backstage/User/service.php

xqd
@@ -7,12 +7,12 @@ use Illuminate\Database\Eloquent\Model;
 
 class service extends RowAction
 {
-    public $name = '服务包';
+    public $name = '服务包管理';
 
     public function handle(Model $model)
     {
         // $model ...
-        return $this->response()->success('跳转服务包库成功')->redirect('/admin/user_orders?patient_id='.$this->row->id.'&product_type=6');
+        return $this->response()->success('跳转服务包库成功')->redirect('/admin/user_order?user_id='.$this->row->id.'&product_type=6');
 
     }
 

+ 3 - 0
app/Admin/Controllers/CommunityNotice/CommunityNotices.php

xqd xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Admin\Controllers\CommunityNotice;
 
 use App\Models\CommunityNotice;
+use App\Models\Organization;
 use Encore\Admin\Auth\Database\Administrator;
 use Encore\Admin\Controllers\AdminController;
 use Encore\Admin\Facades\Admin;
@@ -28,6 +29,7 @@ class CommunityNotices extends AdminController
     {
         $grid = new Grid(new CommunityNotice());
         $grid->column('id', __('Id'))->sortable();
+        $grid->column('organization.name', __('发放社区'));
         $grid->column('title', __('标题'));
         $grid->column('type', __('类型'))->using([1=>'社区通告']);
         $grid->column('content', __('内容'))->limit(100,'...');
@@ -66,6 +68,7 @@ class CommunityNotices extends AdminController
     {
         $form = new Form(new CommunityNotice());
         $form->text('title', __('标题'));
+        $form->select('organization_id', __('发放的社区'))->options(Organization::all()->pluck('name','id'));
         $form->select('type', __('类型'))->options([1=>'社区端通告']);
         $form->editor('content', __('内容'));
         $form->submitted(function ($form){

+ 30 - 0
app/Admin/Controllers/CouponManagement/CouponManagementController.php

xqd
@@ -48,6 +48,36 @@ class CouponManagementController extends AdminController
         $grid->column('icon', __('券图标'))->image('',100,100);
         $grid->column('type', __('类型'))->using([1=>'满减券',2=>'折扣券']);
         $grid->column('usable_type', __('可用类型'))->using([1=>'全部产品通用',2=>'部分产品可用']);
+        $grid->column('CouponType', __('可用产品'))->pluck('product_type','id')->display(function ($i){
+            $name = [];
+            foreach ($i as $value)
+            {
+                switch ($value){
+                    case 1:
+                        array_push($name,'电话咨询');
+                        break;
+                    case 2:
+                        array_push($name,'图文咨询');
+                        break;
+                    case 3:
+                        array_push($name,'门诊咨询');
+                        break;
+                    case 4:
+                        array_push($name,'疫苗接种');
+                        break;
+                    case 5:
+                        array_push($name,'儿保预约');
+                        break;
+                    case 6:
+                        array_push($name,'服务包');
+                        break;
+                    case 7:
+                        array_push($name,'充值');
+                        break;
+                }
+            }
+            return $name;
+        })->label('info');
         $grid->column('money', __('满减券的优惠钱数'))->display(function ($money){
             return $money/100;
         });

+ 11 - 10
app/Admin/Controllers/ServiceManagement/ServiceController.php

xqd xqd xqd
@@ -46,18 +46,18 @@ class ServiceController extends AdminController
         $grid->column('ondocter.name','医生名称');
         $grid->column('ondocter.sex','性别')->using([1=>'男',2=>'女']);
         $grid->column('docterorganization', __('所属机构'))->pluck('organization_id')->display(function ($organization){
-            $value = Organization::whereIn('id',$organization)->pluck('name');
+            $value = Organization::whereIn('id',$organization->toArray())->pluck('name')->toArray();
             return $value;
         })->label('info');
         $grid->column('ondocter.label', __('标签'))->display(function ($label){
-            if($label==null)
+            if($label==null || $label == '无')
             {
                 return '无';
             }else{
-                $label_value = DocterLabel::whereIn('id',$label)->pluck('label_name');
+                $label_value = DocterLabel::whereIn('id',$label)->pluck('label_name')->toArray();
                 return $label_value;
             }
-        })->label('info');
+        })->label(['info']);
 
 
         $grid->column('status', __('状态'))->using([1=>'审核',2=>'已通过',3=>'已拒绝'])->label([
@@ -71,11 +71,12 @@ class ServiceController extends AdminController
         $grid->filter(function ($filter){
             $filter->equal('service_type','服务类型')->select([1 => '图文', 2 => '电话', 3 => '问诊']);
             $filter->equal('status','服务类型')->select([1=>'待审核',2 =>'已通过 ',3=>'已拒绝']);
-            $filter->where(function ($query) {
-                $query->whereHas('organization',function ($query){
-                    $query->where('name','like',"%{$this->input}%");
-                });
-            },'机构名');
+//            $filter->where(function ($query) {
+//                $query->whereHas('organization',function ($query){
+//                    $query->where('name','like',"%{$this->input}%");
+//                });
+//            },'机构名');
+            $filter->equal('docterorganization.organization_id','机构')->select(Organization::pluck('name','id'));
         });
         $grid->actions(function ($actions) {
             $actions->disableEdit();
@@ -89,4 +90,4 @@ class ServiceController extends AdminController
         return $grid;
     }
 
-}
+}

+ 3 - 1
app/Admin/Controllers/UserManagement/BmUser/UserListController.php

xqd xqd
@@ -8,6 +8,7 @@ use App\Admin\Actions\backstage\User\BalanceLog;
 use App\Admin\Actions\backstage\User\BlackList;
 use App\Admin\Actions\backstage\User\coupons;
 use App\Admin\Actions\backstage\User\Orders;
+use App\Admin\Actions\backstage\User\service;
 use App\Models\Patient;
 use App\Models\User;
 use Encore\Admin\Controllers\AdminController;
@@ -40,11 +41,12 @@ class UserListController extends AdminController
         $actions->disableEdit();
         // 去掉查看
         $actions->disableView();
-        $actions->add(new archives());
+//        $actions->add(new archives());
         $actions->add(new BalanceLog());
         $actions->add(new BlackList());
         $actions->add(new coupons());
         $actions->add(new Orders());
+        $actions->add(new service());
     });
         //筛选
         $grid->filter(function ($filter){

+ 15 - 16
app/Admin/Controllers/UserManagement/BmUser/UserOrdersController.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\UserManagement\BmUser;
 
+use App\Admin\Actions\backstage\Orders\ServicePack;
 use App\Models\Order;
 use Encore\Admin\Controllers\AdminController;
 use Encore\Admin\Form;
@@ -43,22 +44,20 @@ class UserOrdersController extends AdminController
             return date('Y-m-d H:i:s',$time);
         });
         $grid->column('product_type', __('产品类型'))->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值']);
-        $grid->column('payment_type', __('支付方式'))->using([1=>'微信支付',2=>'余额支付',3=>'服务包支付']);
-//        $grid->column('payment_type', __('支付方式'))->display(function ($payment_type){
-//            if ($payment_type == 1)
-//            {
-//                return '微信支付';
-//            }
-//            if ($payment_type == 2){
-//                return '余额支付';
-//            }
-//            if ($payment_type == 3){
-//////                dd($this);
-////                $patient_id = $this->patient_id;
-////                $orde_id = Order::where('patient_id',$patient_id)->where('product_type',6)->get('id');
-//                return '服务包支付';
-//            }
-//        });
+        $grid->column('payment_type', __('支付方式'))->display(function ($payment_type){
+            if ($payment_type == 1)
+            {
+                return '微信支付';
+            }
+            if ($payment_type == 2){
+                return '余额支付';
+            }
+            if ($payment_type == 3){
+                $name = ServicePack::where('id',$this->pay_order_pack_id)->pluck('name');
+                return '服务包支付('.$name[0].')';
+            }
+            return '';
+        });
         $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
         $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款']);
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){

+ 3 - 3
app/Admin/Controllers/UserManagement/BmUser/UserPatientsController.php

xqd xqd
@@ -19,7 +19,7 @@ class UserPatientsController extends AdminController
      *
      * @var string
      */
-    protected $title = '档案';
+    protected $title = '患者列表';
 
     /**
      * Make a grid builder.
@@ -43,14 +43,14 @@ class UserPatientsController extends AdminController
             // 去掉编辑
             $actions->disableEdit();
             //服务包
-            $actions->add(new service());
+//            $actions->add(new service());
 
         });
         $grid->column('id', __('档案id'));
         $grid->column('user_id', __('用户id'));
         $grid->column('name', __('患者姓名'));
         $grid->column('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女',]);
-        $grid->column('avatar', __('头像'))->image("",100,100);
+        $grid->column('avatar', __('头像'))->image("",'',50);
         $grid->column('age', __('年龄'));
         $grid->column('email', __('邮箱'));
         $grid->column('phone', __('联系电话'));

+ 2 - 2
app/Admin/Controllers/UserManagement/BmUser/UserServiceController.php

xqd xqd
@@ -18,7 +18,7 @@ class UserServiceController extends AdminController
      *
      * @var string
      */
-    protected $title = '服务包-保单';
+    protected $title = '服务包管理';
 
     /**
      * Make a grid builder.
@@ -32,7 +32,7 @@ class UserServiceController extends AdminController
         $uesr_id = \request('user_id');
         $grid->filter(function ($filter){
             $filter->disableIdFilter();
-            $filter->equal('patient_id','档案id');
+            $filter->equal('user_id','用户id');
             $filter->equal('product_type','订单类型');
         });
         $grid->actions(function ($actions) {

+ 2 - 2
app/Admin/routes.php

xqd
@@ -94,8 +94,8 @@ Route::group([
     $router->resource('users', UserManagement\BmUser\UserListController::class);
     //用户列表->查看患者档案
     $router->resource('user_patients', UserManagement\BmUser\UserPatientsController::class);
-    //查看患者档案->服务包
-    $router->resource('user_orders', UserManagement\BmUser\UserServiceController::class);
+    //用户列表->服务包管理
+    $router->resource('user_order', UserManagement\BmUser\UserServiceController::class);
     //用户列表->余额明细
     $router->resource('user_balance_logs', UserManagement\BmUser\UserBalanceLogController::class);
     //用户管理->优惠券管理

+ 283 - 137
app/Http/Controllers/ScheDuleController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -173,8 +173,6 @@ class ScheDuleController  extends Controller
                         ->where('organization_id','!=',$org_id)->where('docter_id','=',$docter_id)->count();
                     $is_mo_self = SchedulePeriod::whereIn('schedule_id',$sche_dule)->where('schedule_date',$str_time)->whereIn('time_period_id',$times[$j])
                         ->where('organization_id',$org_id)->where('docter_id',$docter_id)->count();
-//                    echo $i.'--'.$j.'is_self---'.$is_mo_self.'<br>';
-
                     if($is_mo_self){
                         $sche_dule_arr[$j][$week_arr[$i]] = true;
                     }
@@ -322,38 +320,38 @@ class ScheDuleController  extends Controller
         $first_day = strtotime($start_time);
         //周字段映射
         $week_arr = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'];
-//        $data = [
-//            [
-//                'date'=>"上午",
-//                'monday'=>false,
-//                'tuesday'=>false,
-//                'wednesday'=>false,
-//                'thursday'=>true,
-//                'friday'=>false,
-//                'saturday'=>false,
-//                'sunday'=>false,
-//            ],
-//            [
-//                'date'=>"下午",
-//                'monday'=>false,
-//                'tuesday'=>true,
-//                'wednesday'=>false,
-//                'thursday'=>false,
-//                'friday'=>false,
-//                'saturday'=>false,
-//                'sunday'=>false,
-//            ],
-//            [
-//                'date'=>"晚上",
-//                'monday'=>false,
-//                'tuesday'=>false,
-//                'wednesday'=>true,
-//                'thursday'=>false,
-//                'friday'=>false,
-//                'saturday'=>false,
-//                'sunday'=>false,
-//            ]
-//        ];
+        $data = [
+            [
+                'date'=>"上午",
+                'monday'=>false,
+                'tuesday'=>false,
+                'wednesday'=>false,
+                'thursday'=>true,
+                'friday'=>false,
+                'saturday'=>false,
+                'sunday'=>false,
+            ],
+            [
+                'date'=>"下午",
+                'monday'=>false,
+                'tuesday'=>true,
+                'wednesday'=>false,
+                'thursday'=>false,
+                'friday'=>false,
+                'saturday'=>false,
+                'sunday'=>false,
+            ],
+            [
+                'date'=>"晚上",
+                'monday'=>false,
+                'tuesday'=>false,
+                'wednesday'=>true,
+                'thursday'=>false,
+                'friday'=>false,
+                'saturday'=>false,
+                'sunday'=>false,
+            ]
+        ];
 
 
         //时段区间id
@@ -550,14 +548,21 @@ class ScheDuleController  extends Controller
         $org_id = request('org_id');
         $date = request('date');
         $type = request('type','1,2'); //1 上午,2 下午,3 晚上
-        $schedule_type = request('schedule_type');
+        $schedule_type = request('schedule_type',1);
+        $Ttype = 1;
+        if($schedule_type == 1) $Ttype = 2;
         $self_setting = DocterSetting::where(['docter_id'=>$docter_id])->first();
         $times = [];
         if(!empty($self_setting)){
             $time_period = object_array(json_decode($self_setting->service_time));
-            $times[1] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[0]['startTime']),intval($time_period[0]['endTime'])])->pluck('id')->toArray();
-            $times[2] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['startTime']),intval($time_period[1]['endTime'])])->pluck('id')->toArray();
-            $times[3] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[2]['startTime']),intval($time_period[2]['endTime'])])->pluck('id')->toArray();
+            $where = ['docter_id'=>$docter_id,'type'=>$Ttype];
+            if($Ttype == 1){
+                $where['org_id'] = $org_id;
+            }
+//            dd($time_period);
+            $times[1] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[1]['amStartTime']),intval($time_period[1]['amEndTime'])])->pluck('id')->toArray();
+            $times[2] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[2]['pmStartTime']),intval($time_period[2]['pmEndTime'])])->pluck('id')->toArray();
+            $times[3] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[3]['nightStartTime']),intval($time_period[3]['nightEndTime'])])->pluck('id')->toArray();
         }
         if(count($times) <3){
             return apiReturn(602,'请设置真确的时间段');
@@ -583,6 +588,7 @@ class ScheDuleController  extends Controller
                     'docter_id'=>$docter_id,
                     'type'=>intval($t)
                 ];
+
                 foreach ($times[intval($t)] as $id){
                     $self_schedule['time_period_id'] = $id;
                     $is_have = SelfSchedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id,'schedule_date'=>$date,'type'=>intval($t),'week'=>$week,'time_period_id'=>$id])->value('id');
@@ -602,28 +608,31 @@ class ScheDuleController  extends Controller
     //更新用戶設置
     public function updateDocterSetting()
     {
-        $docter_id = request('docter_id',1);
-        $configData = request('configData');
-        $type = request('type');
+        $docter_id = intval(request('docter_id',1));
+        $configData = request('configData',1);
+        $type = request('type',1);//医生类型 1 机构 2 医生
+        $schedule_type = request('schedule_type',1); //排班类型 1门诊 2计免 3儿保
+        $org_id = intval(request('org_id',0));
         if(empty($docter_id) || empty($configData)){
             return apiReturn(604,'参数错误');
         }
 
-        $configData = object_array(json_decode($configData));
-//        $configData = [
-//            'amEndTime'=>"11:30",
-//            'amNum'=>20,
-//            'amStartTime'=>"09:00",
-//            'nightEndTime'=>"19:30",
-//            'nightNum'=>8,
-//            'nightStartTime'=>"11:30",
-//            'pmEndTime'=>"16:00",
-//            'pmNum'=>20,
-//            'pmStartTime'=>"13:30",
-//            'serviceNum'=>2,
-//            'status'=>false,
-//            'timeSpan'=>15,
-//        ];
+//        $configData = object_array(json_decode($configData));
+        $configData = [
+            'amEndTime'=>"11:30",
+            'amNum'=>5,
+            'amStartTime'=>"09:00",
+            'nightEndTime'=>"20:30",
+            'nightStartTime'=>"19:00",
+            'nightNum'=>3,
+            'pmEndTime'=>"16:00",
+            'pmNum'=>5,
+            'pmStartTime'=>"13:30",
+            'showDayNumber'=>7,
+            'serviceNum'=>2,
+            'status'=>false,
+            'timeSpan'=>30,
+        ];
 
 //        configData: {
 //                amEndTime: "11:30",    //上午结束时间  string
@@ -640,14 +649,19 @@ class ScheDuleController  extends Controller
 //        status: false,   //  是否开启  true false
 //        timeSpan: "15",   // 就诊时长  string
 //      },
+//        $config = [
+//            ['amStartTime'],
+//        ];
         $setting  = DocterSetting::where(['docter_id'=>$docter_id])->first()->toArray();
 
         $self_config = object_array(json_decode($setting['service_time']));
+
         $is_new = [];
+        $is_change = false;
 //
-//        if(intval($configData['timeSpan']) != $setting['service_num']){
-//            $is_new[] = 4 ;
-//        }
+        if(intval($configData['timeSpan']) != $setting['service_num']){
+            $is_change = true;
+        }
 //
 //        if($configData['amStartTime'] != $self_config[1]['amStartTime'] ||  $configData['amEndTime'] != $self_config[1]['amEndTime']){
 //            $is_new[] = 1;
@@ -660,7 +674,10 @@ class ScheDuleController  extends Controller
 //        if($configData['nightStartTime'] != $self_config[3]['nightStartTime'] ||  $configData['nightEndTime'] != $self_config[3]['nightEndTime']){
 //            $is_new[] = 3;
 //        }
-//
+
+        if(intval($configData['timeSpan']) != $setting['service_num']){
+            $is_new = [1,2,3];
+        }
 //        configData: {
 //                amEndTime: "11:30",    //上午结束时间  string
         //        amNum: 20,  //上午号源 Num
@@ -677,82 +694,136 @@ class ScheDuleController  extends Controller
         //        timeSpan: "15",   // 就诊时长  string
 //      },
         //添加时间段
-        $is_new = [1];
-        if(count($is_new) > 5){
-//            $data = ['docter_id'=>$docter_id,'am_start'=>'8:30','am_end'=>'11:30','pm_start'=>'12:00','pm_end'=>'15:00','ev_start'=>'19:00','ev_end'=>'22:00','service_time'=>15];
-//            $amtimes[] = explode(':',$configData['amStartTime']);
-//            $amtimes[] = explode(':',$configData['amEndTime']);
-//            $amcha = ($amtimes[1][0] - $amtimes[0][0])*60 +($amtimes[1][1] - $amtimes[0][1]);
-//            $amCount = $amcha/$data['service_time'];
-//            $amCount = intval(floor((strtotime($configData['amEndTime']) - strtotime($configData['amStartTime'])) / (60*$configData['timeSpan'])));
-
-//            $pmtimes[] = explode(':',$configData['pmStartTime']);
-//            $pmtimes[] = explode(':',$configData['pmEndTime']);
-//            $pmCount =intval(floor((strtotime($configData['pmEndTime']) - strtotime($configData['pmStartTime'])) / (60*$configData['timeSpan'])));
-//
-//
-//            $evtimes[] = explode(':',$configData['nightStartTime']);
-//            $evtimes[] = explode(':',$configData['nightEndTime']);
-//            $evcha = ($evtimes[1][0] - $evtimes[0][0])*60 +($evtimes[1][1] - $evtimes[0][1]);
-//            $evCount = $evcha/$configData['service_time'];
-            $amCount = $configData['amNum'];
-            $pmCount = $configData['pmNum'];
-            $evCount = $configData['nightNum'];
-
-
-            $today_id = Schedule::where(['docter_id'=>$docter_id])->where('schedule_date','=',date('Y-m-d'))->value('id');
-            if(in_array(4,$is_new)){
-                TimePeriod::where(['docter_id'=>$docter_id])->delete();
-                $schuedule_ids = Schedule::where(['docter_id'=>$docter_id])->where(['schedule_date','>',date('Y-m-d')])->pluck('id')->toArray();
-                SchedulePeriod::where(['docter_id'=>$docter_id])->whereIn('schedule_id',$schuedule_ids)->delete();
-
-                for($i=1;$i<=$amCount;$i++){
-                    $amdata = [
-                        'docter_id'=>$docter_id,
-                        'start_time_period'=> date('H:i',strtotime($configData['amStartTime']) + ($i-1)*$configData['timeSpan']*60),
-                        'end_time_period'=> date('H:i',strtotime($configData['amStartTime']) + $i*$configData['timeSpan']*60),
-                    ];
-                    TimePeriod::insert($amdata);
-                }
-
-                for($i=1;$i<=$pmCount;$i++){
-                    $pmdata = [
-                        'docter_id'=>$docter_id,
-                        'start_time_period'=> date('H:i',strtotime($configData['pmStartTime']) + ($i-1)*$configData['timeSpan']*60),
-                        'end_time_period'=> date('H:i',strtotime($configData['pmStartTime']) + $i*$configData['timeSpan']*60),
-                    ];
-                    TimePeriod::insert($pmdata);
-                }
-
-                for($i=1;$i<=$evCount;$i++){
-                    $evdata = [
-                        'docter_id'=>$docter_id,
-                        'start_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + ($i-1)*$configData['timeSpan']*60),
-                        'end_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + $i*$configData['timeSpan']*60),
-                    ];
-                    TimePeriod::insert($evdata);
-                }
-            } else {
-                if(in_array(1,$is_new)){
-
-                    TimePeriod::where(['docter_id'=>$docter_id,'type'=>1])->delete();
-                    $old_ids = SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->distinct('week')->pluck('week','type')->toArray();
-
-                    $schedule_ids = Schedule::where(['docter_id'=>$docter_id])->where(['schedule_date','>',date('Y-m-d')])->pluck('id')->toArray();
-                    SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->whereIn('schedule_id',$schedule_ids)->delete();
-
-                    SchedulePeriod::where(['docter_id'=>$docter_id])->whereIn('schedule_id',$schedule_ids)->delete();
-                    for($i=1;$i<=$amCount;$i++){
-                        $amdata = [
-                            'docter_id'=>$docter_id,
-                            'start_time_period'=> date('H:i',strtotime($configData['amStartTime']) + ($i-1)*$configData['timeSpan']*60),
-                            'end_time_period'=> date('H:i',strtotime($configData['amStartTime']) + $i*$configData['timeSpan']*60),
-                        ];
-                        TimePeriod::insert($amdata);
+        $is_new = [2,3];
+        $amCount = $configData['amNum'];
+        $pmCount = $configData['pmNum'];
+        $evCount = $configData['nightNum'];
+        $c_r = [
+            ['count'=>$configData['amNum'],'start_time'=>$configData['amStartTime'],'end_time'=>$configData['amEndTime']],
+            ['count'=>$configData['pmNum'],'start_time'=>$configData['pmStartTime'],'end_time'=>$configData['pmEndTime']],
+            ['count'=>$configData['nightNum'],'start_time'=>$configData['nightStartTime'],'end_time'=>$configData['nightEndTime']]
+        ];
+        if($is_change){
+
+            if(in_array(1,$is_new)) {
+                DB::beginTransaction();
+                try {
+                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 1])->pluck('id')->toArray();
+                    $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 1])->distinct('type')->orderBy('week')->pluck('week')->toArray();
+                    $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 1])->distinct('type')
+                        ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
+                    SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
+                    if (empty($week_schedule)) {
+                        Schedule::where(['docter_id' => $docter_id])->delete();
+                        SelfSchedule::where(['docter_id' => $docter_id])->delete();
+                    } else {
+                            $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
+                                ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
+//                        $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
+                        foreach ($schedule as $id => $date) {
+                            $week = intval(date('N', strtotime($date)));
+                            foreach ($week_schedule as $w) {
+                                if ($week == $w) {
+                                    foreach ($time_periods as $idt) {
+                                        $s_t = [
+                                            'organization_id' => $org_id,
+                                            'docter_id' => $docter_id,
+                                            'type' => $type,
+                                            'schedule_date' => $date,
+                                            'schedule_id' => $id,
+                                            'time_period_id' => $idt
+                                        ];
+                                        $schedule_is_have = SchedulePeriod::where($s_t)->count();
+                                        if ($schedule_is_have) continue;
+                                        $s_t['created_at'] = Carbon::now();
+                                        $s_t['updated_at'] = Carbon::now();
+                                        if ($self_schedule == 1) $s_t['me_sure'] = 1;
+                                        SchedulePeriod::insert($s_t);
+                                    }
+                                }
+                            }
+                        }
+                        SelfSchedule::where(['type'=>1,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
+                        foreach ($self_schedule as $val) {
+                            $self_data = $val;
+                            $self_data['organization_id'] = $org_id;
+                            $self_data['docter_id'] = $docter_id;
+                            foreach ($time_periods as $idt) {
+                                $self_data['time_period_id'] = $idt;
+                                $is_self_have = SelfSchedule::where($self_data)->count();
+                                if ($is_self_have) continue;
+                                $self_data['created_at'] = Carbon::now();
+                                $self_data['updated_at'] = Carbon::now();
+                                SelfSchedule::insert($self_data);
+                            }
+                        }
                     }
+                    DB::commit();
+                } catch (\Exception $e) {
+                    dd($e->getMessage());
+                    DB::rollBack();
                 }
-
+            }
+//                SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->whereIn('schedule_id',$schedule_ids)->delete();
                 if(in_array(2,$is_new)){
+
+                    DB::beginTransaction();
+                    try {
+                        $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 2])->pluck('id')->toArray();
+                        $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 2])->distinct('type')->orderBy('week')->pluck('week')->toArray();
+                        $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 2])->distinct('type')
+                            ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
+                        SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
+                        if (empty($week_schedule)) {
+                            Schedule::where(['docter_id' => $docter_id])->delete();
+                            SelfSchedule::where(['docter_id' => $docter_id])->delete();
+                        } else {
+                            $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
+                                ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
+                            $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
+                            foreach ($schedule as $id => $date) {
+                                $week = intval(date('N', strtotime($date)));
+                                foreach ($week_schedule as $w) {
+                                    if ($week == $w) {
+                                        foreach ($time_periods as $idt) {
+                                            $s_t = [
+                                                'organization_id' => $org_id,
+                                                'docter_id' => $docter_id,
+                                                'type' => $type,
+                                                'schedule_date' => $date,
+                                                'schedule_id' => $id,
+                                                'time_period_id' => $idt
+                                            ];
+                                            $schedule_is_have = SchedulePeriod::where($s_t)->count();
+                                            if ($schedule_is_have) continue;
+                                            $s_t['created_at'] = Carbon::now();
+                                            $s_t['updated_at'] = Carbon::now();
+                                            if ($self_schedule == 1) $s_t['me_sure'] = 1;
+                                            SchedulePeriod::insert($s_t);
+                                        }
+                                    }
+                                }
+                            }
+                            SelfSchedule::where(['type'=>2,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
+                            foreach ($self_schedule as $val) {
+                                $self_data = $val;
+                                $self_data['organization_id'] = $org_id;
+                                $self_data['docter_id'] = $docter_id;
+                                foreach ($time_periods as $idt) {
+                                    $self_data['time_period_id'] = $idt;
+                                    $is_self_have = SelfSchedule::where($self_data)->count();
+                                    if ($is_self_have) continue;
+                                    $self_data['created_at'] = Carbon::now();
+                                    $self_data['updated_at'] = Carbon::now();
+                                    SelfSchedule::insert($self_data);
+                                }
+                            }
+                        }
+                        DB::commit();
+                    } catch (\Exception $e) {
+                        dd($e->getMessage());
+                        DB::rollBack();
+                    }
                     for($i=1;$i<=$pmCount;$i++){
                         $pmdata = [
                             'docter_id'=>$docter_id,
@@ -763,17 +834,81 @@ class ScheDuleController  extends Controller
                     }
                 }
 
-                if(in_array(2,$is_new)) {
-                    for($i=1;$i<=$evCount;$i++){
+            if(in_array(3,$is_new)){
+
+                DB::beginTransaction();
+                try {
+                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 3])->pluck('id')->toArray();
+                    $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 3])->distinct('type')->orderBy('week')->pluck('week')->toArray();
+                    $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 3])->distinct('type')
+                        ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
+                    SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
+                    if (empty($week_schedule)) {
+                        Schedule::where(['docter_id' => $docter_id])->delete();
+                        SelfSchedule::where(['docter_id' => $docter_id])->delete();
+                    } else {
+                            $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
+                                ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
+//                        $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
+                        foreach ($schedule as $id => $date) {
+                            $week = intval(date('N', strtotime($date)));
+                            foreach ($week_schedule as $w) {
+                                if ($week == $w) {
+                                    foreach ($time_periods as $idt) {
+                                        $s_t = [
+                                            'organization_id' => $org_id,
+                                            'docter_id' => $docter_id,
+                                            'type' => $type,
+                                            'schedule_date' => $date,
+                                            'schedule_id' => $id,
+                                            'time_period_id' => $idt
+                                        ];
+                                        $schedule_is_have = SchedulePeriod::where($s_t)->count();
+                                        if ($schedule_is_have) continue;
+                                        $s_t['created_at'] = Carbon::now();
+                                        $s_t['updated_at'] = Carbon::now();
+                                        if ($self_schedule == 1) $s_t['me_sure'] = 1;
+                                        SchedulePeriod::insert($s_t);
+                                    }
+                                }
+                            }
+                        }
+                        SelfSchedule::where(['type'=>3,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
+                        foreach ($self_schedule as $val) {
+                            $self_data = $val;
+                            $self_data['organization_id'] = $org_id;
+                            $self_data['docter_id'] = $docter_id;
+                            foreach ($time_periods as $idt) {
+                                $self_data['time_period_id'] = $idt;
+                                $is_self_have = SelfSchedule::where($self_data)->count();
+                                if ($is_self_have) continue;
+                                $self_data['created_at'] = Carbon::now();
+                                $self_data['updated_at'] = Carbon::now();
+                                SelfSchedule::insert($self_data);
+                            }
+                        }
+                    }
+                    DB::commit();
+                } catch (\Exception $e) {
+                    dd($e->getMessage());
+                    DB::rollBack();
+                }
+            }
+
+        } else {
+                foreach ($is_new as $c){
+                    for($i=1;$i<=$c_r[$c];$i++){
                         $evdata = [
                             'docter_id'=>$docter_id,
                             'start_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + ($i-1)*$configData['timeSpan']*60),
                             'end_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + $i*$configData['timeSpan']*60),
                         ];
+                        $is_have = TimePeriod::where($evdata);
+                        if($is_have) continue;
                         TimePeriod::insert($evdata);
                     }
                 }
-            }
+
         }
 //        {"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 = [
@@ -1049,7 +1184,7 @@ class ScheDuleController  extends Controller
     {
         $docter_id = request('docter_id',1);
         $org_id = request('org_id',1);
-        $type = request('type',2);
+        $type = request('type',1);
         if(empty($docter_id) || empty($org_id) || empty($type)){
             return apiReturn(601,'缺少必要参数');
         }
@@ -1099,6 +1234,7 @@ class ScheDuleController  extends Controller
             'organization_id'=>$org_id,
             'docter_id'=>$docter_id
         ];
+
         $k = 0;
         DB::beginTransaction();
 //        $data[0] = array_values(object_array(json_decode($data[0])));
@@ -1141,4 +1277,14 @@ class ScheDuleController  extends Controller
         }
         return apiReturn(200,'ok',$k);
     }
+
+    public static function get_cloumn_value($arr,$cloumn,$index=''){
+        if(!is_array($arr) || count($arr) == 0) return [];
+        foreach ($arr as $key => $val){
+            $arr[$key] = array_column($val,$cloumn,$index);
+        }
+        return $arr;
+    }
+
+
 }

+ 3 - 0
app/Models/CommunityNotice.php

xqd
@@ -8,4 +8,7 @@ class CommunityNotice extends Model
 {
     //
     protected $table = 'community_notice';
+    public function organization(){
+        return $this->hasOne(Organization::class,'id','organization_id');
+    }
 }

+ 3 - 0
app/Models/Organization.php

xqd
@@ -36,4 +36,7 @@ class Organization extends BaseModel
     {
         return $this->hasOne(CdmsUsers::class,'org_id','id');
     }
+    public function communityNotice(){
+        return $this->hasOne(CommunityNotice::class,'organization_id','id');
+    }
 }

+ 3 - 0
routes/web.php

xqd
@@ -27,6 +27,9 @@ Route::get('/setDocChedule', 'ScheDuleController@setDocChedule');
 Route::get('/api/get_month_schedule', 'ScheDuleController@get_month_schedule');
 Route::get('/api/update_docter_setting', 'ScheDuleController@updateDocterSetting');
 Route::get('/api/get_docter_setting', 'ScheDuleController@getDocterSetting');
+Route::get('/api/set_week_schedule', 'ScheDuleController@setWeekSchedule');
+Route::get('/api/get_week_chedule', 'ScheDuleController@getWeekSchedule');
+Route::get('/api/set_self_schedule', 'ScheDuleController@setSelfSchedule');
 
 //用户信息
 Route::get('/api/getScheduleInfo', 'ScheDuleController@getScheduleInfo');