| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 | 
							- <?php
 
- namespace Task\Lib;
 
- use Dever;
 
- # 放到计划任务中的:
 
- # task/lib/cron.clearTask 一天一次 86400
 
- # task/lib/cron.task_commit 任务报告完成 1个小时1次 3600
 
- # task/lib/cron.cash_commit 兑现审核完成 1个小时1次 3600
 
- class Cron
 
- {
 
- 	/**
 
- 	 * 将过期的任务,置为已结束,建议一天运行一次
 
- 	 *
 
- 	 * @return mixed
 
- 	 */
 
- 	public function clearTask()
 
- 	{
 
- 		$data = Dever::db('task/info')->gets();
 
-         $time = time();
 
-         foreach ($data as $k => $v) {
 
-             # 未开始的变成进行中
 
-             $update['where_id'] = $v['id'];
 
-             if ($v['status'] == 2 && $v['sdate'] >= $time) {
 
-                 $update['status'] = 1;
 
-                 Dever::db('task/info')->update($update);
 
-             } elseif ($v['status'] == 1 && $v['edate'] < $time) {
 
-                 $update['status'] = 3;
 
-                 Dever::db('task/info')->update($update);
 
-             }
 
-         }
 
- 	}
 
- 	/**
 
-      * 资料认证审核后的操作
 
-      *
 
-      * @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->updateMsg($v['uid'], $v['score'], 4, $v['task_id']);
 
- 				$this->group($v['uid'], $v['group_score'], $v['task_id'], $v['id'], 1);
 
-     		}
 
-     	}
 
-     	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']);
 
-                 $this->updateMsg($v['uid'], $v['score'], 2, false, false, $v['type'], $v['cash'], $v['cdate']);
 
-                 $this->sendSms($v['uid'], $v['cash']);
 
-     		}
 
-     	}
 
-     	# 失败
 
-     	$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']);
 
-                 $this->updateMsg($v['uid'], $v['score'], 3, false, false, $v['type'], $v['cash'], $v['cdate'], $v['status_desc']);
 
-     		}
 
-     	}
 
-     	return 'yes';
 
-     }
 
-     # 发短信
 
-     private function sendSms($uid, $cash)
 
-     {
 
-         $user = Dever::db('passport/user')->one($uid);
 
-         if ($user && isset($user['mobile']) && $user['mobile']) {
 
-             $url = Dever::load("passport/reg.getUrl", "passport/reg.getMCodeLogin", array("skin" => "cash", "sid" => Dever::id()));
 
-             $url .= '&mobile=' . $user['mobile'] . '&type=msg&content=' . $cash;
 
-             return Dever::daemon($url);
 
-         }
 
-     }
 
-     /**
 
-      * 寻找这个用户的上线 给上线带来收益
 
-      *
 
-      * @return mixed
 
-      */
 
-     private function group($uid, $score, $task_id, $report_id, $level = 1)
 
-     {
 
-     	$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, 1, 0, 0, '', $uid);
 
-                 $this->updateMsg($group_info['uid'], $score, 5, $task_id, $uid);
 
-                 # 继续寻找上线,带来收益
 
-                 $config = Dever::config('base')->level;
 
-                 $level = $level + 1;
 
-                 if ($config >= $level) {
 
-                     $this->group($group_info['uid'], $score, $task_id, $report_id, $level);
 
-                 }
 
- 			}
 
- 		}
 
-     }
 
-     /**
 
-      * 更新用户积分数量
 
-      *
 
-      * @return mixed
 
-      */
 
-     private function updateUserScore($uid, $score)
 
-     {
 
-     	$update['where_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 = '', $group_uid = false)
 
-     {
 
-     	$insert = array();
 
- 		$insert['type'] = $type;
 
- 		$insert['status'] = $status;
 
- 		$insert['score'] = $score;
 
- 		$insert['uid'] = $uid;
 
-         $insert['group_uid'] = $group_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);
 
-     }
 
-     /**
 
-      * 日志记录
 
-      *
 
-      * @return mixed
 
-      */
 
-     private function updateMsg($uid, $score, $type, $task_id = -1, $group_uid = false, $cash_type = 1, $cash = 0, $cash_date = 0, $desc = '')
 
-     {
 
-         $config = Dever::db('main/config')->one();
 
-         if ($type == 4 || $type == 5) {
 
-             $task = Dever::db('task/info')->one($task_id);
 
-             # 完成任务
 
-             $desc = '';
 
-             if ($type == 5) {
 
-                 $desc = '提成';
 
-                 $user = Dever::db('passport/user')->one($group_uid);
 
-             } else {
 
-                 $user = Dever::db('passport/user')->one($uid);
 
-             }
 
-             
 
-             $name = $config['score_name'] . '入账通知';
 
-             $content = '入账'.$config['score_name'].':'.$score.$config['score_name'].'
 
-                     <br /> '.$config['score_name'].'来源:'.$user['username'].'完成任务#'.$task['name'].'的'.$desc.'奖励
 
-                     <br /> 入账时间:' . date('Y-m-d H:i');
 
-         }
 
-         if ($cash_type == 1) {
 
-             $cash_type = '微信';
 
-         } else {
 
-             $cash_type = '支付宝';
 
-         }
 
-         if ($type == 2) {
 
-             $name = $config['score_name'].'兑现成功通知';
 
-             $content = '本次兑现:'.$score.$config['score_name'].'
 
-             <br />兑现途径:'.$cash_type.'
 
-             <br />申请兑现时间:' . date('Y-m-d H:i', $cash_date).'
 
-             <br />兑现完成时间:' . date('Y-m-d H:i');
 
-         }
 
-         if ($type == 3) {
 
-             $name = $config['score_name'].'兑现失败通知';
 
-             $content = '本次兑现:'.$score.$config['score_name'].'
 
-             <br />兑现途径:'.$cash_type.'
 
-             <br />申请兑现时间:' . date('Y-m-d H:i', $cash_date).'
 
-             <br />'.$desc;
 
-         }
 
-         
 
-         $type = 11;
 
-         if (isset($name)) {
 
-             Dever::load('message/lib/data.push', -1, $uid, $name, $content, $type);
 
-         }
 
-     }
 
- }
 
 
  |