shish пре 5 година
родитељ
комит
88d8412e97
3 измењених фајлова са 70 додато и 26 уклоњено
  1. 47 20
      app-hd/controllers/OrderController.php
  2. 21 6
      biz-ghs/order/classes/OrderClass.php
  3. 2 0
      common/components/dict.php

+ 47 - 20
app-hd/controllers/OrderController.php

@@ -131,20 +131,32 @@ class OrderController extends BaseController
                 //$sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
             }
             $post['sendCost'] = $sendCost;
-
-            $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
-
-            //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-            $sourceType = $this->isWx ? 0 : 1;
-            if (httpUtil::isMiniProgram()) {
-                $sourceType = 2;
+            $currentPrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
+            $post['prePrice'] = $currentPrice;
+            if (isset($post['modifyPrice'])) {
+                //商家打折,修改金额
+                $modifyPrice = $post['modifyPrice'] ?? 0;
+                if ($modifyPrice > $currentPrice) {
+                    util::fail('实收金额大于订单总金额');
+                }
+                if ($modifyPrice < $currentPrice) {
+                    $post['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
+                    $post['discountType'] = dict::getDict('discountType', 'discount');
+                    $currentPrice = $modifyPrice;
+                }
             }
-            $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-            $actPrice = $discountData['price'];
-            $post['discountType'] = $discountData['discountType'];
-            $post['discountAmount'] = $discountData['discountAmount'];
-            $post['prePrice'] = $prePrice;
-            $post['actPrice'] = $actPrice;
+            $post['actPrice'] = $currentPrice;
+            $post['realPrice'] = $currentPrice;
+            //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+//            $sourceType = $this->isWx ? 0 : 1;
+//            if (httpUtil::isMiniProgram()) {
+//                $sourceType = 2;
+//            }
+            //会员优惠价
+//            $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+//            $actPrice = $discountData['price'];
+//            $post['discountType'] = $discountData['discountType'];
+//            $post['discountAmount'] = $discountData['discountAmount'];
             $order = OrderClass::addOrder($post);
             $orderId = $order['id'];
             $orderSn = $order['orderSn'];
@@ -161,15 +173,33 @@ class OrderController extends BaseController
             if (empty($product)) {
                 util::fail('请选择花材');
             }
-            $actPrice = $post['packingFee'] ?? 0; //包装费
+            $currentPrice = $post['packingFee'] ?? 0; //包装费
             $orderProduct = [];
             $productInfo = ProductClass::formatProductInfo($product);
-            $actPrice = bcadd($actPrice, $productInfo['price'], 2);
+            $currentPrice = bcadd($currentPrice, $productInfo['price'], 2);
+            $sendCost = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
+            $post['sendCost'] = $sendCost;
+            $currentPrice = bcadd($currentPrice, $sendCost, 2);
+            $post['prePrice'] = $currentPrice;
+            if (isset($post['modifyPrice'])) {
+                //商家打折,修改金额
+                $modifyPrice = $post['modifyPrice'] ?? 0;
+                if ($modifyPrice > $currentPrice) {
+                    util::fail('实收金额大于订单总金额');
+                }
+                if ($modifyPrice < $currentPrice) {
+                    $post['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
+                    $post['discountType'] = dict::getDict('discountType', 'discount');
+                    $currentPrice = $modifyPrice;
+                }
+            }
+            $post['actPrice'] = $currentPrice;
+            $post['realPrice'] = $currentPrice;
+
             foreach ($product as $key => $val) {
                 $productId = $val['productId'];
                 $bigNum = $val['bigNum'];
                 $smallNum = $val['smallNum'];
-
                 $orderProduct[] = [
                     'productId' => $productId,
                     'bigNum' => $bigNum,
@@ -179,9 +209,6 @@ class OrderController extends BaseController
                 ProductClass::decreaseStock($productId, $bigNum, $smallNum);
             }
 
-            $post['prePrice'] = $actPrice;
-            $post['actPrice'] = $actPrice;
-            $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
             $order = OrderClass::addOrder($post);
             $orderId = $order['id'];
             $orderSn = $order['orderSn'];
@@ -194,7 +221,7 @@ class OrderController extends BaseController
         $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
         OrderClass::staffKdPay($payWay, $orderSn);
 
-        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
+        util::success(['orderSn' => $orderSn, 'totalPrice' => $currentPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
     }
 
     //下单要用到的相关信息 ssh 2019.12.6

+ 21 - 6
biz-ghs/order/classes/OrderClass.php

@@ -117,9 +117,24 @@ class OrderClass extends BaseClass
         $data['smallNum'] = $respond['smallNum'] ?? 0;
         $price = $respond['price'] ?? 0;
         $currentPrice = bcadd($price, $sendCost, 2);
-        $data['actPrice'] = $currentPrice;
         $data['prePrice'] = $currentPrice;
+
+        if (isset($data['modifyPrice'])) {
+            //商家打折,修改金额
+            $modifyPrice = $data['modifyPrice'] ?? 0;
+            if ($modifyPrice > $currentPrice) {
+                util::fail('实收金额大于订单总金额');
+            }
+            if ($modifyPrice < $currentPrice) {
+                $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
+                $data['discountType'] = dict::getDict('discountType', 'discount');
+                $currentPrice = $modifyPrice;
+            }
+        }
+
+        $data['actPrice'] = $currentPrice;
         $data['realPrice'] = $currentPrice;
+
         //如果有平台补贴
         if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) {
             $discountAmount = $data['discountAmount'] ?? 0;
@@ -418,7 +433,7 @@ class OrderClass extends BaseClass
         $id = $order->id;
         $expressId = $expressInfo['expressId'] ?? 1;
         $expressName = $expressInfo['deliveryName'] ?? '达达';
-        $expressRemark = $expressInfo['remark']??'';
+        $expressRemark = $expressInfo['remark'] ?? '';
 
         $order->status = self::ORDER_STATUS_SENDING;
         $order->sendType = self::SEND_TYPE_THIRD;
@@ -441,7 +456,7 @@ class OrderClass extends BaseClass
 
         //达达
 
-        $dadaRes = DadaExpressServices::addOrder($order,$expressRemark);
+        $dadaRes = DadaExpressServices::addOrder($order, $expressRemark);
 
         $orderSn = $order->orderSn;
         $sjId = $order->sjId ?? 0;
@@ -456,9 +471,9 @@ class OrderClass extends BaseClass
         OrderSendClass::thirdSend($order);
           */
         $sendTime = $order->sendTime;
-        if($sendTime =='0000-00-00 00:00:00'){
+        if ($sendTime == '0000-00-00 00:00:00') {
             $sendTime = time();
-        }else{
+        } else {
             $sendTime = strtotime($order->sendTime);
         }
         $expData = [
@@ -471,7 +486,7 @@ class OrderClass extends BaseClass
             'distance' => $dadaRes['distance'],
             'status' => 1,
             'expressName' => $expressName,
-            'remark' =>$expressRemark,
+            'remark' => $expressRemark,
         ];
         OrderExpressClass::addExpress($expData);
         OrderSendClass::thirdSend($order);

+ 2 - 0
common/components/dict.php

@@ -88,6 +88,8 @@ class dict
             'noDiscount' => 1,
             //使用平台优惠券
             'usePtCoupon' => 2,
+            //商家打折
+            'discount'=>3,
         ],
 
         'payStatus' => ['cancel' => -1, 'waitForPay' => 0, 'waitForSend' => 1],