zilong 4 years ago
parent
commit
ee8b06953b

+ 3 - 3
app/Http/Controllers/Api/V1/DocterController.php

xqd
@@ -187,9 +187,9 @@ class DocterController extends AuthController
         ]);
         $user = $this->user;
         $builder = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_type', 1)->where('schedule_day', '>=', date('Ymd'))->orderBy('schedule_day');
-//        if (!empty($req['organization_id'])) {
-//            $builder->where('organization_id', $req['organization_id']);
-//        }
+        if (!empty($req['organization_id'])) {
+            $builder->where('organization_id', $req['organization_id']);
+        }
         $data = $builder->paginate($req['per_page']??15)->toArray();
         \Log::info($data);
         if (!empty($data)) {

+ 9 - 3
app/Http/Controllers/Api/V1/OrderController.php

xqd xqd xqd
@@ -14,6 +14,7 @@ use App\Models\OrderNurse;
 use App\Models\OrderPack;
 use App\Models\OrderPatient;
 use App\Models\OrderVaccine;
+use App\Models\OrganizationVaccine;
 use App\Models\Patient;
 use App\Models\Payment;
 use App\Models\ServicePack;
@@ -244,6 +245,14 @@ class OrderController extends AuthController
             }
         }
 
+        //疫苗预约检查库存是否足够
+        if ($req['product_type'] == 4) {
+            $stock = OrganizationVaccine::where('org_id', $req['organization_id'])->where('vaccine_id', $req['vaccine_id'])->value('stock');
+            if ($stock <= 0) {
+                return out(null, 10009, '该疫苗库存不足');
+            }
+        }
+
         if ($req['payment_type'] == 3) {
             OrderPack::checkUserServicePack($req['order_pack_id'], $user['id'], $req['product_type'], $payment_amount);
         }
@@ -399,9 +408,6 @@ class OrderController extends AuthController
         }
 
         $addPatient = Patient::select(['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'info', 'card_type', 'card_number', 'card_img_url', 'card_back_img_url', 'email', 'phone as patient_phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'])->where('id', $req['patient_id'])->first()->getOriginal();
-        if (empty($addPatient['card_img_url'])) {
-            return out(null, 70011, '该患者未上传身份证');
-        }
 
         $payment_amount = $req['total_amount'] - $discount_amount;
         $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;

+ 34 - 4
app/Models/Order.php

xqd xqd xqd xqd xqd
@@ -10,7 +10,7 @@ namespace App\Models;
 
 class Order extends BaseModel
 {
-    protected $appends = ['is_evaluate', 'order_duration'];
+    protected $appends = ['is_evaluate', 'order_duration', 'consult_duration', 'callback_phone'];
 
     CONST UNPAID = 1, NOTACCEPT = 2, ISING = 3, FINISHED = 4,CANCELED=5,ISOUT=6; //订单状态(1.未支付 2.进行中 3.已完成 4.已取消)
     public static  $_order_status = [
@@ -44,7 +44,7 @@ class Order extends BaseModel
      * Create By 2020/11/18 11:06
      */
     public function userDocter(){
-        return $this->hasOne(UserDocter::class,'user_id','user_id')->select(['id', 'remark']);;
+        return $this->hasOne(UserDocter::class,'user_id','user_id')->select(['id', 'remark']);
     }
 
     public function patients(){
@@ -120,10 +120,10 @@ class Order extends BaseModel
             OrderPack::deductPackData($order['pay_order_pack_id'], $order['product_type'], $order['payment_amount']);
         }
 
-        if (!empty($order['docter_id'])) {
+       /* if (!empty($order['docter_id'])) {
             //更新医生的服务人数
             Docter::where('id', $order['docter_id'])->increment('service_persons');
-        }
+        }*/
 
         //如果是门诊预约,预约时间段的订单数要加1
         if ($order['product_type'] == 3) {
@@ -132,6 +132,12 @@ class Order extends BaseModel
             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');
         }
 
+        //如果是疫苗就减少疫苗库存
+        if ($order['product_type'] == 4) {
+            $orderVaccine = OrderVaccine::where('order_id', $order_id)->first();
+            OrganizationVaccine::where('org_id', $order['organization_id'])->where('vaccine_id', $orderVaccine['vaccine_id'])->decrement('stock');
+        }
+
         return true;
     }
 
@@ -188,4 +194,28 @@ class Order extends BaseModel
 
         return true;
     }
+
+    public function getConsultDurationAttribute()
+    {
+        $duration = 0;
+        if ($this->product_type == 1) {
+            $duration = CallLog::where('order_id', $this->id)->where('talk_time', '<>', null)->sum('talk_time');
+            $duration = !empty($duration) ? $duration : 0;
+        }
+        elseif ($this->product_type == 2) {
+            $duration = $this->end_time - $this->receiving_time;
+        }
+
+        return $duration > 0 ? $duration : 0;
+    }
+
+    public function getCallbackPhoneAttribute()
+    {
+        $secret_no = '';
+        if ($this->product_type == 1) {
+            $secret_no = CallLog::where('order_id', $this->id)->orderBy('id', 'desc')->value('secret_no');
+        }
+
+        return !empty($secret_no) ? $secret_no : '';
+    }
 }