dever 4 years ago
parent
commit
7623dd02f7
3 changed files with 142 additions and 5 deletions
  1. 36 0
      database/info.php
  2. 89 0
      database/type.php
  3. 17 5
      lib/Handle.php

+ 36 - 0
database/info.php

@@ -1,5 +1,17 @@
 <?php
 
+$type = function()
+{
+    $array = array();
+    $info = Dever::db('short/type')->state();
+    
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 return array
 (
     # 表名
@@ -25,6 +37,19 @@ return array
             'list'      => true,
         ),
 
+        'type_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '分类',
+            'default'   => '1',
+            'desc'      => '分类',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'        => true,
+        ),
+
         'url'      => array
         (
             'type'      => 'varchar-800',
@@ -37,6 +62,17 @@ return array
             'list'      => true,
         ),
 
+        'param'      => array
+        (
+            'type'      => 'varchar-2000',
+            'name'      => '参数',
+            'default'   => '',
+            'desc'      => '参数',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
         'key'      => array
         (
             'type'      => 'varchar-32',

+ 89 - 0
database/type.php

@@ -0,0 +1,89 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'type',
+    # 显示给用户看的名称
+    'lang' => '类别管理',
+    # 是否显示在后台菜单
+    'order' => 1,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'order'     => 'asc',
+            'list'      => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-24',
+            'name'      => '分类名称',
+            'default'   => '',
+            'desc'      => '分类名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'host'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '域名',
+            'default'   => '',
+            'desc'      => '域名',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+        
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'search'    => 'date',
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+    ),
+
+    'default' => array
+    (
+        'col' => 'id, name,state,cdate',
+        'value' => array
+        (
+            '1, "默认分类",1,' . DEVER_TIME,
+        ),
+    ),
+
+    'request' => array
+    (
+        
+    )
+);

+ 17 - 5
lib/Handle.php

@@ -6,9 +6,12 @@ use Dever;
 
 class Handle
 {
-    public function get($url)
+    public function get($type, $url, $param)
     {
-        $where['key'] = md5($url);
+        $param = json_encode($param);
+        $where['type'] = $type;
+        $type = Dever::db('short/type')->one($type);
+        $where['key'] = md5($url . '?' . $param);
 
         $info = Dever::db('short/info')->one($where);
 
@@ -16,19 +19,28 @@ class Handle
             $id = $info['id'];
         } else {
             $where['url'] = $url;
+            $where['param'] = $param;
             $id = Dever::db('short/info')->insert($where);
         }
 
-        return Dever::idtostr($id);
+        return $type['host'] . Dever::uid($id);
     }
 
     public function show($str)
     {
-        $id = Dever::strtoid($str);
+        $id = Dever::uid($str, 'decode');
         if ($id && $id > 0) {
             $info = Dever::db('short/info')->one($id);
             if ($info && $info['url']) {
-                Dever::location($info['url']);
+                $param = json_decode($info['param'], true);
+                foreach ($param as $k => $v) {
+                    if (strstr($v, '|')) {
+                        $temp = explode('|', $v);
+                        $v = Dever::load($temp[1], $temp[0]);
+                        $param[$k] = $v;
+                    }
+                }
+                Dever::location($info['url'] . '?' . http_build_query($param));
             }
         }