Commit 06f77153 by lujunyi

新增药店同步id=1的药店的药品

parent 076e42d0
......@@ -4,6 +4,7 @@
use App\Admin\Repositories\PharmacyRepository;
use App\Models\PharmacistModel;
use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel;
use App\Models\User;
use Dcat\Admin\Form;
......@@ -12,7 +13,6 @@
use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Models\Role;
use Dcat\Admin\Show;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
// 药店
......@@ -162,19 +162,24 @@ protected function form()
});
$form->saved(function (Form $form, $result) {
DB::beginTransaction();
try {
// 获取店铺管理员角色
$role = Role::where('slug', 'pharmacy')->first();
$pharmacyId = $form->getKey();
// 从表单模型获取手机号和其他信息
$mobile = $form->mobile;
$name = $form->name;
$pharmacyId = $form->getKey();
// 复制药店pharmacy_id=1的药店商品到新建药店
if ($form->isCreating()) {
$originalModels = PharmacyDrugModel::where('pharmacy_id', 1)->get();
foreach ($originalModels as $model) {
$pharmacyModel = $model->replicate();
$pharmacyModel->pharmacy_id = $pharmacyId;
$pharmacyModel->save();
}
}
// 获取店铺管理员角色
$role = Role::where('slug', 'pharmacy')->first();
// 查找当前是否已有管理员
$admin = Administrator::where('pharmacy_id', $pharmacyId)->first();
if ($admin) {
if ($mobile && $name) {
$admin->username = $mobile; // 更新账号
......@@ -194,11 +199,6 @@ protected function form()
$admin->roles()->attach($role->id);
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
throw new \Exception($e->getMessage());
}
});
// 右上角按钮控制
......
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