rabin 1 week ago
parent
commit
52bedd7ca7
2 changed files with 16 additions and 4 deletions
  1. 8 3
      app/Lib/Sku.php
  2. 8 1
      app/Lib/Spec.php

+ 8 - 3
app/Lib/Sku.php

@@ -10,6 +10,8 @@ class Sku
             $where['key'] = '-1';
             $sku = Dever::db($app . '/sku')->find($where);
         } elseif ($spec_type == 3) {
+            $where['price'] = ['!=', 'null'];
+            //$where['code'] = ['!=', 'null'];
             $sku = Dever::db($app . '/sku')->find($where, ['order' => 'price asc']);
         }
         if (isset($sku) && $sku && $sku['key']) {
@@ -32,6 +34,8 @@ class Sku
         $where['state'] = 1;
         $info = Dever::db($app . '/sku')->find($where);
         if ($info) {
+            unset($info['state']);
+            unset($info['cdate']);
             $info['name'] = $this->getName($info['key'], $app);
             if (!$info['pic']) {
                 $key = explode(',', $info['key']);
@@ -44,7 +48,8 @@ class Sku
         return $info;
     }
 
-    # 获取价格列表
+    # 获取价格列表 废弃 一次性读取不好
+    /*
     public function getList($where, $sku_id, $app)
     {
         $result = [];
@@ -58,7 +63,7 @@ class Sku
                 unset($v['cdate']);
                 $k = $v['key'];
                 $v['name'] = $this->getName($v['key'], $app);
-                $result['price'][$k] = $v;
+                //$result['price'][$k] = $v;
                 if ($sku_id && $sku_id == $v['id']) {
                     $result['info'] = $v;
                     $spec = explode(',', $v['key']);
@@ -67,7 +72,7 @@ class Sku
             $result['spec'] = Dever::load(Spec::class)->getList($where, $app, $spec);
         }
         return $result;
-    }
+    }*/
 
     # 获取某个sku的名称
     public function getName($key, $app, $show = false)

+ 8 - 1
app/Lib/Spec.php

@@ -36,9 +36,16 @@ class Spec
     }
 
     # 获取列表
-    public function getList($where, $app, $select = false)
+    public function getList($where, $sku_id, $app)
     {
+        $select = [];
         $where['state'] = 1;
+        if ($sku_id) {
+            $sku = Dever::db($app . '/sku')->find(['id' => $sku_id]);
+            if ($sku) {
+                $select = explode(',', $sku['key']);
+            }
+        }
         $data = Dever::db($app . '/spec')->select($where, ['col' => 'id,name']);
         if ($data) {
             foreach ($data as &$v) {