<?php
namespace common\models\forms;

use common\helpers\user\Perf;
use common\models\CalcBonus;
use common\models\CalcBonusFX;
use common\models\CalcBonusQY;
use common\models\CalcBonusYC;
use common\models\CFLXAudit;
use common\models\ExcelAddUser;
use common\models\ExcelImport;
use common\models\FlowBonus;
use common\models\FlowCF;
use common\models\FlowLX;
use common\models\InvoiceAudit;
use common\models\InvoiceBalanceAudit;
use common\models\InvoiceFlow;
use common\models\Message;
use common\models\MessageText;
use common\models\PerfAudit;
use common\models\PerfCompany;
use common\models\PerfMonth;
use common\models\PerfOrder;
use common\models\PerfPeriod;
use common\models\ReconsumeAudit;
use common\models\ReconsumePool;
use common\models\ReconsumePoolFlow;
use common\models\RegInfoAudit;
use common\models\ResendQY;
use common\models\DecOrder;
use common\models\Transfer;
use common\models\User;
use common\models\UserBind;
use common\models\UserBonus;
use common\models\UserClose;
use common\models\UserMove;
use common\models\UserNetwork;
use common\models\UserPerf;
use common\models\UserPerfUpdate;
use common\models\UserRelation;
use common\models\UserStatusAudit;
use common\models\UserSystem;
use common\models\UserTeamwork;
use common\models\UserToken;
use common\models\Withdraw;
use Yii;
use common\components\Model;
use common\models\Period;
use common\models\UserInfo;

/**
 * Login form
 */
class ClearDataForm extends Model
{

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
        ];
    }


    public function clear(){
        $userAddSqls = [
            "INSERT INTO AR_USER_INFO (USER_ID, USER_NAME, ZC_PV, CON_UID, REC_UID, CON_NUM, REC_NUM, NETWORK_DEEP, RELATION_DEEP, SYSTEM_ID, IS_TEAM, IS_BIND, IS_TEAM_MAIN, IS_BIND_MAIN, IS_AUTO_WITHDRAW, CLOSE_LOGIN, REG_TYPE, REG_NAME, CREDIT_CODE, PREMISES, LEGAL_PERSON, REG_EXPIRES, STORE_TYPE, INVOICE_BALANCE, PERIOD_NUM, CREATED_AT, UPDATED_AT, CLOSE_LOGIN_AT, PULLED_AT) VALUES ('670B84FD7C216D4EE055736AECE8644D', 'tester001', 600.000, '0', '0', 3, 3, 0, 0, null, 0, 0, 0, 0, 1, 0, '56D9181C0F5D428FA2DBD4CAB263BF2F', null, null, null, null, null, 2, 0.00, 100, 1520667339, 0, 0, 1548917447)",
            "INSERT INTO AR_USER_INFO (USER_ID, USER_NAME, ZC_PV, CON_UID, REC_UID, CON_NUM, REC_NUM, NETWORK_DEEP, RELATION_DEEP, SYSTEM_ID, IS_TEAM, IS_BIND, IS_TEAM_MAIN, IS_BIND_MAIN, IS_AUTO_WITHDRAW, CLOSE_LOGIN, REG_TYPE, REG_NAME, CREDIT_CODE, PREMISES, LEGAL_PERSON, REG_EXPIRES, STORE_TYPE, INVOICE_BALANCE, PERIOD_NUM, CREATED_AT, UPDATED_AT, CLOSE_LOGIN_AT, PULLED_AT) VALUES ('B322C18F7E274A9D9FC5DADC3B385E8B', 'tester002', 101000.000, '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 0, 0, 1, 1, null, 0, 0, 0, 0, 0, 0, '56D9181C0F5D428FA2DBD4CAB263BF2F', null, null, null, null, null, 0, 0.00, 100, 1524560688, 0, 0, 1546569294)",
            "INSERT INTO AR_USER_INFO (USER_ID, USER_NAME, ZC_PV, CON_UID, REC_UID, CON_NUM, REC_NUM, NETWORK_DEEP, RELATION_DEEP, SYSTEM_ID, IS_TEAM, IS_BIND, IS_TEAM_MAIN, IS_BIND_MAIN, IS_AUTO_WITHDRAW, CLOSE_LOGIN, REG_TYPE, REG_NAME, CREDIT_CODE, PREMISES, LEGAL_PERSON, REG_EXPIRES, STORE_TYPE, INVOICE_BALANCE, PERIOD_NUM, CREATED_AT, UPDATED_AT, CLOSE_LOGIN_AT, PULLED_AT) VALUES ('638A5A3B617F46C999C5E4D072EED369', 'tester003', 101000.000, '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 0, 0, 1, 1, null, 0, 0, 0, 0, 0, 0, '56D9181C0F5D428FA2DBD4CAB263BF2F', null, null, null, null, null, 0, 0.00, 100, 1524620621, 0, 0, 0)",
            "INSERT INTO AR_USER_INFO (USER_ID, USER_NAME, ZC_PV, CON_UID, REC_UID, CON_NUM, REC_NUM, NETWORK_DEEP, RELATION_DEEP, SYSTEM_ID, IS_TEAM, IS_BIND, IS_TEAM_MAIN, IS_BIND_MAIN, IS_AUTO_WITHDRAW, CLOSE_LOGIN, REG_TYPE, REG_NAME, CREDIT_CODE, PREMISES, LEGAL_PERSON, REG_EXPIRES, STORE_TYPE, INVOICE_BALANCE, PERIOD_NUM, CREATED_AT, UPDATED_AT, CLOSE_LOGIN_AT, PULLED_AT) VALUES ('3C313C66D1724D658BF10B08194022BB', 'tester004', 101000.000, '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 0, 0, 1, 1, null, 0, 0, 0, 0, 0, 0, '56D9181C0F5D428FA2DBD4CAB263BF2F', null, null, null, null, null, 0, 0.00, 100, 1524621346, 0, 0, 0)"
        ];
        $userNetworkSqls = [
            "INSERT INTO AR_USER_NETWORK (ID, USER_ID, PARENT_UID, LOCATION, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('D2DCC45A9B3A414F80F4239521A9744A', '638A5A3B617F46C999C5E4D072EED369', '670B84FD7C216D4EE055736AECE8644D', 2, '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524620621, 0)",
            "INSERT INTO AR_USER_NETWORK (ID, USER_ID, PARENT_UID, LOCATION, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('E953B0CA08B74D9DB722813E9297BAF2', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D', 1, '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524560688, 0)",
            "INSERT INTO AR_USER_NETWORK (ID, USER_ID, PARENT_UID, LOCATION, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('8F793577F2A44947A5918852976AE290', '670B84FD7C216D4EE055736AECE8644D', '0', 0, '670B84FD7C216D4EE055736AECE8644D', 0, 100, 1522378282, 0)",
            "INSERT INTO AR_USER_NETWORK (ID, USER_ID, PARENT_UID, LOCATION, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('707F8F4ADEA14A4EA98ABC9A99999C7B', '3C313C66D1724D658BF10B08194022BB', '670B84FD7C216D4EE055736AECE8644D', 3, '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524621346, 1549072802)"
        ];
        $userRelationSqls = ["INSERT INTO AR_USER_RELATION (ID, USER_ID, PARENT_UID, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('392F8963D2A4489F8854FC12A4D9E2F6', '638A5A3B617F46C999C5E4D072EED369', '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524620621, 0)",
            "INSERT INTO AR_USER_RELATION (ID, USER_ID, PARENT_UID, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('EBBD679E049C4B60993FFB751C7AF410', '3C313C66D1724D658BF10B08194022BB', '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524621346, 0)",
            "INSERT INTO AR_USER_RELATION (ID, USER_ID, PARENT_UID, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('585A9E67D922443698C09D99A32F33A9', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D', '670B84FD7C216D4EE055736AECE8644D', 1, 100, 1524560688, 0)",
            "INSERT INTO AR_USER_RELATION (ID, USER_ID, PARENT_UID, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('EF010C38C7144BD0844593A1FF8AC7AD', '670B84FD7C216D4EE055736AECE8644D', '0', '670B84FD7C216D4EE055736AECE8644D', 0, 100, 1522378282, 0)"
        ];
//        UserInfo::updateAll(['CON_NUM' => 3, 'REC_NUM' => 3, 'NETWORK_DEEP'=>0, 'RELATION_DEEP'=>0], 'USER_ID=:USER_ID', [':USER_ID'=>'670B84FD7C216D4EE055736AECE8644D']);
//        UserInfo::deleteAll("USER_ID NOT IN ('638A5A3B617F46C999C5E4D072EED369', '3C313C66D1724D658BF10B08194022BB', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D')");
//        UserNetwork::deleteAll("USER_ID NOT IN ('638A5A3B617F46C999C5E4D072EED369', '3C313C66D1724D658BF10B08194022BB', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D')");
//        UserRelation::deleteAll("USER_ID NOT IN ('638A5A3B617F46C999C5E4D072EED369', '3C313C66D1724D658BF10B08194022BB', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D')");
//        UserInfo::updateAll(['CON_NUM' => 0, 'REC_NUM' => 0, 'IS_TEAM'=>0, 'IS_BIND'=>0, 'IS_TEAM_MAIN'=>0, 'IS_BIND_MAIN'=>0, 'IS_AUTO_WITHDRAW'=>0, 'CLOSE_LOGIN'=>0, 'REG_TYPE'=>'56D9181C0F5D428FA2DBD4CAB263BF2F', 'REG_NAME'=>null], "USER_ID IN ('638A5A3B617F46C999C5E4D072EED369', '3C313C66D1724D658BF10B08194022BB', 'B322C18F7E274A9D9FC5DADC3B385E8B')");
        UserInfo::deleteAll('1=1');
        UserNetwork::deleteAll('1=1');
        UserRelation::deleteAll('1=1');
        foreach($userAddSqls as $value){
            Yii::$app->db->createCommand($value)->query();
        }
        foreach($userNetworkSqls as $value){
            Yii::$app->db->createCommand($value)->query();
        }
        foreach($userRelationSqls as $value){
            Yii::$app->db->createCommand($value)->query();
        }
//        Period::updateAll(['IS_CLOSED'=>0, 'IS_CALCULATED'=>0, 'IS_SENT'=>0, 'IS_CALCING'=>0, 'CALCULATED_AT'=>null, ], '1=1');
        CalcBonus::deleteAll('1=1');
        CalcBonusFX::deleteAll('1=1');
        CalcBonusQY::deleteAll('1=1');
        CalcBonusYC::deleteAll('1=1');
        CFLXAudit::deleteAll('1=1');
        ExcelAddUser::deleteAll('1=1');
        ExcelImport::deleteAll('1=1');
        FlowBonus::deleteAll('1=1');
        FlowCF::deleteAll('1=1');
        FlowLX::deleteAll('1=1');
        InvoiceAudit::deleteAll('1=1');
        InvoiceBalanceAudit::deleteAll('1=1');
        InvoiceFlow::deleteAll('1=1');
        Message::deleteAll('1=1');
        MessageText::deleteAll('1=1');
        PerfAudit::deleteAll('1=1');
        PerfCompany::deleteAll('1=1');
        PerfMonth::deleteAll('1=1');
        PerfOrder::deleteAll('1=1');
        PerfPeriod::deleteAll('1=1');
        ReconsumeAudit::deleteAll('1=1');
        ReconsumePool::deleteAll('1=1');
        ReconsumePoolFlow::deleteAll('1=1');
        RegInfoAudit::deleteAll('1=1');
        ResendQY::deleteAll('1=1');
        Transfer::deleteAll('1=1');
        UserBind::deleteAll('1=1');
        UserBonus::deleteAll('1=1');
        UserClose::deleteAll('1=1');
        UserMove::deleteAll('1=1');
        UserPerf::deleteAll('1=1');
        UserPerfUpdate::deleteAll('1=1');
        UserStatusAudit::deleteAll('1=1');
        UserSystem::deleteAll('1=1');
        UserTeamwork::deleteAll('1=1');
        UserToken::deleteAll('1=1');
        Withdraw::deleteAll('1=1');

        // 商城表
        User::deleteAll("ID NOT IN ('638A5A3B617F46C999C5E4D072EED369', '3C313C66D1724D658BF10B08194022BB', 'B322C18F7E274A9D9FC5DADC3B385E8B', '670B84FD7C216D4EE055736AECE8644D')");
        DecOrder::deleteAll('1=1');

        return true;
    }
}
