rabin 6 months ago
parent
commit
6e392a99ee

+ 4 - 3
api/Manage.php

@@ -4,16 +4,17 @@ use Manage\Lib\Auth;
 class Manage extends Auth
 {
     # 将sku中的key解析成前端可以读取的格式
-    public function keyToField($key)
+    public function keyToField($key, $param = array())
     {
+        $project = $param['project'] ?? 'api';
         if ($key != -1) {
             $result = array();
             $array = explode(',', $key);
             $result['key']['set'] = array();
             foreach ($array as $k => $v) {
-                $value = Dever::db('spec_value', 'api')->find($v);
+                $value = Dever::db('spec_value', $project)->find($v);
                 if ($value) {
-                    $spec = Dever::db('spec', 'api')->find($value['spec_id']);
+                    $spec = Dever::db('spec', $project)->find($value['spec_id']);
                     $result['key']['set']['s_' . $spec['id']] = array($spec['name'], $value['value']);
                 }
             }

+ 47 - 0
lib/Sku.php

@@ -0,0 +1,47 @@
+<?php namespace Api\Lib;
+use Dever;
+class Sku
+{
+    # 获取价格
+    public function getPrice($where, $spec_type, $score, $app)
+    {
+        $result = array();
+        $result['value'] = 0;
+        $result['text'] = '免费';
+        $result['spec'] = array();
+        $result['list'] = array();
+        if ($spec_type == 2) {
+            $where['key'] = '-1';
+            $sku = Dever::db('sku', $app)->find($where);
+            if ($sku) {
+                $result['value'] = $sku['price'];
+                $result['text'] = $sku['price'] . $score;
+            }
+        } elseif ($spec_type == 3) {
+            $sku = Dever::db('sku', $app)->select($where, array('order' => 'price asc,id desc'));
+            if ($sku) {
+                $min = $sku[0];
+                #$max = $sku[count($sku)-1];
+                $result['value'] = $min['price'];
+                $result['text'] = $min['price'] . $score;
+                $result['spec'] = Dever::load('spec', 'api')->getList($app, $where);
+                foreach ($sku as $k => $v) {
+                    $t = array();
+                    $k = $v['key'];
+                    $t['pic'] = $v['pic'];
+                    $t['value'] = $v['price'];
+                    $t['text'] = $v['price'] . $score;
+                    $result['list'][$k] = $t;
+                }
+            }
+        }
+        return $result;
+    }
+
+    # 获取某个sku的名称
+    public function getName($key, $app)
+    {
+        $where['id'] = array('in', $key);
+        $data = Dever::db('spec_value', $app)->kv($where);
+    }
+}

+ 19 - 4
lib/Spec.php

@@ -3,11 +3,11 @@ use Dever;
 class Spec
 {
     # 获取规格数据
-    public function manage($app_func_id)
+    public function manage($table, $field, $id)
     {
         $result = array();
-        if ($app_func_id) {
-            $result = Dever::db('spec', 'api')->select(array('app_func_id' => $app_func_id));
+        if ($id) {
+            $result = Dever::db($table)->select(array($field => $id));
             if ($result) {
                 foreach ($result as $k => $v) {
                     $result[$k]['type'] = 'show';
@@ -15,7 +15,7 @@ class Spec
                     $result[$k]['show'] = true;
                     $result[$k]['fixed'] = true;
                     $result[$k]['key'] = $v['name'];
-                    $value = Dever::db('spec_value', 'api')->select(array('app_func_id' => $app_func_id, 'spec_id' => $v['id']));
+                    $value = Dever::db($table . '_value')->select(array($field => $id, 'spec_id' => $v['id']));
                     if ($value) {
                         foreach ($value as $k1 => $v1) {
                             $value[$k1]['parent'] = $result[$k]['key'];
@@ -34,4 +34,19 @@ class Spec
         }
         return $result;
     }
+
+    # 获取列表
+    public function getList($where, $app)
+    {
+        $where['state'] = 1;
+        $data = Dever::db('spec', $app)->select($where, array('col' => 'id,name'));
+        if ($data) {
+            foreach ($data as &$v) {
+                $w = $where;
+                $w['spec_id'] = $v['id'];
+                $v['value'] = Dever::db('spec_value', $app)->select($w, array('col' => 'id,value'));
+            }
+        }
+        return $data;
+    }
 }

+ 4 - 3
lib/Util.php

@@ -3,14 +3,15 @@ use Dever;
 class Util
 {
     # 生成订单号
-    public function createNumber($prefix, $table)
+    public function createNumber($prefix, $table, $where = array())
     {
         $number = \Dever\Helper\Str::order($prefix);
-        $state = Dever::db($table)->find(array('order_num' => $number));
+        $where['order_num'] = $number;
+        $state = Dever::db($table)->find($where);
         if (!$state) {
             return $number;
         } else {
-            return $this->createNumber($prefix, $table);
+            return $this->createNumber($prefix, $table, $where);
         }
     }
 

+ 2 - 1
manage/app_func.php

@@ -53,7 +53,7 @@ return array
             'type',
             'key' => array
             (
-                'desc' => '如果为空,将自动按照名称拼音生成',
+                'tips' => '如果为空,将自动按照名称拼音生成',
             ),
             'desc' => 'textarea',
             'status' => array
@@ -92,6 +92,7 @@ return array
                     # 默认值
                     array
                     (
+                        'key' => '-1',
                         'price' => '',
                         'num' => '',
                         'day_num' => '',

+ 2 - 1
manage/sku.php

@@ -8,11 +8,12 @@ return array
             'key' => array
             (
                 'type' => 'hidden',
-                'remote' => 'api/manage.keyToField',
+                'remote' => 'api/manage.keyToField?project=api',
             ),
             'price' => array
             (
                 'type' => 'text',
+                'tips' => '设置价格',
                 'rules' => true,
             ),
             'num' => array

+ 3 - 3
table/account.php

@@ -6,19 +6,19 @@ return array
     (
         'name'      => array
         (
-            'type'      => 'varchar(60)',
+            'type'      => 'varchar(32)',
             'name'      => '账户名称',
         ),
 
         'key'       => array
         (
-            'type'      => 'varchar(60)',
+            'type'      => 'varchar(32)',
             'name'      => '账户标识',
         ),
 
         'app_platform'       => array
         (
-            'type'      => 'varchar(500)',
+            'type'      => 'varchar(30)',
             'name'      => '应用与平台',
         ),
 

+ 1 - 1
table/account_cert.php

@@ -21,7 +21,7 @@ return array
         'number' => array
         (
             'name'      => '证书序列号',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(100)',
         ),
 
         'public' => array

+ 2 - 2
table/api.php

@@ -15,13 +15,13 @@ return array
         'name' => array
         (
             'name'      => '接口名称',
-            'type'      => 'varchar(150)',
+            'type'      => 'varchar(32)',
         ),
 
         'uri' => array
         (
             'name'      => '接口地址',
-            'type'      => 'varchar(1000)',
+            'type'      => 'varchar(100)',
         ),
 
         'method' => array

+ 1 - 1
table/api_notify_code.php

@@ -14,7 +14,7 @@ return array
         'key' => array
         (
             'name'      => '状态码标识',
-            'type'      => 'varchar(150)',
+            'type'      => 'varchar(32)',
         ),
 
         'value' => array

+ 1 - 1
table/api_path.php

@@ -14,7 +14,7 @@ return array
         'key' => array
         (
             'name'      => '路径参数名',
-            'type'      => 'varchar(150)',
+            'type'      => 'varchar(32)',
         ),
 
         'value' => array

+ 2 - 2
table/api_save.php

@@ -14,7 +14,7 @@ return array
         'table' => array
         (
             'name'      => '数据表表名',
-            'type'      => 'varchar(200)',
+            'type'      => 'varchar(100)',
         ),
 
         'key' => array
@@ -26,7 +26,7 @@ return array
         'value' => array
         (
             'name'      => '响应参数名/参数值',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(100)',
         ),
 
         'type' => array

+ 1 - 1
table/app.php

@@ -14,7 +14,7 @@ return array
         'desc' => array
         (
             'name'      => '应用描述',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(300)',
         ),
 
         'status' => array

+ 2 - 8
table/app_func.php

@@ -20,13 +20,13 @@ return array
         'key' => array
         (
             'name'      => '功能标识',
-            'type'      => 'varchar(80)',
+            'type'      => 'varchar(32)',
         ),
 
         'desc' => array
         (
             'name'      => '功能描述',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(300)',
         ),
 
         'type' => array
@@ -55,12 +55,6 @@ return array
             'default'   => '0',
         ),
 
-        'desc' => array
-        (
-            'name'      => '功能描述',
-            'type'      => 'varchar(800)',
-        ),
-
         'spec_type' => array
         (
             'name'      => '规格类型',

+ 1 - 1
table/platform_request_body.php

@@ -14,7 +14,7 @@ return array
         'key' => array
         (
             'name'      => '参数名',
-            'type'      => 'varchar(150)',
+            'type'      => 'varchar(32)',
         ),
 
         'value' => array

+ 2 - 2
table/platform_setting.php

@@ -14,13 +14,13 @@ return array
         'name' => array
         (
             'name'      => '参数描述',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(32)',
         ),
 
         'key' => array
         (
             'name'      => '参数名',
-            'type'      => 'varchar(800)',
+            'type'      => 'varchar(32)',
         ),
 
         'sort' => array