Browse Source

双十一活动

gorden 4 months ago
parent
commit
9cb4fe5f9c

+ 16 - 6
app/admin/controller/order/GoodsController.php

@@ -211,7 +211,7 @@ class GoodsController extends Curd
                 ->exists()) {
                 $item['have_success_paydetail'] = 'Y';
             }
-            $item['payDetail'] = PayDetailService::getPayWay($item['order_groupby'],$item['order_id']);
+            $item['payDetail'] = PayDetailService::getPayWay($item['order_groupby'], $item['order_id']);
         }
 
         return $items;
@@ -1785,20 +1785,30 @@ class GoodsController extends Curd
                 }
             }
             // 推荐人
+            $orderAmount = [];
             $params['order_extend_json']['referee'] = $params['referee'] ?? '';
             foreach ($params['goodsContentList'] as $goods) {
+                $amountPay = floatval($goods['goods_sales_price']) * $goods['nbr'];
                 $discountJson = [];
                 if (!empty($params['order_discount_json'])) {
                     $discountJson = json_decode($params['order_discount_json'], true);
-                    foreach ($discountJson as &$item) {
-                        if (!empty($item['coupon_value'])) {
-                            $item['coupon_value'] = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $item['coupon_value'], 2);
+                    foreach ($discountJson as $item) {
+//                        if (!empty($item['coupon_value'])) {
+//                            $item['coupon_value'] = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $item['coupon_value'], 2);
+//                        }
+                        if (!empty($item['coupon_id'])) {
+                            $orderAmount = OrderService::countAndAmount($params['goodsContentList'], $item['coupon_id']);
+                            $payAmountUseCoupon = $params['order_amount_pay'] - ($params['order_amount_total'] - $orderAmount['amount']);
+                            if (in_array($goods['goods_id'], $orderAmount['goodsIds'])) {
+                                $amountPay = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $orderAmount['amount']) * $payAmountUseCoupon, 2);
+                            }
+                        } else {
+                            $orderAmount['amount'] = $params['order_amount_pay'];
+                            $amountPay = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $params['order_amount_pay'], 2);
                         }
                     }
                 }
                 $orderId = 'OD' . date('ymdHi') . random_string(4, 'up');
-                $amountPay = round((floatval($goods['goods_sales_price']) * $goods['nbr'] / $params['order_amount_total']) * $params['order_amount_pay'], 2);
-//                $amountPay = round(floatval($goods['goods_sales_price']) * $goods['nbr'] * $params['order_ratio'], 2);
                 $data = [
                     'order_id' => $orderId,
                     'order_groupby' => $params['orderGroupId'],

+ 4 - 0
app/admin/controller/order/RefundController.php

@@ -619,6 +619,7 @@ class RefundController extends Curd
             throw new BusinessException("余额账户异常");
         }
         $account->member_account_surplus = $account->member_account_surplus + $amount;
+        $account->member_account_expend  = $account->member_account_expend - $amount;
         $account->save();
     }
 
@@ -639,6 +640,7 @@ class RefundController extends Curd
             throw new BusinessException("余额账户异常");
         }
         $account->member_account_surplus = $account->member_account_surplus + $amount;
+        $account->member_account_expend  = $account->member_account_expend - $amount;
         $account->save();
     }
 
@@ -659,6 +661,7 @@ class RefundController extends Curd
             throw new BusinessException("余额账户异常");
         }
         $account->member_account_surplus = $account->member_account_surplus + $amount;
+        $account->member_account_expend  = $account->member_account_expend - $amount;
         $account->save();
     }
 
@@ -680,6 +683,7 @@ class RefundController extends Curd
             throw new BusinessException("储值卡账户异常");
         }
         $account->member_account_surplus = $account->member_account_surplus + $amount;
+        $account->member_account_expend  = $account->member_account_expend - $amount;
         $account->save();
     }
 

+ 3 - 1
app/admin/service/order/OrderService.php

@@ -882,17 +882,19 @@ class OrderService
                 ->toArray();
             $count = 0;
             $amount = 0;
+            $goodsIds = [];
             foreach ($couponGoods as $couponGood) {
                 foreach ($goods as $good) {
 //                    if ($good['goods_id'] == $couponGood['join_coupon_goods_id'] && $good['sku_id'] == $couponGood['join_coupon_goods_sku_id']) {
                     if ($good['goods_id'] == $couponGood['join_coupon_goods_id']) {
                         $count += $good['nbr'];
                         $amount += $good['goods_sales_price'] * $good['nbr'];
+                        $goodsIds[] = $good['goods_id'];
                     }
                 }
             }
 
-            return compact('count', 'amount');
+            return compact('count', 'amount','goodsIds');
         } catch (\Exception $e) {
             dump($e->getTrace());
         }