189 lines
5.9 KiB
PHP
189 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace admin\models\forms\drug;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\Drug;
|
|
use yii\db\Exception;
|
|
|
|
class DrugForm extends BaseModel
|
|
{
|
|
public $id;
|
|
public $drug_name;
|
|
public $is_otc;
|
|
public $pinyin_simple;
|
|
public $drug_number;
|
|
public $bar_code;
|
|
public $specification;
|
|
public $guozi_no;
|
|
public $function;
|
|
public $source;
|
|
public $place;
|
|
public $category_first;
|
|
public $category_second;
|
|
public $instruction;
|
|
public $image;
|
|
public $type;
|
|
public $status;
|
|
public $usage;
|
|
public $drugstore;
|
|
public $unit_id;
|
|
public $frequency_id;
|
|
public $type_id;
|
|
public $time_id;
|
|
public $drug_alias;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id', 'type', 'unit_id', 'frequency_id', 'type_id', 'time_id'], 'integer'],
|
|
[['drugstore', 'place','drug_alias'], 'string'],
|
|
[['pinyin_simple', 'is_otc', 'drug_name', 'drug_number', 'bar_code', 'specification', 'guozi_no', 'function', 'source', 'instruction', 'type', 'usage', 'image', 'status', 'frequency_id', 'type_id'], 'required']
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'frequency_id'=>'使用频率',
|
|
'type_id'=>'使用方法',
|
|
'unit_id'=>'单位',
|
|
'time_id'=>'使用时间',
|
|
'drug_alias'=>'别名',
|
|
'place'=>'产地',
|
|
'drugstore'=>'仓库',
|
|
'pinyin_simple'=>'拼音首拼',
|
|
'is_otc'=>'是否处方药',
|
|
'drug_name'=>'药名',
|
|
'drug_number'=>'药品编号',
|
|
'usage'=>'用法',
|
|
'status'=>'状态 1草稿 2下架 3上架',
|
|
'image'=>'药品图片',
|
|
'instruction'=>'说明书图片',
|
|
'source'=>'货源(厂家)',
|
|
'function'=>'功能主治',
|
|
'guozi_no'=>'国字准号',
|
|
'specification'=>'规格',
|
|
'bar_code'=>'条形码',
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
if (!$this->validate()) {
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
$Drug = new Drug();
|
|
$Drug->attributes = $this->attributes;
|
|
|
|
$Drug->created_at = time();
|
|
$Drug->updated_at = time();
|
|
if (!$Drug->saveOrFail()) {
|
|
throw new Exception('新增失败');
|
|
}
|
|
|
|
// $decode=json_decode($this->drugstore,true);
|
|
//
|
|
// foreach ($decode as $value){
|
|
// $DrugStoreDrug = DrugStoreDrug::find()->where([
|
|
// 'drugstore_id' => $value['drugstore_id'],
|
|
// 'drug_id' => $DRUG->id,
|
|
// 'is_delete' => 0
|
|
// ])->one();
|
|
// if ($DrugStoreDrug) {
|
|
// $DrugStoreDrug ->is_delete=1;
|
|
// $DrugStoreDrug->saveOrFail();
|
|
// }
|
|
//
|
|
// $drug = new DrugStoreDrug();
|
|
// $drug->drugstore_id = $value['drugstore_id'];
|
|
// $drug->drug_id = $DRUG->id;
|
|
// $drug->type = $value['type'];
|
|
// $drug->price = $value['price'];
|
|
// $drug->stock =$value['stock'];
|
|
// $drug->saveOrFail();
|
|
// }
|
|
|
|
return ['新增成功'];
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
|
|
$drug = Drug::find()->where([
|
|
'id' => $this->id,
|
|
])->one();
|
|
|
|
if (!$drug) throw new Exception('该药品不存在');
|
|
|
|
$drug->type = $this->type ?? $drug->type;
|
|
$drug->drug_name = $this->drug_name ?? $drug->drug_name;
|
|
$drug->drug_number = $this->drug_number ?? $drug->drug_number;
|
|
$drug->bar_code = $this->bar_code ?? $drug->bar_code;
|
|
$drug->specification = $this->specification ?? $drug->specification;
|
|
$drug->guozi_no = $this->guozi_no ?? $drug->guozi_no;
|
|
$drug->source = $this->source ?? $drug->source;
|
|
$drug->function = $this->function ?? $drug->function;
|
|
$drug->image = $this->image ?? $drug->image;
|
|
$drug->usage = $this->usage ?? $drug->usage;
|
|
$drug->instruction = $this->instruction ?? $drug->instruction;
|
|
$drug->place = $this->place ?? $drug->place;
|
|
$drug->is_otc = $this->is_otc ?? $drug->is_otc;
|
|
$drug->status = $this->status ?? $drug->status;
|
|
$drug->place = $this->place ?? $drug->place;
|
|
$drug->time_id = $this->time_id ?? $drug->time_id;
|
|
$drug->type_id = $this->type_id ?? $drug->type_id;
|
|
$drug->frequency_id = $this->frequency_id ?? $drug->frequency_id;
|
|
$drug->unit_id = $this->unit_id ?? $drug->unit_id;
|
|
$drug->drug_alias = $this->drug_alias ?? $drug->drug_alias;
|
|
$drug->updated_at = time();
|
|
|
|
if (!$drug->saveOrFail()) {
|
|
throw new Exception('编辑失败');
|
|
}
|
|
return ['编辑成功'];
|
|
}
|
|
|
|
//上下架
|
|
public function IsSale()
|
|
{
|
|
$drug = Drug::find()->where([
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
])->one();
|
|
if (!$drug) throw new Exception('该药品不存在');
|
|
|
|
$drug->status = $this->status;
|
|
if (!$drug->saveOrFail()) throw new Exception('上下架失败');
|
|
|
|
return ['成功上下架'];
|
|
}
|
|
|
|
//基础药品-草稿
|
|
public function Draft()
|
|
{
|
|
$drug = Drug::find()->where([
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
])->one();
|
|
if (!$drug) throw new Exception('该药品不存在');
|
|
|
|
$drug->status = 1;
|
|
if (!$drug->saveOrFail()) throw new Exception('修改为草稿失败');
|
|
|
|
return ['成功修改为草稿'];
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$drug = Drug::find()->where([
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
])->one();
|
|
|
|
if (!$drug) throw new Exception('该药品不存在');
|
|
|
|
return $drug;
|
|
}
|
|
}
|