dever 6 years ago
parent
commit
9c6d59e904
5 changed files with 199 additions and 8 deletions
  1. 40 0
      database/action_log.php
  2. 3 2
      database/user.php
  3. 11 0
      database/user_log.php
  4. 127 0
      database/user_score.php
  5. 18 6
      lib/Core.php

+ 40 - 0
database/action_log.php

@@ -18,6 +18,13 @@ $score_type = array
 	3 => '达到积分上限',
 );
 
+$cron_type = array
+(
+	1 => '未开始',
+	2 => '进行中',
+	3 => '已完成',
+);
+
 return array
 (
 	# 表名
@@ -36,6 +43,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
+			'list'		=> true,
 		),
 
 		'uid'		=> array
@@ -82,6 +90,19 @@ return array
 			'list'		=> true,
 		),
 
+		'cron_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '是否增加积分',
+			'default' 	=> '3',
+			'desc' 		=> '是否增加积分',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $cron_type,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
 		'score'		=> array
 		(
 			'type' 		=> 'varchar-30',
@@ -139,4 +160,23 @@ return array
 		'edit' => false,
 		'insert' => false,
 	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getDataByDate' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'start' => array('yes-cdate', '>='),
+				'end' => array('yes-cdate', '<='),
+				'score_type' => 'yes',
+				'action_id' => 'yes',
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => 'id',
+		),
+	)
 );

+ 3 - 2
database/user.php

@@ -28,6 +28,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
+			'list'		=> true,
 		),
 
 		'uid'		=> array
@@ -68,7 +69,7 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '可用数量',
 			'match' 	=> 'option',
-			'update'	=> 'textarea',
+			'update'	=> 'text',
 			'search'	=> 'order',
 			'list'		=> true,
 		),
@@ -80,7 +81,7 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '冻结数量',
 			'match' 	=> 'option',
-			'update'	=> 'textarea',
+			'update'	=> 'text',
 			'search'	=> 'order',
 			'list'		=> true,
 		),

+ 11 - 0
database/user_log.php

@@ -94,6 +94,17 @@ return array
 			'list'		=> true,
 		),
 
+		'action_log_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属行为日志',
+			'default' 	=> '1',
+			'desc' 		=> '所属行为日志',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
 		'status'        => array
         (
             'type'      => 'tinyint-1',

+ 127 - 0
database/user_score.php

@@ -0,0 +1,127 @@
+<?php
+$config = function()
+{
+	$array = array();
+	$info = Dever::db('score/config')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+	# 表名
+	'name' => 'user_score',
+	# 显示给用户看的名称
+	'lang' => '用户积分列表',
+	'order' => 100,
+	'menu' => 'passport',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户名',
+			'default' 	=> '0',
+			'desc' 		=> '请选择用户',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			//'search'	=> 'select',
+			'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+		),
+
+		'config_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '积分名称',
+			'default' 	=> '1',
+			'desc' 		=> '积分名称',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $config,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'score'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '可用数量',
+			'default' 	=> '0',
+			'desc' 		=> '可用数量',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'no_score'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '冻结数量',
+			'default' 	=> '0',
+			'desc' 		=> '冻结数量',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		'insert' => false,
+
+		# 列表
+		'list_button' => 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',
+		),
+	)
+);

+ 18 - 6
lib/Core.php

@@ -31,13 +31,19 @@ class Core
 			if ($num > 0) {
 				$insert['num'] = $num;
 			}
+			$insert['cron_type'] = 1;
 			$log_id = Dever::db('score/action_log')->insert($insert);
 
-			Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
+			//Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
 			//Dever::load('score/lib/core.oper?log_id='.$log_id);
 		}
 	}
 
+	public function oper_api()
+	{
+
+	}
+
 	/**
 	 * 根据用户行为,增加积分
 	 *
@@ -50,6 +56,8 @@ class Core
 		$log = Dever::db('score/action_log')->one($log_id);
 
 		$this->operAction($log);
+
+		return $log;
 	}
 
 	private function rule($log, $info)
@@ -63,6 +71,7 @@ class Core
 			$info['num'] = $info['num'] * $log['num'];
 		}
 		if ($info['num'] == 0) {
+			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'cron_type' => 3));
 			return;
 		}
 
@@ -81,11 +90,11 @@ class Core
 		if ($info['upper'] == 2 && $info['upper_limit'] >= 1) {
 			$upper = $this->upper($uid, $info, $log);
 			if (!$upper) {
-				Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 3, 'score' => '0'));
+				Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 3, 'cron_type' => 3, 'score' => '0'));
 				return;
 			}
-			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 2, 'score' => $num));
 		}
+		Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 2, 'cron_type' => 3, 'score' => $num));
 
 		$update = array();
 		$update['where_id'] = $user['id'];
@@ -93,10 +102,12 @@ class Core
 
 		$insert['uid'] = $uid;
 		$insert['config_id'] = $info['config_id'];
+		$insert['action_log_id'] = $log['id'];
 		$insert['action_id'] = $info['action_id'];
 		$insert['status'] = 1;
 		$insert['num'] = $num;
 		$insert['total'] = $update['score'];
+		$insert['cdate'] = time();
 		$user_log_id = Dever::db('score/user_log')->insert($insert);
 
 		Dever::db('score/user')->update($update);
@@ -153,7 +164,8 @@ class Core
 
 	private function operAction($log)
 	{
-		if ($log && $log['score_type'] == 1) {
+		if ($log && $log['cron_type'] == 1) {
+			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'cron_type' => 2));
 			$where = array();
 			$where['state'] = 1;
 			$where['id'] = $log['action_id'];
@@ -172,13 +184,13 @@ class Core
 	}
 
     /**
-	 * 根据积分日志和规则,增加积分,这是一个定时任务,暂时不开启了
+	 * 根据积分日志和规则,增加积分,这是一个定时任务,可以设置每天凌晨启动
 	 *
 	 * @return mixed
 	 */
 	public function cron()
 	{
-		$where['score_type'] = 1;
+		$where['cron_type'] = 1;
 		$log = Dever::db('score/action_log')->all($where);
 		if ($log) {
 			foreach ($log as $k => $v) {