dever 4 years ago
parent
commit
3a37f7cf4f
4 changed files with 150 additions and 37 deletions
  1. 16 3
      database/col.php
  2. 120 0
      lib/Data.php
  3. 1 34
      lib/Manage.php
  4. 13 0
      src/Api.php

+ 16 - 3
database/col.php

@@ -47,6 +47,18 @@ return array
 			'list'		=> true,
 		),
 
+		'ename'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '字段英文名称-用于前台使用',
+			'default' 	=> '',
+			'desc' 		=> '字段英文名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
 		'desc'		=> array
 		(
 			'type' 		=> 'varchar-200',
@@ -149,11 +161,12 @@ return array
 
 	'default' => array
 	(
-		'col' => '`name`,`desc`,`type`,`state`,`cdate`',
+		'col' => '`name`,`ename`,`desc`,`type`,`state`,`cdate`',
 		'value' => array
 		(
-			'"标题","标题",1, 1,' . DEVER_TIME,
-			'"图片","图片",4, 1,' . DEVER_TIME,
+			'"标题","name","标题",1, 1,' . DEVER_TIME,
+			'"图片","pic","图片",4, 1,' . DEVER_TIME,
+			'"链接","link","链接",1, 1,' . DEVER_TIME,
 		),
 	),
 

+ 120 - 0
lib/Data.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace Push\Lib;
+
+use Dever;
+
+class Data
+{
+    public function get($key, $name, $total = 10, $col = '1,2,3', $function = '-1', $page = false, $limit = false, $cdate = 'Y-m-d H:i')
+    {
+        $info = Dever::db('push/info')->one(array('key' => $key));
+
+        if (!$info) {
+            $insert['key'] = $key;
+            $insert['name'] = $name;
+            $insert['num'] = $total;
+            $insert['col'] = $col;
+            $insert['function'] = $function;
+            $info['id'] = Dever::db('push/info')->insert($insert);
+            $info['num'] = $insert['num'];
+        }
+
+        $data = array();
+        if ($info) {
+            if (!$info['num']) {
+                $info['num'] = 20;
+            }
+            if ($limit > 0) {
+                $info['num'] = $limit;
+            }
+
+            $where = array();
+            $where['info_id'] = $info['id'];
+
+            if ($page) {
+                $where['page'] = array($info['num'], 'list');
+                $data = Dever::db('push/data')->getAllPage($where);
+            } else {
+                $where['limit'] = '0,' . $info['num'];
+                $data = Dever::db('push/data')->getAll($where);
+            }
+
+            if ($data) {
+                foreach ($data as $k => $v) {
+                    $data[$k] = $this->getOne($v, 2, $cdate);
+                }
+            }
+        }
+
+        return $data;
+    }
+
+    public function getOne($info, $state = 2, $cdate = 'Y-m-d H:i')
+    {
+        $data = is_array($info) ? $info : Dever::db('push/data')->one($info);
+
+        $source = array();
+        $info = array();
+        $col = array();
+        if ($data['type'] > 0) {
+            $func = Dever::db('push/info')->config['func'];
+            $func = $func();
+            $method = false;
+            if ($func) {
+                foreach ($func as $k => $v) {
+                    if ($v['id'] == $data['type']) {
+                        $method = $v['api'];
+                        $col = Dever::array_decode($v['col']);
+                        break;
+                    }
+                }
+            }
+
+            if ($method) {
+                $source = Dever::load($method, $data['type_id']);
+            }
+        }
+        if ($state == 1) {
+            $result = array();
+        } else {
+            $result = $data;
+            unset($result['data']);
+            $result['cdate_string'] = date($cdate, $result['cdate']);
+        }
+        
+        $text = $data['data'];
+        $text = Dever::array_decode($text);
+        foreach ($text as $k => $v) {
+            foreach ($v as $k1 => $v1) {
+                if (strstr($k1, 'col_')) {
+                    $id = str_replace('col_', '', $k1);
+                    $col_info = Dever::db('push/col')->one($id);
+
+                    if (!$v1 && $source && $col) {
+                        foreach ($col as $k2 => $v2) {
+                            if ($v2['col_id'] == $id && isset($source[$v2['name']]) && $source[$v2['name']]) {
+                                $v1 = $source[$v2['name']];
+                            }
+                        }
+                    }
+
+                    if ($state == 1) {
+                        if (strstr($v1, 'jpg') || strstr($v1, 'png') || strstr($v1, 'gif')) {
+                            $v1 = '<img src="'.$v1.'" width="150"/>';
+                        }
+                        if (!isset($result[$k])) {
+                            $result[$k] = array();
+                        }
+
+                        $result[$k][$col_info['name']] = $v1;
+                    } else {
+                        $result[$col_info['ename']] = $v1;
+                    }
+                }
+            }
+        }
+
+        return $result;
+    }
+}

+ 1 - 34
lib/Manage.php

@@ -74,40 +74,7 @@ class Manage
 
     public function show($id)
     {
-        $data = Dever::db('push/data')->one($id);
-
-        $info = array();
-        if ($data['type'] > 0) {
-            $func = Dever::db('push/info')->config['func'];
-            $func = $func();
-            $method = false;
-            if ($func) {
-                foreach ($func as $k => $v) {
-                    if ($v['id'] == $data['type']) {
-                        $method = $v['api'];
-                        break;
-                    }
-                }
-            }
-
-            if ($method) {
-
-            }
-        }
-        $table = array();
-        $text = $data['data'];
-        $text = Dever::array_decode($text);
-        foreach ($text as $k => $v) {
-            $table[$k] = array();
-            foreach ($v as $k1 => $v1) {
-                if (strstr($k1, 'col_')) {
-                    $id = str_replace('col_', '', $k1);
-                    $col = Dever::db('push/col')->one($id);
-                    $table[$k][$col['name']] = $v1;
-                }
-            }
-        }
-
+        $table = Dever::load('push/lib/data')->getOne($id, 1);
         if (count($table) == 1) {
             $table = $table[0];
         }

+ 13 - 0
src/Api.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace Push\Src;
+
+use Dever;
+
+class Api
+{
+	public function test()
+	{
+		return Dever::load('push/lib/data')->get('focus', '焦点图', 5);
+	}
+}