dever 7 years ago
parent
commit
d06661c8d2
2 changed files with 31 additions and 4 deletions
  1. 17 0
      database/template.php
  2. 14 4
      src/Api.php

+ 17 - 0
database/template.php

@@ -137,4 +137,21 @@ return array
 			'list' => array('模块', '"model&project=poster&search_option_template_id={id}&oper_parent=template&oper_project=poster"'),
 		),
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'key' => 'yes',
+				'ids' => array('yes-id', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => '*',
+		),
+	)
 );

+ 14 - 4
src/Api.php

@@ -24,15 +24,23 @@ class Api
 
     public function get($name, $key, $set, $update = false, $num = 1)
 	{
-		$where['key'] = $key;
-		$template = Dever::db('poster/template')->state($where);
-		if (!$update) {
-			$update = $template['update'];
+		if (strstr($key, ',') || is_numeric($key)) {
+			$where['ids'] = $key;
+		} else {
+			$where['key'] = $key;
 		}
+
+		$template = Dever::db('poster/template')->getAll($where);
+
 		$key = array_rand($template, 1);
 		$template = $template[$key];
 
 		if ($template) {
+
+			if (!$update) {
+				$update = $template['update'];
+			}
+
 			$where = array();
 			$where['template_id'] = $template['id'];
 			$model = Dever::db('poster/model')->state($where);
@@ -53,6 +61,8 @@ class Api
 
 					return Dever::pic($result);
 				}
+			} else {
+				return Dever::pic($template['background']);
 			}
 		}