/** * 保存金钱 * @param bool $runValidation * @param null $attributeNames * @return bool * @throws HttpException */ public function saveMoney($runValidation = true, $attributeNames = null) { $this->trigger(self::EVENT_BEFORE_SAVE_MONEY); foreach ($this->_money as $money) { /** @var AssetMoney $money */ try { $money->save(); } catch (\Exception $e) { throw new HttpException(500, "程序错误"); break; } } $save = parent::save($runValidation, $attributeNames); $this->trigger(self::EVENT_AFTER_SAVE_MONEY); return $save; }
public function behaviors() { return Utils::behaviorMerge(self::className(), parent::behaviors()); }
public function beforeSave($insert) { if ($insert) { if (empty($this->code)) { $this->code = rand(1000, 9999); } if (empty($this->type)) { if ((new EmailValidator())->validate($this->field)) { $this->type = self::TYPE_EMAIL; } elseif (Utils::phoneVerify($this->field)) { $this->type = self::TYPE_PHONE; } else { throw new ErrorException('格式错误', ErrorCode::Vcode_not_field); } $this->_sendVcode(); } if ($insert) { $this->status = self::STATUS_VERIFY_UNSUCCESS; } } return parent::beforeSave($insert); }