Commit 8eeac34b by lujunyi

导入药店复制药品用量

parent f883b50a
......@@ -2,6 +2,8 @@
namespace App\Admin\Extensions\ToolBar\Forms;
use App\Models\DosageModel;
use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Widgets\Form;
......@@ -36,10 +38,12 @@ public function handle(array $input): JsonResponse
return is_string($value) ? trim($value) : $value;
}, $row);
$pharmacyModel = null;
$flagNew = false;
if (isset($item['药店管理员手机号']) && $item['药店管理员手机号']) {
$pharmacyModel = PharmacyModel::where('mobile', $item['药店管理员手机号'])->first();
}
if (! $pharmacyModel) {
$flagNew = true;
$pharmacyModel = new PharmacyModel;
}
$pharmacyModel->name = $item['药店名称'] ?? 0;
......@@ -51,6 +55,22 @@ public function handle(array $input): JsonResponse
if ($pharmacyModel->save()) {
$successNum++;
}
if ($flagNew) {
// 复制药品
$originalPharmacyModels = PharmacyDrugModel::where('pharmacy_id', 1)->get();
foreach ($originalPharmacyModels as $originalPharmacyModel) {
$pharmacyNewModel = $originalPharmacyModel->replicate();
$pharmacyNewModel->pharmacy_id = $pharmacyModel->id;
$pharmacyNewModel->save();
}
// 复制用法用量
$originalDosageModels = DosageModel::where('pharmacy_id', 1)->get();
foreach ($originalDosageModels as $dosageModel) {
$dosageNewModel = $dosageModel->replicate();
$dosageNewModel->pharmacy_id = $pharmacyModel->id;
$dosageNewModel->save();
}
}
}
});
$return = $this->response()->success("导入成功{$successNum}条")->refresh();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment