zilong 4 年 前
コミット
cf9a36cae4
3 ファイル変更40 行追加14 行削除
  1. 9 0
      app/Http/Controllers/Api/V1/OrderController.php
  2. 26 9
      app/Models/Order.php
  3. 5 5
      config/config.php

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

xqd xqd
@@ -688,6 +688,7 @@ class OrderController extends AuthController
         $this->validate(request(), [
             'order_id' => 'required|integer'
         ]);
+        $user = $this->user;
 
         $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first();
         if ($order['order_status'] == 4) {
@@ -712,6 +713,14 @@ class OrderController extends AuthController
         try {
             Order::orderCancel($req['order_id'], '用户取消订单');
 
+            //发送取消订单消息
+            $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first();
+            $keyword2 = config('config.product_type_map')[$order['product_type']];
+            $server_name = '';
+            $official_arr = [$user['openid'], $order['order_sn'], $keyword2, round($order['total_amount']/100, 2), date('Y-m-d H:i:s', $order['payment_time']), $order['order_patient']['name'], $server_name, '', ''];
+            $subscribe_arr = [];
+            send_wechat_message(9, $official_arr, $subscribe_arr);
+
             DB::commit();
         } catch (Exception $e) {
             DB::rollBack();

+ 26 - 9
app/Models/Order.php

xqd xqd
@@ -91,7 +91,7 @@ class Order extends BaseModel
     //支付完成的处理方法
     public static function payCompletedHandle($order_id)
     {
-        $order = Order::with(['organization', 'orderVaccine', 'orderNurse', 'orderPack'])->where('id', $order_id)->first();
+        $order = Order::with(['organization', 'orderVaccine', 'orderNurse', 'orderPack'])->where('id', $order_id)->first()->toArray();
         $orderPatient = OrderPatient::where('order_id', $order_id)->first();
         $user = User::select(['balance', 'openid'])->where('id', $order['user_id'])->first();
         //发送下单消息
@@ -211,16 +211,33 @@ class Order extends BaseModel
         //改变订单状态
         $updateOrder = ['order_status' => 5, 'order_notes' => $order_notes];
         if ($order['payment_status'] > 1) {
-            //退钱到余额
-            if (!empty($order['payment_amount']) && $can_refund && $order['product_type'] != 5) {
-                User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '取消订单退款');
-            }
-            $updateOrder['cancel_time'] = time();
-            if ($can_refund) {
+            //判断是余额支付还是服务包支付
+            if ($order['payment_type'] == 2) {
+                //退服务包的次数
+                $map = [1 => 'phone_minutes', 2 => 'chat_num', 3 => 'appoint_num', 4 => 'vaccine_limit_amount', 5 => 'nurses_limit_amount'];
+                $addNum = $order['product_type'] == 1 ? 10 : 1;
+                OrderPack::where('id', $order['pay_order_pack_id'])->increment($map[$order['product_type']], $addNum);
+                $updateOrder['cancel_time'] = time();
                 $updateOrder['payment_status'] = 4;
+                if ($order['product_type'] == 3 && !$can_refund) {
+                    $updateOrder['payment_status'] = 2;
+                }
             }
-            if ($order['product_type'] == 5) {
-                $updateOrder['payment_status'] = 5;
+            else {
+                //退钱到余额
+                if (!empty($order['payment_amount']) && $can_refund && $order['product_type'] != 5) {
+                    User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '取消订单退款');
+                }
+                $updateOrder['cancel_time'] = time();
+                if ($can_refund) {
+                    $updateOrder['payment_status'] = 4;
+                }
+                if ($order['product_type'] == 5) {
+                    $updateOrder['payment_status'] = 5;
+                }
+                if ($order['product_type'] == 3 && !$can_refund) {
+                    $updateOrder['payment_status'] = 2;
+                }
             }
         }
         Order::where('id', $order_id)->update($updateOrder);

+ 5 - 5
config/config.php

xqd xqd
@@ -349,11 +349,11 @@ return [
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'page' => '%s',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
-                        'value' => '%s',
+                        'value' => '尊敬的用户,你有一笔订单已取消!',
                     ],
                     'keyword1' => [
                         'value' => '%s',
@@ -362,16 +362,16 @@ return [
                         'value' => '%s',
                     ],
                     'keyword3' => [
-                        'value' => '%s',
+                        'value' => '%s',
                     ],
                     'keyword4' => [
                         'value' => '%s',
                     ],
                     'keyword5' => [
-                        'value' => '%s',
+                        'value' => '%s患者在%s的服务终止',
                     ],
                     'remark' => [
-                        'value' => '%s',
+                        'value' => '订单备注:%s; 支付状态:%s; 点击进入小程序查看相关详情,如有疑问,请联系我们',
                     ],
                 ],
             ],