Browse Source

下单改进

lizhen_gitee 11 months ago
parent
commit
72acd6c70a

+ 7 - 4
addons/unishop/behavior/Order.php

@@ -174,21 +174,23 @@ class Order
         }
 
         // 条件三
-        $delivery = (new DeliveryRuleModel())->cityInScopeOfDelivery($extra['city_id'], $extra['delivery_id']);
+        /*$delivery = (new DeliveryRuleModel())->cityInScopeOfDelivery($extra['city_id'], $extra['delivery_id']);
         if (!$delivery) {
             throw new Exception(__('Your receiving address is not within the scope of delivery'));
         } else {
             if ($delivery['min'] > array_sum($numbers)) {
                 throw new Exception(__('You must purchase at least %s item to use this shipping method', $delivery['min']));
             }
-        }
+        }*/
+        $delivery = [];
+
         $address = (new Address)->where(['id' => $extra['address_id'], 'user_id' => $extra['userId']])->find();
         if (!$address) {
             throw new Exception(__('Address not exist'));
         }
 
         // 条件四
-        if ($extra['coupon_id']) {
+        /*if ($extra['coupon_id']) {
             $coupon = Coupon::get($extra['coupon_id']);
             if ($coupon['switch'] == Coupon::SWITCH_OFF || $coupon['deletetime'] || $coupon['starttime'] > time() || $coupon['endtime'] < time()) {
                 throw new Exception('此优惠券不可用');
@@ -199,7 +201,8 @@ class Order
             }
         } else {
             $coupon = [];
-        }
+        }*/
+        $coupon = [];
 
         $params = [$products, $delivery, $coupon, $baseProductInfo, $address, $orderPrice, $specs, $numbers];
     }

+ 17 - 4
addons/unishop/model/Order.php

@@ -234,15 +234,28 @@ class Order extends Model
         $snowflake = new Snowflake();
         $id = $snowflake->id();
         // 优惠费用
-        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+//        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+        $discountPrice = 0;
         // 订单费用
         //$orderPrice;
         // 运费
-        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+//        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+        $deliveryPrice = '0';
+        foreach ($products as &$product) {
+            $deliveryPrice = bcadd($deliveryPrice,$product['yunfei_price'],2);
+        }
+
         // 总费用
         $totalPrice = bcadd(bcsub($orderPrice, $discountPrice, 2), $deliveryPrice, 2);
 
         $out_trade_no = date('Ymd',time()).uniqid().$userId;
+
+        $db_pay_type = [
+            'wallet' => 2,
+            'wechat' => 3,
+            'alipay' => 4,
+        ];
+
         (new self)->save([
             'id' => $id,
             'user_id' => $userId,
@@ -251,7 +264,7 @@ class Order extends Model
             'discount_price' => $discountPrice,
             'delivery_price' => $deliveryPrice,
             'total_price' => $totalPrice,
-            'pay_type' => $data['pay_type'],
+            'pay_type' => $db_pay_type[$data['pay_type']],
             'ip' => $_SERVER['REMOTE_ADDR'] ?? '',
             'remark' => $data['remark'] ?? '',
             'status' => self::STATUS_NORMAL,
@@ -262,7 +275,7 @@ class Order extends Model
             'order_id' => $id,
             'coupon_id' => $coupon ? $coupon['id'] : 0,
             'coupon_json' => json_encode($coupon),
-            'delivery_id' => $delivery['id'],
+            'delivery_id' => $delivery ? $delivery['id'] : 0,
             'delivery_json' => json_encode($delivery),
             'address_id' => $address['id'],
             'address_json' => json_encode($address),

+ 2 - 2
addons/unishop/validate/Order.php

@@ -44,8 +44,8 @@ class Order extends Validate
      * 验证场景
      */
     protected $scene = [
-        'submit'  => ['product_id', 'number', /*'city_id',*/ 'address_id', 'delivery_id', 'remark'], // 创建订单
-        'submitFlash'  => ['product_id', 'number',/* 'city_id',*/ 'address_id', 'delivery_id', 'remark', 'flash_id'], // 秒杀创建订单
+        'submit'  => ['product_id', 'number', /*'city_id',*/ 'address_id', /*'delivery_id',*/ 'remark'], // 创建订单
+        'submitFlash'  => ['product_id', 'number',/* 'city_id',*/ 'address_id', /*'delivery_id',*/ 'remark', 'flash_id'], // 秒杀创建订单
     ];
 
 }