rabin 2 місяців тому
батько
коміт
9d86920ab1
6 змінених файлів з 51 додано та 30 видалено
  1. 13 0
      api/Manage.php
  2. 7 6
      lib/App.php
  3. 19 20
      lib/Sku.php
  4. 9 1
      lib/Spec.php
  5. 1 2
      lib/Util.php
  6. 2 1
      manage/api.php

+ 13 - 0
api/Manage.php

@@ -64,4 +64,17 @@ class Manage extends Auth
             return $data;
         });
     }
+
+    # 复制一个接口
+    public function copyApi()
+    {
+        $id = Dever::input('id');
+        if ($id) {
+            $info = Dever::db('api', 'api')->find($id);
+            unset($info['id']);
+            unset($info['cdate']);
+            Dever::db('api', 'api')->insert($info);
+        }
+        return '复制成功';
+    }
 }

+ 7 - 6
lib/App.php

@@ -63,18 +63,19 @@ class App
     {
         $set['join'] = array
         (
+            # t0
             array
             (
-                'table' => 'api',
+                'table' => 'api_api',
                 'type' => 'left join',
-                'on' => 'api.id=app_func_work.api_id',
+                'on' => 't0.id=main.api_id',
             ),
         );
-        $set['col'] = 'api.*';
-        $set['order'] = 'app_func_work.sort asc,api.id desc';
-        $where['app_func_work.app_func_id'] = $func_id;
+        $set['col'] = 't0.*';
+        $set['order'] = 'main.sort asc,t0.id desc';
+        $where['main.app_func_id'] = $func_id;
         if ($env) {
-            $where['api.env'] = $env;
+            $where['t0.env'] = $env;
         }
         return Dever::db('app_func_work', 'api')->select($where, $set);
     }

+ 19 - 20
lib/Sku.php

@@ -2,14 +2,9 @@
 use Dever;
 class Sku
 {
-    # 获取当前价格
+    # 获取当前最低价格
     public function getPrice($where, $spec_type, $app)
     {
-        /*
-        $result['price'] = 0;
-        $result['id'] = 0;
-        $result['name'] = '';
-        */
         $result = array();
         if ($spec_type == 2) {
             $where['key'] = '-1';
@@ -20,8 +15,8 @@ class Sku
         if (isset($sku) && $sku && $sku['key']) {
             $result['price'] = $sku['price'];
             $result['id'] = $sku['id'];
-            if (isset($sku['num'])) {
-                $result['num'] = $sku['num'];
+            if (isset($sku['unum'])) {
+                $result['unum'] = $sku['unum'];
             }
             $result['key'] = str_replace(',', '_', $sku['key']);
             $result['name'] = $this->getName($sku['key'], $app);
@@ -35,25 +30,28 @@ class Sku
     public function getList($where, $sku_id, $app)
     {
         $result = array();
-        $sku = Dever::db('sku', $app)->select($where, array('order' => 'price asc,id desc'));
+        $sku = Dever::db('sku', $app)->select($where);
         if ($sku) {
-            $result['sku'] = array();
-            $result['spec'] = Dever::load('spec', 'api')->getList($where, $app);
+            $spec = array();
+            $result['info'] = array();
             foreach ($sku as $k => $v) {
-                $t = array();
+                $t = $where;
                 $k = str_replace(',', '_', $v['key']);
                 $t['id'] = $v['id'];
+                $t['key'] = $k;
                 $t['pic'] = $v['pic'];
                 $t['price'] = $v['price'];
-                if (isset($v['num'])) {
-                    $t['num'] = $v['num'];
+                if (isset($v['unum'])) {
+                    $t['unum'] = $v['unum'];
                 }
+                $t['name'] = $this->getName($v['key'], $app);
                 $result['price'][$k] = $t;
                 if ($sku_id && $sku_id == $v['id']) {
-                    $t['name'] = $this->getName($v['key'], $app);
-                    $result['sku'] = $t;
+                    $result['info'] = $t;
+                    $spec = explode(',', $v['key']);
                 }
             }
+            $result['spec'] = Dever::load('spec', 'api')->getList($where, $app, $spec);
         }
         return $result;
     }
@@ -62,18 +60,19 @@ class Sku
     public function getName($key, $app)
     {
         if (!$key || $key == '-1') {
-            return '规格';
+            return '默认规格';
         } else {
             $name = array();
             $where['id'] = array('in', $key);
-            $data = Dever::db('spec_value', $app)->select($where);
+            $data = Dever::db('spec_value', $app)->select($where, array('order' => 'field(id, '.$key.')'));
             if ($data) {
                 foreach ($data as $k => $v) {
                     $info = Dever::db('spec', $app)->find($v['spec_id']);
-                    $name[] = $info['name'] . ':' . $v['value'];
+                    //$name[] = $info['name'] . ':' . $v['value'];
+                    $name[] = $v['value'];
                 }
             }
-            return implode(',', $name);
+            return implode(' & ', $name);
         }
     }
 }

+ 9 - 1
lib/Spec.php

@@ -36,7 +36,7 @@ class Spec
     }
 
     # 获取列表
-    public function getList($where, $app)
+    public function getList($where, $app, $select = false)
     {
         $where['state'] = 1;
         $data = Dever::db('spec', $app)->select($where, array('col' => 'id,name'));
@@ -46,6 +46,14 @@ class Spec
                 $w['spec_id'] = $v['id'];
                 unset($v['id']);
                 $v['value'] = Dever::db('spec_value', $app)->select($w, array('col' => 'id,value'));
+                if ($select) {
+                    foreach ($v['value'] as &$v1) {
+                        $v1['selected'] = false;
+                        if (in_array($v1['id'], $select)) {
+                            $v1['selected'] = true;
+                        }
+                    }
+                }
             }
         }
         return $data;

+ 1 - 2
lib/Util.php

@@ -10,9 +10,8 @@ class Util
         $state = Dever::db($table)->find($where);
         if (!$state) {
             return $number;
-        } else {
-            return $this->createNumber($prefix, $table, $where);
         }
+        return $this->createNumber($prefix, $table, $where);
     }
 
     # 获取openid 仅jspai和小程序需要openid

+ 2 - 1
manage/api.php

@@ -28,7 +28,8 @@ $config = array
         'data_button' => array
         (
             '设置' => array('edit', array('platform_id' => $platform_id)),
-            '删除' => 'delete',
+            //'删除' => 'delete',
+            '复制' => array('api', 'api/manage.copyApi'),
         ),
         'button' => array
         (