dever 7 năm trước cách đây
mục cha
commit
3a358102bd

+ 20 - 7
main/database/help.php

@@ -43,6 +43,20 @@ return array
 			'match' 	=> 'option',
 			'update'	=> 'editor',
 		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
 		
 		'state'		=> array
 		(
@@ -76,21 +90,20 @@ return array
 	(
 		
 	),
-	
-	# request 请求接口定义
+
 	'request' => array
 	(
-		# all 取所有
 		'getAll' => array
 		(
-			'where' => array
+			# 匹配的正则或函数 选填项
+			'option' => array
 			(
 				'state' => 1,
 			),
 			'type' => 'all',
-			'order' => array('id', 'desc'),
-			'limit' => array(10, 0),
+			'order' => array('reorder' => 'desc', 'cdate' => 'desc'),
+			'page' => array(15, 'list'),
 			'col' => '*',
 		),
-	),
+	)
 );

+ 93 - 0
task/api/main.php

@@ -0,0 +1,93 @@
+<?php
+# 注册api,这里是为了安全考虑,否则可以不用在此注册,注册之后
+# api仅有三种类型:get、update、delete
+
+return array
+(
+	'info.submit' => array
+	(
+		'name' => '领取任务',
+		'request' => array
+		(
+			'id' => '任务id',
+			//'uid' => '用户id',
+		),
+		'response' => array
+		(
+			'info' => '领取信息',
+		),
+		'order' => 100,
+		'type' => 2,
+		# 安全加密
+		'secure' => true,
+	),
+	
+	'report.submit' => array
+	(
+		'name' => '发布报告',
+		'request' => array
+		(
+			'id' => '任务id',
+			//'uid' => '用户id',
+		),
+		'response' => array
+		(
+			'info' => '报告信息',
+		),
+		'order' => 99,
+		'type' => 2,
+		# 安全加密
+		'secure' => true,
+	),
+
+	'score.submit' => array
+	(
+		'name' => '金币兑换',
+		'request' => array
+		(
+			'uid' => '用户id',
+		),
+		'response' => array
+		(
+			'info' => '信息',
+		),
+		'order' => 98,
+		'type' => 2,
+		# 安全加密
+		'secure' => true,
+	),
+
+	'group.submit' => array
+	(
+		'name' => '加入小组',
+		'request' => array
+		(
+			'uid' => '用户id',
+		),
+		'response' => array
+		(
+			'info' => '信息',
+		),
+		'order' => 98,
+		'type' => 2,
+		# 安全加密
+		'secure' => true,
+	),
+
+	'user.submit' => array
+	(
+		'name' => '资料认证',
+		'request' => array
+		(
+			'uid' => '用户id',
+		),
+		'response' => array
+		(
+			'info' => '信息',
+		),
+		'order' => 98,
+		'type' => 2,
+		# 安全加密
+		'secure' => true,
+	),
+);

+ 22 - 4
task/database/info.php

@@ -53,7 +53,25 @@ return array
 	'name' => 'info',
 	# 显示给用户看的名称
 	'lang' => '任务管理',
+	'desc' => '可将lib/cron.task加入到计划任务,建议间隔时间为86400,每天凌晨执行,将自动清理过期的任务',
 	'order' => 200,
+	# 更新后,要把company_id等信息同步给user_task,方便统计
+	'sync' => array
+	(
+		'task/user_task' => array
+		(
+			# 更新另外一个表的字段 => 本表的字段
+			'where' => array('task_id', 'id'),
+			# 要更新的数据
+			'update' => array(
+				'company_id' => 'company_id',
+				'level_id' => 'level_id',
+				'cate_id' => 'cate_id',
+			),
+			# 同步更新的类型,delete为先删再插入,update为直接更新
+			'type' => 'update',
+		)
+	),
 	# 数据结构
 	'struct' => array
 	(
@@ -169,7 +187,7 @@ return array
 			//'list'		=> true,
 		),
 
-		'report_cate_num'		=> array
+		'cate_num'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '同一类别参与次数',
@@ -180,7 +198,7 @@ return array
 			//'list'		=> true,
 		),
 
-		'report_company_num'		=> array
+		'company_num'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '同一商家参与次数',
@@ -220,7 +238,7 @@ return array
 			'attr'		=> '',
 		),
 
-		'task_cash'		=> array
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '单任务报告酬劳',
@@ -231,7 +249,7 @@ return array
 			//'list'		=> true,
 		),
 
-		'group_cash'		=> array
+		'group_score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '下线提成酬劳',

+ 1 - 1
task/database/level.php

@@ -35,7 +35,7 @@ return array
 			'list'		=> true,
 		),
 
-		'num'		=> array
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '级别积分',

+ 36 - 3
task/database/user_cash.php

@@ -11,7 +11,13 @@ $status = array
 	1 => '申请中',
 	2 => '兑现中',
 	3 => '已完成',
-	//4 => '失败',
+	4 => '失败',
+);
+
+$cron = array
+(
+	1 => '待机',
+	2 => '完成',
 );
 
 return array
@@ -54,7 +60,7 @@ return array
 			'list'		=> 'Dever::load("passport/user-one#username", {uid})',
 		),
 
-		'num'		=> array
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '兑现积分',
@@ -67,7 +73,7 @@ return array
 			'modal'		=> '查看详情',
 		),
 
-		'cash_num'		=> array
+		'cash'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '兑换金额',
@@ -104,6 +110,28 @@ return array
 			'list'		=> true,
 		),
 
+		'status_desc'		=> array
+		(
+			'type' 		=> 'varchar-300',
+			'name' 		=> '审核说明',
+			'default' 	=> '',
+			'desc' 		=> '请输入审核说明',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'show'		=> 'status=4',
+		),
+
+		'cron'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '计划任务状态',
+			'default' 	=> '1',
+			'desc' 		=> '计划任务状态',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $cron,
+		),
+
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -131,5 +159,10 @@ return array
 		'insert' => false,
 		'edit' => false,
 		'delete' => false,
+		# 快捷更新
+		'list_button' => array
+		(
+			'edit' => array('审核', 'status,status_desc'),
+		),
 	),
 );

+ 18 - 0
task/database/user_group_member.php

@@ -106,4 +106,22 @@ return array
 		'edit' => false,
 		'delete' => false,
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'group_id' => 'yes',
+				'status' => 2,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('cdate' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => '*',
+		),
+	)
 );

+ 33 - 4
task/database/user_report.php

@@ -7,7 +7,7 @@ $status = array
 	3 => '审核未通过',
 );
 
-$num_status = array
+$score_status = array
 (
 	1 => '未入账',
 	2 => '已入账',
@@ -138,7 +138,7 @@ return array
 			'update'	=> 'textarea',
 		),
 
-		'num'		=> array
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '积分',
@@ -148,7 +148,18 @@ return array
 			'update'	=> 'text',
 		),
 
-		'num_status'		=> array
+		'group_score'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '下线提成酬劳',
+			'default' 	=> '0',
+			'match' 	=> '下线提成酬劳',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'score_status'		=> array
 		(
 			'type' 		=> 'tinyint-1',
 			'name' 		=> '是否入账',
@@ -156,7 +167,7 @@ return array
 			'desc' 		=> '是否入账',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'select',
-			'option'	=> $num_status,
+			'option'	=> $score_status,
 			'search'	=> 'select',
 			'list'		=> true,
 		),
@@ -194,4 +205,22 @@ return array
 			'edit' => array('审核', 'status,status_desc'),
 		),
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'status' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('cdate' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => '*',
+		),
+	)
 );

+ 20 - 3
task/database/user_score.php

@@ -41,12 +41,12 @@ return array
 			'list'		=> 'Dever::load("passport/user-one#username", {uid})',
 		),
 
-		'num'		=> array
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '积分',
+			'name' 		=> '可用积分',
 			'default' 	=> '',
-			'desc' 		=> '积分',
+			'desc' 		=> '可用积分',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 		),
@@ -79,4 +79,21 @@ return array
 		'edit' => false,
 		'delete' => false,
 	),
+
+	'request' => array
+	(
+		'updateScore' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'uid' => 'yes',
+			),
+			'set' => array
+			(
+				'score' => array('yes', '+='),
+			),
+			'type' => 'update',
+		),
+	)
 );

+ 77 - 8
task/database/user_score_log.php

@@ -6,7 +6,7 @@ $status = array
 	2 => '收入',
 );
 
-$cash = array
+$cash_type = array
 (
 	1 => '微信',
 	2 => '支付宝',
@@ -14,10 +14,13 @@ $cash = array
 
 $type = array
 (
-	1 => '积分兑现',
-	2 => '任务奖励',
-	3 => '任务提成',
-	4 => '系统奖励',
+	1 => '积分兑现-申请',
+	2 => '积分兑现-完成',
+	3 => '积分兑现-失败',
+
+	4 => '任务奖励',
+	5 => '任务提成',
+	6 => '系统奖励',
 );
 
 return array
@@ -60,7 +63,24 @@ return array
 			'list'		=> 'Dever::load("passport/user-one#username", {uid})',
 		),
 
-		'num'		=> array
+		'group_uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '下限用户名',
+			'default' 	=> '',
+			'desc' 		=> '下限用户名',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+			'search'	=> array
+			(
+				'api' => 'passport/user-all',
+				'col' => 'username',
+				'result' => 'id',
+			),
+			'list'		=> 'Dever::load("passport/user-one#username", {uid})',
+		),
+
+		'score'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '积分',
@@ -70,6 +90,16 @@ return array
 			'update'	=> 'text',
 		),
 
+		'cash'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '兑换现金',
+			'default' 	=> '',
+			'desc' 		=> '兑换现金',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
 		'task_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -87,6 +117,15 @@ return array
 			'list'		=> '{task_id} > 0 ? Dever::load("task/info-one#name", {task_id}) : "系统"',
 		),
 
+		'report_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '报告',
+			'default' 	=> '-1',
+			'desc' 		=> '报告',
+			'match' 	=> 'is_numeric',
+		),
+
 		'type'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -101,7 +140,17 @@ return array
 			'edit'		=> true,
 		),
 
-		'cash'		=> array
+		'type_desc'		=> array
+		(
+			'type' 		=> 'varchar-300',
+			'name' 		=> '积分类型描述',
+			'default' 	=> '',
+			'desc' 		=> '请输入积分类型描述',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+		),
+
+		'cash_type'		=> array
 		(
 			'type' 		=> 'tinyint-1',
 			'name' 		=> '兑现途径',
@@ -109,7 +158,7 @@ return array
 			'desc' 		=> '兑现途径',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'select',
-			'option'	=> $cash,
+			'option'	=> $cash_type,
 			'search'	=> 'select',
 			'list'		=> true,
 		),
@@ -165,4 +214,24 @@ return array
 		//'edit' => false,
 		'delete' => false,
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'task_id' => 'yes',
+				'report_id' => 'yes',
+				'status' => 'yes',
+				'type' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('cdate' => 'desc'),
+			'col' => '*',
+		),
+	)
 );

+ 48 - 4
task/database/user_task.php

@@ -2,8 +2,11 @@
 
 $status = array
 (
-	1 => '正常',
-	2 => '异常',
+	1 => '进行中',
+	2 => '已提交报告',
+	3 => '已完成一次报告',
+	4 => '已完成',
+	9 => '冻结',
 );
 
 $company = function()
@@ -28,6 +31,17 @@ $cate = function()
 	return $array;
 };
 
+$level = function()
+{
+	$array = array();
+	$info = Dever::load('task/level-state');
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
 return array
 (
 	# 表名
@@ -111,12 +125,25 @@ return array
 			'list'		=> true,
 		),
 
+		'level_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '等级',
+			'default' 	=> '-1',
+			'desc' 		=> '等级',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			'search'	=> 'select',
+			'option'	=> $level,
+			'list'		=> true,
+		),
+
 		'status'		=> array
 		(
 			'type' 		=> 'tinyint-1',
-			'name' 		=> '审核状态',
+			'name' 		=> '状态',
 			'default' 	=> '1',
-			'desc' 		=> '审核状态',
+			'desc' 		=> '状态',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'select',
 			'option'	=> $status,
@@ -153,4 +180,21 @@ return array
 		'edit' => false,
 		'delete' => false,
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'cdate' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => '*',
+		),
+	)
 );

+ 51 - 7
task/lib/Base.php

@@ -6,14 +6,58 @@ use Dever;
 
 class Base
 {
-    # 定义返回数据
-    protected $data;
+	# 定义返回数据
+	protected $data;
 
-    public function __construct()
+	public function __construct()
+	{
+		$this->data['config'] = Dever::db('main/config')->one(1);
+		$this->data['time'] = time();
+		$this->data['uid'] = Dever::input('uid', 1);
+		$this->data['session'] = Dever::input('session');
+	}
+
+	/**
+	 * 检测用户信息
+	 *
+	 * @return mixed
+	 */
+	protected function checkUser($state = false)
+	{
+		# 检测用户是否登录
+		$where['uid'] = $this->data['uid'];
+
+		# 获取用户积分
+		$this->data['user_score'] = Dever::db('task/user_score')->one($where);
+		if (!$this->data['user_score']) {
+			$this->data['user_score'] = array();
+        	$this->data['user_score']['num'] = 0;
+        	$this->data['user_score']['uid'] = $where['uid'];
+        	$this->data['user_score']['id'] = Dever::db('task/user_score')->insert($this->data['user_score']);
+        }
+
+		# 检测用户是否认证
+		$this->data['user_info'] = Dever::db('task/user_info')->one($where);
+
+		if ($this->data['user_info'] && $this->data['user_info']['status'] == 2) {
+			# 已认证
+			return true;
+		} else {
+			if ($state == true) {
+				# 未认证 code = 110 就是需要认证,需要跳转到认证页面
+				Dever::alert('资料认证通过后才能领取任务', 110);
+			}
+			return false;
+		}
+	}
+
+	public function token($request)
+    {
+        return http_build_query(Dever::token($request));
+    }
+
+    public function url($method, $request)
     {
-        $this->data['config'] = Dever::db('main/config')->one(1);
-        $this->data['time'] = time();
-        $this->data['uid'] = Dever::input('uid', 1);
-        $this->data['session'] = Dever::input('session');
+        return Dever::proxy($method, $this->token($request));
     }
 }

+ 172 - 0
task/lib/Cron.php

@@ -0,0 +1,172 @@
+<?php
+
+namespace Task\Lib;
+
+use Dever;
+
+class Cron
+{
+	/**
+	 * 将过期的任务,置为已结束,建议一天运行一次
+	 *
+	 * @return mixed
+	 */
+	public function task()
+	{
+		
+	}
+
+	/**
+     * 资料认证审核后的操作
+     *
+     * @return mixed
+     */
+    public function submit_commit()
+    {
+
+    }
+
+    /**
+     * 任务报告完成后的操作
+     *
+     * @return mixed
+     */
+    public function task_commit()
+    {
+    	# 审核成功 入账
+    	$where['status'] = 2;
+    	$where['score_status'] = 1;
+    	$data = Dever::db('task/user_report')->state($where);
+
+    	if ($data) {
+    		foreach ($data as $k => $v) {
+    			$update['where_id'] = $v['id'];
+    			$update['score_status'] = 2;
+    			Dever::db('task/user_report')->update($update);
+
+    			$this->updateUserScore($v['uid'], $v['score']);
+
+    			$this->updateScoreLog($v['uid'], $v['score'], 4, 2, $v['task_id'], $v['id']);
+
+				$this->group($v['uid'], $v['group_score'], $v['task_id'], $v['id']);
+				
+    		}
+    	}
+
+    	return 'yes';
+    }
+
+    /**
+     * 兑现审核完成后的操作
+     *
+     * @return mixed
+     */
+    public function cash_commit()
+    {
+    	# 成功
+    	$where['status'] = 3;
+    	$where['cron'] = 1;
+    	$data = Dever::db('task/user_cash')->state($where);
+
+    	if ($data) {
+    		foreach ($data as $k => $v) {
+    			$update['where_id'] = $v['id'];
+    			$update['cron'] = 2;
+    			Dever::db('task/user_cash')->update($update);
+
+
+    			$this->updateScoreLog($v['uid'], $v['score'], 2, 1, -1, -1, $v['type'], $v['cash'], $v['cdate']);
+    		}
+    	}
+
+    	# 失败
+    	$where['status'] = 4;
+    	$where['cron'] = 1;
+    	$data = Dever::db('task/user_cash')->state($where);
+
+    	if ($data) {
+    		foreach ($data as $k => $v) {
+    			$update['where_id'] = $v['id'];
+    			$update['cron'] = 2;
+    			Dever::db('task/user_cash')->update($update);
+
+    			# 失败了就把积分再加回去吧
+    			$this->updateUserScore($v['uid'], $v['score']);
+
+    			$this->updateScoreLog($v['uid'], $v['score'], 3, 1, -1, -1, $v['type'], $v['cash'], $v['cdate'], $v['status_desc']);
+
+    			# 记录日志
+    			$insert = array();
+    			$insert['type'] = 3;
+				$insert['status'] = 1;
+				$insert['cash_type'] = $v['type'];
+				$insert['cash'] = $v['cash'];
+				$insert['score'] = $v['score'];
+				$insert['uid'] = $v['uid'];
+				
+				$insert['cash_date'] = $v['cdate'];
+				Dever::db('task/user_score_log')->insert($insert);
+    		}
+    	}
+
+    	return 'yes';
+    }
+
+    /**
+     * 寻找这个用户的上线 给上线带来收益
+     *
+     * @return mixed
+     */
+    private function group($uid, $score, $task_id, $report_id)
+    {
+    	$group_member = Dever::db('task/user_group_member')->one(array('uid' => $uid));
+		if ($group_member) {
+			$group_info = Dever::db('task/user_group')->one($group_member['group_id']);
+			if ($group_info && $group_info['state'] == 1 && $group_info['uid'] > 0 && $group_info['uid'] != $uid) {
+				
+    			$this->updateUserScore($group_info['uid'], $score);
+
+    			$this->updateScoreLog($group_info['uid'], $score, 5, 2, $task_id, $report_id);
+			}
+		}
+    }
+
+    /**
+     * 更新用户积分数量
+     *
+     * @return mixed
+     */
+    private function updateUserScore($uid, $score)
+    {
+    	$update['uid'] = $uid;
+		$update['score'] = $score;
+		Dever::db('task/user_score')->updateScore($update);
+    }
+
+    /**
+     * 日志记录
+     *
+     * @return mixed
+     */
+    private function updateScoreLog($uid, $score, $type, $status, $task_id = -1, $report_id = -1, $cash_type = 1, $cash = 0, $cash_date = 0, $type_desc = '')
+    {
+    	$insert = array();
+		$insert['type'] = $type;
+		$insert['status'] = $status;
+		$insert['score'] = $score;
+		$insert['uid'] = $uid;
+		$insert['task_id'] = $task_id;
+		$insert['report_id'] = $report_id;
+
+		$insert['cash_type'] = $cash_type;
+		$insert['cash'] = $cash;
+
+		if ($cash_date) {
+			$insert['cash_date'] = $cash_date;
+		}
+
+		$insert['type_desc'] = $type_desc;
+
+		Dever::db('task/user_score_log')->insert($insert);
+    }
+}

+ 10 - 0
task/lib/Manage.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace Task\Lib;
+
+use Dever;
+
+class Manage
+{
+	
+}

+ 82 - 0
task/src/Group.php

@@ -0,0 +1,82 @@
+<?php
+
+namespace Task\Src;
+
+use Dever;
+use Task\Lib\Base;
+
+class Group extends Base
+{
+    /**
+     * 我的小队
+     *
+     * @return mixed
+     */
+    public function user()
+    {
+        $group = $this->one();
+
+        if ($group) {
+        	$data = Dever::db('task/user_group_member')->getAll(array('group_id' => $group['id']));
+
+        	return $data;
+        }
+
+        return $data;
+    }
+
+    /**
+     * 我的邀请码
+     *
+     * @return mixed
+     */
+    public function one()
+    {
+        $this->checkUser();
+
+        $where['uid'] = $this->data['uid'];
+        $group = Dever::db('task/user_group')->one($where);
+
+        if (!$group) {
+        	# 生成邀请码
+        	
+        }
+
+        return $group;
+    }
+
+    /**
+     * 加入小队
+     *
+     * @return mixed
+     */
+    public function submit()
+    {
+        # 检测用户是否登录
+        $this->checkUser();
+        
+        $code = Dever::input('code');
+
+        if (!$code) {
+        	Dever::alert('邀请码不正确');
+        }
+
+        $where['code'] = $code;
+        $group = Dever::db('task/user_group')->one($where);
+
+        if (!$group) {
+        	Dever::alert('邀请码不正确');
+        }
+
+        $info = Dever::db('task/user_group_member')->one(array('uid' => $this->data['uid']));
+
+        if (!$info) {
+            $insert['uid'] = $this->data['uid'];
+            $insert['group_id'] = $grou['id'];
+            $insert['status'] = 2;
+            return Dever::db('task/user_group_member')->insert($insert);
+        }
+
+        return $info['id'];
+    }
+}

+ 37 - 0
task/src/Help.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Task\Src;
+
+use Dever;
+use Task\Lib\Base;
+
+class Help extends Base
+{
+    /**
+     * 帮助列表
+     *
+     * @return mixed
+     */
+    public function all()
+    {
+        $data = Dever::db('main/help')->getAll();
+        return $data;
+    }
+    /**
+     * 任务详情
+     *
+     * @return mixed
+     */
+    public function one()
+    {
+        $this->checkUser();
+
+        $id = Dever::input('id');
+        $info = array();
+        if ($id > 0) {
+            $info = Dever::db('main/help')->one($id);
+        }
+        
+        return $info;
+    }
+}

+ 188 - 19
task/src/Info.php

@@ -22,6 +22,26 @@ class Info extends Base
                 $this->getOne($data[$k]);
             }
         }
+
+        return $data;
+    }
+
+    /**
+     * 用户任务列表
+     *
+     * @return mixed
+     */
+    public function user()
+    {
+        $this->data['cate'] = Dever::db('task/cate')->state();
+
+        $data = Dever::db('task/user_task')->getAll();
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $this->getOne($data[$k]);
+            }
+        }
+
         return $data;
     }
 
@@ -32,30 +52,91 @@ class Info extends Base
      */
     public function one()
     {
+        $this->checkUser();
+
         $id = Dever::input('id');
         $info = array();
         if ($id > 0) {
             $this->data['cate'] = Dever::db('task/cate')->state();
             $info = Dever::db('task/info')->one($id);
-            $this->getOne($info);
+            # 检测用户是否登录,是否认证,仅显示认证信息
+
+            $this->getOne($info, $button = true);
         }
         
         return $info;
     }
 
-    private function getOne(& $data)
+    /**
+     * 领取任务
+     *
+     * @return mixed
+     */
+    public function submit()
+    {
+        # 检测用户是否登录,是否认证
+        $this->checkUser(true);
+
+        $id = Dever::input('id');
+        $info = array();
+        if ($id > 0) {
+            $info = Dever::db('task/info')->one($id);
+            $this->getOne($info, $button = true);
+
+            if (isset($info['button']) && is_array($info['button']) && isset($info['button']['status']) && $info['button']['status'] > 0) {
+                if ($info['button']['status'] == 1) {
+                    # 可以领取
+                    return $this->submit_action($info);
+                } else {
+                    Dever::alert($info['button']['desc']);
+                }
+            } else {
+                Dever::alert('领取失败');
+            }
+        }
+        Dever::alert('领取失败');
+    }
+
+    /**
+     * 立刻领取
+     *
+     * @return mixed
+     */
+    private function submit_action($info)
+    {
+        $user = Dever::db('task/user_task')->one(array('task_id' => $info['id'], 'uid' => $this->data['uid'], 'rand' => Dever::id()));
+        if (!$user) {
+            $insert['uid'] = $this->data['uid'];
+            $insert['task_id'] = $info['id'];
+            $insert['company_id'] = $info['company_id'];
+            $insert['cate_id'] = $info['cate_id'];
+            $insert['level_id'] = $info['level_id'];
+            $insert['status'] = 1;
+            $info['user_task'] = Dever::db('task/user_task')->insert($insert);
+            return $info;
+        } else {
+            Dever::alert('领取失败');
+        }
+    }
+
+    /**
+     * 任务详情信息
+     *
+     * @return mixed
+     */
+    private function getOne(& $data, $button = false)
     {
         # 多少人领取
         $data['user_num'] = Dever::db('task/user_task')->total(array('task_id' => $data['id']));
 
         # 3 金币/项
-        $data['list_score'] = $data['task_cash'] . ' ' . $this->data['config']['score_name'] . '/' . $this->data['config']['score_name_ext'];
+        $data['list_score'] = $data['score'] . ' ' . $this->data['config']['score_name'] . '/项';
 
         # 组员贡献 1 金币/项
-        $data['list_group_score'] = '组员贡献 ' . $data['task_cash'] . ' ' . $this->data['config']['score_name'] . '/' . $this->data['config']['score_name_ext'];
+        $data['list_group_score'] = '组员贡献 ' . $data['score'] . ' ' . $this->data['config']['score_name'] . '/项';
 
         #3 金币 + 1 金币
-        $data['score'] = $data['task_cash'] . ' ' . $this->data['config']['score_name'] . ' + ' . $data['task_cash'] . ' ' . $this->data['config']['score_name'];
+        $data['score'] = $data['score'] . ' ' . $this->data['config']['score_name'] . ' + ' . $data['score'] . ' ' . $this->data['config']['score_name'];
 
         # 任务类别
         $data['cate'] = $this->data['cate'][$data['cate_id']];
@@ -64,37 +145,125 @@ class Info extends Base
         $data['sdate_str'] = date('Y.m.d', $data['sdate']);
         $data['edate_str'] = date('Y.m.d', $data['edate']);
 
-        $data['button'] = $this->button($data);
-        
+        if ($button) {
+            $data['button'] = $this->button($data);
+        }
+
+        if (isset($data['uid']) && $data['uid'] > 0 && $this->data['uid'] > 0 && $data['uid'] == $this->data['uid']) {
+            $data['score'] = $this->score($data);
+        }
+    }
+
+    /**
+     * 当前用户获取的积分
+     *
+     * @return mixed
+     */
+    private function score($data)
+    {
+        # 查看该用户完成的报告数
+        $where = array();
+        $where['uid'] = $data['uid'];
+        $where['status'] = 2;
+        $log = Dever::db('task/user_score_log')->getAll($where);
+
+        # 三项描述
+        $result = array();
+        $result['report'] = $result['group'] = $result['total'] = '';
+        $result['report_num'] = $result['report_score'] = $result['group_score'] = $result['total_score'] = 0;
+
+        if ($log) {
+            $result['report_num'] = count($report);
+            foreach ($log as $k => $v) {
+                if ($v['type'] == 4 && $v['report_id'] > 0) {
+                    $result['report_score'] += $v['score'];
+                    $result['report_num']++;
+                } elseif ($v['type'] == 5) {
+                    $result['group_score'] += $v['score'];
+                }
+            }
+
+            $result['total_score'] = $result['report_score'] + $result['group_score'];
+
+            if ($result['report_score'] > 0) {
+                $result['report'] = '已完成 '.$result['report_num'].' 份任务报告,获得 '.$result['report_score'].' ' . $this->data['config']['score_name'];
+            }
+            
+            if ($result['group_score'] > 0) {
+                $result['group'] = '组员贡献 '.$result['group_score'].' ' . $this->result['config']['score_name'];
+            }
+            
+            if ($result['total_score'] > 0) {
+                $result['total'] = '合计获得 '.$result['total_score'].' ' . $this->data['config']['score_name'];
+            }
+        }
+
+        return $result;
     }
 
+    /**
+     * 领取任务按钮的状态
+     *
+     * @return mixed
+     */
     private function button($data)
     {
-        # 领取任务按钮的状态
-        # 1 可以领取 2 任务已过期 3 抢光了 4 已领取 5 等级不够 6 已领取过该商家任务 7 已领取过该类别任务
         # 大于1都不能点击
         $button = 1;
 
         if ($this->data['time'] > $data['edate']) {
             # 任务已到期
             $button = 2;
-        } elseif ($data['user_num'] >= $this->data['config']['num']) {
+        } elseif ($data['user_num'] >= $data['num']) {
             # 抢光了
             $button = 3;
         } elseif (isset($this->data['uid']) && $this->data['uid']) {
-            # 判断是否领取
-            $user = Dever::db('task/user_task')->one(array('task_id' => $data['id'], 'uid' => $this->data['uid']));
-
-            if ($user) {
-                # 已领取
+            # 判断等级
+            $level = Dever::db('task/level')->one($data['level_id']);
+            if ($level && isset($this->data['user_score']) && $this->data['uesr_score'] && $level['score'] > $this->data['user_score']['score']) {
+                # 等级不够
                 $button = 4;
             } else {
-                # 判断商家领取次数
-                $company = Dever::db('task/user_task')->total(array('company_id' => $data['company_id']));
-                if ($data['company_'])
+                # 判断是否领取
+                $user = Dever::db('task/user_task')->one(array('task_id' => $data['id'], 'uid' => $this->data['uid']));
+                if ($user) {
+                    # 已领取
+                    $button = 5;
+                } else {
+                    # 判断类别领取次数
+                    $cate = Dever::db('task/user_task')->total(array('uid' => $this->data['uid'], 'cate_id' => $data['cate_id'], 'status' => 3));
+                    if ($data['cate_num'] >= $cate) {
+                        $button = 6;
+                    } else {
+                        # 判断商家领取次数
+                        $company = Dever::db('task/user_task')->total(array('uid' => $this->data['uid'], 'company_id' => $data['company_id'], 'status' => 3));
+                        if ($data['company_num'] >= $company) {
+                            $button = 7;
+                        }
+                    }
+                }
             }
         }
 
-        return $button;
+        $config = array
+        (
+            1 => '可以领取',
+            2 => '任务已过期',
+            3 => '抢光了',
+            4 => '等级不够',
+            5 => '已领取',
+            6 => '已领取过该商家'.$data['cate']['name'],
+            7 => '已领取过该商家任务',
+        );
+
+        $result['status'] = $button;
+        $result['desc'] = $config[$button];
+        $result['icon'] = '';
+
+        if ($result['status'] == 4) {
+            $result['icon'] = 'level';
+        }
+
+        return $result;
     }
 }

+ 148 - 0
task/src/Report.php

@@ -0,0 +1,148 @@
+<?php
+
+namespace Task\Src;
+
+use Dever;
+use Task\Lib\Base;
+
+class Report extends Base
+{
+    /**
+     * 报告列表:我的
+     *
+     * @return mixed
+     */
+    public function all()
+    {
+    	$where['uid'] = $this->data['uid'];
+        $data = Dever::db('task/user_report')->getAll($where);
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $this->getOne($data[$k]);
+            }
+        }
+
+        return $data;
+    }
+
+    /**
+     * 报告详情
+     *
+     * @return mixed
+     */
+    public function one()
+    {
+        $id = Dever::input('id');
+        $info = array();
+        if ($id > 0) {
+            $info = Dever::db('task/user_report')->one($id);
+            $this->getOne($info);
+        }
+        
+        return $info;
+    }
+
+    /**
+     * 提交报告
+     *
+     * @return mixed
+     */
+    public function submit()
+    {
+		$info = Dever::load('task/info.one');
+
+		if (isset($info['button']) && is_array($info['button']) && isset($info['button']['status']) && $info['button']['status'] > 0) {
+            if ($info['button']['status'] == 2) {
+                # 可以提交
+                return $this->submit_action($info);
+            } else {
+                Dever::alert($info['button']['desc']);
+            }
+        } else {
+            Dever::alert('提交失败');
+        }
+    }
+
+    /**
+     * 立刻提交
+     *
+     * @return mixed
+     */
+    private function submit_action($info)
+    {
+    	$username = Dever::input('username');
+    	$pic = Dever::input('pic');
+    	$link = Dever::input('link');
+    	$desc = Dever::input('desc');
+        $id = Dever::input('id');
+
+    	if (!$username) {
+    		Dever::alert('账号名不能为空');
+    	}
+
+    	if (!$pic) {
+    		Dever::alert('任务截屏不能为空');
+    	}
+
+    	if (!$link) {
+    		Dever::alert('链接不能为空');
+    	}
+
+    	if (!$desc) {
+    		Dever::alert('文字说明不能为空');
+    	}
+
+    	$report_id = Dever::input('report_id');
+    	if ($report_id > 0) {
+            $update['username'] = $username;
+            $update['pic'] = $pic;
+            $update['link'] = $link;
+            $update['desc'] = $desc;
+            $update['score'] = $info['score'];
+            $update['group_score'] = $info['group_score'];
+            $update['where_id'] = $report_id;
+            Dever::db('task/user_report')->update($update);
+            $info['user_report'] = $report_id;
+            return $info;
+    	} else {
+            $insert['uid'] = $this->data['uid'];
+            $insert['task_id'] = $info['id'];
+            $insert['username'] = $username;
+            $insert['pic'] = $pic;
+            $insert['link'] = $link;
+            $insert['desc'] = $desc;
+            $insert['score'] = $info['score'];
+            $insert['group_score'] = $info['group_score'];
+            $insert['status'] = 1;
+            $info['user_report'] = Dever::db('task/user_report')->insert($insert);
+            return $info;
+        }
+
+        Dever::alert('提交失败');
+    }
+
+    /**
+     * 任务详情信息
+     *
+     * @return mixed
+     */
+    private function getOne(& $data)
+    {
+        # 审核文字
+        if ($data['status'] == 1) {
+        	$data['audit'] = '待审核';
+        	$data['audit_desc'] = '';
+        } elseif ($data['status'] == 2) {
+        	$data['audit'] = '审核通过';
+        	$data['audit_desc'] = '获得' . $this->data['config']['score_name'] . ':' . $data['score'] . $this->data['config']['score_name_ext'];
+        	if ($data['score_status'] == 1) {
+        		$data['audit_desc'] .= '(未入账)';
+        	} else {
+        		$data['audit_desc'] .= '(已入账)';
+        	}
+        } elseif ($data['status'] == 3) {
+        	$data['audit'] = '审核未通过';
+        	$data['audit_desc'] = $data['status_desc'];
+        }
+    }
+}

+ 190 - 0
task/src/Score.php

@@ -0,0 +1,190 @@
+<?php
+
+namespace Task\Src;
+
+use Dever;
+use Task\Lib\Base;
+
+class Score extends Base
+{
+    /**
+     * 我的积分
+     *
+     * @return mixed
+     */
+    public function user()
+    {
+        # 检测用户是否登录
+        $this->checkUser();
+
+        return $this->data['uesr_score'];
+    }
+
+    /**
+     * 金币兑换
+     *
+     * @return mixed
+     */
+    public function exchange()
+    {
+        $user = $this->user();
+
+        $user['score_name'] = $this->data['config']['score_name'];
+        $user['score_name_ext'] = $this->data['config']['score_name_ext'];
+        $user['exchange'] = $this->data['config']['exchange'];
+        $user['exchange_min'] = $this->data['config']['exchange_min'];
+        $user['cash'] = floor($user['score']/$user['exchange']);
+
+        if ($user['exchange_min'] > 0) {
+        	$user['desc'] = '最低兑换数量'.$user['exchange_min'].$user['score_name'];
+        } else {
+        	$user['desc'] = '';
+        }
+        
+        $user['exchange'] = '可兑换'.$user['cash'].$user['score_name_ext'];
+
+        return $user;
+    }
+
+    /**
+     * 金币兑换
+     *
+     * @return mixed
+     */
+    public function submit_commit()
+    {
+		$user = $this->exchange();
+		$type = Dever::input('type');
+		$score = Dever::input('score');
+
+		if (!$score) {
+			Dever::alert('请输入' . $user['score_name'] . '数量');
+		}
+
+		if (!$type) {
+			Dever::alert('请选择兑现途径');
+		}
+
+		if ($type != 1 && $type != 2) {
+			Dever::alert('请选择兑现途径');
+		}
+
+		if ($user['exchange_min'] > 0 && $score < $user['exchange_min']) {
+			Dever::alert($user['desc']);
+		}
+
+		if ($score > $user['score']) {
+			Dever::alert('实际兑换数量不能超过剩余' . $user['score_name'] . '数量');
+		}
+
+		$insert['cash'] = floor($score/$user['exchange']);
+		$insert['score'] = $score;
+		$insert['uid'] = $user['uid'];
+		$insert['type'] = $type;
+		$insert['status'] = 1;
+		Dever::db('task/user_cash')->insert($insert);
+
+		$insert['type'] = 1;
+		$insert['status'] = 1;
+		$insert['cash'] = $type;
+		Dever::db('task/user_score_log')->insert($insert);
+
+		# 剩余数量
+		$sur_score = $user['score'] - $score;
+
+		$update['score'] = $sur_score;
+		$update['where_id'] = $user['id'];
+
+		Dever::db('task/user_score')->update($update);
+
+		return 'yes';
+    }
+
+    /**
+     * 我的积分日志列表
+     *
+     * @return mixed
+     */
+    public function logs()
+    {
+        # 检测用户是否登录
+        $this->checkUser();
+
+        $where['uid'] = $this->data['uid'];
+        $name = $this->data['config']['score_name'];
+        $ext = $this->data['config']['score_name_ext'];
+        $data = Dever::db('task/user_score_log')->getAll($where);
+        if ($data) {
+        	foreach ($data as $k => $v) {
+        		$data[$k]['name'] = '';
+        		$data[$k]['info'] = '';
+        		$data[$k]['desc'] = '';
+        		$data[$k]['yes_date'] = '';
+        		$data[$k]['date'] = '';
+        		if ($v['type'] <= 3) {
+        			$data[$k]['name'] = $name . '兑换';
+
+        			if ($v['type'] == 1) {
+        				# 兑现申请
+        				$data[$k]['info'] = '本次兑现'.$name.' '.$v['score'].'枚,申请兑现';
+        				$data[$k]['date'] = $this->date($v['cdate']);
+        			} elseif ($v['type'] == 2) {
+        				# 兑现完成
+        				$data[$k]['info'] = '本次兑现'.$name.' '.$v['score'].'枚,兑现完成';
+        				$data[$k]['desc'] = '成功兑现¥'.$v['cash'].'元';
+
+        				# 完成时间
+        				$data[$k]['yes_date'] = $this->date($v['cdate']);
+        				$data[$k]['date'] = $this->date($v['cash_date']);
+        			} elseif ($v['type'] == 3) {
+        				# 兑现完成
+        				$data[$k]['info'] = '本次兑现'.$name.' '.$v['score'].'枚,兑现失败';
+        				$data[$k]['desc'] = $v['type_desc'];
+
+        				# 完成时间
+        				$data[$k]['yes_date'] = $this->date($v['cdate']);
+        				$data[$k]['date'] = $this->date($v['cash_date']);
+        			}
+
+        			if ($v['cash_type'] == 1) {
+        				$data[$k]['cash_desc'] = '微信';
+        			} else {
+        				$data[$k]['cash_desc'] = '支付宝';
+        			}
+
+
+        		} else {
+        			$data[$k]['date'] = $this->date($v['cdate']);
+
+        			if ($v['type'] == 4) {
+        				$task = Dever::db('task/info')->one($v['task_id']);
+        				$user = Dever::db('passport/user')->one($v['uid']);
+        				# 任务奖励
+        				$data[$k]['name'] = $name . '入账';
+        				$data[$k]['info'] = $name.$ext.',已入账';
+        				$data[$k]['desc'] = $user['username'] . '完成任务'.$task['name'].'的奖励';
+        			} elseif ($v['type'] == 5) {
+        				$task = Dever::db('task/info')->one($v['task_id']);
+        				$user = Dever::db('passport/user')->one($v['group_uid']);
+        				# 任务提成
+        				$data[$k]['name'] = $name . '入账';
+        				$data[$k]['info'] = $name.$ext.',已入账';
+        				$data[$k]['desc'] = $user['username'] . '完成任务'.$task['name'].'的提成奖励';
+        			} elseif ($v['type'] == 6) {
+        				$task = Dever::db('task/info')->one($v['task_id']);
+        				$user = Dever::db('passport/user')->one($v['group_uid']);
+        				# 系统奖励
+        				$data[$k]['name'] = $name . '入账';
+        				$data[$k]['info'] = $name.$ext.',已入账';
+        				$data[$k]['desc'] = '系统奖励:'.$v['type_desc'];
+        			}
+        		}
+        	}
+        }
+    }
+
+    private function date($value)
+    {
+    	return date('Y-m-d H:i', $value);
+    }
+}

+ 79 - 6
task/src/User.php

@@ -3,18 +3,91 @@
 namespace Task\Src;
 
 use Dever;
+use Task\Lib\Base;
 
-class User
+class User extends Base
 {
     /**
-     * 任务列表
+     * 用户资料
      *
      * @return mixed
      */
-    public function list()
+    public function one()
     {
-        $info = Dever::db(self::INFO);
-        $data = $info->state();
-        return $data;
+        # 检测用户是否认证
+        $where['uid'] = $this->data['uid'];
+        return Dever::db('task/user_info')->one($where);
+    }
+
+    /**
+     * 资料认证
+     *
+     * @return mixed
+     */
+    public function submit()
+    {
+        # 检测用户是否登录
+        $this->checkUser();
+        return $this->submit_action();
+    }
+
+    /**
+     * 立刻认证
+     *
+     * @return mixed
+     */
+    private function submit_action()
+    {
+        $user = $this->one();
+
+        $truename = Dever::input('truename');
+        $card = Dever::input('card');
+        $card_front = Dever::input('card_front');
+        $card_end = Dever::input('card_end');
+        $wechat = Dever::input('wechat');
+        $alipay = Dever::input('alipay');
+
+        if (!$truename) {
+            Dever::alert('真实姓名不能为空');
+        }
+
+        if (!$card) {
+            Dever::alert('身份证号不能为空');
+        }
+
+        if (!$card_front) {
+            Dever::alert('身份证正面不能为空');
+        }
+
+        if (!$card_end) {
+            Dever::alert('身份证反面不能为空');
+        }
+
+        if (!$wechat && !$alipay) {
+            Dever::alert('微信号或者支付宝账号不能为空');
+        }
+
+        if (!$user) {
+            $insert['uid'] = $this->data['uid'];
+            $insert['truename'] = $truename;
+            $insert['card'] = $card;
+            $insert['card_front'] = $card_front;
+            $insert['card_end'] = $card_end;
+            $insert['wechat'] = $wechat;
+            $insert['alipay'] = $alipay;
+            $insert['status'] = 1;
+            return Dever::db('task/user_info')->insert($insert);
+        } else {
+            $update['truename'] = $truename;
+            $update['card'] = $card;
+            $update['card_front'] = $card_front;
+            $update['card_end'] = $card_end;
+            $update['wechat'] = $wechat;
+            $update['alipay'] = $alipay;
+            $update['status'] = 1;
+            $update['where_id'] = $user['id'];
+            Dever::db('task/user_info')->update($update);
+            return $user['id'];
+        }
     }
 }