Ver Fonte

Merge branch 'dev'

gorden há 2 meses atrás
pai
commit
9f4b20df2f

+ 418 - 107
app/admin/controller/order/KangyangCityController.php

@@ -2,21 +2,30 @@
 
 namespace app\admin\controller\order;
 
+use app\admin\service\coupon\CouponService;
 use app\admin\service\member\MemberService;
 use app\admin\service\order\OrderService;
 use app\admin\validate\order\OrderValidate;
 use app\controller\Curd;
 use app\model\Appointment;
+use app\model\ClientConfig;
+use app\model\Coupon;
 use app\model\Goods;
 use app\model\GoodsComponent;
 use app\model\GoodsRunning;
 use app\model\GoodsSku;
 use app\model\Member;
 use app\model\MemberAccount;
+use app\model\MemberBenefit;
+use app\model\MemberRole;
 use app\model\Order;
+use app\model\OrderExpress;
+use app\model\OrderReturn;
 use app\model\OrderSheet;
 use app\model\PayDetail;
+use app\model\Supplier;
 use app\model\SysDept;
+use app\model\SysUser;
 use support\Db;
 use support\exception\BusinessException;
 use support\Redis;
@@ -24,7 +33,8 @@ use support\Request;
 use support\Response;
 use Webman\Event\Event;
 
-class KangyangCityController extends Curd{
+class KangyangCityController extends Curd
+{
     public function __construct()
     {
         $this->model = new Order();
@@ -54,9 +64,9 @@ class KangyangCityController extends Curd{
         // $where['order_id'] = '';
         $where['order_category'] = 'VIP';
         // $goodsClassify = 'VIP';
-        $goodsName = $request->get('goods_name','');
-        if (!empty($goodsName) && empty($goodsClassify)){
-            $goodsIds = Goods::where('goods_name','like','%'.$request->get('goods_name').'%')->pluck('goods_id')->toArray();
+        $goodsName = $request->get('goods_name', '');
+        if (!empty($goodsName) && empty($goodsClassify)) {
+            $goodsIds = Goods::where('goods_name', 'like', '%' . $request->get('goods_name') . '%')->pluck('goods_id')->toArray();
         }
         // else if(!empty($goodsClassify)){
         //     if($goodsClassify == 'SERVICE'){
@@ -71,10 +81,10 @@ class KangyangCityController extends Curd{
 
         //     $goodsIds = $goodsModel->pluck('goods_id')->toArray();
         // }
-        if(!empty($goodsIds)){
-            $orderIds = OrderSheet::whereIn('join_sheet_goods_id',$goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if($orderIds){
-                $where['order_id'] = ['in',implode(',',$orderIds)];
+        if (!empty($goodsIds)) {
+            $orderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
+            if ($orderIds) {
+                $where['order_id'] = ['in', implode(',', $orderIds)];
             }
         }
 
@@ -86,7 +96,7 @@ class KangyangCityController extends Curd{
     {
         $model = $this->model->with([
             'sheets' => function ($query) {
-                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num','order_sheet_price');
+                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num', 'order_sheet_price');
             },
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
@@ -104,8 +114,8 @@ class KangyangCityController extends Curd{
             // 'express' => function ($query) {
             //     $query->select('join_express_order_id', 'order_express_type');
             // }
-        ])->leftJoin('order_return','order_return.join_return_order_id','=','order.order_id')
-        ->leftJoin('order_express','order_express.join_express_order_id','=','order.order_id');
+        ])->leftJoin('order_return', 'order_return.join_return_order_id', '=', 'order.order_id')
+            ->leftJoin('order_express', 'order_express.join_express_order_id', '=', 'order.order_id');
         // ->leftJoin('order_sheet','join_sheet_order_id','=','order.order_id');
         foreach ($where as $column => $value) {
             if (is_array($value)) {
@@ -139,7 +149,7 @@ class KangyangCityController extends Curd{
         if ($field) {
             $model = $model->orderBy($field, $order);
         }
-        $model = $model->select('order.*','order_express.join_express_order_id','order_express.order_express_type','order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status','order_return.order_return_apply_json','order_return.order_return_remark');
+        $model = $model->select('order.*', 'order_express.join_express_order_id', 'order_express.order_express_type', 'order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status', 'order_return.order_return_apply_json', 'order_return.order_return_remark');
         return $model;
     }
 
@@ -150,29 +160,29 @@ class KangyangCityController extends Curd{
             $item['sheet'] = $item['sheets'][0] ?? [];
             if (!empty($item['sheet'])) {
                 $goods = Goods::where('goods_id', $item['sheet']['join_sheet_goods_id'])->first();
-                if(count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS'){
+                if (count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS') {
                     $sheetDeng = ' 等餐品';
                 }
-                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name.$sheetDeng : '';
+                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name . $sheetDeng : '';
                 $item['sheet']['goods_classify'] = $goods->goods_classify ?? '';
                 $item['sheet']['order_sheet_num'] = intval($item['sheet']['order_sheet_num']);
             }
             unset($item['sheets']);
-            if (isset($item['orders_return_id'])){
+            if (isset($item['orders_return_id'])) {
                 $item['return'] = [
-                    'orders_return_id'=>$item['orders_return_id'],
+                    'orders_return_id' => $item['orders_return_id'],
                     'join_return_order_id' => $item['join_return_order_id'],
                     'order_return_status' => $item['order_return_status'],
                     'order_return_apply_json' => $item['order_return_apply_json'],
-                    'order_return_remark'=>$item['order_return_remark']
+                    'order_return_remark' => $item['order_return_remark']
                 ];
             }
-            if (isset($item['join_express_order_id'])){
+            if (isset($item['join_express_order_id'])) {
                 $item['express'] = [
-                    'join_express_order_id'=>$item['join_express_order_id'],
-                    'order_express_type'=>$item['order_express_type']
+                    'join_express_order_id' => $item['join_express_order_id'],
+                    'order_express_type' => $item['order_express_type']
                 ];
-                unset($item['join_express_order_id'],$item['order_express_type']);
+                unset($item['join_express_order_id'], $item['order_express_type']);
             }
             // if (!empty($item['order_extend_json'])){
             //     $orderExtendJson = json_decode($item['order_extend_json'],true);
@@ -306,27 +316,6 @@ class KangyangCityController extends Curd{
                         throw new BusinessException('付款码无效');
                     }
 
-                    // 组合支付,追加加一条支付记录 pay_detail
-                    if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0 && $params['order_status_payment'] == 'SUCCESS') {
-                        $insertPayDetailData = [
-                            'join_pay_member_id' => $params['join_order_member_id'],
-                            'join_pay_order_id' => $params['orderGroupId'],
-                            'pay_status' => 'SUCCESS',
-                            'pay_category' => $params['goods_classify'],
-                            'pay_amount' => $params['order_amount_pay'],
-                            'pay_paytimes' => date('Y-m-d H:i:s'),
-                            'pay_prepayid' => $params['pay_category'],
-                            'pay_json_request' => json_encode($params),
-                            'pay_json_response' => $params['pay_json_response'],
-                            'pay_addtimes' => time()
-                        ];
-
-                        PayDetail::insert($insertPayDetailData);
-
-                        // 组合支付,还原提交的支付分类
-                        $params['pay_category'] = $submitPayCategory;
-                    }
-
                     // 账户支付的金额
                     $params['order_amount_pay'] = $accountAmount;
                 }
@@ -341,31 +330,45 @@ class KangyangCityController extends Curd{
                 //     'express' => 'Y',
                 // ]);
             }
-            $params['order_amount_pay'] = $params['order_amount_pay'] + $qrcodePayAmount;
             $params['order_config_json'] = json_encode($orderConfigJson);
-            // 写入主订单
-            $this->insertMain($params);
-            // 订单详情
-            $sheetId = $this->insertSheet($params);
+            // 查询是否有未完全支付订单
+            $paidOrder = Order::where('join_order_member_id', $params['join_order_member_id'])
+                ->where('order_category', 'VIP')
+                ->where('order_status_system', 'PAYING')
+                ->first();
+
+            if (empty($paidOrder)) {
+                // 写入主订单
+                $this->insertMain($params);
+                // 订单详情
+                $this->insertSheet($params);
+            } else {
+                $params['orderGroupId'] = $paidOrder->order_groupby;
+                $params['order_amount_paid'] = $paidOrder->order_amount_paid;
+                $paidOrder->order_amount_paid = $paidOrder->order_amount_paid + $params['order_amount_pay'];
+                $paidOrder->order_amount_pay = $paidOrder->order_amount_paid;
+                if (floatval($paidOrder->order_amount_paid) >= $paidOrder->order_amount_total) {
+                    $paidOrder->order_is_complete = 'Y';
+                    $paidOrder->order_status_system = 'DONE';
+                    $paidOrder->order_status_payment = 'SUCCESS';
+                    // 更新sheet
+                    OrderSheet::where('join_sheet_order_id', $paidOrder->order_id)->update(['order_sheet_status'=>'DONE']);
+                }
+                $paidOrder->save();
+
+            }
             // 支付记录
-            $params['order_amount_pay'] = $params['order_amount_pay'] - $qrcodePayAmount;
             $this->insertPayDetail($params);
 
-            $params['order_express_goods'] = json_encode(['sheet' => [$sheetId]]);
+//            $params['order_express_goods'] = json_encode(['sheet' => [$sheetId]]);
 
             // 2.4W 康养城
-            if ($params['goods_classify'] == 'VIP' && $params['order_status_payment'] == 'SUCCESS') {
+            if ($params['goods_classify'] == 'VIP' && $params['order_status_payment'] == 'SUCCESS' && (!empty($paidOrder) && floatval($paidOrder->order_amount_paid) >= $paidOrder->order_amount_total || floatval($params['order_amount_pay']) >= $params['order_amount_total'])) {
                 $params['member_id'] = $params['join_order_member_id'];
                 Event::dispatch('order.kangyangCityVIP.grant', $params);
             }
 
             Db::commit();
-
-            // 会员升级
-            if (!empty($params['order_is_complete']) && $params['order_is_complete'] == 'Y' && $params['order_status_payment'] == 'SUCCESS') {
-                Event::dispatch('order.complete', $params);
-            }
-
             if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
                 _syslog("订单", "支付异常,检查是否有轮询");
                 return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
@@ -435,6 +438,7 @@ class KangyangCityController extends Curd{
         if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
             $systemStatus = "WAITING";
         }
+        $paymentStatus = 'PENDING';
         Db::beginTransaction();
         try {
             // 组合支付时,付款码应收金额
@@ -442,6 +446,7 @@ class KangyangCityController extends Curd{
             if ($params['pay_category'] == 'OFFLINE' || $params['pay_category'] == 'MONEY') {
                 $order->order_status_system = $systemStatus;
                 $order->order_status_payment = 'SUCCESS';
+                $paymentStatus = 'SUCCESS';
                 if ($params['pay_category'] == 'OFFLINE' && !empty($params['pay_category_sub'])) {
                     $params['pay_category'] = $params['pay_category_sub'];
                 }
@@ -473,6 +478,7 @@ class KangyangCityController extends Curd{
                     } else {
                         $order->order_status_system = $systemStatus;
                         $order->order_status_payment = 'SUCCESS';
+                        $paymentStatus = 'SUCCESS';
                     }
                 } else if (in_array($prefix, [25, 26, 27, 28, 29, 30])) {
                     $params['pay_category'] = 'ALIPAY';
@@ -485,33 +491,12 @@ class KangyangCityController extends Curd{
                     } else {
                         $order->order_status_system = $systemStatus;
                         $order->order_status_payment = 'SUCCESS';
+                        $paymentStatus = 'SUCCESS';
                     }
                 } else {
                     throw new BusinessException('付款码无效');
                 }
 
-                // 组合支付,追加加一条支付记录 pay_detail
-                if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0) {
-                    $insertPayDetailData = [
-                        'join_pay_member_id' => $params['join_order_member_id'],
-                        'join_pay_order_id' => $params['orderGroupId'],
-                        'pay_status' => 'SUCCESS',
-                        'pay_category' => $params['goods_classify'],
-                        'pay_amount' => $params['order_amount_pay'],
-                        'pay_paytimes' => date('Y-m-d H:i:s'),
-                        'pay_prepayid' => $params['pay_category'],
-                        'pay_json_request' => json_encode($params),
-                        'pay_json_response' => $params['pay_json_response'],
-                        'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]',
-                        'pay_addtimes' => time()
-                    ];
-
-                    PayDetail::insert($insertPayDetailData);
-
-                    // 组合支付,还原提交的支付分类
-                    $params['pay_category'] = $submitPayCategory;
-                }
-
                 // 账户支付的金额
                 $params['order_amount_pay'] = $accountAmount;
             }
@@ -524,25 +509,35 @@ class KangyangCityController extends Curd{
                 SysDept::where('dept_id', $orderConfigJson['tableid'])->where('dept_category', '桌台')->update(['dept_status' => 'ACTIVED']);
             }
             $order->order_config_json = json_encode($orderConfigJson);
-            $order->order_amount_pay = $params['order_amount_pay'] + $qrcodePayAmount;
+            $order->order_amount_paid = $order->order_amount_paid + $params['order_amount_pay'];
+            $order->order_amount_pay = $order->order_amount_paid;
             // 康养城订单,支付完就结束了
-            if ($order->order_status_payment == 'SUCCESS' && $params['goods_classify'] == 'VIP') {
+            if ($order->order_status_payment == 'SUCCESS' && $params['goods_classify'] == 'VIP' && floatval($order->order_amount_paid) >= $order->order_amount_total) {
                 $order->order_is_complete = 'Y';
             }
+            if (floatval($order->order_amount_paid) < $order->order_amount_total) {
+                $order->order_status_system = 'PAYING';
+                $order->order_status_payment = 'PENDING';
+                $order->order_is_complete = 'N';
+            }
             // 主订单
             $order->save();
 
             // sheet
             if ($order->order_status_payment == 'SUCCESS') {
-                OrderSheet::where('join_sheet_order_id', $params['order_id'])->update([
-                    'order_sheet_status' => $systemStatus,
-                ]);
+                $data = [
+                    'order_sheet_status'=>$systemStatus
+                ];
+                if (floatval($order->order_amount_paid) < $order->order_amount_total){
+                    $data['order_sheet_status'] = 'BEING';
+                }
+                OrderSheet::where('join_sheet_order_id', $params['order_id'])->update($data);
             }
             // payDetail
             $payData = [
                 'pay_amount' => $params['order_amount_pay']
             ];
-            if ($order->order_status_payment == 'SUCCESS') {
+            if ($paymentStatus == 'SUCCESS') {
                 $payData['pay_paytimes'] = date('Y-m-d H:i:s');
                 $payData['pay_status'] = 'SUCCESS';
             }
@@ -565,26 +560,26 @@ class KangyangCityController extends Curd{
                 $payData['pay_prepayid'] = 'MONEY';
             }
             // 如果 是APP 过来的菜订单,可能没有paydetail
-            if (!PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->exists()) {
-                $payData['join_pay_member_id'] = $params['join_order_member_id'];
-                $payData['join_pay_order_id'] = $order->order_groupby;
-                $payData['pay_status'] = $payData['pay_status'] == 'SUCCESS' ? $payData['pay_status'] : 'WAITING';
-                $payData['pay_category'] = $params['goods_classify'] ?? '';
-                $payData['pay_json_request'] = json_encode($params);   // {"pay-result": "支付成功", "result-datetime": "2024-07-29 18:38:21"}
-                $payData['pay_json_response'] = $payData['pay_status'] == 'SUCCESS' ? json_encode([
-                    'pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')
-                ]) : '[]';
-                $payData['join_pay_object_json'] = !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]';
-                $payData['pay_addtimes'] = time();
-
-                PayDetail::insert($payData);
-            } else {
-                // 更新非微信支付宝的支付记录
-                PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->update($payData);
-            }
+//            if (!PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->exists()) {
+            $payData['join_pay_member_id'] = $params['join_order_member_id'];
+            $payData['join_pay_order_id'] = $order->order_groupby;
+            $payData['pay_status'] = $payData['pay_status'] == 'SUCCESS' ? $payData['pay_status'] : 'WAITING';
+            $payData['pay_category'] = $params['goods_classify'] ?? '';
+            $payData['pay_json_request'] = json_encode($params);   // {"pay-result": "支付成功", "result-datetime": "2024-07-29 18:38:21"}
+            $payData['pay_json_response'] = $payData['pay_status'] == 'SUCCESS' ? json_encode([
+                'pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')
+            ]) : '[]';
+            $payData['join_pay_object_json'] = !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]';
+            $payData['pay_addtimes'] = time();
+
+            PayDetail::insert($payData);
+//            } else {
+//                // 更新非微信支付宝的支付记录
+//                PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_category', '<>', 'WXPAY')->where('pay_category', '<>', 'ALIPAY')->update($payData);
+//            }
 
             // 2.4W 康养城
-            if ($params['goods_classify'] == 'VIP' && $order->order_status_payment == 'SUCCESS') {
+            if ($params['goods_classify'] == 'VIP' && $order->order_status_payment == 'SUCCESS' && floatval($order->order_amount_paid) >= $order->order_amount_total) {
                 $params['member_id'] = $params['join_order_member_id'];
                 Event::dispatch('order.kangyangCityVIP.grant', $params);
             }
@@ -595,7 +590,7 @@ class KangyangCityController extends Curd{
                 Event::dispatch('order.complete', $params);
             }
 
-            if ($order->order_status_payment != 'SUCCESS') {
+            if ($order->order_status_payment != 'SUCCESS' && $paymentStatus != 'SUCCESS') {
                 _syslog("订单", "支付异常,检查是否有轮询");
                 return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
             }
@@ -651,10 +646,12 @@ class KangyangCityController extends Curd{
                 'order_name' => date('Y-m-d H:i:s') . '-订单',
                 'order_amount_total' => $params['order_amount_total'],
                 'order_amount_pay' => $params['order_amount_pay'],
+                'order_amount_paid' => $params['order_amount_pay'],
                 'order_category' => $orderCategory,
-                'order_is_complete' => $params['order_is_complete'] ?? 'N',
-                'order_status_system' => $params['order_status_system'],
-                'order_status_payment' => $params['order_status_payment'],
+                'order_classify' => $orderCategory,
+                'order_is_complete' => floatval($params['order_amount_pay']) >= floatval($params['order_amount_total']) ? 'Y' : 'N',
+                'order_status_system' => floatval($params['order_amount_pay']) >= floatval($params['order_amount_total']) ? 'DONE' : 'PAYING',
+                'order_status_payment' => floatval($params['order_amount_pay']) >= floatval($params['order_amount_total']) ? 'SUCCESS' : 'PENDING',
                 'order_status_storage' => $params['order_status_storage'],
                 'order_platform' => $params['order_platform'],
                 'order_remark' => $params['order_remark'] ?? '',
@@ -695,12 +692,20 @@ class KangyangCityController extends Curd{
                 if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') {
                     $extendJson['table'] = null;
                 }
+                $orderSheetStatus = 'PAYING';
+                if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS'){
+                    if (floatval($params['order_amount_pay']) >= floatval($params['order_amount_total'])){
+                        $orderSheetStatus = 'DONE';
+                    }else{
+                        $orderSheetStatus = 'BEING';
+                    }
+                }
                 $data = [
                     'join_sheet_member_id' => $params['join_order_member_id'],
                     'join_sheet_order_id' => $params['orderId'],
                     'join_sheet_goods_id' => $goods['goods_id'],
                     'join_sheet_goods_sku_id' => $goods['sku_id'],
-                    'order_sheet_status' => $params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS' ? 'DONE' : 'PAYING',
+                    'order_sheet_status' =>  $orderSheetStatus,
                     'order_sheet_category' => (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') ? 'DISHES' : 'NORMAL',
                     'order_sheet_num' => $goods['nbr'],
                     'order_sheet_price' => $goods['goods_sales_price'],
@@ -795,4 +800,310 @@ class KangyangCityController extends Curd{
             throw new BusinessException('创建支付记录失败');
         }
     }
+
+
+    /**
+     * @Desc 订单商品详情
+     * @Author Gorden
+     * @Date 2024/3/29 8:50
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function sheet(Request $request)
+    {
+        try {
+            $orderId = $request->get('order_id');
+            $orderSheet = OrderSheet::with([
+                'member' => function ($query) {
+                    $query->select('member_id', 'member_mobile', 'member_is_owner', 'join_member_role_id');
+                },
+                'goods' => function ($query) {
+                    $query->select('goods_id', 'goods_name', 'goods_cover', 'goods_market_price', 'goods_sales_price', 'goods_classify', 'goods_if_express');
+                },
+                'memberInfo',
+                'cert',
+                'sku' => function ($query) {
+                    $query->where('goods_sku_status', 'ON')
+                        ->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price');
+                },
+                'skus',
+                'refund' => function ($query) {
+                    $query->select('join_return_order_id', 'order_return_status');
+                }
+            ])->where('join_sheet_order_id', $orderId)
+                ->orderBy('order_sheet_id', 'DESC')
+                ->get()
+                ->toArray();
+
+            $order = Order::where('order_id', $orderId)->first();
+            $express = OrderExpress::where('join_express_order_id', $orderId)->first();
+            $premises = '';
+            if ($express && $express->order_express_type == '自提') {
+                $premises = $express->order_express_company;
+            }
+            $sheetAmount = 0;
+            foreach ($orderSheet as &$item) {
+                $sheetAmount += $item['order_sheet_amount'];
+                $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
+                if (!empty($item['goods']) && $item['goods']['goods_classify'] == 'PACKAGE') {
+                    $components = GoodsComponent::with('goods')
+                        ->where('join_component_master_goods_id', $item['goods']['goods_id'])
+                        ->select('join_component_master_goods_id', 'join_component_goods_id', 'goods_component_price',
+                            'goods_component_price', 'goods_component_json')
+                        ->get()
+                        ->toArray();
+                    $goodsArr = [];
+                    foreach ($components as $component) {
+                        $configJson = !empty($component['goods_component_json']) ? json_decode($component['goods_component_json'], true) : [];
+                        if (!empty($component['goods'])) {
+                            $supplierName = Supplier::where('supplier_id', $component['goods']['join_goods_supplier_id'])->value('supplier_name');
+                            $benefit = MemberBenefit::where('join_benefit_member_id', $item['join_sheet_member_id'])
+                                ->where('join_benefit_goods_id', $component['goods']['goods_id'])
+                                ->where('join_benefit_order_id', $orderId)
+                                ->first();
+                            $goodsArr[] = [
+                                'goods_name' => $component['goods']['goods_name'],
+                                'goods_cover' => getenv('STORAGE_DOMAIN') . $component['goods']['goods_cover'],
+                                'supplier_name' => $supplierName,
+                                'nbr' => $configJson['nbr'] ?? 0,
+                                'used' => !empty($benefit->member_benefit_used_count) ? intval($benefit->member_benefit_used_count) : ''
+                            ];
+                        }
+                    }
+
+                    $item['goods']['components'] = $goodsArr;
+                }
+                if (!empty($item['sku'])) {
+                    if (!empty($item['sku']['goods_sku_specs_json'])) {
+                        $specsJson = json_decode($item['sku']['goods_sku_specs_json'], true);
+                        $skuName = '';
+                        foreach ($specsJson as $specsKey => $skuSpecs) {
+                            if (is_array($skuSpecs)) {
+                                $skuName = $skuName . ' ' . implode(' ', $skuSpecs) . ';';
+                            } else {
+                                $skuName = $skuName . ' ' . $skuSpecs . ';';
+                            }
+                        }
+                        $item['sku']['goods_sku_title'] = rtrim($skuName, ';');
+                    }
+                }
+                if (!empty($item['skus'])) {
+                    foreach ($item['skus'] as $key => $skus) {
+                        if (!empty($skus['goods_sku_specs_json'])) {
+                            $item['skus'][$key]['goods_sku_specs_json'] = json_decode($skus['goods_sku_specs_json']);
+
+                            $skuName = '';
+                            foreach ($item['skus'][$key]['goods_sku_specs_json'] as $specsKey => $skuSpecs) {
+                                $keyStr = ($specsKey == '规格') ? '' : ($specsKey . ':');
+                                if (is_array($skuSpecs)) {
+                                    $skuName = $skuName . $keyStr . ' ' . implode(' ', $skuSpecs) . '; ';
+                                } else {
+                                    $skuName = $skuName . $keyStr . ' ' . $skuSpecs . '; ';
+                                }
+                            }
+                            $item['skus'][$key]['sku_name'] = rtrim($skuName, '; ');
+                        }
+                    }
+                } else {
+                    $item['skus'] = [];
+                }
+                if (in_array($item['goods']['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $order->order_status_system == 'DONE') {
+                    $item['appontment'] = [];
+                    $appontments = Appointment::where('join_appointment_order_id', $orderId)
+                        ->where('appointment_status', 'DONE')
+                        ->select('appointment_status', 'appointment_id', 'appointment_done_datetime', 'appointment_done_json', 'appointment_apply_json')
+                        ->get()
+                        ->toArray();
+                    foreach ($appontments as $appontment) {
+                        $doneJson = [];
+                        $username = '';
+                        if (!empty($appontment['appointment_done_json'])) {
+                            $doneJson = json_decode($appontment['appointment_done_json'], true);
+                            if (isset($doneJson['charge'])) {
+                                $username = SysUser::where('user_id', $doneJson['charge']['charge_user_id'])->value('user_name');
+                            }
+                        }
+                        $person = 1;
+                        if (!empty($appontment->appointment_apply_json)) {
+                            $applyJson = json_decode($appontment->appointment_apply_json, true);
+                            if (isset($applyJson['person'])) {
+                                $person = $applyJson['person'];
+                            }
+                        }
+                        $item['appontment'][] = [
+                            'member' => ($item['cert'] ? $item['cert']['member_cert_name'] . '-' : '') . ($item['member'] ? $item['member']['member_mobile'] : ''),
+                            'goods_name' => $item['goods']['goods_name'],
+                            'premisses' => isset($doneJson['charge']) ? $doneJson['charge']['charge_premises'] : '',
+                            'username' => $username,
+                            'nbr' => $person,
+                            'done_time' => $appontment['appointment_done_datetime'],
+                            'appointment_status' => $appontment['appointment_status'],
+                        ];
+                    }
+                }
+                if (!empty($item['order_sheet_extend_json']) && !$express) {
+                    $extendJson = json_decode($item['order_sheet_extend_json'], true);
+                    if (isset($extendJson['address_id'])) {
+                        $address = ClientConfig::where('client_config_id', $extendJson['address_id'])->first();
+                        if (!empty($address)) {
+                            $valJson = json_decode($address->client_config_val_json, true);
+                            $express = [
+                                'order_express_address' => $valJson['address'] . ($valJson['numbers'] ?? ''),
+                                'order_express_city' => $valJson['city'],
+                                'order_express_mobile' => $valJson['mobile'],
+                                'order_express_person' => $valJson['person']
+                            ];
+                        }
+                    }
+                }
+                $item['member']['level'] = '普通用户';
+                if (!empty($item['member']['join_member_role_id'])) {
+                    $item['member']['level'] = MemberRole::where('member_role_id', $item['member']['join_member_role_id'])->value('member_role_name');
+                }
+            }
+            $order->sheet_amount = number_format($sheetAmount, 2);
+
+            $payDetails = PayDetail::where('join_pay_order_id', $order->order_groupby)
+                ->where('pay_category', 'VIP')
+                ->where('pay_status', 'SUCCESS')
+                ->select('pay_id', 'pay_category', 'pay_prepayid', 'pay_paytimes', 'pay_status', 'pay_amount', 'pay_extend_json')
+                ->orderBy('pay_addtimes', 'DESC')
+                ->get();
+            $order->pay_amount_total = 0;
+            foreach ($payDetails as &$payDetail) {
+                $categoryArray = explode('-', $payDetail->pay_prepayid);
+                if (isset($categoryArray[1])) {
+                    $payDetail->pay_category = $categoryArray[1];
+                } else if (in_array($categoryArray[0], ['WXPAY', 'ALIPAY', 'OFFLINE', 'OFFLINE_ALIPAY', 'OFFLINE_WXPAY', 'MONEY'])) {
+                    $payDetail->pay_category = $categoryArray[0];
+                }
+                if (!empty($payDetail->pay_extend_json)) {
+                    $payExtendJson = json_decode($payDetail->pay_extend_json, true);
+                    $order->cancel_times = $payExtendJson['cancel_times'] ?? '';
+                }
+                $order->pay_amount_total += $payDetail->pay_amount;
+            }
+            $refund = OrderReturn::where('join_return_order_id', $orderId)
+                ->select('order_return_status', 'order_return_apply_datetime', 'order_return_apply_json', 'order_return_accept_datetime', 'order_return_refund_json', 'order_return_extend_json')
+                ->first();
+            if (!empty($refund->order_return_refund_json)) {
+                $returnRefundJson = json_decode($refund->order_return_refund_json, true);
+                if (isset($returnRefundJson['user_id'])) {
+                    $userName = SysUser::where('user_id', $returnRefundJson['user_id'])->value('user_name');
+                    $returnRefundJson['person'] = $userName;
+                    unset($returnRefundJson['user_id']);
+                }
+
+                $refund->order_return_refund_json = json_encode($returnRefundJson);
+            }
+            if (!empty($order->order_config_json)) {
+                $orderConfigJson = json_decode($order->order_config_json, true);
+                if (isset($orderConfigJson['reach'])) {
+                    $order->reach = $orderConfigJson['reach'];
+                }
+                if (isset($orderConfigJson['table'])) {
+                    $order->table = $orderConfigJson['table'];
+                }
+                if (isset($orderConfigJson['eat'])) {
+                    $order->eat = $orderConfigJson['eat'];
+                }
+                if (isset($orderConfigJson['express'])) {
+                    $order->express = $orderConfigJson['express'];
+                }
+                if (isset($orderConfigJson['premises'])) {
+                    $order->premises = $orderConfigJson['premises'];
+                }
+                if (isset($orderConfigJson['tableid'])) {
+                    $order->dept_table_id = $orderConfigJson['tableid'];
+                }
+            }
+            if (!empty($order->order_extend_json)) {
+                $orderExtendJson = json_decode($order->order_extend_json, true);
+                $order->referee = $orderExtendJson['referee'] ?? '';
+                if (isset($orderExtendJson['cancel_times'])) {
+                    $order->cancel_times = $orderExtendJson['cancel_times'];
+                }
+                if (isset($orderExtendJson['free_remark'])) {
+                    $order->free_remark = $orderExtendJson['free_remark'];
+                }
+            }
+            $discount = ['coupon_name' => '', 'classify' => '', 'value' => 0];
+            if (!empty($order->order_discount_json)) {
+                $orderDiscountJson = json_decode($order->order_discount_json, true);
+                foreach ($orderDiscountJson as $discountItem) {
+                    if (!empty($discountItem['coupon_id'])) {
+                        $coupon = Coupon::where('coupon_id', $discountItem['coupon_id'])
+                            ->select('coupon_name', 'coupon_classify', 'coupon_category', 'coupon_value', 'coupon_minimum_limit')
+                            ->first();
+                        if (!$coupon) {
+                            continue;
+                        }
+                        $classify = CouponService::couponClassifyInfo($coupon->coupon_classify, $coupon->coupon_category, $coupon->coupon_value, $coupon->coupon_minimum_limit);
+                        $discount['coupon_name'] .= $coupon->coupon_classify . ':' . $coupon->coupon_name . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
+                    }
+                    if ($discountItem['coupon_classify'] == '退款') {
+                        continue;
+                    }
+                    if (empty($discountItem['coupon_id']) && !empty($discountItem['coupon_classify'])) {
+                        if (!empty($discountItem['coupon_detail_id'])) {
+
+                            $discount['classify'] .= $discountItem['coupon_detail_id'][0] . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
+                        } else {
+                            $discount['classify'] .= $discountItem['coupon_classify'] . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
+                        }
+                    }
+                    if (!empty($discountItem['coupon_value'])) {
+                        $discount['value'] += $discountItem['coupon_value'];
+                    }
+                }
+                if (!empty($discount['coupon_name'])) {
+                    $discount['coupon_name'] = rtrim($discount['coupon_name'], ', ');
+                }
+                if (!empty($discount['classify'])) {
+                    $discount['classify'] = rtrim($discount['classify'], ', ');
+                }
+            }
+            $discount['value'] = sprintf("%.2f", $discount['value']);
+            $order->discount = $discount;
+
+            $order->premises = $order->premises ?? $premises;
+            $data = [
+                'order' => $order,
+                'refund' => json_decode(json_encode($refund)),
+                'sheet' => json_decode(json_encode($orderSheet)),
+                'express' => json_decode(json_encode($express)),
+                'payDetails' => json_decode(json_encode($payDetails))
+            ];
+
+            return json_success('', $data);
+
+        } catch (\Exception $e) {
+            dump($e->getMessage());
+        }
+    }
+
+    /**
+     * @Desc 获取分期的订单
+     * @Author Gorden
+     * @Date 2024/9/10 15:14
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function getPaidOrder(Request $request)
+    {
+        $memberId = $request->get('member_id');
+        if (!$memberId){
+            return json_fail('参数异常');
+        }
+
+        $order = Order::where('join_order_member_id',$memberId)
+            ->where('order_category','VIP')
+            ->where('order_status_system','PAYING')
+            ->select('order_id','order_amount_total','order_amount_paid','order_amount_pay')
+            ->first();
+
+        return json_success('',$order);
+    }
 }

+ 150 - 14
app/admin/controller/order/PackagesController.php

@@ -2,15 +2,34 @@
 
 namespace app\admin\controller\order;
 
+use app\admin\service\coupon\CouponService;
+use app\admin\service\order\OrderService;
 use app\admin\validate\order\OrderValidate;
 use app\controller\Curd;
+use app\model\Appointment;
+use app\model\ClientConfig;
+use app\model\Coupon;
 use app\model\Goods;
+use app\model\GoodsComponent;
+use app\model\Member;
+use app\model\MemberBenefit;
+use app\model\MemberRole;
 use app\model\Order;
+use app\model\OrderExpress;
+use app\model\OrderReturn;
 use app\model\OrderSheet;
+use app\model\PayDetail;
+use app\model\Supplier;
+use app\model\SysDept;
+use app\model\SysUser;
+use support\Db;
+use support\Redis;
 use support\Request;
 use support\Response;
+use Webman\Event\Event;
 
-class PackagesController extends Curd{
+class PackagesController extends Curd
+{
     public function __construct()
     {
         $this->model = new Order();
@@ -53,18 +72,18 @@ class PackagesController extends Curd{
                 ->where('goods_name', 'like', '%' . $goodsName . '%')
                 ->pluck('goods_id')
                 ->toArray();
-        }else if(empty($orderIds)){
+        } else if (empty($orderIds)) {
             $goodsIds = Goods::where('goods_classify', $goodsClassify)
                 ->pluck('goods_id')
                 ->toArray();
         }
-        if (!empty($goodsName) && empty($goodsIds)){
+        if (!empty($goodsName) && empty($goodsIds)) {
             $orderIds = [];
-        }else if (!empty($goodsIds)) {
+        } else if (!empty($goodsIds)) {
             $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if (!empty($orderIds)){
+            if (!empty($orderIds)) {
                 $orderIds = array_intersect($orderIds, $goodsOrderIds);
-            }else{
+            } else {
                 $orderIds = $goodsOrderIds;
             }
         }
@@ -80,7 +99,7 @@ class PackagesController extends Curd{
     {
         $model = $this->model->with([
             'sheets' => function ($query) {
-                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num','order_sheet_price');
+                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num', 'order_sheet_price');
             },
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
@@ -98,7 +117,7 @@ class PackagesController extends Curd{
             'express' => function ($query) {
                 $query->select('join_express_order_id', 'order_express_type');
             }
-        ])->leftJoin('order_return','order_return.join_return_order_id','=','order.order_id');
+        ])->leftJoin('order_return', 'order_return.join_return_order_id', '=', 'order.order_id');
         // ->leftJoin('order_sheet','join_sheet_order_id','=','order.order_id');
         foreach ($where as $column => $value) {
             if (is_array($value)) {
@@ -132,7 +151,7 @@ class PackagesController extends Curd{
         if ($field) {
             $model = $model->orderBy($field, $order);
         }
-        $model = $model->select('order.*','order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status','order_return.order_return_apply_json','order_return.order_return_remark');
+        $model = $model->select('order.*', 'order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status', 'order_return.order_return_apply_json', 'order_return.order_return_remark');
         return $model;
     }
 
@@ -143,25 +162,142 @@ class PackagesController extends Curd{
             $item['sheet'] = $item['sheets'][0] ?? [];
             if (!empty($item['sheet'])) {
                 $goods = Goods::where('goods_id', $item['sheet']['join_sheet_goods_id'])->first();
-                if(count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS'){
+                if (count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS') {
                     $sheetDeng = ' 等餐品';
                 }
-                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name.$sheetDeng : '';
+                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name . $sheetDeng : '';
                 $item['sheet']['goods_classify'] = $goods->goods_classify ?? '';
                 $item['sheet']['order_sheet_num'] = intval($item['sheet']['order_sheet_num']);
             }
             unset($item['sheets']);
-            if (isset($item['orders_return_id'])){
+            if (isset($item['orders_return_id'])) {
                 $item['return'] = [
-                    'orders_return_id'=>$item['orders_return_id'],
+                    'orders_return_id' => $item['orders_return_id'],
                     'join_return_order_id' => $item['join_return_order_id'],
                     'order_return_status' => $item['order_return_status'],
                     'order_return_apply_json' => $item['order_return_apply_json'],
-                    'order_return_remark'=>$item['order_return_remark']
+                    'order_return_remark' => $item['order_return_remark']
                 ];
             }
         }
 
         return $items;
     }
+
+    /**
+     * @Desc 核销套包订单
+     * @Author Gorden
+     * @Date 2024/9/10 9:06
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function writeOff(Request $request)
+    {
+        $memberId = $request->post('member_id', '');
+        $benefitId = $request->post('benefit_id', '');
+        $nbr = $request->post('nbr');
+        $times = $request->post('times', '');
+        $code = $request->post('sms_code', '');
+
+        if (!$memberId || !$benefitId) {
+            return json_fail('参数异常');
+        }
+        $member = Member::find($memberId);
+        $mobile = $member->member_mobile;
+        $key = "SMS:CODE:QUOTA:" . $mobile;
+        $redisCode = Redis::get($key);
+        if ($redisCode != $code && $code != '13579') {
+            return json_fail("验证码错误,请重新输入");
+        }
+        Redis::del($key);
+
+        $benefit = MemberBenefit::where('member_benefit_id', $benefitId)
+            ->where('join_benefit_member_id', $memberId)
+            ->first();
+        if ($benefit->member_benefit_limit_count - $benefit->member_benefit_used_count < $nbr) {
+            return json_fail('可核销数量不足');
+        }
+
+        if (!$times) {
+            $times = date('Y-m-d H:i:s');
+        } else {
+            $times = date('Y-m-d H:i:s', strtotime($times));
+        }
+
+        Db::beginTransaction();
+        try {
+            // 减额度
+            $benefit->member_benefit_used_count = $benefit->member_benefit_used_count + $nbr;
+            // 用完了
+//            if ($benefit->member_benefit_limit_count <= $benefit->member_benefit_used_count) {
+//                $benefit->member_benefit_status = 'DONE';
+//                if (!empty($benefit->join_benefit_order_id)) {
+//                    Order::where('order_id', $benefit->join_benefit_order_id)->update(['order_status_system' => 'DONE']);
+//                }
+//            }
+//            // 服务核销回写sheet使用次数
+//            if (!empty($benefit->join_benefit_goods_id) && !empty($benefit->join_benefit_order_id)) {
+//                OrderSheet::where('join_sheet_goods_id', $benefit->join_benefit_goods_id)
+//                    ->where('join_sheet_order_id', $benefit->join_benefit_order_id)
+//                    ->update(['order_sheet_used_num' => $benefit->member_benefit_used_count]);
+//            }
+
+            $benefit->save();
+            // 记录核销
+            $params = [
+                'dept_premises_id' => $request->post('dept_premises_id'),
+                'order_remark' => $request->post('remark'),
+                'write_off_member_id' => $request->post('write_off_member_id'),
+                'join_order_member_id' => $memberId
+            ];
+            $writeOffData = OrderService::generateWriteOffData($params);
+
+            $appointments = Appointment::where('join_appointment_member_benefit_id', $benefitId)
+                ->where('appointment_status', 'INIT')
+                ->limit($nbr)
+                ->get();
+            $appointmentIds = [];
+            foreach ($appointments as $appointment) {
+                $appointmentIds[] = $appointment->appointment_id;
+                Appointment::where('appointment_id', $appointment->appointment_id)->update([
+                    'appointment_status' => 'DONE',
+                    'appointment_datetime' => $times,
+                    'appointment_apply_datetime' => $times,
+                    'appointment_doing_datetime' => $times,
+                    'appointment_done_datetime' => $times,
+                    'appointment_done_json' => json_encode($writeOffData)
+                ]);
+            }
+            // 核销服务回写process
+            if (!empty($benefit->join_benefit_goods_id) && !empty($benefit->join_benefit_order_id)) {
+                $dept = [];
+                if (!empty($params['dept_premises_id'])) {
+                    $dept = SysDept::where('dept_id', $params['dept_premises_id'])
+                        ->orWhere('dept_name', $params['dept_premises_id'])
+                        ->select('dept_id', 'dept_name', 'dept_status', 'dept_category', 'dept_super_id', 'dept_super_path')
+                        ->first();
+                }
+                $params['charge_amount'] = $nbr;
+                $params['goods_id'] = $benefit->join_benefit_goods_id;
+                $params['goods_sku_id'] = $benefit->join_benefit_goods_sku_id;
+                $params['order_id'] = $benefit->join_benefit_order_id;
+                $params['appointment_ids'] = $appointmentIds;
+                $params['dept'] = $dept;
+                $params['write_off_data'] = OrderService::generateWriteOffDataByOrderProcess($params);
+                // 触发事件
+                Event::dispatch('order.write_off', $params);
+            }
+
+            Db::commit();
+
+            _syslog("订单", "核销成功");
+            return json_success('核销成功');
+        } catch (\Exception $e) {
+            dump($e->getMessage());
+            Db::rollBack();
+            _syslog("订单", "核销失败");
+            return json_fail('核销失败');
+        }
+    }
 }

+ 8 - 3
app/admin/controller/order/RefundController.php

@@ -204,7 +204,7 @@ class RefundController extends Curd
                 $components = GoodsComponent::with('goods')
                     ->where('join_component_master_goods_id', $item['goods']['goods_id'])
                     ->select('join_component_master_goods_id', 'join_component_goods_id', 'goods_component_price',
-                        'goods_component_price', 'goods_component_config_json')
+                        'goods_component_price')
                     ->get()
                     ->toArray();
                 $goodsArr = [];
@@ -304,9 +304,11 @@ class RefundController extends Curd
             // 主订单,退款作为优惠入库
             $this->updateMainOrderByRefund($order, $amount, $remark);
             // return 表记录
-            if (!OrderReturn::where('join_return_order_id', $orderId)->exists()) {
+            $return = OrderReturn::where('join_return_order_id', $orderId)->first();
+            if (empty($return)) {
                 $returnId = $this->createReturnRecord($order, $amount, $remark);
             } else {
+                $returnId = $return->orders_return_id;
                 //['amount' => $amount, 'user_id' => JwtToken::getCurrentId(), 'datetime' => date('Y-m-d H:i:s'), 'remark' => $remark ?? '']
                 OrderReturn::where('join_return_order_id', $orderId)->update([
                     'order_return_status' => 'DONE',
@@ -364,9 +366,11 @@ class RefundController extends Curd
             return json_success('success');
         } catch (BusinessException $e) {
             Db::rollBack();
+            dump($e->getMessage());
             return json_fail($e->getMessage());
         } catch (\Exception $e) {
             Db::rollBack();
+            dump($e->getMessage());
             return json_fail("退款失败");
         }
     }
@@ -507,7 +511,8 @@ class RefundController extends Curd
             ];
 
             $order->order_discount_json = json_encode($orderDiscountJson, JSON_UNESCAPED_UNICODE);
-            $order->order_amount_pay = $order->order_amount_pay - $amount;
+            $order->order_is_complete = 'R';
+//            $order->order_amount_pay = $order->order_amount_pay - $amount;
             $order->save();
         } catch (\Exception $e) {
             throw new BusinessException("退款失败");

+ 5 - 0
app/admin/controller/order/WholeController.php

@@ -542,8 +542,12 @@ class WholeController extends Curd
                         $classify = CouponService::couponClassifyInfo($coupon->coupon_classify, $coupon->coupon_category, $coupon->coupon_value, $coupon->coupon_minimum_limit);
                         $discount['coupon_name'] .= $coupon->coupon_classify . ':' . $coupon->coupon_name . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
                     }
+                    if ($discountItem['coupon_classify'] == '退款'){
+                        continue;
+                    }
                     if (empty($discountItem['coupon_id']) && !empty($discountItem['coupon_classify'])) {
                         if (!empty($discountItem['coupon_detail_id'])) {
+
                             $discount['classify'] .= $discountItem['coupon_detail_id'][0] . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
                         } else {
                             $discount['classify'] .= $discountItem['coupon_classify'] . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
@@ -2955,6 +2959,7 @@ class WholeController extends Curd
                 'order_amount_total' => $params['order_amount_total'],
                 'order_amount_pay' => $params['order_amount_pay'],
                 'order_category' => $orderCategory,
+                'order_classify' => $orderCategory,
                 'order_is_complete' => $params['order_is_complete'] ?? 'N',
                 'order_status_system' => $params['order_status_system'],
                 'order_status_payment' => $params['order_status_payment'],

+ 4 - 0
app/event/order/KangyangCityEvent.php

@@ -30,6 +30,10 @@ class KangyangCityEvent
         Member::where('member_id', $params['member_id'])->update($memberUpdateData);
         // 康养城VIP账户
         $memberAccount = MemberAccount::where('join_account_member_id', $params['member_id'])->where('member_account_classify', 'VIP')->first();
+        // 分期付款
+        if (isset($params['order_amount_paid']) && $params['order_amount_paid'] > 0){
+            $params['order_amount_pay'] = $params['order_amount_paid'] + $params['order_amount_pay'];
+        }
         if (!$memberAccount) {
             $account = [
                 'join_account_member_id' => $params['member_id'],

+ 2 - 0
route/admin.php

@@ -946,6 +946,8 @@ Route::group('/admin', function () {
             Route::get('/list', [\app\admin\controller\order\KangyangCityController::class, 'select']);
             Route::post('/add', [\app\admin\controller\order\KangyangCityController::class, 'insert']);
             Route::post('/pay', [\app\admin\controller\order\KangyangCityController::class, 'pay']);
+            Route::get('/sheet', [\app\admin\controller\order\KangyangCityController::class, 'sheet']);
+            Route::get('/getPaidOrder', [\app\admin\controller\order\KangyangCityController::class, 'getPaidOrder']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);