<?php
/**
 * 计划任务积分自动清零
 * @Copyright (C) 2017 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <xiaoq@570035208.com>
 */
namespace Common\Vendor\Cron;
class IntegralReset{
	/**
     * 计划任务积分自动清零
     */
    public function index($config_info){
    	if(!empty($config_info)){
    		$maps = $map = array();
	        $maps['classname'] = 'IntegralReset';
	        $corn = M('Cron')->where($maps)->field(true)->find();
	        $map['status'] = 1;
	        $member=M('Member')->where($map)->limit($corn['param1'],$corn['param2'])->field('id,usepoints')->select();
	        if($member){
		        foreach ($member as $k => $v) {
		        	account_change($v['id'],-$v['usepoints'],4,5,'积分到期自动清零');
		        }
		        $save['param1'] = $corn['param1'] + $corn['param2'];
		        M('Cron')->where($maps)->save($save);
		        $config_info['next_time'] = NOW_TIME;
		        $config_info['interval_time'] = 20;
		        $config_info['execute_time'] = 1;
		    }else{
		    	$save['param1'] = 0;
		    	M('Cron')->where($maps)->save($save);
		    	$config_info['next_time'] = NOW_TIME;
		        $config_info['interval_time'] = $corn['interval_time'];
		        $config_info['execute_time'] = $corn['execute_time'];
		    }
		    $config_info['id'] = $corn['id'];
			//更新计划任务
			updatetask($config_info);
		}else{return '';}
	}
}
?>