dever 6 лет назад
Родитель
Сommit
70c4e5a4e3
4 измененных файлов с 112 добавлено и 23 удалено
  1. 18 3
      score/database/level.php
  2. 17 1
      score/database/user.php
  3. 35 1
      score/database/user_level.php
  4. 42 18
      score/lib/Core.php

+ 18 - 3
score/database/level.php

@@ -16,9 +16,10 @@ return array
     # 表名
     'name' => 'level',
     # 显示给用户看的名称
-    'lang' => '等级设置',
+    'lang' => '积分等级设置',
     # 后台菜单排序
     'order' => 8,
+    'check' => 'level',
     # 数据结构
     'struct' => array
     (
@@ -30,8 +31,8 @@ return array
             'desc'      => '',
             'match'     => 'is_numeric',
             'search'    => 'order',
-            'list'      => true,
-            'order'     => 'desc',
+            //'list'      => true,
+            //'order'     => 'desc',
         ),
         
         'name'      => array
@@ -78,6 +79,20 @@ return array
             ),
         ),
 
+        'level'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '等级数字-请直接输入等级数字,每次升级按照该数字进行匹配,如果设置为1,则为lv1,不允许重复,用户升级',
+            'default'   => '1',
+            'desc'      => '等级数字',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+            'edit'      => true,
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 17 - 1
score/database/user.php

@@ -15,7 +15,7 @@ return array
 	# 表名
 	'name' => 'user',
 	# 显示给用户看的名称
-	'lang' => '用户积分',
+	'lang' => '用户积分列表',
 	'order' => 100,
 	'menu' => 'passport',
 	# 数据结构
@@ -108,4 +108,20 @@ return array
 			'list' => array('积分日志', '"user_log&search_option_uid={uid}&oper_parent=user"'),
 		),
 	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getScoreByConfig' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => 'uid,config_id,score|config_id',
+		),
+	)
 );

+ 35 - 1
score/database/user_level.php

@@ -10,12 +10,18 @@ $level = function()
 	return $array;
 };
 
+$type = array
+(
+	1 => '自动升级',
+	2 => '手动升级',
+);
+
 return array
 (
 	# 表名
 	'name' => 'user_level',
 	# 显示给用户看的名称
-	'lang' => '用户等级',
+	'lang' => '用户积分等级',
 	'order' => 99,
 	'menu' => 'passport',
 	# 数据结构
@@ -59,8 +65,36 @@ return array
 			'option'	=> $level,
 			'search'	=> 'select',
 			'list'		=> true,
+			'edit'		=> true,
 		),
 
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '升级方式',
+			'default' 	=> '1',
+			'desc' 		=> '升级方式',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $type,
+			'search'	=> 'select',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'info'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '备注',
+            'default'   => '',
+            'desc'      => '备注',
+            'match'     => 'option',
+            'update'    => 'textarea',
+            //'show'        => 'status=5'
+            'list'      => '"{info}" ? "{info}" : "双击添加备注"',
+            'edit'      => true,
+        ),
+
 		'cdate'		=> array
 		(
 			'type' 		=> 'int-11',

+ 42 - 18
score/lib/Core.php

@@ -23,8 +23,8 @@ class Core
 		if (isset($action['id'])) {
 			$log_id = Dever::db('score/action_log')->insert(array('uid' => $uid, 'action_id' => $action['id'], 'callback' => $callback));
 
-			//Dever::deamon('lib/core.oper?log_id='.$log_id, 'score');
-			Dever::load('score/lib/core.oper?log_id='.$log_id);
+			Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
+			//Dever::load('score/lib/core.oper?log_id='.$log_id);
 		}
 	}
 
@@ -83,6 +83,9 @@ class Core
 
 		Dever::db('score/user')->update($update);
 
+		# 提升等级
+		$this->setLevel($uid);
+
 		if ($log['callback']) {
 			if (strstr($log['callback'], '?')) {
 				Dever::load($log['callback'] . '&user_log_id=' . $user_log_id);
@@ -166,33 +169,54 @@ class Core
 		}
 	}
 
-	public function cron_api()
-	{}
-
-
 	/**
 	 * 根据积分算等级
 	 *
 	 * @return mixed
 	 */
-	public function level()
+	public function setLevel($uid)
 	{
-		$level = Dever::db('score/level')->state();
-
-		foreach ($level as $k => $v) {
-			$config = Dever::array_decode($v['score']);
-			if ($config) {
-				foreach ($config as $k1 => $v1) {
-					$score = $v1['config'];
-					$num = $v1['num'];
-
-					$user = Dever::db('score/user')->state(array('config_id' => $score, 'score' => $num));
+		# 获取当前用户的等级
+		$where['uid'] = $uid;
+		$user_level = Dever::db('score/user_level')->one($where);
+		if ($user_level && $user_level['type'] == 2) {
+			return;
+		} elseif ($user_level && $user_level['type'] == 1) {
+			$config = Dever::db('score/level')->one($user_level['level_id']);
+			$level = $config['level'] + 1;
+		} else {
+			$level = 1;
+		}
 
-					if ($user) {
+		$config = Dever::db('score/level')->one(array('level' => $level, 'state' => 1));
 
+		if ($config) {
+			# 是否能升级
+			$yes = false;
+			$rule = Dever::array_decode($config['score']);
+			if ($rule) {
+				$user_score = Dever::db('score/user')->getScoreByConfig($where);
+				if ($user_score) {
+					foreach ($rule as $k => $v) {
+						$score = $v['config'];
+						$num = $v['num'];
+						if (isset($user_score[$score]) && $user_score[$score]['score'] && $user_score[$score]['score'] >= $num) {
+							$yes = $config['id'];
+						} else {
+							$yes = false;
+						}
 					}
 				}
 			}
+
+			if ($yes) {
+				# 可以升级
+				if ($user_level) {
+					Dever::db('score/user_level')->update(array('where_id' => $user_level['id'], 'level_id' => $yes));
+				} else {
+					Dever::db('score/user_level')->insert(array('uid' => $uid,'level_id' => $yes, 'type' => 1));
+				}
+			}
 		}
 	}
 }