lizhen_gitee 6 mēneši atpakaļ
vecāks
revīzija
123b72ac5a

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

@@ -174,27 +174,43 @@ 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']));
             }
-        }
-        $address = (new Address)->where(['id' => $extra['address_id'], 'user_id' => $extra['userId']])->find();
+        }*/
+        $delivery = [];
+
+        /*$address = (new Address)->where(['id' => $extra['address_id'], 'user_id' => $extra['userId']])->find();
         if (!$address) {
             throw new Exception(__('Address not exist'));
-        }
+        }*/
+        $address = [];
 
         // 条件四
         if ($extra['coupon_id']) {
-            $coupon = Coupon::get($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('此优惠券不可用');
-            }
+            }*/
+            $coupon = Db::name('unishop_coupon_user')->alias('cu')
+                ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime'])
+                ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
+                ->where('cu.user_id',$extra['userId'])
+                ->where('cu.status',0)
+                ->where('c.deletetime',NULL)
+                ->where('c.switch',Coupon::SWITCH_ON)
+                ->where('c.starttime','<',time())
+                ->where('c.endtime','>',time())
+                ->find('c.id',$extra['coupon_id']);
+
             // 至少消费多少钱
-            if ($coupon['least'] > $orderPrice) {
+            if (!empty($coupon) && $coupon['least'] > $orderPrice) {
                 throw new Exception('选中的优惠券不满足使用条件');
             }
         } else {

+ 10 - 1
addons/unishop/model/Order.php

@@ -238,11 +238,19 @@ class Order extends Model
         // 订单费用
         //$orderPrice;
         // 运费
-        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+//        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+        $deliveryPrice = '0';
         // 总费用
         $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,6 +259,7 @@ class Order extends Model
             'discount_price' => $discountPrice,
             'delivery_price' => $deliveryPrice,
             'total_price' => $totalPrice,
+            'pay_type' => $db_pay_type[$data['pay_type']],
             'ip' => $_SERVER['REMOTE_ADDR'] ?? '',
             'remark' => $data['remark'] ?? '',
             'status' => self::STATUS_NORMAL,

+ 1 - 1
addons/unishop/model/Product.php

@@ -147,7 +147,7 @@ class Product extends Model
     {
         $data = (new \addons\unishop\extend\Product)->getBaseData($this->getData(), $spec);
         if ($data['stock'] < 1) {
-            //throw new Exception('产品库存不足');
+            throw new Exception('产品库存不足');
         }
         $product = $this->getData();
         $data['title'] = $product['title'];

+ 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'], // 秒杀创建订单
     ];
 
 }