产品服务包,分账
This commit is contained in:
@@ -24,6 +24,9 @@ class ServerForm extends BaseModel
|
||||
public $usage;
|
||||
public $function;
|
||||
public $drugstore;
|
||||
public $platform_ledger;
|
||||
public $store_ledger;
|
||||
public $supplier_ledger;
|
||||
|
||||
public $pinyin_simple;
|
||||
|
||||
@@ -34,7 +37,7 @@ class ServerForm extends BaseModel
|
||||
{
|
||||
return [
|
||||
[['id','is_otc'],'integer'],
|
||||
[['drug_name','drug_number','image','specification','pinyin_simple','function','status'],'required'],
|
||||
[['drug_name','drug_number','image','specification','pinyin_simple','platform_ledger','store_ledger','supplier_ledger','function','status'],'required'],
|
||||
[['place','source','instruction','drugstore','pinyin_simple','usage'],'string'],
|
||||
];
|
||||
}
|
||||
@@ -55,13 +58,22 @@ class ServerForm extends BaseModel
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
$ledgerTotal = $this->platform_ledger + $this->store_ledger + $this->supplier_ledger;
|
||||
|
||||
if ($ledgerTotal>100 || $ledgerTotal<0) {
|
||||
throw new Exception('分账比例之和不能大于100或小于0');
|
||||
}
|
||||
$t = \Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
$drug=new Drug();
|
||||
$drug->attributes=$this->attributes;
|
||||
$drug->specification = $this->specification;
|
||||
$drug->usage = $this->usage;
|
||||
$drug->platform_ledger = $this->platform_ledger;
|
||||
$drug->store_ledger = $this->store_ledger;
|
||||
$drug->supplier_ledger = $this->supplier_ledger;
|
||||
$drug->type = '5';
|
||||
|
||||
$drug->created_at=time();
|
||||
$drug->saveOrFail();
|
||||
|
||||
@@ -75,9 +87,14 @@ class ServerForm extends BaseModel
|
||||
|
||||
public function update()
|
||||
{
|
||||
$ledgerTotal = $this->platform_ledger + $this->store_ledger + $this->supplier_ledger;
|
||||
|
||||
if ($ledgerTotal>100 || $ledgerTotal<0) {
|
||||
throw new Exception('分账比例之和不能大于100或小于0');
|
||||
}
|
||||
$drug=Drug::find()->where([
|
||||
'id'=>$this->id,
|
||||
'type'=>3,
|
||||
'type'=>5,
|
||||
])->one();
|
||||
if (!$drug) throw new Exception('该服务包不存在');
|
||||
$drug->pinyin_simple=$this->pinyin_simple??$drug->pinyin_simple;
|
||||
@@ -89,6 +106,10 @@ class ServerForm extends BaseModel
|
||||
$drug->place=$this->place??$drug->place;
|
||||
$drug->source=$this->source??$drug->source;
|
||||
$drug->instruction=$this->instruction??$drug->instruction;
|
||||
$drug->platform_ledger = $this->platform_ledger;
|
||||
$drug->store_ledger = $this->store_ledger;
|
||||
$drug->supplier_ledger = $this->supplier_ledger;
|
||||
|
||||
|
||||
$drug->saveOrFail();
|
||||
return ['编辑成功'];
|
||||
|
||||
Reference in New Issue
Block a user