73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace admin\models\forms\drug;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\BaseConfig;
|
|
use yii\db\Exception;
|
|
|
|
//协议Form
|
|
class AgreeForm extends BaseModel
|
|
{
|
|
public $id;
|
|
|
|
public $end;
|
|
public $desc;
|
|
public $type;
|
|
public $content;
|
|
public $status;
|
|
public $change_at;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id', 'status', 'end', 'type', 'change_at','end'], 'integer'],
|
|
[['desc', 'content'], 'string'],
|
|
[['content', 'type'], 'required'],
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
if (!$this->validate()) {
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
|
|
if (!$this->id) {
|
|
$BaseConfig = new BaseConfig();
|
|
} else {
|
|
$BaseConfig = BaseConfig::find()->where([
|
|
'id' => $this->id,
|
|
])->one();
|
|
if (!$BaseConfig) {
|
|
throw new Exception('协议不存在');
|
|
}
|
|
}
|
|
|
|
$BaseConfig->end = $this->end ?? $BaseConfig->end;
|
|
$BaseConfig->desc = $this->desc ?? $BaseConfig->desc;
|
|
$BaseConfig->type = $this->type ?? $BaseConfig->type;
|
|
$BaseConfig->content = $this->content ?? $BaseConfig->content;
|
|
$BaseConfig->change_at = time();
|
|
$BaseConfig->saveOrFail();
|
|
|
|
return ['success'];
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
$BaseConfig = BaseConfig::find()->where([
|
|
'id' => $this->id
|
|
])->one();
|
|
|
|
if (!$BaseConfig) {
|
|
throw new Exception('协议不存在');
|
|
}
|
|
|
|
$BaseConfig->status = 1;
|
|
if (!$BaseConfig->saveOrFail()) {
|
|
throw new Exception('删除失败');
|
|
}
|
|
return ['已删除'];
|
|
}
|
|
} |