dever 7 years ago
parent
commit
410c6d0429
2 changed files with 27 additions and 5 deletions
  1. 20 3
      database/template.php
  2. 7 2
      src/Api.php

+ 20 - 3
database/template.php

@@ -6,6 +6,12 @@ $type = array
 	'im' => 'ImageMagic库',
 );
 
+$update = array
+(
+	1 => '仅生成一次',
+	2 => '每次访问都生成',
+);
+
 return array
 (
 	# 表名
@@ -13,7 +19,7 @@ return array
 	# 显示给用户看的名称
 	'lang' => '模板设置',
 	'order' => 20,
-	'check' => 'key',
+	//'check' => 'key',
 	# 数据结构
 	'struct' => array
 	(
@@ -44,7 +50,7 @@ return array
 		'key'		=> array
 		(
 			'type' 		=> 'varchar-32',
-			'name' 		=> '模板标识-调用模板时,使用该标识来获取模板信息',
+			'name' 		=> '模板标识-调用模板时,使用该标识来获取模板信息,相同的模板标识,将随机抽取一条',
 			'default' 	=> '',
 			'desc' 		=> '模板标识',
 			'match' 	=> 'is_string',
@@ -57,7 +63,7 @@ return array
 		(
 			'type' 		=> 'varchar-32',
 			'name' 		=> '使用的图形库',
-			'default' 	=> 'im',
+			'default' 	=> 'gd',
 			'desc' 		=> '使用的图形库',
 			'match' 	=> 'is_string',
 			'update'	=> 'select',
@@ -65,6 +71,17 @@ return array
 			'search'	=> 'select',
 		),
 
+		'update'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '生成规则',
+			'default' 	=> '1',
+			'desc' 		=> '生成规则',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $update,
+		),
+
 		'background'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 7 - 2
src/Api.php

@@ -22,10 +22,15 @@ class Api
 		), 1) . '" />';
 	}
 
-    public function get($name, $key, $set, $update = 2)
+    public function get($name, $key, $set, $update = false, $num = 1)
 	{
 		$where['key'] = $key;
-		$template = Dever::db('poster/template')->one($where);
+		$template = Dever::db('poster/template')->state($where);
+		if (!$update) {
+			$update = $template['update'];
+		}
+		$key = array_rand($template, 1);
+		$template = $template[$key];
 
 		if ($template) {
 			$where = array();