Commit d3eaacd5 by 赵增煜
parents 778e3a2c 06f77153
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
use App\Admin\Repositories\PharmacyRepository; use App\Admin\Repositories\PharmacyRepository;
use App\Models\PharmacistModel; use App\Models\PharmacistModel;
use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel; use App\Models\PharmacyModel;
use App\Models\User; use App\Models\User;
use Dcat\Admin\Form; use Dcat\Admin\Form;
...@@ -12,7 +13,6 @@ ...@@ -12,7 +13,6 @@
use Dcat\Admin\Models\Administrator; use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Models\Role; use Dcat\Admin\Models\Role;
use Dcat\Admin\Show; use Dcat\Admin\Show;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str; use Illuminate\Support\Str;
// 药店 // 药店
...@@ -162,19 +162,24 @@ protected function form() ...@@ -162,19 +162,24 @@ protected function form()
}); });
$form->saved(function (Form $form, $result) { $form->saved(function (Form $form, $result) {
DB::beginTransaction(); $pharmacyId = $form->getKey();
try {
// 获取店铺管理员角色
$role = Role::where('slug', 'pharmacy')->first();
// 从表单模型获取手机号和其他信息 // 从表单模型获取手机号和其他信息
$mobile = $form->mobile; $mobile = $form->mobile;
$name = $form->name; $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(); $admin = Administrator::where('pharmacy_id', $pharmacyId)->first();
if ($admin) { if ($admin) {
if ($mobile && $name) { if ($mobile && $name) {
$admin->username = $mobile; // 更新账号 $admin->username = $mobile; // 更新账号
...@@ -194,11 +199,6 @@ protected function form() ...@@ -194,11 +199,6 @@ protected function form()
$admin->roles()->attach($role->id); $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