zilong 4 年之前
父节点
当前提交
930725ed22

+ 9 - 1
app/Http/Controllers/Api/V1/DocterController.php

xqd
@@ -187,19 +187,27 @@ class DocterController extends AuthController
         $req = request()->post();
         $this->validate(request(), [
             'docter_id' => 'required|integer',
+            'organization_id' => 'integer',
             'per_page' => 'integer',
             'latitude' => 'numeric',
             'longitude' => 'numeric',
         ]);
         $user = $this->user;
 
-        $data = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'))->paginate($req['per_page']??15)->toArray();
+        $builder = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'));
+        if (!empty($req['organization_id'])) {
+            $builder->where('organization_id', $req['organization_id']);
+        }
+        $data = $builder->paginate($req['per_page']??15)->toArray();
         if (!empty($data)) {
             foreach ($data['data'] as $k => &$v) {
                 foreach ($v['schedule_period'] as $k1 => &$v1) {
                     if (!empty($v1['organization'])) {
                         $v1['organization']['distance'] = get_user_distance($user, $v1['organization']['latitude'], $v1['organization']['longitude']);
                     }
+
+                    $can_appoint_num = $v['per_time_num'] - $v1['order_num'];
+                    $v1['can_appoint_num'] = $can_appoint_num < 0 ? 0 : $can_appoint_num;
                 }
             }
         }

+ 49 - 0
app/Http/Controllers/Api/V1/OrderController.php

xqd xqd xqd
@@ -8,6 +8,7 @@
 
 namespace App\Http\Controllers\Api\V1;
 
+use App\Models\Docter;
 use App\Models\Nurse;
 use App\Models\Order;
 use App\Models\OrderNurse;
@@ -16,6 +17,7 @@ use App\Models\OrderPatient;
 use App\Models\OrderVaccine;
 use App\Models\Patient;
 use App\Models\Payment;
+use App\Models\SchedulePeriod;
 use App\Models\ServicePack;
 use App\Models\Team;
 use App\Models\TimePeriod;
@@ -626,4 +628,51 @@ class OrderController extends AuthController
 
         return out($config);
     }
+
+    public function orderCancel()
+    {
+        $req = request()->post();
+        $this->validate(request(), [
+            'order_id' => 'required|integer'
+        ]);
+
+        $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first();
+        if ($order['order_status'] == 4) {
+            return out(null, 10001, '订单已完成,不能取消了');
+        }
+        if ($order['order_status'] == 5) {
+            return out(null, 10002, '订单已取消了,请勿重复操作');
+        }
+
+        if ($order['product_type'] == 3) {
+            if ($order['order_patient']['appoint_start_time'] + 1800 > time()) {
+                return out(null, 10003, '预约时间临近,不能取消订单了');
+            }
+
+            DB::beginTransaction();
+            try {
+                //改变订单状态
+                Order::where('id', $req['order_id'])->update(['order_status' => 5]);
+                //退钱到余额
+                User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '取消订单退款');
+                //预约时间段的订单数减1
+                $orderPatient = OrderPatient::select(['time_period_id', 'appoint_start_time'])->where('order_id', $req['order_id'])->first();
+                $schedule_date = date('Y-m-d', $orderPatient['appoint_start_time']);
+                SchedulePeriod::where('docter_id', $order['docter_id'])->where('organization_id', $order['organization_id'])->where('time_period_id', $orderPatient['time_period_id'])->where('schedule_date', $schedule_date)->decrement('order_num');
+                //更新医生的服务人数
+                Docter::where('id', $order['docter_id'])->decrement('service_persons');
+
+                DB::commit();
+            } catch (Exception $e) {
+                DB::rollBack();
+
+                return out(null, 500, '取消订单失败,请稍后重试', $e->getMessage());
+            }
+        }
+        else {
+            return out(null, 10001, '暂时只支持取消门诊预约的订单');
+        }
+
+        return out();
+    }
 }

+ 0 - 5
app/Http/Controllers/Api/V1/PayCallbackController.php

xqd
@@ -61,11 +61,6 @@ class PayCallbackController extends Controller
                             'payment_time' => time(),
                         ]);
 
-                        if (!empty($order['docter_id'])) {
-                            //更新医生的服务人数
-                            Docter::where('id', $order['docter_id'])->increment('service_persons');
-                        }
-
                         Order::payCompletedHandle($order['id']);
 
                         // 提交事务

+ 1 - 1
app/Http/Controllers/Api/V1/VaccineController.php

xqd
@@ -22,7 +22,7 @@ class VaccineController extends AuthController
             'sort_type' => 'in:0,1,2',
         ]);
 
-        $builder = Vaccine::join('organization_vaccines', 'organization_vaccines.vaccine_id', '=', 'vaccines.id')->select(['vaccines.id', 'vaccines.type', 'vaccines.price', 'vaccines.name', 'vaccines.remark', 'vaccines.supplier', 'organization_vaccines.stock']);
+        $builder = Vaccine::join('organization_vaccines', 'organization_vaccines.vaccine_id', '=', 'vaccines.id')->select(['vaccines.id', 'vaccines.type', 'vaccines.price', 'vaccines.name', 'vaccines.remark', 'vaccines.supplier', 'organization_vaccines.stock'])->where('organization_vaccines.stock', '>', 0);
         if (!empty($req['type'])) {
             $builder->where('vacciness.type', $req['type']);
         }

+ 13 - 1
app/Models/Order.php

xqd xqd
@@ -76,7 +76,7 @@ class Order extends BaseModel
     //支付完成的处理方法
     public static function payCompletedHandle($order_id)
     {
-        $order = Order::select(['user_id', 'docter_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount', 'order_sn', 'pay_order_pack_id'])->where('id', $order_id)->first();
+        $order = Order::select(['user_id', 'docter_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount', 'order_sn', 'pay_order_pack_id', 'organization_id'])->where('id', $order_id)->first();
         //发送下单消息
         if ($order['product_type'] < 6) {
             $product_type_text = config('config.product_type_map')[$order['product_type']];
@@ -105,6 +105,18 @@ class Order extends BaseModel
             OrderPack::deductPackData($order['pay_order_pack_id'], $order['payment_type'], $order['payment_amount']);
         }
 
+        if (!empty($order['docter_id'])) {
+            //更新医生的服务人数
+            Docter::where('id', $order['docter_id'])->increment('service_persons');
+        }
+
+        //如果是门诊预约,预约时间段的订单数要加1
+        if ($order['product_type'] == 3) {
+            $orderPatient = OrderPatient::select(['time_period_id', 'appoint_start_time'])->where('order_id', $order_id)->first();
+            $schedule_date = date('Y-m-d', $orderPatient['appoint_start_time']);
+            SchedulePeriod::where('docter_id', $order['docter_id'])->where('organization_id', $order['organization_id'])->where('time_period_id', $orderPatient['time_period_id'])->where('schedule_date', $schedule_date)->increment('order_num');
+        }
+
         return true;
     }