<?php
class currencyModel extends CI_Model
{
	public function __construct(){
        parent::__construct();
        $this->load->model('oo');
    }
    
    
    
    /**
     * Notes:定时创建流水表
     * User: wsc
     * Time: 2020/6/12 19:44
     * @param string $do
     */
    public function cronCreatAssessTable($do="false"){
        if(date('w',time())==5||$do){
            $sql = oo::cfg('sql')['assetslog'];
            for($i=1;$i<8;$i++){
                $d = date("Ymd",time()+$i*86400);
//                $tb = 'assetslog_'.$d;
//                $query = str_replace('#table#', $tb, $sql);
//                $res = funs::createTable("crazygod_log.".$tb,$query);
                //oo::logs()->commlog("Create Table {$tb} Res:{$res}",'createAssessTable');
//                logMessage('createtable',"Create Table {$tb} Res:{$res}");
                for($j=0;$j<10;$j++){
                    $tb = 'assetslog_'.$d.'_'.$j;
                    $query = str_replace('#table#', $tb, $sql);
                    $res = funs::createTable("crazygod_log.".$tb,$query);
                    //oo::logs()->commlog("Create Table {$tb} Res:{$res}",'createAssessTable');
//                    logMessage('createtable',"Create Table {$tb} Res:{$res}");
                }
            }
        }
    }

    /**
     * Notes:定时创建活动流水表
     * User: wsc
     * Time: 2021/3/23 20:46
     * @param string $do
     */
    public function cronCreatActAssessTable($do="false"){
        if(date('w',time())==5||$do){
            $sql = oo::cfg('sql')['act_assetslog'];
            for($i=1;$i<8;$i++){
                $d = date("Ymd",time()+$i*86400);
                $tb = 'act_assetslog_'.$d;
                $query = str_replace('#table#', $tb, $sql);
                $res = funs::createTable("crazygod_log.".$tb,$query);
            }
        }
    }
    /**
     * Notes:定时创建每日盈亏统计记录表
     * User: Hss
     * Time: 2020/6/12 19:44
     * @param string $do
     */
    public function cronCreatSpinsAddLowTable($do="false"){
        if(date('w',time())==5||$do){
            $sql = oo::cfg('sql')['today_spinslog'];
            for($i=1;$i<8;$i++){
                $d = date("Ymd",time()+$i*86400);
                $tb = 'today_spinslog_'.$d;
                $query = str_replace('#table#', $tb, $sql);
                $res = funs::createTable("crazygod_log.".$tb,$query);
                //oo::logs()->commlog("Create Table {$tb} Res:{$res}",'createAssessTable');
//                logMessage('createtable',"Create Table {$tb} Res:{$res}");
            }
        }
    }

    /**
     * Notes:定时删除用户流水表
     * User: Hss
     * Time: 2021/2/1 15:50
     * @param string $do
     */
    public function delLog($date = ''){
        if(empty($date)){
            $date = date('Ymd', strtotime("-8 day"));
        }
        $count = 0;
        for($i = 1;$i <= 10;$i++){
            $tb = otable::Assetslog($date,$i);
            $sql = "DROP TABLE {$tb}";
            $ret = oo::commonOprDb('log')->query($sql);
            $ret && $count++;
        }

        oo::logs()->debug3(["time"=>time(),"date"=>$date,"count"=>$count],'delLog');
    }
}
