Parcourir la source

购物车列表,vip价格

lizhen_gitee il y a 3 mois
Parent
commit
4091162342
2 fichiers modifiés avec 15 ajouts et 9 suppressions
  1. 9 9
      addons/unishop/controller/Cart.php
  2. 6 0
      addons/unishop/extend/Product.php

+ 9 - 9
addons/unishop/controller/Cart.php

@@ -55,7 +55,7 @@ class Cart extends Base
         $carts = (new CartModel)->where(['user_id' => $this->auth->id])
             ->with([
                 'product' => function ($query) {
-                    $query->field(['id', 'image', 'title', 'specTableList','sales','market_price','sales_price','stock','use_spec', 'switch']);
+                    $query->field(['id', 'image', 'title', 'specTableList','sales','real_sales','market_price','sales_price','stock','use_spec', 'switch']);
                 }
             ])
             ->order(['createtime' => 'desc'])
@@ -77,15 +77,15 @@ class Cart extends Base
         $choose_price_total = '0';//已选中的总价格
         $choose_number = 0;//已选中的个数
         foreach ($carts as $item) {
-            $oldProduct = json_decode($item['snapshot'], true);
-            $oldData = $productExtend->getBaseData($oldProduct, $item['spec'] ?? '');
+//            $oldProduct = json_decode($item['snapshot'], true);
+//            $oldData = $productExtend->getBaseData($oldProduct, $item['spec'] ?? '');
 
             if (empty($item['product'])) { //商品被删了的情况
                 continue;//不要了
-                $tempData = $oldData;
+                /*$tempData = $oldData;
                 $tempData['isset'] = false; // 失效
                 $tempData['title'] = $oldProduct['title'];
-                $tempData['choose'] = 0;
+                $tempData['choose'] = 0;*/
             } else {
                 $productData = $item['product']->getData();
                 $tempData = $productExtend->getBaseData($productData, $item['spec'] ?? '');
@@ -104,9 +104,9 @@ class Cart extends Base
             $tempData['spec'] = $item['spec'];
             $tempData['number'] = $item['number'];
 
-            $tempData['image'] = Config::getImagesFullUrl($oldData['image']);
-            $tempData['oldPrice'] = round($oldData['sales_price'], 2);
-            $tempData['nowPrice'] = round($tempData['sales_price'], 2);
+            $tempData['image'] = Config::getImagesFullUrl($tempData['image']);
+//            $tempData['oldPrice'] = round($oldData['sales_price'], 2);
+//            $tempData['nowPrice'] = round($tempData['sales_price'], 2);
             //新增此商品总价
             $tempData['Price_total'] = bcmul($tempData['sales_price'],$tempData['number'],2);
             //已选中商品,总价格
@@ -171,7 +171,7 @@ class Cart extends Base
             $cartModel->product_id = $id;
             $spec && $cartModel->spec = $spec;
             $cartModel->number = $number;
-            $cartModel->snapshot = json_encode($product->getData(), true);
+//            $cartModel->snapshot = json_encode($product->getData(), true);
             $result = $cartModel->save();
         }
 

+ 6 - 0
addons/unishop/extend/Product.php

@@ -28,6 +28,12 @@ class Product
         if (!$product) {
             return [];
         }
+
+        //vip改价格
+        $productmodel = new \addons\unishop\model\Product();
+        $product['sales_price']   = $productmodel->getSalesPriceAttr($product['sales_price'],$product);
+        $product['specTableList'] = json_encode($productmodel->getSpecTableListAttr($product['specTableList'],$product));
+
         $data = [];
         if ($spec && $product['use_spec'] == \addons\unishop\model\Product::SPEC_ON && !empty($product['specTableList'])) {
             $specValueArr = json_decode($product['specTableList'], true);