<?php

namespace common\helpers\bonus\Calc;


use common\helpers\Date;
use common\models\Period;

class BasePerfBusiness extends BaseBusiness
{
    protected $_periodNum = 0;

    protected $_calc_db_name = 'dbCalcServer';

    protected $_limit = 10000;


    public function __construct($periodNum)
    {
        parent::__construct($periodNum);
    }

    public function setCalcStatus($type)
    {
        if ($type == 'start') {
            Period::updateAll(['IS_PERFING' => 1, 'IS_PERFED' => Period::PERF_NONE, 'PERF_STARTED_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
        } elseif ($type == 'end') {
            Period::updateAll(['IS_PERFING' => 0, 'IS_PERFED' => Period::PERF_FINISH, 'PERFED_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
        } elseif ($type == 'fail') {
            Period::updateAll(['IS_PERFING' => 0, 'IS_PERFED' => Period::PERF_FAIL, 'PERFED_AT' => 0], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
        }
    }
}
