Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d3eaacd5
authored
Nov 25, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.imohe.com/zhaozengyu/tzt-admin
parents
778e3a2c
06f77153
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
36 deletions
+36
-36
app/Admin/Controllers/PharmacyController.php
+36
-36
No files found.
app/Admin/Controllers/PharmacyController.php
View file @
d3eaacd5
...
@@ -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,42 +162,42 @@ protected function form()
...
@@ -162,42 +162,42 @@ protected function form()
});
});
$form
->
saved
(
function
(
Form
$form
,
$result
)
{
$form
->
saved
(
function
(
Form
$form
,
$result
)
{
DB
::
beginTransaction
();
$pharmacyId
=
$form
->
getKey
();
try
{
// 从表单模型获取手机号和其他信息
// 获取店铺管理员角色
$mobile
=
$form
->
mobile
;
$role
=
Role
::
where
(
'slug'
,
'pharmacy'
)
->
first
();
$name
=
$form
->
name
;
// 复制药店pharmacy_id=1的药店商品到新建药店
// 从表单模型获取手机号和其他信息
if
(
$form
->
isCreating
())
{
$mobile
=
$form
->
mobile
;
$originalModels
=
PharmacyDrugModel
::
where
(
'pharmacy_id'
,
1
)
->
get
();
$name
=
$form
->
name
;
foreach
(
$originalModels
as
$model
)
{
$pharmacyId
=
$form
->
getKey
();
$pharmacyModel
=
$model
->
replicate
();
$pharmacyModel
->
pharmacy_id
=
$pharmacyId
;
// 查找当前是否已有管理员
$pharmacyModel
->
save
();
$admin
=
Administrator
::
where
(
'pharmacy_id'
,
$pharmacyId
)
->
first
();
}
}
if
(
$admin
)
{
if
(
$mobile
&&
$name
)
{
// 获取店铺管理员角色
$admin
->
username
=
$mobile
;
// 更新账号
$role
=
Role
::
where
(
'slug'
,
'pharmacy'
)
->
first
();
$admin
->
name
=
$name
;
// 更新账号姓名
// 查找当前是否已有管理员
$admin
->
save
();
$admin
=
Administrator
::
where
(
'pharmacy_id'
,
$pharmacyId
)
->
first
();
}
if
(
$admin
)
{
}
else
{
if
(
$mobile
&&
$name
)
{
if
(
$mobile
&&
$name
&&
$pharmacyId
)
{
$admin
->
username
=
$mobile
;
// 更新账号
$admin
=
new
Administrator
();
$admin
->
name
=
$name
;
// 更新账号姓名
$admin
->
username
=
$mobile
;
// 药店手机号作为管理员账号
$admin
->
save
();
$admin
->
name
=
$name
;
// 药店名称当做用户的姓名
}
$admin
->
password
=
bcrypt
(
Str
::
random
(
10
));
// 设置管理员密码
}
else
{
$admin
->
pharmacy_id
=
$pharmacyId
;
// 药店ID
if
(
$mobile
&&
$name
&&
$pharmacyId
)
{
$admin
->
save
();
// 保存新管理员
$admin
=
new
Administrator
();
$admin
->
username
=
$mobile
;
// 药店手机号作为管理员账号
// 关联药店管理员角色
$admin
->
name
=
$name
;
// 药店名称当做用户的姓名
$admin
->
roles
()
->
attach
(
$role
->
id
);
$admin
->
password
=
bcrypt
(
Str
::
random
(
10
));
// 设置管理员密码
}
$admin
->
pharmacy_id
=
$pharmacyId
;
// 药店ID
$admin
->
save
();
// 保存新管理员
// 关联药店管理员角色
$admin
->
roles
()
->
attach
(
$role
->
id
);
}
}
DB
::
commit
();
}
catch
(
\Exception
$e
)
{
DB
::
rollBack
();
throw
new
\Exception
(
$e
->
getMessage
());
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment