Gorden 6 месяцев назад
Родитель
Сommit
3f8d656f9f

+ 9 - 5
app/admin/controller/coupon/CouponDetailController.php

@@ -194,6 +194,7 @@ class CouponDetailController extends Curd
     {
         $memberId = $request->get('member_id', '');
         $goods = $request->get('goods', []);
+        $settlementNow = $request->get('settlement_now', 'N');
         if ($memberId == '') {
             return json_fail("参数异常");
         }
@@ -213,11 +214,14 @@ class CouponDetailController extends Curd
             'coupon' => function ($query) {
                 $query->select('coupon_id', 'coupon_name', 'coupon_classify', 'coupon_value', 'coupon_category', 'coupon_minimum_limit');
             }
-        ])
-            ->whereIn('join_detail_coupon_id', $couponIds)
-            ->where('join_coupon_detail_member_id', $memberId)
-            ->where('coupon_detail_status', 'ACTIVED')
-            ->selectRaw('join_detail_coupon_id,join_coupon_detail_member_id,COUNT(*) as count')
+        ])->whereIn('join_detail_coupon_id', $couponIds)
+            ->where('join_coupon_detail_member_id', $memberId);
+            if ($settlementNow == 'Y') {
+                $details = $details->whereIn('coupon_detail.coupon_detail_status', ['ACTIVED', 'WAITING']);
+            } else {
+                $details = $details->where('coupon_detail.coupon_detail_status', 'ACTIVED');
+            }
+            $details = $details->selectRaw('join_detail_coupon_id,join_coupon_detail_member_id,COUNT(*) as count')
             ->groupBy('join_detail_coupon_id', 'join_coupon_detail_member_id')
             ->get()
             ->toArray();

+ 1 - 1
app/admin/controller/member/MemberController.php

@@ -530,7 +530,7 @@ class MemberController
             ->where('join_coupon_detail_member_id', $memberId)
             ->where('coupon.coupon_classify', $classify);
         $total = $coupons->count();
-        $rows = $coupons->select('coupon_detail.*', 'coupon.coupon_name', 'coupon.coupon_classify')
+        $rows = $coupons->select('coupon_detail.*', 'coupon.coupon_name', 'coupon.coupon_classify','coupon_value')
             ->forPage($page, $pageSize)
             ->get()
             ->toArray();

+ 68 - 5
app/admin/controller/order/PayDetailController.php

@@ -34,6 +34,20 @@ class PayDetailController extends Curd
             $where['pay_status'] = 'SUCCESS';
             $where['pay_category'] = ['<>', 'RECHARGE'];
         }
+        if (!empty($where['pay_addtimes'])) {
+            $where['pay_addtimes'][0] = !empty($where['pay_addtimes'][0]) ? strtotime($where['pay_addtimes'][0]) : '';
+            $where['pay_addtimes'][1] = !empty($where['pay_addtimes'][1]) ? strtotime($where['pay_addtimes'][1]) : '';
+        }
+        if (!empty($request->get('premises_id'))) {
+            $payIds = PayDetail::whereJsonContains('pay_extend_json->remark->premises_id', intval($request->get('premises_id')))
+                ->pluck('pay_id')
+                ->toArray();
+            $where['pay_id'] = '';
+            if (!empty($payIds)) {
+                $where['pay_id'] = ['in', $payIds];
+            }
+        }
+
         // else if ($where['pay_category'] == 'RECHARGE') {
         //     $where['pay_status'] = 'SUCCESS';
         //     $where['pay_category'] = 'RECHARGE';
@@ -76,8 +90,8 @@ class PayDetailController extends Curd
             }
         }
         $model = $model->where(function ($query) {
-            $query->whereIn('pay_prepayid',['ALIPAY','WXPAY'])
-                ->orWhere('pay_prepayid','like','%CASH%');
+            $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY'])
+                ->orWhere('pay_prepayid', 'like', '%CASH%');
         });
 
         if ($field) {
@@ -85,6 +99,7 @@ class PayDetailController extends Curd
         }
         return $model;
     }
+
     public function selectWelfare(Request $request): Response
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
@@ -137,7 +152,7 @@ class PayDetailController extends Curd
             }
         }
         $model = $model->where(function ($query) {
-            $query->Where('pay_prepayid','like','%WELFARE%');
+            $query->Where('pay_prepayid', 'like', '%WELFARE%');
         });
 
         if ($field) {
@@ -154,13 +169,22 @@ class PayDetailController extends Curd
                 $item->pay_prepayid = $prepayId[1];
             }
             $memberAccount = [];
-            if(!empty($item->memberAccount)){
-                foreach($item->memberAccount as $account){
+            if (!empty($item->memberAccount)) {
+                foreach ($item->memberAccount as $account) {
                     $memberAccount[strtolower($account->member_account_classify)] = $account;
                 }
 
                 $item->memberAccount = $memberAccount;
             }
+            if (!empty($item->pay_extend_json)) {
+                $payExtendJson = json_decode($item->pay_extend_json, true);
+                if (isset($payExtendJson['remark'])) {
+                    $item->service = $payExtendJson['remark']['service'] ?? '';
+                    $item->business = $payExtendJson['remark']['business'] ?? '';
+                    $item->premises_id = $payExtendJson['remark']['premises_id'] ?? '';
+                    $item->premises_name = $payExtendJson['remark']['premises_name'] ?? '';
+                }
+            }
         }
 
         return $items;
@@ -362,4 +386,43 @@ class PayDetailController extends Curd
         $data['pay_prepayid'] = 0;
         return $data;
     }
+
+    /**
+     * @Desc 加备注-门店、服务人员、业务人员
+     * @Author Gorden
+     * @Date 2024/8/29 16:14
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function remark(Request $request)
+    {
+        $payId = $request->post('pay_id', '');
+        if (!$payId) {
+            return json_fail('参数异常');
+        }
+        $payDetail = PayDetail::where('pay_id', $payId)->first();
+        if (!$payDetail) {
+            return json_fail("数据异常");
+        }
+        try {
+            $data = [
+                'premises_id' => $request->post('premises_id', ''),
+                'premises_name' => $request->post('premises_name', ''),
+                'business' => $request->post('business', ''),
+                'service' => $request->post('service', '')
+            ];
+            $payExtendJson = [];
+            if (!empty($payDetail->pay_extend_json)) {
+                $payExtendJson = json_decode($payDetail->pay_extend_json, true);
+            }
+            $payExtendJson['remark'] = $data;
+            $payDetail->pay_extend_json = json_encode($payExtendJson, JSON_UNESCAPED_UNICODE);
+            $payDetail->save();
+
+            return json_success('success');
+        } catch (\Exception $e) {
+            return json_fail('备注保存失败');
+        }
+    }
 }

+ 138 - 94
app/admin/controller/order/WholeController.php

@@ -15,6 +15,7 @@ use app\controller\Curd;
 use app\model\Appointment;
 use app\model\ClientConfig;
 use app\model\Coupon;
+use app\model\CouponDetail;
 use app\model\Device;
 use app\model\Goods;
 use app\model\GoodsComponent;
@@ -246,7 +247,7 @@ class WholeController extends Curd
             } else {
                 $item['payWay'] = null;
             }
-            if (count($payDetails) > 0){
+            if (count($payDetails) > 0) {
                 $payDetail0 = $payDetails[0];
                 $item['pay_times'] = $payDetail0['pay_paytimes'];
             }
@@ -502,7 +503,7 @@ class WholeController extends Curd
         if (!empty($order->order_extend_json)) {
             $orderExtendJson = json_decode($order->order_extend_json, true);
             $order->referee = $orderExtendJson['referee'] ?? '';
-            if (isset($orderExtendJson['cancel_times'])){
+            if (isset($orderExtendJson['cancel_times'])) {
                 $order->cancel_times = $orderExtendJson['cancel_times'];
             }
         }
@@ -521,7 +522,11 @@ class WholeController extends Curd
                     $discount['coupon_name'] .= $coupon->coupon_classify . ':' . $coupon->coupon_name . '(优惠¥' . $discountItem['coupon_value'] . '), ';
                 }
                 if (empty($discountItem['coupon_id']) && !empty($discountItem['coupon_classify'])) {
-                    $discount['classify'] .= $discountItem['coupon_classify'] . '(¥' . round($discountItem['coupon_value'], 2) . '), ';
+                    if (!empty($discountItem['coupon_detail_id'])) {
+                        $discount['classify'] .= $discountItem['coupon_detail_id'][0] . '(优惠¥' . round($discountItem['coupon_value'], 2) . '), ';
+                    } else {
+                        $discount['classify'] .= $discountItem['coupon_classify'] . '(优惠¥' . round($discountItem['coupon_value'], 2) . '), ';
+                    }
                 }
                 if (!empty($discountItem['coupon_value'])) {
                     $discount['value'] += $discountItem['coupon_value'];
@@ -792,12 +797,12 @@ class WholeController extends Curd
             // 使用优惠券
             $couponUseJson = [];
             if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
-                $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
+                $couponResult = OrderService::payUseCoupon('pay', 'Y', $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
                 if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
                     throw new BusinessException("计算优惠后,实付金额错误!");
                 }
                 // 组装优惠券使用数据,存主表优惠里
-                if (!empty($couponResult['use_coupon_json'])){
+                if (!empty($couponResult['use_coupon_json'])) {
                     $couponUseJson = $couponResult['use_coupon_json'];
                     if (!empty($order->order_discount_json)) {
                         $orderDiscountJson = json_decode($order->order_discount_json, true);
@@ -1147,32 +1152,52 @@ class WholeController extends Curd
             }
 
             // // 买的单个服务
-            // $writeOffDate = [];
-            // // 服务已完成,生成核销数据
-            // if ($order->order_status_payment == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
-            //     $writeOffDate = OrderService::generateWriteOffData($params);
-            // }
-            // if (in_array($goods['goods_classify'],['SERVICE','CHNMED','CHNNCD'])) {
-            //     // 订单状态已完成
-            //     Order::where('order_id',$params['orderId'])->update([
-            //         'order_status_system'=>'DONE'
-            //     ]);
-            //     // 权益用完
-            //     $benefits = MemberBenefit::where('join_benefit_order_id',$params['orderId'])->get();
-            //     foreach($benefits as $benefit){
-            //         MemberBenefit::where('member_benefit_id',$benefit->member_benefit_id)->update([
-            //             'member_benefit_used_count'=>$benefit->member_benefit_limit_count,
-            //             'member_benefit_status'=>'DONE'
-            //         ]);
-            //         dump($writeOffDate);
-            //         // 核销记录
-            //         Appointment::where('join_appointment_member_benefit_id',$benefit->member_benefit_id)->update([
-            //             'appointment_status'=>'DONE',
-            //             'appointment_done_datetime'=>date('Y-m-d H:i:s'),
-            //             'appointment_done_json' => json_encode($writeOffDate)
-            //         ]);
-            //     }
-            // }
+            if ($order->order_status_payment == 'SUCCESS') {
+                foreach ($params['goodsContentList'] as $goods) {
+                    $params['join_sheet_goods_id'] = $goods['goods_id'];
+                    if (in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
+                        $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
+                        $params['order_sheet_num'] = $goods['nbr'];
+                        // 预约表
+                        for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
+                            $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(6, 'up');
+                            // 入预约记录
+                            $this->insertAppointment($params, $writeOffDate, $applyData);
+                        }
+                        $goods['skuId'] = $goods['sku_id'];
+                        $goods['category'] = $goods['goods_classify'];
+                        // 权益表
+                        $this->insertMemberBenefit($params, $goods);
+                    } elseif ($goods['goods_classify'] == 'PACKAGE') {  // 一个套餐买多个
+                        $params['packageId'] = $goods['goods_id'];
+                        $components = GoodsComponent::with([
+                            'goods' => function ($query) {
+                                $query->select('goods_id', 'goods_name', 'goods_classify');
+                            }
+                        ])->where('join_component_master_goods_id', $params['packageId'])
+                            ->get()
+                            ->toArray();
+                        foreach ($components as $component) {
+                            $componentJson = json_decode($component['goods_component_json'], true);
+                            $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
+                            $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
+                            $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
+                            for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
+                                $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(8, 'up');
+                                // 入预约记录
+                                $this->insertAppointment($params, $writeOffDate);
+                            }
+                            $goods['goods_id'] = $component['join_component_goods_id'];
+                            $goods['goods_name'] = $component['goods']['goods_name'];
+                            $goods['goods_classify'] = $component['goods']['goods_classify'];
+                            $goods['skuId'] = $goods['sku_id'];
+                            $goods['category'] = 'SERVICE';
+                            // 权益表
+                            $this->insertMemberBenefit($params, $goods);
+                        }
+                    }
+                }
+            }
 
             // 2.4W 康养城
             if ($params['goods_classify'] == 'VIP' && $order->order_status_payment == 'SUCCESS') {
@@ -1254,11 +1279,11 @@ class WholeController extends Curd
                 }
                 $couponClassifyDesc = $couponClassify = '餐厅前台优惠';
             } else if (!empty($params['preferential']) && intval($params['preferential'][0]) < 100 && intval($params['preferential'][0]) >= 50) {
-                if (($params['order_amount_total'] * intval($params['preferential'])) / 100 !== $params['order_amount_pay']) {
+                if (($params['order_amount_total'] * intval($params['preferential'][0])) / 100 != $params['order_amount_pay']) {
                     throw new BusinessException("折扣后实际支付金额错误");
                 }
                 $couponClassify = '折扣';
-                $couponClassifyDesc = $params['preferential'] . '折';
+                $couponClassifyDesc = intval($params['preferential'][0]) / 10 . '折';
                 $params['order_discount_amount'] = $params['order_amount_total'] - $params['order_amount_pay'];
             } else {
                 return $json;
@@ -1349,7 +1374,7 @@ class WholeController extends Curd
         try {// 使用优惠券
             $couponUseJson = [];
             if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
-                $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
+                $couponResult = OrderService::payUseCoupon('pay','Y', $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
                 if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
                     throw new BusinessException("计算优惠后,实付金额错误!");
                 }
@@ -1712,6 +1737,19 @@ class WholeController extends Curd
             if ($order->order_status_system != 'PAYING' || $order->order_category != 'DISHES') {
                 return json_fail('仅未支付的餐饮订单可以取消!');
             }
+            if (!empty($order->order_discount_json)) {
+                $orderDiscountJson = json_decode($order->order_discount_json, true);
+                foreach ($orderDiscountJson as $discount) {
+                    if (!empty($discount['coupon_id']) && !empty($discount['coupon_detail_id'])) {
+                        foreach ($discount['coupon_detail_id'] as $detailId) {
+                            if (substr($detailId, 0, 4) == 'CUDT') {
+                                // 恢复优惠券
+                                CouponDetail::where('coupon_detail_id', $detailId)->update(['coupon_detail_status' => 'ACTIVED']);
+                            }
+                        }
+                    }
+                }
+            }
             // sheet 表
             OrderSheet::where('join_sheet_order_id', $orderId)->update(['order_sheet_status' => 'CANCEL']);
             // payDetail 表
@@ -1769,7 +1807,7 @@ class WholeController extends Curd
             // 使用优惠券
             $couponUseJson = [];
             if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
-                $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
+                $couponResult = OrderService::payUseCoupon('insert', $params['settlement_now'], $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
                 if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
                     throw new BusinessException("计算优惠后,实付金额错误!");
                 }
@@ -1843,7 +1881,6 @@ class WholeController extends Curd
             $qrcodePayAmount = 0;
             $params['orderId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
             $params['orderGroupId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
-            $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
 
             $systemStatus = 'SENDING';  // 待发货
             // 立即结算
@@ -2192,55 +2229,61 @@ class WholeController extends Curd
             }
 
             // 买的单个服务
-            // $writeOffDate = [];
-            // $applyData = [];
-            // // 服务已完成,生成核销数据
-            // if ($params['order_status_payment'] == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
-            //     $writeOffDate = OrderService::generateWriteOffData($params);
-            //     $applyData = OrderService::generateAppointmentApplyData($params);
-            // }
-            // if (in_array($goods['goods_classify'],['SERVICE','CHNMED','CHNNCD'])) {
-            //     // 预约表
-            //     for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-            //         $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(6, 'up');
-            //         // 入预约记录
-            //         $this->insertAppointment($params, $writeOffDate,$applyData);
-            //     }
-            //     $goods['skuId'] = $params['join_sheet_goods_sku_id'];
-            //     $goods['category'] = $goods['goods_classify'];
-            //     // 权益表
-            //     $this->insertMemberBenefit($params, $goods);
-            // } elseif ($goods['goods_classify'] == 'PACKAGE') {  // 一个套餐买多个
-            //     $params['packageId'] = $params['join_sheet_goods_id'];
-            //     $components = GoodsComponent::with([
-            //         'goods' => function ($query) {
-            //             $query->select('goods_id', 'goods_name', 'goods_classify');
-            //         }
-            //     ])->where('join_component_master_goods_id', $params['join_sheet_goods_id'])
-            //         ->get()
-            //         ->toArray();
-            //     $orderSheetNum = $params['order_sheet_num'];
-            //     foreach ($components as $component) {
-            //         $params['order_sheet_num'] = $orderSheetNum;
-            //         $componentJson = json_decode($component['goods_component_json'], true);
-            //         $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
-            //         $params['join_sheet_goods_id'] = $component['join_component_goods_id'];
-            //         $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
-            //         $params['order_sheet_num'] = $params['order_sheet_num'] * $componentJson['nbr'];
-            //         for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-            //             $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(8, 'up');
-            //             // 入预约记录
-            //             $this->insertAppointment($params, $writeOffDate);
-            //         }
-            //         $goods['goods_id'] = $component['join_component_goods_id'];
-            //         $goods['goods_name'] = $component['goods']['goods_name'];
-            //         $goods['goods_classify'] = $component['goods']['goods_classify'];
-            //         $goods['skuId'] = $params['join_sheet_goods_sku_id'];
-            //         $goods['category'] = 'SERVICE';
-            //         // 权益表
-            //         $this->insertMemberBenefit($params, $goods);
-            //     }
-            // }
+            $writeOffDate = [];
+            $applyData = [];
+            // 服务已完成,生成核销数据
+//             if ($params['order_status_payment'] == 'SUCCESS' && in_array($goods['goods_classify'], ['SERVICE','CHNMED','CHNNCD', 'PACKAGE'])) {
+//                 $writeOffDate = OrderService::generateWriteOffData($params);
+//                 $applyData = OrderService::generateAppointmentApplyData($params);
+//             }
+            if ($params['order_status_payment'] == 'SUCCESS') {
+                foreach ($params['goodsContentList'] as $goods) {
+                    $params['join_sheet_goods_id'] = $goods['goods_id'];
+                    if (in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
+                        $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
+                        $params['join_sheet_goods_sku_id'] = $goods['sku_id'];
+                        $params['goods_id'] = $goods['goods_id'];
+                        $params['order_sheet_num'] = $goods['nbr'];
+                        // 预约表
+                        for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
+                            $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(6, 'up');
+                            // 入预约记录
+                            $this->insertAppointment($params, $writeOffDate, $applyData);
+                        }
+                        $goods['skuId'] = $goods['sku_id'];
+                        $goods['category'] = $goods['goods_classify'];
+                        // 权益表
+                        $this->insertMemberBenefit($params, $goods);
+                    } elseif ($goods['goods_classify'] == 'PACKAGE') {  // 一个套餐买多个
+                        $params['packageId'] = $goods['goods_id'];
+                        $components = GoodsComponent::with([
+                            'goods' => function ($query) {
+                                $query->select('goods_id', 'goods_name', 'goods_classify');
+                            }
+                        ])->where('join_component_master_goods_id', $params['packageId'])
+                            ->get()
+                            ->toArray();
+                        foreach ($components as $component) {
+                            $componentJson = json_decode($component['goods_component_json'], true);
+                            $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
+                            $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
+                            $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
+                            for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
+                                $params['appointmentId'] = 'AP' . date('YmdHis') . random_string(8, 'up');
+                                // 入预约记录
+                                $this->insertAppointment($params, $writeOffDate);
+                            }
+                            $goods['goods_id'] = $component['join_component_goods_id'];
+                            $goods['goods_name'] = $component['goods']['goods_name'];
+                            $goods['goods_classify'] = $component['goods']['goods_classify'];
+                            $goods['skuId'] = $goods['sku_id'];
+                            $goods['category'] = 'SERVICE';
+                            // 权益表
+                            $this->insertMemberBenefit($params, $goods);
+                        }
+                    }
+                }
+            }
 
             // 2.4W 康养城
             if ($params['goods_classify'] == 'VIP' && $params['order_status_payment'] == 'SUCCESS') {
@@ -2351,7 +2394,7 @@ class WholeController extends Curd
             // 使用优惠券
             $couponUseJson = [];
             if (!empty($params['join_order_member_id']) && !empty($params['preferential'])) {
-                $couponResult = OrderService::payUseCoupon($params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
+                $couponResult = OrderService::payUseCoupon('insert', $params['settlement_now'], $params['join_order_member_id'], $params['goodsContentList'], $params['preferential'], $params['order_amount_total']);
                 if (!empty($couponResult['pay_amount']) && $couponResult['pay_amount'] != $params['order_amount_pay']) {
                     throw new BusinessException("计算优惠后,实付金额错误!");
                 }
@@ -3035,16 +3078,16 @@ class WholeController extends Curd
                 'join_appointment_order_id' => $params['orderId'],
                 'join_appointment_member_benefit_id' => $params['benefitId'],
                 'appointment_classify' => $params['goods_classify'],
-                'appointment_status' => $params['order_status_system'] == 'DONE' ? 'DONE' : 'INIT',
+                'appointment_status' => 'INIT',
                 'appointment_category' => 'NORMAL',
                 'appointment_platform' => 'SYSTEM',
                 'appointment_addtimes' => time(),
-                'appointment_datetime' => $params['order_status_system'] == 'DONE' ? date('Y-m-d') : '',
-                'appointment_apply_datetime' => $params['order_status_system'] == 'DONE' ? date('Y-m-d H:i:s') : '',
-                'appointment_apply_json' => $params['order_status_system'] == 'DONE' && $applyData ? json_encode($applyData) : '[]',
-                'appointment_done_datetime' => $params['order_status_system'] == 'DONE' ? date('Y-m-d H:i:s') : '',
+                'appointment_datetime' => '',
+                'appointment_apply_datetime' => '',
+                'appointment_apply_json' => '[]',
+                'appointment_done_datetime' => '',
                 'appointment_remark' => $params['order_remark'] ?? '',
-                'appointment_done_json' => $params['order_status_system'] == 'DONE' && $writeOffDate ? json_encode($writeOffDate) : '[]'
+                'appointment_done_json' => '[]'
             ];
             Appointment::insert($data);
         } catch (\Exception $e) {
@@ -3077,7 +3120,7 @@ class WholeController extends Curd
                 'member_benefit_category' => $goods['category'],
                 'member_benefit_name' => $goods['goods_name'],
                 'member_benefit_limit_count' => $params['order_sheet_num'],
-                'member_benefit_used_count' => $params['order_status_system'] == 'DONE' ? $params['order_sheet_num'] : 0,
+                'member_benefit_used_count' => 0,
                 'member_benefit_remark' => $params['order_remark'] ?? '',
                 'member_benefit_addtimes' => time()
             ];
@@ -4361,6 +4404,7 @@ class WholeController extends Curd
         $coupon = $request->post('coupon', []);
         $payAmount = $request->post('pay_amount', 0);
         $memberId = $request->post('member_id', '');
+        $settlementNow = $request->post('settlement_now', 'N');
         if (empty($goods) || empty($coupon) || empty($memberId)) {
             return json_fail("参数异常");
         }
@@ -4375,7 +4419,7 @@ class WholeController extends Curd
             'cut_balance' => 0,
         ];
         foreach ($goods as $good) {
-            $result = OrderService::chooseCoupon($memberId, $goods, $good, $coupon, $amountBalance);
+            $result = OrderService::chooseCoupon($settlementNow, $memberId, $goods, $good, $coupon, $amountBalance);
             $amountBalance = [
                 'pay_amount' => $result['pay_amount'],
                 'welfare_balance' => $result['welfare_balance'],

+ 3 - 1
app/admin/service/member/MemberService.php

@@ -55,7 +55,9 @@ class MemberService
             })->when($level != '', function ($query) use ($level) {
                 if ($level == 'other') {
                     $query->where('member.join_member_role_id', NULL)->orWhere('member.join_member_role_id', '');
-                } else {
+                } else if($level == 'VIP'){
+                    $query->where('member.member_is_vip', 'Y');
+                }else {
                     $query->where('member_role.member_role_id', $level);
                 }
             })->when($isAuth != '', function ($query) use ($isAuth) {

+ 33 - 13
app/admin/service/order/OrderService.php

@@ -439,7 +439,7 @@ class OrderService
      * @param $payAmount
      * @return array|mixed
      */
-    public static function payUseCoupon($memberId, $goods, $coupon, $payAmount)
+    public static function payUseCoupon($type, $settlementNow, $memberId, $goods, $coupon, $payAmount)
     {
         try {
             foreach ($coupon as $item) {
@@ -453,7 +453,7 @@ class OrderService
                 'cut_balance' => 0,
             ];
             foreach ($goods as $good) {
-                $result = OrderService::useCoupon($memberId, $goods, $good, $coupon, $amountBalance);
+                $result = OrderService::useCoupon($type,$settlementNow, $memberId, $goods, $good, $coupon, $amountBalance);
                 $amountBalance = [
                     'pay_amount' => $result['pay_amount'],
                     'welfare_balance' => $result['welfare_balance'],
@@ -476,9 +476,8 @@ class OrderService
         }
     }
 
-    public static function useCoupon($memberId, $goods, $good, $coupon, $amountBalance)
+    public static function useCoupon($type,$settlementNow, $memberId, $goods, $good, $coupon, $amountBalance)
     {
-        dump("进到useCoupon");
         try {
             $cacheKey = "ORDER:USE:COUPON:" . $memberId;
             $cacheDiscountKey = "ORDER:USE:COUPON:DISCOUNT:" . $memberId;
@@ -501,12 +500,27 @@ class OrderService
                     ->where('coupon_goods.join_coupon_goods_id', $goodsId)
                     ->where('coupon_goods.join_coupon_goods_sku_id', $good['sku_id'])
                     ->where('join_goods_coupon_id', $couponId)
-                    ->where('coupon_detail.join_coupon_detail_member_id', $memberId)
-                    ->where('coupon_detail.coupon_detail_status', 'ACTIVED')
+                    ->where('coupon_detail.join_coupon_detail_member_id', $memberId);
+                if ($settlementNow == 'Y' && $type == 'pay') {
+                    $couponDetail = $couponDetail->whereIn('coupon_detail.coupon_detail_status', ['ACTIVED', 'WAITING']);
+                } else {
+                    $couponDetail = $couponDetail->where('coupon_detail.coupon_detail_status', 'ACTIVED');
+                }
+                $couponDetail = $couponDetail->orderBy('coupon_detail_id', 'DESC')
                     ->first();
                 if (!$couponDetail) {
                     continue;
                 }
+                if ($settlementNow == 'Y') {
+                    $updateData = [
+                        'coupon_detail_status' => 'USED',
+                        'coupon_detail_used_datetime' => date('Y-m-d H:i:s')
+                    ];
+                } else {
+                    $updateData = [
+                        'coupon_detail_status' => 'WAITING',
+                    ];
+                }
                 // 计算优惠券包含的优惠商品的件数和总价
                 $countAndAmount = self::countAndAmount($goods, $couponId);
                 // 如果是计件
@@ -528,7 +542,8 @@ class OrderService
                             'coupon_detail_id' => [$couponDetail->coupon_detail_id]
                         ];
                         Redis::set($cacheDiscountKey, json_encode($discountData, JSON_UNESCAPED_UNICODE));
-                        CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update(['coupon_detail_status' => 'USED', 'coupon_detail_used_datetime' => date('Y-m-d H:i:s')]);
+
+                        CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update($updateData);
                     }
                 } elseif ($couponDetail->coupon_classify == '折扣券') {
                     if (Redis::sIsMember($cacheKey, $couponId)) {
@@ -546,14 +561,14 @@ class OrderService
                             'coupon_detail_id' => [$couponDetail->coupon_detail_id]
                         ];
                         Redis::set($cacheDiscountKey, json_encode($discountData, JSON_UNESCAPED_UNICODE));
-                        CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update(['coupon_detail_status' => 'USED', 'coupon_detail_used_datetime' => date('Y-m-d H:i:s')]);
+                        CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update($updateData);
                     }
                 } elseif (in_array($couponDetail->coupon_classify, ['抵用券', '赠品券'])) {
                     if (Redis::sIsMember($cacheKey, $couponId)) {
                         continue;
                     }
                     Redis::sAdd($cacheKey, $couponId);
-                    CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update(['coupon_detail_status' => 'USED', 'coupon_detail_used_datetime' => date('Y-m-d H:i:s')]);
+                    CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update($updateData);
                     if ($good['nbr'] > 1) {
                         $diyongAmount = $good['goods_sales_price'];
                         $payAmount = $payAmount - $diyongAmount;
@@ -574,7 +589,7 @@ class OrderService
                         continue;
                     }
                     Redis::sAdd($cacheKey, $couponId);
-                    CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update(['coupon_detail_status' => 'USED', 'coupon_detail_used_datetime' => date('Y-m-d H:i:s')]);
+                    CouponDetail::where('coupon_detail_id', $couponDetail->coupon_detail_id)->update($updateData);
                     $fuliAmount = 0;
                     if (!empty($couponDetail->coupon_value)) {
                         $fuliAmount = $couponDetail->coupon_value;
@@ -652,7 +667,7 @@ class OrderService
      * @param $amountBalance
      * @return array|void
      */
-    public static function chooseCoupon($memberId, $goods, $good, $coupon, $amountBalance)
+    public static function chooseCoupon($settlementNow, $memberId, $goods, $good, $coupon, $amountBalance)
     {
         try {
             $cacheKey = "ORDER:USE:COUPON:" . $memberId;
@@ -668,8 +683,13 @@ class OrderService
                     ->where('coupon_goods.join_coupon_goods_id', $goodsId)
                     ->where('coupon_goods.join_coupon_goods_sku_id', $good['sku_id'])
                     ->where('join_goods_coupon_id', $couponId)
-                    ->where('coupon_detail.join_coupon_detail_member_id', $memberId)
-                    ->where('coupon_detail.coupon_detail_status', 'ACTIVED')
+                    ->where('coupon_detail.join_coupon_detail_member_id', $memberId);
+                if ($settlementNow == 'Y') {
+                    $couponDetail = $couponDetail->whereIn('coupon_detail.coupon_detail_status', ['ACTIVED', 'WAITING']);
+                } else {
+                    $couponDetail = $couponDetail->where('coupon_detail.coupon_detail_status', 'ACTIVED');
+                }
+                $couponDetail = $couponDetail->orderBy('coupon_detail_id', 'DESC')
                     ->first();
                 if (!$couponDetail) {
                     continue;