dever 6 years ago
parent
commit
430699d9c7

+ 2 - 0
act/lib/Comment.php

@@ -71,6 +71,8 @@ class Comment
         $table = Dever::config('base')->type_table[$type];
         Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
 
+        Dever::score($uid, 'submit_commit', '发表评论');
+
         return true;
     }
 }

+ 2 - 0
act/lib/Like.php

@@ -58,6 +58,8 @@ class Like
         $table = Dever::config('base')->type_table[$type];
         Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
 
+        Dever::score($uid, 'submit_like', '喜欢');
+
         return true;
     }
 }

+ 27 - 0
act/lib/Share.php

@@ -31,6 +31,8 @@ class Share
             Dever::db('act/share')->update($where);
         }
 
+        Dever::score($uid, 'share_friend', '邀请好友');
+
         return true;
     }
 
@@ -47,6 +49,31 @@ class Share
 
         $share = Dever::db('act/share')->one($where);
         if ($share) {
+
+            $user = Dever::load('passport/user')->one($uid);
+            if ($user && $type <= 4) {
+                $method = '';
+                $name = Dever::config('base')->type[$type];
+                if ($type == 1) {
+                    $method = 'article';
+                }
+                if ($type == 2) {
+                    $method = 'vod';
+                }
+                if ($type == 3) {
+                    $method = 'live';
+                }
+                if ($type == 4) {
+                    $method = 'journal';
+                }
+                if ($user['temp'] == 2) {
+                    Dever::score($source_uid, 'share_'.$method.'_reflux', '邀请到用户');
+                } else {
+                    Dever::score($source_uid, 'share_'.$method.'_reflux', '邀请到用户');
+                }
+            }
+            
+
             $where['share_id'] = $share['id'];
             $info = Dever::db('act/share_reflux')->one($where);
             if (!$info) {

+ 0 - 143
journal/database/content_text.php

@@ -1,143 +0,0 @@
-<?php
-
-$location = array
-(
-    1 => '上左',
-    2 => '上中',
-    3 => '上右',
-    4 => '中左',
-    5 => '正中',
-    6 => '中右',
-    7 => '下左',
-    8 => '下中',
-    9 => '下右',
-    //10 => '自定义',
-);
-return array
-(
-    # 表名
-    'name' => 'content_text',
-    # 显示给用户看的名称
-    'lang' => '内页管理的文字设置',
-    'menu' => false,
-    'location' => $location,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            'update'    => 'hidden',
-            'value'     => Dever::input('where_id')
-            //'list'        => true,
-        ),
-
-        'info_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '小刊',
-            'default'   => '',
-            'desc'      => '小刊',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_info_id')
-        ),
-
-        'content_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '小刊内页',
-            'default'   => '',
-            'desc'      => '小刊内页',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_content_id')
-        ),
-
-        'name'     => array
-        (
-            'type'      => 'varchar-800',
-            'name'      => '文字内容',
-            'default'   => '',
-            'desc'      => '文字内容',
-            'match'     => 'is_string',
-            'update'    => 'textarea',
-            'list'      => true,
-        ),
-        
-
-        'location'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '文字显示位置',
-            'default'   => '1',
-            'desc'      => '显示位置',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'option'    => $location,
-            'value'     => Dever::input('search_option_location'),
-        ),
-
-        'color'     => array
-        (
-            'type'      => 'varchar-10',
-            'name'      => '文字颜色',
-            'default'   => '#000000',
-            'desc'      => '文字颜色',
-            'match'     => 'is_string',
-            'update'    => 'color',
-        ),
-
-        'bgcolor'     => array
-        (
-            'type'      => 'varchar-10',
-            'name'      => '背景颜色',
-            'default'   => '#000000',
-            'desc'      => '背景颜色',
-            'match'     => 'is_string',
-            'update'    => 'color',
-        ),
-
-        'size'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '文字大小-直接输入像素数字',
-            'default'   => '16',
-            'desc'      => '文字大小',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-        ),
-
-        'state'     => array
-        (
-            'type'      => 'tinyint-1',
-            'name'      => '状态',
-            'default'   => '1',
-            'desc'      => '请选择状态',
-            'match'     => 'is_numeric',
-        ),
-        
-        'cdate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '创建时间',
-            'match'     => array('is_numeric', time()),
-            'desc'      => '',
-            # 只有insert时才生效
-            'insert'    => true,
-            'search'    => 'date',
-            //'list'      => 'date("Y-m-d H:i:s", {cdate})',
-        ),
-    ),
-
-    'manage' => array
-    (
-
-    ),
-);

+ 1 - 1
main/lib/Core.php

@@ -19,7 +19,7 @@ class Core
         if ($this->data['uid'] < 0) {
             $this->data['uid'] = 0;
         }
-        //$this->data['uid'] = 1;
+        $this->data['uid'] = 1;
 
         # 获取基本配置
         $this->data['config'] = Dever::db('main/config')->one();

+ 6 - 4
main/src/View.php

@@ -24,7 +24,7 @@ class View extends Core
         return $this->data;
     }
 
-    private function get($method, $name, $type = 1)
+    private function get($method, $name, $type = 1, $key = '')
     {
         $id = Dever::input('id');
         if (!$id) {
@@ -71,6 +71,8 @@ class View extends Core
 
             # 当前用户是否点赞
             $this->data['user_act']['up'] = Dever::load('act/lib/like')->get($this->data['uid'], $id, $type);
+
+            Dever::score($this->data['uid'], 'view_' . $key, '浏览' . $name);
             
         } else {
             $this->data['user_act']['share'] = 0;
@@ -97,18 +99,18 @@ class View extends Core
     # 获取图文详情
     public function article()
     {
-    	return $this->get('content/lib/article', '图文', 1);
+    	return $this->get('content/lib/article', '图文', 1, 'article');
     }
 
     # 获取视频详情
     public function vod()
     {
-        return $this->get('video/lib/vod', '视频', 2);
+        return $this->get('video/lib/vod', '视频', 2, 'vod');
     }
 
     # 获取直播详情
     public function live()
     {
-    	return $this->get('video/lib/live', '直播', 3);
+    	return $this->get('video/lib/live', '直播', 3, 'live');
     }
 }

+ 77 - 0
score/database/action.php

@@ -0,0 +1,77 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'action',
+	# 显示给用户看的名称
+	'lang' => '用户行为配置',
+	'order' => 10,
+	'check' => 'key',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '行为名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入行为名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '行为标识-用于程序中统计积分总数',
+			'default' 	=> '',
+			'desc' 		=> '行为标识',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		# 列表
+		'list_button' => array
+		(
+			'list' => array('行为日志', '"action_log&search_option_action_id={id}&oper_parent=action"'),
+		),
+	),
+);

+ 124 - 0
score/database/action_log.php

@@ -0,0 +1,124 @@
+<?php
+
+$action = function()
+{
+	$array = array();
+	$info = Dever::db('score/action')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$score_type = array
+(
+	1 => '未加积分',
+	2 => '已加积分',
+	3 => '达到积分上限',
+);
+
+return array
+(
+	# 表名
+	'name' => 'action_log',
+	# 显示给用户看的名称
+	'lang' => '积分行为日志',
+	'order' => 10,
+	'menu' => false,
+	# 数据结构
+	'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}) : "匿名用户"',
+		),
+		
+		'action_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属行为',
+			'default' 	=> '1',
+			'desc' 		=> '所属行为',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $action,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'score_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '是否增加积分',
+			'default' 	=> '1',
+			'desc' 		=> '是否增加积分',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $score_type,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'score'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '增加积分数',
+			'default' 	=> '0',
+			'desc' 		=> '积分数',
+			'match' 	=> 'is_string',
+			'list'		=> true,
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '行为描述',
+			'default' 	=> '',
+			'desc' 		=> '行为描述',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'      => 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		'insert' => false,
+	),
+);

+ 76 - 0
score/database/config.php

@@ -0,0 +1,76 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'config',
+	# 显示给用户看的名称
+	'lang' => '积分名称设置',
+	'order' => 1,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '积分名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入积分名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+		),
+	),
+
+	'manage' => array
+	(
+		# 列表
+		'list_button' => array
+		(
+			'list' => array('规则设置', '"rule&search_option_config_id={id}&oper_parent=config"'),
+		),
+	),
+);

+ 111 - 0
score/database/level.php

@@ -0,0 +1,111 @@
+<?php
+
+$config = function()
+{
+    $array = array();
+    $info = Dever::db('score/config')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+return array
+(
+    # 表名
+    'name' => 'level',
+    # 显示给用户看的名称
+    'lang' => '等级设置',
+    # 后台菜单排序
+    'order' => 8,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-32',
+            'name'      => '等级名称',
+            'default'   => '',
+            'desc'      => '请输入名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+        
+        'score'       => array
+        (
+            'type'      => 'text-1000',
+            'name'      => '积分设置',
+            'default'   => '',
+            'desc'      => '积分设置',
+            'match'     => 'is_string',
+            'update'    => array
+            (
+                array
+                (
+                    'col'       => 'config',
+                    'name'      => '积分名称',
+                    'default'   => '',
+                    'desc'      => '积分名称',
+                    'match'     => 'is_string',
+                    'update'    => 'select',
+                    'option'    => $config,
+                ),
+
+                array
+                (
+                    'col'       => 'num',
+                    'name'      => '所需积分数',
+                    'default'   => '0',
+                    'desc'      => '所需积分数',
+                    'match'     => 'is_string',
+                    'update'    => 'text',
+                ),
+            ),
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+
+    ),
+
+    'request' => array
+    (
+        
+    ),
+);

+ 167 - 0
score/database/rule.php

@@ -0,0 +1,167 @@
+<?php
+
+$config = function()
+{
+	$array = array();
+	$info = Dever::db('score/config')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$action = function()
+{
+	$array = array();
+	$info = Dever::db('score/action')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$upper = array
+(
+	1 => '无上限',
+	2 => '有上限',
+);
+
+$upper_type = array
+(
+	1 => '按自然天-每天0点重置',
+	2 => '按小时',
+	3 => '永久',
+);
+
+return array
+(
+	# 表名
+	'name' => 'rule',
+	# 显示给用户看的名称
+	'lang' => '积分规则设置',
+	'order' => 10,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'config_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '积分名称',
+			'default' 	=> '1',
+			'desc' 		=> '积分名称',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $config,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'action_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属行为',
+			'default' 	=> '1',
+			'desc' 		=> '所属行为',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $action,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'num'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '增加积分数-如果为负数,则是减少积分',
+			'default' 	=> '',
+			'desc' 		=> '增加积分数',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'upper'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '是否有上限限制',
+			'default' 	=> '1',
+			'desc' 		=> '是否有上限限制',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $upper,
+			'search'	=> 'select',
+			'control'	=> 'upper',
+		),
+
+		'upper_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '上限限制类型',
+			'default' 	=> '1',
+			'desc' 		=> '上限限制类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $upper_type,
+			'show'		=> 'upper=2',
+			'control'	=> 'upper_type',
+		),
+
+		'upper_time'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '间隔小时数',
+			'default' 	=> '12',
+			'desc' 		=> '间隔小时数',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'show'		=> 'upper_type=2'
+		),
+
+		'upper_limit'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '上限限制次数-小于1则不限制',
+			'default' 	=> '2',
+			'desc' 		=> '上限限制次数',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'show'		=> 'upper=2'
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+		),
+	),
+
+	'manage' => array
+	(
+		
+	),
+);

+ 111 - 0
score/database/user.php

@@ -0,0 +1,111 @@
+<?php
+$config = function()
+{
+	$array = array();
+	$info = Dever::db('score/config')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+	# 表名
+	'name' => 'user',
+	# 显示给用户看的名称
+	'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"'),
+		),
+	),
+);

+ 81 - 0
score/database/user_level.php

@@ -0,0 +1,81 @@
+<?php
+$level = function()
+{
+	$array = array();
+	$info = Dever::db('score/level')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+	# 表名
+	'name' => 'user_level',
+	# 显示给用户看的名称
+	'lang' => '用户等级',
+	'order' => 99,
+	'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}) : "匿名用户"',
+		),
+
+		'level_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '等级名称',
+			'default' 	=> '1',
+			'desc' 		=> '等级名称',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $level,
+			'search'	=> 'select',
+			'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,
+	),
+);

+ 214 - 0
score/database/user_log.php

@@ -0,0 +1,214 @@
+<?php
+
+$config = function()
+{
+	$array = array();
+	$info = Dever::db('score/config')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$action = function()
+{
+	$array = array();
+	$info = Dever::db('score/action')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+
+$status = array
+(
+    1 => '收入',
+    2 => '支出',
+);
+
+
+return array
+(
+	# 表名
+	'name' => 'user_log',
+	# 显示给用户看的名称
+	'lang' => '用户积分日志',
+	'order' => 10,
+	'menu' => false,
+	# 数据结构
+	'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,
+		),
+		
+		'action_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属行为',
+			'default' 	=> '1',
+			'desc' 		=> '所属行为',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $action,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '收入支出状态',
+            'default'   => '1',
+            'desc'      => '收入支出状态',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $status,
+            //'search'  => 'select',
+            'list'      => true,
+            //'edit'        => true,
+        ),
+
+		'num'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '增加积分数-如果为负数,则是减少积分',
+			'default' 	=> '',
+			'desc' 		=> '增加积分数',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'total'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '总积分数',
+			'default' 	=> '',
+			'desc' 		=> '总积分数',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'desc'     => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '描述',
+            'default'   => '',
+            'desc'      => '描述',
+            'match'     => 'option',
+            'update'    => 'textarea',
+        ),
+
+        'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'      => 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		'insert' => false,
+
+		# 列表
+		'list_button' => array
+		(
+			//'list' => array('行为日志', '"action_log&search_option_action_id={action_id}&search_option_uid={uid}&oper_parent=user_log"'),
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getNew' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'config_id' => 'yes',
+				'action_id' => 'yes',
+				'uid' => 'yes',
+				'status' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('cdate' => 'desc'),
+			'col' => '*',
+		),
+
+		'getNewTotal' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'config_id' => 'yes',
+				'action_id' => 'yes',
+				'uid' => 'yes',
+				'status' => 'yes',
+				'state' => 1,
+				'start' => array('yes-cdate', '>='),
+				'end' => array('yes-cdate', '<='),
+			),
+			'type' => 'count',
+			'order' => array('cdate' => 'desc'),
+			'col' => 'count(1) as total',
+		),
+	)
+);

+ 8 - 0
score/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'score');
+define('DEVER_APP_LANG', '积分规则配置');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 1);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-credit-card layui-icon-chat');
+include(DEVER_APP_PATH . '../boot.php');

+ 184 - 0
score/lib/Core.php

@@ -0,0 +1,184 @@
+<?php
+
+namespace Score\Lib;
+
+use Dever;
+
+class Core
+{
+	/**
+	 * 增加日志 Dever::load('score/lib/core')->log($uid, $key, $name);
+	 *
+	 * @return mixed
+	 */
+	public function log($uid, $action_key, $action_name, $content = '')
+	{
+		$action = Dever::db('score/action')->one(array('key' => $action_key));
+
+		if (!$action) {
+			$action = array();
+			$action['id'] = Dever::db('score/action')->insert(array('key' => $action_key, 'name' => $action_name));
+		}
+
+		if (isset($action['id'])) {
+			$log_id = Dever::db('score/action_log')->insert(array('uid' => $uid, 'action_id' => $action['id'], 'content' => $content));
+
+			//Dever::deamon('lib/core.oper?log_id='.$log_id, 'score');
+			Dever::load('score/lib/core.oper?log_id='.$log_id);
+		}
+	}
+
+	/**
+	 * 根据用户行为,增加积分
+	 *
+	 * @return mixed
+	 */
+	public function oper()
+	{
+		$log_id = Dever::input('log_id');
+
+		$log = Dever::db('score/action_log')->one($log_id);
+
+		$this->operAction($log);
+	}
+
+	private function rule($log, $info)
+	{
+		if ($info['num'] == 0) {
+			return;
+		}
+
+		$uid = $log['uid'];
+
+		$user = Dever::db('score/user')->one(array('uid' => $uid, 'config_id' => $info['config_id']));
+		if (!$user) {
+			$user = array();
+			$user['id'] = Dever::db('score/user')->insert(array('uid' => $uid, 'config_id' => $info['config_id'], 'score' => 0, 'no_score' => 0));
+			$user['score'] = 0;
+		}
+
+		$num = $info['num'];
+
+		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'));
+				return;
+			}
+			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 2, 'score' => $num));
+		}
+
+		$update = array();
+		$update['where_id'] = $user['id'];
+		$update['score'] = $user['score'] + $num;
+
+		$insert['uid'] = $uid;
+		$insert['config_id'] = $info['config_id'];
+		$insert['action_id'] = $info['action_id'];
+		$insert['status'] = 1;
+		$insert['num'] = $num;
+		$insert['total'] = $update['score'];
+		Dever::db('score/user_log')->insert($insert);
+
+		Dever::db('score/user')->update($update);
+	}
+
+	private function upper($uid, $info)
+	{
+		# 有上限限制
+		$limit = $info['upper_limit'];
+		# 获取用户最新一次积分变化日志
+
+		$time = time();
+
+		$where = array();
+		$where['config_id'] = $info['config_id'];
+		$where['action_id'] = $info['action_id'];
+		$where['uid'] = $uid;
+		$where['status'] = 1;
+		$user_log = Dever::db('score/user_log')->getNew($where);
+		if ($user_log) {
+			if ($info['upper_type'] == 1) {
+				# 按天
+				$where['start'] = Dever::maketime(date('Y-m-d 00:00:00', $time));
+				//$where['end'] = $end;
+			} elseif ($info['upper_type'] == 2) {
+				# 按小时
+				$where['start'] = $time - ($info['upper_time'] * 3600);
+				//$where['end'] = $end;
+			} elseif ($info['upper_type'] == 3) {
+				# 永久
+			} else {
+				return true;
+			}
+
+			$user_log_num = Dever::db('score/user_log')->getNewTotal($where);
+			if ($user_log_num >= $info['upper_limit']) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
+	private function operAction($log)
+	{
+		if ($log && $log['score_type'] == 1) {
+			$where = array();
+			$where['state'] = 1;
+			$where['id'] = $log['action_id'];
+			$action = Dever::db('score/action')->one($where);
+
+			if ($action) {
+				$rule = Dever::db('score/rule')->state(array('action_id' => $action['id']));
+
+				if ($rule) {
+					foreach ($rule as $k => $v) {
+						$this->rule($log, $v);
+					}
+				}
+			}
+		}
+	}
+
+    /**
+	 * 根据积分日志和规则,增加积分,这是一个定时任务,暂时不开启了
+	 *
+	 * @return mixed
+	 */
+	public function cron()
+	{
+		$where['score_type'] = 1;
+		$log = Dever::db('score/action_log')->state($where);
+		if ($log) {
+			$this->operAction($log['id']);
+		}
+	}
+
+
+	/**
+	 * 根据积分算等级
+	 *
+	 * @return mixed
+	 */
+	public function level()
+	{
+		$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));
+
+					if ($user) {
+
+					}
+				}
+			}
+		}
+	}
+}

+ 64 - 0
score/lib/Manage.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace Score\Lib;
+
+use Dever;
+
+class Manage
+{
+	/**
+	 * 显示用户信息
+	 *
+	 * @return mixed
+	 */
+	public function showUserInfo($uid, $ldate = false)
+	{
+		if ($uid) {
+			$user = Dever::load('passport/user.info', $uid);
+			if ($user) {
+				$table = array();
+				$table['用户名'] = $user['username'];
+				$table['手机号'] = $user['mobile'];
+				$table['领取时间'] = date('Y-m-d H:i:s', $ldate);
+				return Dever::table($table);
+			}
+		} else {
+			return '';
+		}
+	}
+
+    /**
+	 * 创建兑换码
+	 *
+	 * @return mixed
+	 */
+	public function create($id, $name, $param)
+	{
+		$code = Dever::param('num', $param);
+		$product_id = Dever::param('product_id', $param);
+
+		//$total = Dever::db('code/info')->total(array('product_id' => $product_id, 'type' => 1));
+		$total = 0;
+		if ($code > 0 && $code > $total) {
+			$num = $code - $total;
+
+			for ($i = 0; $i < $num; $i++) {
+				$this->createCode($product_id);
+			}
+		}
+	}
+
+	private function createCode($product_id)
+	{
+		$code = Dever::rand(8, 0);
+		$data['product_id'] = $product_id;
+		$data['code'] = $code;
+		$total = Dever::db('code/info')->total($data);
+		if ($total > 0) {
+			return $this->createCode($product_id, $id);
+		}
+		$data['type'] = 1;
+		Dever::db('code/info')->insert($data);
+		return $code;
+	}
+}