108 lines
2.8 KiB
PHP
108 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace admin\models\forms\drug;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\Drug;
|
|
use yii\db\Exception;
|
|
|
|
//颗粒配方form
|
|
class ServerForm extends BaseModel
|
|
{
|
|
public $id;
|
|
public $drug_name;
|
|
public $drug_number;
|
|
public $drug_alias;
|
|
public $unit_id;
|
|
|
|
public $place;
|
|
public $image;
|
|
public $source;
|
|
public $instruction;
|
|
public $specification;
|
|
public $type;
|
|
public $usage;
|
|
public $function;
|
|
public $drugstore;
|
|
|
|
public $pinyin_simple;
|
|
|
|
public $is_otc;
|
|
public $status;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id','is_otc'],'integer'],
|
|
[['drug_name','drug_number','image','specification','pinyin_simple','function','status'],'required'],
|
|
[['place','source','instruction','drugstore','pinyin_simple','usage'],'string'],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'drug_name'=>'服务包',
|
|
'drug_number'=>'服务包编号',
|
|
'unit_id'=>'单位',
|
|
'pinyin_simple'=>'拼音首拼',
|
|
'status'=>'状态 1草稿 2下架 3上架',
|
|
];
|
|
}
|
|
public function save()
|
|
{
|
|
if (!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
$drug=new Drug();
|
|
$drug->attributes=$this->attributes;
|
|
$drug->specification = $this->specification;
|
|
$drug->usage = $this->usage;
|
|
$drug->type = '5';
|
|
$drug->created_at=time();
|
|
$drug->saveOrFail();
|
|
|
|
$t->commit();
|
|
return ['新增成功'];
|
|
}catch (\Exception $e){
|
|
$t->rollBack();
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$drug=Drug::find()->where([
|
|
'id'=>$this->id,
|
|
'type'=>3,
|
|
])->one();
|
|
if (!$drug) throw new Exception('该服务包不存在');
|
|
$drug->pinyin_simple=$this->pinyin_simple??$drug->pinyin_simple;
|
|
$drug->status=$this->status??$drug->status;
|
|
$drug->drug_name=$this->drug_name??$drug->drug_name;
|
|
$drug->drug_number=$this->drug_number??$drug->drug_number;
|
|
$drug->drug_alias=$this->drug_alias??$drug->drug_alias;
|
|
$drug->unit_id=$this->unit_id??$drug->unit_id;
|
|
$drug->place=$this->place??$drug->place;
|
|
$drug->source=$this->source??$drug->source;
|
|
$drug->instruction=$this->instruction??$drug->instruction;
|
|
|
|
$drug->saveOrFail();
|
|
return ['编辑成功'];
|
|
}
|
|
|
|
|
|
public function info()
|
|
{
|
|
$drug= Drug::find()->where([
|
|
'id'=>$this->id,
|
|
'type'=>3,
|
|
])->one();
|
|
if (!$drug) throw new Exception('该服务包不存在');
|
|
return $drug;
|
|
}
|
|
|
|
} |