dever 4 年之前
当前提交
5a81f5501a
共有 4 个文件被更改,包括 142 次插入0 次删除
  1. 83 0
      database/info.php
  2. 8 0
      index.php
  3. 37 0
      lib/Handle.php
  4. 14 0
      src/Api.php

+ 83 - 0
database/info.php

@@ -0,0 +1,83 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'info',
+    # 显示给用户看的名称
+    'lang' => '短域名',
+    # 是否显示在后台菜单
+    'order' => 1,
+    'menu' => false,
+    'auto' => 10000000,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'order'     => 'asc',
+            'list'      => true,
+        ),
+
+        'url'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '转换的url',
+            'default'   => '',
+            'desc'      => '转换的url',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'key'      => array
+        (
+            'type'      => 'varchar-32',
+            'name'      => '关键字',
+            'default'   => '',
+            'desc'      => '关键字',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            '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
+    (
+
+    ),
+
+    'request' => array
+    (
+        
+    )
+);

+ 8 - 0
index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'short');
+define('DEVER_APP_LANG', '短域名管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 98);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-component');
+include(DEVER_APP_PATH . '../boot.php');

+ 37 - 0
lib/Handle.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Short\Lib;
+
+use Dever;
+
+class Handle
+{
+    public function get($url)
+    {
+        $where['key'] = md5($url);
+
+        $info = Dever::db('short/info')->one($where);
+
+        if ($info) {
+            $id = $info['id'];
+        } else {
+            $where['url'] = $url;
+            $id = Dever::db('short/info')->insert($where);
+        }
+
+        return Dever::idtostr($id);
+    }
+
+    public function show($str)
+    {
+        $id = Dever::strtoid($str);
+        if ($id && $id > 0) {
+            $info = Dever::db('short/info')->one($id);
+            if ($info && $info['url']) {
+                Dever::location($info['url']);
+            }
+        }
+
+        return 'error';
+    }
+}

+ 14 - 0
src/Api.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace Short\Src;
+
+use Dever;
+
+class Api
+{
+    public function show()
+    {
+        $str = Dever::input('code');
+        return Dever::load('short/lib/handle')->show($str);
+    }
+}