门店仓库药品管理
This commit is contained in:
@@ -350,6 +350,48 @@ class ImportForm extends BaseModel
|
||||
}
|
||||
|
||||
public function ExportUpdateDrugPrice($data, $storeId)
|
||||
{
|
||||
if (empty($data)) {
|
||||
throw new Exception('导入数据为空');
|
||||
} else {
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
if (empty(trim($item['药品ID']))) {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:药品ID为空';
|
||||
continue;
|
||||
}
|
||||
if (empty(trim($item['销售价格']))) {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:药品价格为空【'. $item['销售价格'].'】';
|
||||
continue;
|
||||
}
|
||||
$DrugStoreDrug = DrugStoreDrug::find()->where(['drug_id' => trim($item['药品ID']), 'store_id' => $storeId])->one();
|
||||
|
||||
if ($DrugStoreDrug) {
|
||||
$DrugStoreDrug->setAttribute('drug_id', trim($item['药品ID']));
|
||||
$DrugStoreDrug->setAttribute('market_price', trim($item['销售价格']));
|
||||
$DrugStoreDrug->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
if (!$DrugStoreDrug->save()) {
|
||||
$errorsMsg = array_values($DrugStoreDrug->getFirstErrors());
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:保存失败;'.$errorsMsg[0];
|
||||
}else{
|
||||
$success[] = $item['药品ID'] . '导入成功!';
|
||||
}
|
||||
} else {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:未找到对应药品';
|
||||
}
|
||||
}
|
||||
$t->commit();
|
||||
} catch (\Exception $e) {
|
||||
$t->rollBack();
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
return ['success' => $success, 'error' => $errors];
|
||||
}
|
||||
}
|
||||
|
||||
public function ExportUpdateDrugPriceByStore($data, $storeId)
|
||||
{
|
||||
if (empty($data)) {
|
||||
throw new Exception('导入数据为空');
|
||||
|
||||
Reference in New Issue
Block a user