소스 검색

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

ChenWuJie 4 년 전
부모
커밋
7a1f732413

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

xqd xqd xqd
@@ -740,43 +740,43 @@ class ApiController extends Controller
         }
 
         TimePeriod::where(['org_id' => $org_id, 'type' => $sType, 'docter_id' => $docter_id])->delete();
+        if($configData['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']],
@@ -879,9 +879,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;
     }
@@ -898,7 +898,6 @@ class ApiController extends Controller
                 'end_time_period' => date('H:i', strtotime($timeConfig['start_time']) + $i * $serviceTime * 60),
             ];
             $isHave = TimePeriod::where($timePreiod)->count();
-//            dump($timePreiod);
 //            dump($isHave);
 
             if ($isHave == 0) $allData[] = $timePreiod;

+ 11 - 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,15 @@ 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('order_sn','订单号');
+                $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', __('下单时间'));

+ 66 - 10
app/Http/Controllers/AppiontController.php

xqd
@@ -159,17 +159,73 @@ class AppiontController extends Controller
     public function orverTime()
     {
         $st = strtotime('2021-02-25 18:00:00');
-        $orders = Order::select('id')
-            ->where(['product_type'=>4,'order_status'=>7])
-            ->where('appoint_end_time','<',$st)->get();
-//        DB::enableQueryLog();
-//        $orders = Order::leftjoin('order_patients','order_patients.order_id','=','orders.id')->where(['orders.product_type'=>4,'orders.order_status'=>7])->where('order_patients.appoint_end_time','<',$st)->get(['orders.id']);
-//        dd(DB::getQueryLog());
-        if(request('c') && !empty($orders)) return count($orders->toArray());
-        if(request('b') && !empty($orders)) dd($orders->toArray());
-        foreach ($orders as $order){
-            Order::where('id',$order->id)->update(['order_status'=>6]);
+        $type = intval(request('type'));
+        if($type == 2){
+            $orders = Order::where(['product_type'=>2,'order_status'=>6])->where('appoint_end_time','<',$st)->get();
+            foreach ($orders as $order){
+                if(strpos($order->order_notes,'取') || in_array(intval($order->payment_status),[3,4,5])){
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                    echo 'id:---'.$order->id.PHP_EOL;
+                }
+                if(intval($order->payment_status) == 0 || intval($order->payment_status) == 1){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>1]);
+                }
+                if(intval($order->payment_status) == 4){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                }
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) > 0 && $order->end_time == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>3]);
+                }
+
+                if(intval($order->payment_status) == 2  && $order->end_time > 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>4]);
+                }
+
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>2]);
+                }
+            }
+        } else if($type == 1) {
+            $orders = Order::where(['product_type'=>1,'order_status'=>6])->where('appoint_end_time','<',$st)->get();
+
+            foreach ($orders as $order){
+                if(strpos($order->order_notes,'取') || in_array(intval($order->payment_status),[3,4,5])){
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                    echo 'id:---'.$order->id.PHP_EOL;
+                }
+                if(intval($order->payment_status) == 0 || intval($order->payment_status) == 1){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>1]);
+                }
+                if(intval($order->payment_status) == 4){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                }
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) > 0 && $order->end_time == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>3]);
+                }
+
+                if(intval($order->payment_status) == 2  && $order->end_time > 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>4]);
+                }
+
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>2]);
+                }
+            }
         }
+
+
+////        DB::enableQueryLog();
+//        $orders = Order::leftjoin('order_patients','order_patients.order_id','=','orders.id')->where(['orders.product_type'=>4,'orders.order_status'=>7])->where('order_patients.appoint_end_time','<',$st)->get(['orders.id']);
+////        dd(DB::getQueryLog());
+//        if(request('c') && !empty($orders)) return count($orders->toArray());
+//        if(request('b') && !empty($orders)) dd($orders->toArray());
+//        foreach ($orders as $order){
+//            Order::where('id',$order->id)->update(['order_status'=>6]);
+//        }
     }
 
 

+ 25 - 59
app/Imports/Order/chatOrder.php

xqd xqd xqd
@@ -8,6 +8,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Log;
@@ -29,34 +30,7 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
 
         foreach ($collection as $row) {
             if ($row[0] == '订单编号') continue;
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
 
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-//                $pp = Patient::where('user_id',$user_id)->get()->toArray();
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
-
-            //如果没有用户不导入该订单
-            if (empty($user_id)) {
-                Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL);
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -68,43 +42,35 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
             if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
 
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
 
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => $row[12] * 100,
-                'discount_amount' => $row[13] * 100,
-                'payment_amount' => $row[15] * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 2,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[0],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
         }
         return null;
     }

+ 27 - 57
app/Imports/Order/phoneOrder.php

xqd xqd xqd
@@ -7,6 +7,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\ToCollection;
@@ -21,28 +22,6 @@ class phoneOrder implements ToCollection
         foreach ($collection as $row){
             if ($row[0] == '订单编号') continue;
 
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
-            //支付状态(1.待付款 2.已付款 3.退款中 4.已退款 5.待退款)
-            //如果没有用户不导入该订单
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -50,47 +29,38 @@ class phoneOrder implements ToCollection
             $paystatus = Order::getPayStatus();
             $pay_status = array_search($row[18], $paystatus);
             $order_status = array_search($row[9], $status);
-
-            if( $row[18] == '已退款') $pay_status = 4;
             if($row[9] == '已过期') $order_status = 6;
+            if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
+
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
-
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => intval($row[12]) * 100,
-                'discount_amount' => intval($row[13]) * 100,
-                'payment_amount' => intval($row[15]) * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 1,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[2],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
         }
         return null;
     }