rabin 2 days ago
parent
commit
071738d4fb
1 changed files with 13 additions and 5 deletions
  1. 13 5
      lib/Sku.php

+ 13 - 5
lib/Sku.php

@@ -17,11 +17,16 @@ class Sku
         } elseif ($spec_type == 3) {
             $sku = Dever::db('sku', $app)->find($where, array('order' => 'price asc,id desc'));
         }
-        if (isset($sku) && $sku) {
+        if (isset($sku) && $sku && $sku['key']) {
             $result['price'] = $sku['price'];
             $result['id'] = $sku['id'];
+            if (isset($sku['num'])) {
+                $result['num'] = $sku['num'];
+            }
             $result['key'] = str_replace(',', '_', $sku['key']);
             $result['name'] = $this->getName($sku['key'], $app);
+        } else {
+            Dever::error('价格传入错误');
         }
         return $result;
     }
@@ -32,18 +37,21 @@ class Sku
         $result = array();
         $sku = Dever::db('sku', $app)->select($where, array('order' => 'price asc,id desc'));
         if ($sku) {
-            $result['info'] = array();
+            $result['sku'] = array();
             $result['spec'] = Dever::load('spec', 'api')->getList($where, $app);
             foreach ($sku as $k => $v) {
                 $t = array();
                 $k = str_replace(',', '_', $v['key']);
                 $t['id'] = $v['id'];
                 $t['pic'] = $v['pic'];
-                $t['value'] = $v['price'];
+                $t['price'] = $v['price'];
+                if (isset($v['num'])) {
+                    $t['num'] = $v['num'];
+                }
                 $result['price'][$k] = $t;
                 if ($sku_id && $sku_id == $v['id']) {
                     $t['name'] = $this->getName($v['key'], $app);
-                    $result['info'] = $t;
+                    $result['sku'] = $t;
                 }
             }
         }
@@ -54,7 +62,7 @@ class Sku
     public function getName($key, $app)
     {
         if (!$key || $key == '-1') {
-            return '';
+            return '无规格';
         } else {
             $name = array();
             $where['id'] = array('in', $key);