Преглед на файлове

商品列表,商品详情,vip价格

lizhen_gitee преди 2 месеца
родител
ревизия
4b374a53d0
променени са 2 файла, в които са добавени 25 реда и са изтрити 1 реда
  1. 1 1
      addons/unishop/controller/Product.php
  2. 24 0
      addons/unishop/model/Product.php

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

@@ -172,7 +172,7 @@ class Product extends Base
             ->where(['switch' => productModel::SWITCH_ON])
             ->page($page, $pagesize)
             ->order($by, $desc)
-            ->field('id,title,image,sales_price')
+            ->field('id,title,image,sales_price,market_price')
             ->select();
 
         if ($result) {

+ 24 - 0
addons/unishop/model/Product.php

@@ -60,6 +60,7 @@ class Product extends Model
         'videothumb',
         'specList',
         'specTableList',
+        'salesPrice'
     ];
 
     /**
@@ -126,6 +127,18 @@ class Product extends Model
         return !empty($data['specList']) ? json_decode($data['specList'], true) : [];
     }
 
+    public function getSalesPriceAttr($value, $data){
+        //vip改价格
+        $auth = \app\common\library\Auth::instance();
+        $is_vipprice = 0;
+        if($auth->isLogin() && $auth->getUser()->is_vipprice == 1){
+            $is_vipprice = 1;
+        }
+
+        //vip改价格
+        return $is_vipprice == 1 ? $data['market_price'] : $data['sales_price'];
+    }
+
     /**
      * 处理规格值
      * @param $value
@@ -134,6 +147,14 @@ class Product extends Model
      */
     public function getSpecTableListAttr($value, $data) {
         $specs = !empty($data['specTableList']) ? json_decode($data['specTableList'], true) : [];
+
+        //vip改价格
+        $auth = \app\common\library\Auth::instance();
+        $is_vipprice = 0;
+        if($auth->isLogin() && $auth->getUser()->is_vipprice == 1){
+            $is_vipprice = 1;
+        }
+
         foreach ($specs as &$spec) {
             unset($spec['code']);
 
@@ -143,6 +164,9 @@ class Product extends Model
             if(!empty($spec['value'])){
                 $spec['value_text'] = implode(',',$spec['value']);
             }
+
+            //vip改价格
+            $spec['sales_price'] = $is_vipprice == 1 ? $spec['market_price'] : $spec['sales_price'];
         }
         return $specs;
     }