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
e0705467
authored
Nov 29, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化药店药品数据
parent
6fb540e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
app/Console/Commands/InitPharmacyDrugCommand.php
+66
-0
No files found.
app/Console/Commands/InitPharmacyDrugCommand.php
0 → 100644
View file @
e0705467
<?php
namespace
App\Console\Commands
;
use
App\Models\PharmacyDrugModel
;
use
App\Models\PharmacyModel
;
use
Illuminate\Console\Command
;
class
InitPharmacyDrugCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'init:pharmacy_drug {pharmacy_id}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'药店药品复制'
;
/**
* Execute the console command.
*/
public
function
handle
()
{
$this
->
info
(
'开始药店药品复制...'
);
// 以药店1的药品为模板复制到其他药店
$pharmacy_id
=
$this
->
argument
(
'pharmacy_id'
)
??
0
;
if
(
intval
(
$pharmacy_id
)
<=
1
)
{
$this
->
info
(
'请输入正确的药店id'
);
return
;
}
// 查找一下传入的药店id是否存在
$pharmacy
=
PharmacyModel
::
where
(
'id'
,
$pharmacy_id
)
->
first
();
if
(
empty
(
$pharmacy
))
{
$this
->
info
(
'药店不存在,请重新输入'
);
return
;
}
$pharmacyDrugList
=
PharmacyDrugModel
::
where
(
'pharmacy_id'
,
1
)
->
get
();
if
(
$pharmacyDrugList
->
count
()
<=
0
)
{
$this
->
info
(
'模板药店药品为空'
);
return
;
}
foreach
(
$pharmacyDrugList
as
$pharmacyDrug
)
{
// 查找该药品在该药店是否存在,如果存在则跳过,如果不存在则复制
$is_exists
=
PharmacyDrugModel
::
where
(
'pharmacy_id'
,
$pharmacy_id
)
->
where
(
'drug_id'
,
$pharmacyDrug
->
drug_id
)
->
first
();
if
(
!
empty
(
$is_exists
))
{
continue
;
}
$newPharmacyDrug
=
new
PharmacyDrugModel
();
$newPharmacyDrug
->
pharmacy_id
=
$pharmacy_id
;
$newPharmacyDrug
->
drug_id
=
$pharmacyDrug
->
drug_id
;
$newPharmacyDrug
->
unit
=
$pharmacyDrug
->
unit
;
$newPharmacyDrug
->
save
();
}
}
}
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