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
ed25d4f7
authored
Nov 20, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
7日内限购
parent
e51250b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
app/Api/Controllers/DrugController.php
+20
-0
No files found.
app/Api/Controllers/DrugController.php
View file @
ed25d4f7
...
@@ -6,9 +6,11 @@
...
@@ -6,9 +6,11 @@
use
App\Models\DrugModel
;
use
App\Models\DrugModel
;
use
App\Models\PharmacyDrugModel
;
use
App\Models\PharmacyDrugModel
;
use
App\Models\PharmacyModel
;
use
App\Models\PharmacyModel
;
use
App\Models\PrescriptionModel
;
use
App\Models\User
;
use
App\Models\User
;
use
App\Services\SmsService
;
use
App\Services\SmsService
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Carbon
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
// 药品控制器
// 药品控制器
...
@@ -93,6 +95,24 @@ public function drugLimit(Request $request)
...
@@ -93,6 +95,24 @@ public function drugLimit(Request $request)
if
(
$drug
&&
$drug
->
limit_buy_7
>
0
)
{
if
(
$drug
&&
$drug
->
limit_buy_7
>
0
)
{
$limit_num
=
$drug
->
limit_buy_7
;
$limit_num
=
$drug
->
limit_buy_7
;
}
}
$patient_id
=
$request
->
input
(
'patient_id'
);
$sevenDaysAgo
=
Carbon
::
now
()
->
subDays
(
7
);
$prescriptions
=
PrescriptionModel
::
where
(
'patient_id'
,
$patient_id
)
->
where
(
'created_at'
,
'>='
,
$sevenDaysAgo
)
->
get
();
$drugCounts
=
[];
foreach
(
$prescriptions
as
$prescription
)
{
$drugs
=
json_decode
(
$prescription
->
drugs
,
true
);
// Parse JSON data
foreach
(
$drugs
as
$drug
)
{
$drugId
=
$drug
[
'drug_id'
];
$drugCounts
[
$drugId
]
=
(
$drugCounts
[
$drugId
]
??
0
)
+
$drug
[
'num'
];
}
}
$purchaseCount
=
$drugCounts
[
$drug_id
]
??
0
;
// 计算获取剩余可买的次数
$limit_num
=
$limit_num
-
$purchaseCount
;
return
$this
->
success
(
$limit_num
);
return
$this
->
success
(
$limit_num
);
...
...
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