<?php

namespace app\sever\controller;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use \think\Controller;
class Sever extends Commone{
    //验证key是否正确
    private function key(){
        if ('sadhsajhddsa324gusandjsakughdk23' != $this->request->get('key')) exit('密钥错误');
    }
    
    //计划任务处理订单过期
    public function order_renwu(){
        
        ini_set('max_execution_time','0');
        $this->key();
        
        $order_time = config_set('order_time_set');
        $time = intval($order_time['value']) * 60;
        //先将所有过期订单列出来
        $timeTakes = intval(time()-$time);
        $where['order_time'] = ['<',$timeTakes];
        $where['state'] = 1;
        Db::name('orders')->where($where)->update(array("state"=>3));//将过期的订单pass
        $this->land_renwu();
        echo '---'.date('H:i:s',time()).'已执行订单过期操作---';
        
        
    }
    
    //释放限量的账户
    public function land_renwu(){
        ini_set('max_execution_time','0');
        $this->key();
        //先将所有限量账号列出来
        $land_list = Db::name('land')->limit(10000)->where('ds_status',1)->select();
        foreach ($land_list as $value) {
            $ds_time = time()-$value['ds_status_time'];
            if($ds_time > ($value['ds_time']*60)){
                //释放限量
                Db::name('land')->where('id',$value['id'])->update(['ds_status'=>0,'ds_status_time'=>time()]);
            }
        }
        echo '---'.date('H:i:s',time()).'已执行释放限量账户操作---';
    }
    
    
    public function reback_renwu(){
        ini_set('max_execution_time','0');
        $order_id = $this->request->get('order_id');
        $order_list = Db::name('orders')->where('num',$order_id)->find();
        $user = Db::name('user')->where('id',$order_list['userid'])->find();
        api_request($order_list['id'],$user);
        
    }
    
   

}