瀏覽代碼

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

whj 4 年之前
父節點
當前提交
d173287ad7

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

xqd
@@ -34,7 +34,7 @@ class DocterController extends AuthController
 
         $distance_field = get_user_distance_field($user);
 
-        $builder = Docter::with('office', 'qualification')->select(['id', 'type', 'name', 'phone', 'sex', 'birthday', 'avatar', 'status', 'label', 'sign', 'intro', 'office_id', 'qualification_id', 'score', 'service_persons', 'eva_num', 'service_days', 'phone_minutes', 'chat_price', 'phone_price', 'appoint_price', 'is_chat', 'is_phone', 'is_appoint', 'latitude', 'longitude', DB::raw($distance_field)])->where('status', 1);
+        $builder = Docter::with('office', 'qualification')->select(['id', 'type', 'name', 'phone', 'sex', 'birthday', 'avatar', 'status', 'label', 'sign', 'intro', 'office_id', 'qualification_id', 'score', 'service_persons', 'eva_num', 'service_days', 'phone_minutes', 'chat_price', 'phone_price', 'appoint_price', 'is_chat', 'is_phone', 'is_appoint', 'latitude', 'longitude', DB::raw($distance_field)])->where('status', 1)->where('is_then', 1)->where('phone', '<>', '');
         $list_type = !empty($req['list_type']) ? $req['list_type'] : 0;
         if ($list_type == 1) {
             $builder->where('is_phone', 1);

+ 6 - 0
app/Http/Controllers/Api/V1/EvaluateController.php

xqd xqd
@@ -8,7 +8,9 @@
 
 namespace App\Http\Controllers\Api\V1;
 
+use App\Models\DocterMessage;
 use App\Models\Evaluate;
+use App\Models\Order;
 
 class EvaluateController extends AuthController
 {
@@ -47,6 +49,10 @@ class EvaluateController extends AuthController
         $req['user_id'] = $user['id'];
         Evaluate::create($req);
 
+        //发送医生端消息
+        $order = Order::select(['order_sn'])->where('id', $req['order_id'])->first();
+        DocterMessage::saveMessage($req['docter_id'], $req['user_id'], 4, $req['order_id'], [$order['order_sn']]);
+
         return out();
     }
 }

+ 2 - 2
app/Http/Controllers/Api/V1/OrderController.php

xqd xqd
@@ -466,7 +466,7 @@ class OrderController extends AuthController
         ]);
         $user = $this->user;
 
-        $builder = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack', 'orderNurse', 'orderVaccine', 'organization.docter'])->where('user_id', $user['id']);
+        $builder = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack', 'orderNurse', 'orderVaccine', 'organization.docter', 'suggest'])->where('user_id', $user['id']);
         if (!empty($req['product_type'])) {
             $builder->where('product_type', $req['product_type']);
         }
@@ -517,7 +517,7 @@ class OrderController extends AuthController
         ]);
         $user = $this->user;
 
-        $data = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack.team.docter', 'orderNurse', 'orderVaccine', 'organization.docter'])->where('id', $req['order_id'])->where('user_id', $user['id'])->first();
+        $data = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack.team.docter', 'orderNurse', 'orderVaccine', 'organization.docter', 'suggest'])->where('id', $req['order_id'])->where('user_id', $user['id'])->first();
 
         return out($data);
     }

+ 2 - 2
app/Http/Controllers/Api/V1/SuggestController.php

xqd xqd
@@ -16,7 +16,7 @@ class SuggestController extends AuthController
     {
         $user = $this->user;
 
-        $data = Suggest::with('order.docter')->where('user_id', $user['id'])->orderBy('id', 'desc')->paginate();
+        $data = Suggest::with(['suggestsDetail', 'order.docter'])->where('user_id', $user['id'])->orderBy('id', 'desc')->paginate();
 
         return out($data);
     }
@@ -28,7 +28,7 @@ class SuggestController extends AuthController
             'suggest_id' => 'required|integer',
         ]);
 
-        $data = Suggest::with('order.docter')->where('id', $req['suggest_id'])->first();
+        $data = Suggest::with(['suggestsDetail', 'order.docter'])->where('id', $req['suggest_id'])->first();
 
         return out($data);
     }

+ 24 - 0
app/Models/DocterMessage.php

xqd
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Models;
+
+class DocterMessage extends BaseModel
+{
+    public static function saveMessage($docter_id, $user_id, $type, $relation_id = 0, $param = [], $content = '')
+    {
+        if (empty($content)) {
+            $content = config('config.docter_message_map')[$type] ?? '';
+            $content = vsprintf($content, $param);
+        }
+        DocterMessage::create([
+            'docter_id' => $docter_id,
+            'status' => 1,
+            'user_id' => $user_id,
+            'type' => $type,
+            'relation_id' => $relation_id,
+            'content' => $content,
+        ]);
+
+        return true;
+    }
+}

+ 36 - 1
app/Models/Order.php

xqd xqd xqd
@@ -10,6 +10,8 @@ namespace App\Models;
 
 class Order extends BaseModel
 {
+    protected $appends = ['is_evaluate', 'order_duration'];
+
     CONST UNPAID = 1, ISING = 2, FINISHED = 3,CANCELED=4; //订单状态(1.未支付 2.进行中 3.已完成 4.已取消)
     public static  $_order_status = [
         self::UNPAID=>'未支付',
@@ -62,7 +64,7 @@ class Order extends BaseModel
     //支付完成的处理方法
     public static function payCompletedHandle($order_id)
     {
-        $order = Order::select(['user_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount'])->where('id', $order_id)->first();
+        $order = Order::select(['user_id', 'docter_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount', 'order_sn'])->where('id', $order_id)->first();
         //发送下单消息
         if ($order['product_type'] < 6) {
             $product_type_text = config('config.product_type_map')[$order['product_type']];
@@ -81,7 +83,40 @@ class Order extends BaseModel
             $user = User::select(['balance'])->where('id', $order['user_id'])->first();
             UserMessage::saveMessage($order['user_id'], 8, $order_id, [round($order['payment_amount']/100, 2), round($user['balance']/100, 2)]);
         }
+        //发送医生端消息
+        DocterMessage::saveMessage($order['docter_id'], $order['user_id'], 1, $order_id, [$order['order_sn']]);
 
         return true;
     }
+
+    public function suggest()
+    {
+        return $this->hasOne(Suggest::class)->select(['id', 'order_id']);
+    }
+
+    public function getIsEvaluateAttribute()
+    {
+        $user = User::getUserByToken();
+        $is_evaluate = 0;
+        if (Evaluate::where('order_id', $this->id)->where('user_id', $user['id'])->exists()) {
+            $is_evaluate = 1;
+        }
+
+        return $is_evaluate;
+    }
+
+    public function getOrderDurationAttribute()
+    {
+        if (!empty($this->outtime) && !empty($this->receiving_time)) {
+            $diff = $this->outtime - $this->receiving_time;
+            $hour = round($diff/3600);
+            if ($hour == 0) {
+                return round($diff/60).'分钟';
+            }
+
+            return $hour.'小时';
+        }
+
+        return '';
+    }
 }

+ 5 - 0
app/Models/Suggest.php

xqd
@@ -14,4 +14,9 @@ class Suggest extends BaseModel
     {
         return $this->belongsTo(Order::class);
     }
+
+    public function suggestsDetail()
+    {
+        return $this->hasMany(SuggestsDetail::class);
+    }
 }

+ 8 - 0
app/Models/SuggestsDetail.php

xqd
@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Models;
+
+class SuggestsDetail extends BaseModel
+{
+    protected $table = 'suggests_detail';
+}

+ 5 - 0
config/config.php

xqd
@@ -44,5 +44,10 @@ return [
         11 => '您已成功修改支付密码',
     ],
 
+    'docter_message_map' => [
+        1 => '您接到一个新订单,订单号%s,请尽快确认(点击查看订单详情)',
+        4 => '您的订单号为%s的订单,用户已完成评价(点击查看评价详情)',
+    ],
+
     'no_auth_function_map' => ['docter/docterList', 'docter/docterDetail'],
 ];