Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
note-library
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e00dcea4
authored
Feb 22, 2023
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
打印标签
parent
0a0304df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
12 deletions
app/Http/Controllers/ApiController.php
app/Http/Controllers/Controller.php
app/Services/LabelService.php
public/.htaccess
app/Http/Controllers/ApiController.php
View file @
e00dcea4
...
@@ -36,15 +36,38 @@ Class ApiController extends Controller
...
@@ -36,15 +36,38 @@ Class ApiController extends Controller
* @param Request $request
* @param Request $request
*/
*/
public
function
tryPrintLabel
(
Request
$request
){
public
function
tryPrintLabel
(
Request
$request
){
$list
=
$request
->
input
(
"list"
,
0
);
$list
=
$request
->
input
(
"list"
,[]);
if
(
empty
(
$list
)){
return
$this
->
setError
(
"请求平台打印失败:打印数据不能为空"
);
}
foreach
(
$list
as
&
$item
){
if
(
intval
(
$item
[
"print_num"
])
<=
0
){
$item
[
"print_num"
]
=
1
;
}
elseif
(
intval
(
$item
[
"print_num"
])
>=
100
){
$item
[
"print_num"
]
=
100
;
//单个明细限制100
}
}
if
(
count
(
$list
)
>
150
){
//所有型号数限制150
return
$this
->
setError
(
"请求平台打印失败:型号明细总数超过150了"
);
}
$templateIdList
=
array_pluck
(
$list
,
"template_id"
);
$templateIdListSearch
=
LabelService
::
getTemplateIds
(
$templateIdList
);
foreach
(
$templateIdList
as
$temptId
){
if
(
!
in_array
(
$temptId
,
$templateIdListSearch
)){
return
$this
->
setError
(
sprintf
(
"请求平台打印失败:标签模板id:%s不存在"
,
$temptId
));
}
}
$data
=
json_encode
(
$list
);
$data
=
json_encode
(
$list
);
$key
=
LabelService
::
tryPrintLabel
(
$data
);
$key
=
LabelService
::
tryPrintLabel
(
$data
);
if
(
empty
(
$key
)){
if
(
empty
(
$key
)){
return
[
'code'
=>-
1
,
"msg"
=>
"请求平台打印失败"
,
'data'
=>
[]]
;
return
$this
->
setError
(
"请求平台打印失败"
)
;
}
else
{
}
else
{
return
[
'code'
=>
0
,
"msg"
=>
"请求平台打印成功"
,
'data'
=>
[
return
$this
->
setSuccessData
(
"url"
=>
config
(
"website.erp_print_url"
)
.
"/api/print_label?key="
.
(
string
)
$key
[
"url"
=>
config
(
"website.erp_print_url"
)
.
"/api/print_label?key="
.
(
string
)
$key
],
0
,
0
,
"请求打印成功"
]]
;
)
;
}
}
}
}
...
...
app/Http/Controllers/Controller.php
View file @
e00dcea4
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
App\Http\ApiHelper\ApiCode
;
use
Illuminate\Foundation\Bus\DispatchesJobs
;
use
Illuminate\Foundation\Bus\DispatchesJobs
;
use
Illuminate\Routing\Controller
as
BaseController
;
use
Illuminate\Routing\Controller
as
BaseController
;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
...
@@ -10,4 +11,46 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
...
@@ -10,4 +11,46 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class
Controller
extends
BaseController
class
Controller
extends
BaseController
{
{
use
AuthorizesRequests
,
DispatchesJobs
,
ValidatesRequests
;
use
AuthorizesRequests
,
DispatchesJobs
,
ValidatesRequests
;
public
function
setSuccess
(
$msg
=
'操作成功'
,
$code
=
0
,
$data
=
[])
{
$res_data
=
[
"code"
=>
$code
,
"msg"
=>
$msg
,
'data'
=>
(
object
)
$data
,
];
return
response
()
->
json
(
$res_data
);
}
public
function
setError
(
$msg
,
$code
=
-
1
,
$data
=
[])
{
$res_data
=
[
"code"
=>
$code
,
"msg"
=>
$msg
,
];
if
(
$data
)
{
$res_data
[
'data'
]
=
$data
;
}
return
response
()
->
json
(
$res_data
);
}
public
function
setSuccessData
(
$data
=
[],
$count
=
0
,
$code
=
0
,
$msg
=
'ok'
)
{
$res_data
=
[
"code"
=>
$code
,
"data"
=>
$data
,
];
if
(
$msg
)
{
$res_data
[
'msg'
]
=
$msg
;
}
if
(
$count
)
{
$res_data
[
'count'
]
=
$count
;
}
return
response
()
->
json
(
$res_data
);
}
}
}
app/Services/LabelService.php
View file @
e00dcea4
...
@@ -206,7 +206,7 @@ class LabelService {
...
@@ -206,7 +206,7 @@ class LabelService {
public
static
function
tryPrintLabel
(
$data
){
public
static
function
tryPrintLabel
(
$data
){
$key
=
self
::
getErpPrintLabelRedisKey
();
$key
=
self
::
getErpPrintLabelRedisKey
();
Redis
::
setEx
(
$key
,
3600
*
24
*
5
,
$data
);
Redis
::
setEx
(
$key
,
3600
*
24
,
$data
);
return
$key
;
return
$key
;
}
}
...
@@ -216,9 +216,6 @@ class LabelService {
...
@@ -216,9 +216,6 @@ class LabelService {
$template_ids
=
[];
$template_ids
=
[];
foreach
(
$datas
as
$item
){
foreach
(
$datas
as
$item
){
if
(
intval
(
$item
[
"template_id"
])
<=
0
){
throw
new
\Exception
(
"没有找到对应的标签模板id"
);
}
array_push
(
$template_ids
,
$item
[
"template_id"
]);
array_push
(
$template_ids
,
$item
[
"template_id"
]);
}
}
...
@@ -228,9 +225,6 @@ class LabelService {
...
@@ -228,9 +225,6 @@ class LabelService {
$returnHtml
=
[];
$returnHtml
=
[];
foreach
(
$datas
as
$item
){
foreach
(
$datas
as
$item
){
$pringNums
=
$item
[
"print_num"
];
$pringNums
=
$item
[
"print_num"
];
if
(
intval
(
$pringNums
)
>
50
){
$pringNums
=
50
;
}
for
(
$i
=
0
;
$i
<=
$pringNums
;
$i
++
){
for
(
$i
=
0
;
$i
<=
$pringNums
;
$i
++
){
$html
=
$templateList
[
$item
[
"template_id"
]][
"template_extend"
][
"html"
];
$html
=
$templateList
[
$item
[
"template_id"
]][
"template_extend"
][
"html"
];
$createHtml
=
(
new
\App\Services\LabelService
)
->
getLabelOfflineHtml
(
$html
,
$item
);
$createHtml
=
(
new
\App\Services\LabelService
)
->
getLabelOfflineHtml
(
$html
,
$item
);
...
@@ -242,4 +236,9 @@ class LabelService {
...
@@ -242,4 +236,9 @@ class LabelService {
}
}
return
$returnHtml
;
return
$returnHtml
;
}
}
public
static
function
getTemplateIds
(
$templateIdList
){
$templateListIds
=
TemplateListModel
::
whereIn
(
"id"
,
$templateIdList
)
->
where
(
"status"
,
1
)
->
pluck
(
"id"
)
->
toArray
();
return
$templateListIds
;
}
}
}
\ No newline at end of file
public/.htaccess
View file @
e00dcea4
<
IfModule
mod_rewrite.c
>
<
IfModule
mod_negotiation.c
>
Options
-MultiViews -Indexes
</
IfModule
>
RewriteEngine
On
# Handle Authorization Header
RewriteCond
%{HTTP:Authorization} .
RewriteRule
.* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteCond
%{REQUEST_URI} (.+)/$
RewriteRule
^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteRule
^ index.php [L]
</
IfModule
>
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