初始化仓库
This commit is contained in:
73
admin/models/forms/drug/AgreeForm.php
Normal file
73
admin/models/forms/drug/AgreeForm.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace admin\models\forms\drug;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\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 ['已删除'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user