浏览代码

预下单也要传参coupon_id

lizhen_gitee 6 月之前
父节点
当前提交
8c4544de9b
共有 2 个文件被更改,包括 21 次插入4 次删除
  1. 20 3
      addons/unishop/controller/Order.php
  2. 1 1
      addons/unishop/controller/Product.php

+ 20 - 3
addons/unishop/controller/Order.php

@@ -154,6 +154,7 @@ class Order extends Base
 //            $cityId = $address['city_id'] ? $address['city_id'] : 0;
 //            $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
 
+            //订单费用
             $order_price = '0';
             foreach ($productData as &$product) {
                 $product['image'] = Config::getImagesFullUrl($product['image']);
@@ -164,7 +165,7 @@ class Order extends Base
             }
 
             $coupon = Db::name('unishop_coupon_user')->alias('cu')
-                ->field(['cu.id','c.title','c.least','c.value','c.starttime','c.endtime'])
+                ->field(['cu.id as cu_id','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',$this->auth->id)
                 ->where('cu.status',0)
@@ -172,16 +173,32 @@ class Order extends Base
                 ->where('c.switch',1)
                 ->where('c.starttime','<',time())
                 ->where('c.endtime','>',time())
-                ->where('c.least','>=',$order_price)
+                ->where('c.least','<=',$order_price)
                 ->select();
 
+            //优惠费用
+            $coupon_id = input('coupon_id',0);
+            $discountPrice = 0;
+            if($coupon_id && !empty($coupon)){
+                $coupon_ids = array_column($coupon,'id');
+                if(in_array($coupon_id,$coupon_ids)){
+                    foreach($coupon as $key => $cou){
+                        if($cou['id'] == $coupon_id){
+                            $discountPrice = $cou['value'];
+                        }
+                    }
+                }
+            }
+
+
             $this->success('', [
                 'product' => $productData,
 //                'address' => $address,
                 'coupon' => $coupon,
 //                'delivery' => $delivery['list']
                 'order_price' => $order_price,
-                'total_price' => $order_price
+                'discount_price' => $discountPrice,
+                'total_price' => bcsub($order_price,$discountPrice,2),
             ]);
 
         } catch (Exception $e) {

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

@@ -95,7 +95,7 @@ class Product extends Base
             $data->coupon = [];
             if($this->auth->isLogin()){
                 $data->coupon = Db::name('unishop_coupon_user')->alias('cu')
-                    ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime'])
+                    ->field(['cu.id as cu_id','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',$this->auth->id)
                     ->where('cu.status',0)