导入测试
This commit is contained in:
@@ -6,6 +6,7 @@ use common\core\BaseModel;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\models\Drug;
|
||||
use common\models\DrugStoreDrug;
|
||||
use common\models\DrugStoreRelations;
|
||||
use common\models\Platform;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
use yii\db\Exception;
|
||||
@@ -347,4 +348,37 @@ class ImportForm extends BaseModel
|
||||
return ['success' => $success, 'error' => $errors];
|
||||
}
|
||||
}
|
||||
|
||||
public function ExportUpdateDrugPrice($data, $storeId)
|
||||
{
|
||||
if (empty($data)) {
|
||||
throw new Exception('导入数据为空');
|
||||
} else {
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
$DrugStoreDrug = DrugStoreRelations::find()->where(['drug_id' => trim($item['药品ID']), 'store_id' => $storeId])->one();
|
||||
|
||||
if ($DrugStoreDrug) {
|
||||
$model = new DrugStoreRelations();
|
||||
$model->setAttribute('drug_id', trim($item['药品ID']));
|
||||
$model->setAttribute('price', trim($item['销售价格']));
|
||||
if (!$model->save()) {
|
||||
$errorsMsg = array_values($model->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];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user