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) {
$state = $this->updateUserScore($v['uid'], $v['score']);
if ($state) {
$update['where_id'] = $v['id'];
$update['score_status'] = 2;
Dever::db('task/user_report')->update($update);
$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)
{
if ($score > 0) {
$update['where_uid'] = $uid;
$update['score'] = $score;
$update['time'] = Dever::id();
return Dever::db('task/user_score')->updateScore($update);
}
return false;
}
/**
* 日志记录
*
* @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'].'
'.$config['score_name'].'来源:'.$user['username'].'完成任务#'.$task['name'].'的'.$desc.'奖励
入账时间:' . 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'].'
兑现途径:'.$cash_type.'
申请兑现时间:' . date('Y-m-d H:i', $cash_date).'
兑现完成时间:' . date('Y-m-d H:i');
}
if ($type == 3) {
$name = $config['score_name'].'兑现失败通知';
$content = '本次兑现:'.$score.$config['score_name'].'
兑现途径:'.$cash_type.'
申请兑现时间:' . date('Y-m-d H:i', $cash_date).'
'.$desc;
}
$type = 11;
if (isset($name)) {
Dever::load('message/lib/data.push', -1, $uid, $name, $content, $type);
}
}
}