Ejemplo n.º 1
0
 public function recordOne($state = false)
 {
     if (!$this->schemeId) {
         $scheme = new Scheme();
         $scheme->level = Scheme::LEVEL_ONE;
     } else {
         $scheme = Scheme::findOne($this->schemeId);
     }
     $scheme->usageModeId = $this->usageModeId;
     $scheme->name = $this->name;
     $scheme->payMoney = $this->payMoney;
     $scheme->rebate = $this->rebate;
     $scheme->rebateSelf = $this->rebateSelf;
     $scheme->startDate = $this->startDate;
     $scheme->endDate = $this->endDate;
     if ($state) {
         $checkResult = Scheme::checkScheme($scheme->usageModeId, $this->startDate, $this->endDate);
         //检查方案冲突
         if ($checkResult) {
             CommonFunctions::createAlertMessage("方案设置失败,启用的方案中存在与想要设置的方案时间存在冲突,冲突方案名称是:" . $checkResult, "error");
             return true;
         }
         $scheme->state = Scheme::STATE_ABLE;
     } else {
         $scheme->state = Scheme::STATE_DISABLE;
     }
     if (!$scheme->save()) {
         throw new Exception("practice-form scheme save error");
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * 更新状态
  * @param $schemeId
  * @param $newState
  * @return bool
  * @throws Exception
  * @throws \Exception
  */
 public static function updateState($schemeId, $newState)
 {
     $scheme = Scheme::findOne($schemeId);
     if (!$scheme) {
         throw new Exception("Scheme id not exist");
     }
     if ($newState == Scheme::STATE_ABLE) {
         $checkResult = Scheme::checkScheme($scheme->usageModeId, $scheme->startDate, $scheme->endDate);
         //更新开启状态前检查冲突
         if ($checkResult) {
             return "方案启用失败,启用的方案中存在与想要设置的方案时间存在冲突,冲突方案名称是:" . $checkResult;
         }
     }
     $scheme->state = $newState;
     if (!$scheme->update()) {
         throw new Exception("ExamTemplate update error");
     }
     return false;
 }