Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
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
3a670845
authored
Jan 19, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善上架校验
parent
7767996a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
18 deletions
app/Http/Controllers/Api/SkuApiController.php
app/Http/Services/SkuService.php
resources/views/script/BatchUpdateSkuStatusScript.blade.php
resources/views/script/SkuListScript.blade.php
app/Http/Controllers/Api/SkuApiController.php
View file @
3a670845
...
...
@@ -137,7 +137,10 @@ class SkuApiController extends Controller
$this
->
response
(
-
1
,
'请设置上架有效期'
);
}
}
(
new
SkuService
())
->
batchUpdateSkuStatus
(
$data
);
$result
=
(
new
SkuService
())
->
batchUpdateSkuStatus
(
$data
);
if
(
$result
!==
true
)
{
$this
->
response
(
-
1
,
$result
);
}
$this
->
response
(
0
,
'操作成功,请等待后台上下架任务完成刷新查看'
);
}
...
...
app/Http/Services/SkuService.php
View file @
3a670845
...
...
@@ -326,7 +326,6 @@ class SkuService extends BaseService
//批量更新sku状态,走队列的
public
function
batchUpdateSkuStatus
(
$data
)
{
try
{
$skuIds
=
explode
(
','
,
$data
[
'sku_ids'
]);
//上架时验证cp_time限制
if
(
$data
[
'operate_type'
]
==
SkuService
::
OPERATE_TYPE_PUTAWAY
)
{
...
...
@@ -336,11 +335,16 @@ class SkuService extends BaseService
$now
=
time
();
$redis
=
new
RedisModel
();
$skuList
=
$redis
->
hmget
(
'sku'
,
$skuIds
);
$skuList
=
array_map
(
function
(
$sku
)
{
return
\json_decode
(
$sku
,
true
);
},
$skuList
);
$skuList
=
array_filter
(
$skuList
,
function
(
$value
)
{
return
$value
;
});
$supplierCpTimeMap
=
SupplierChannelModel
::
select
(
'supplier_code'
,
'cp_time_day'
,
'futures_cp_time_day'
)
->
whereIn
(
'supplier_code'
,
array_column
(
$skuList
,
'canal'
))
->
pluck
(
'cp_time_day'
,
'supplier_code'
)
->
toArray
();
$supplierCpTimeMap
=
SupplierChannelModel
::
select
(
'supplier_code'
,
'cp_time_day'
,
'futures_cp_time_day'
)
->
whereIn
(
'supplier_code'
,
array_column
(
$skuList
,
'canal'
))
->
get
()
->
keyBy
(
'supplier_code'
)
->
toArray
();
foreach
(
$skuIds
as
$skuId
)
{
$sku
=
$redis
->
hget
(
'sku'
,
$skuId
);
$sku
=
\json_decode
(
$sku
,
true
);
//获取goods_tag信息
$goodsTagsStr
=
$redis
->
hget
(
'goods_tag'
,
$skuId
);
$isFutures
=
false
;
...
...
@@ -358,22 +362,24 @@ class SkuService extends BaseService
}
//获取SKU信息以获取供应商编码
$skuInfo
=
isset
(
$skuList
[
$skuId
])
?
json_decode
(
$skuList
[
$skuId
],
true
)
:
null
;
$skuInfo
=
$sku
;
if
(
!
$skuInfo
||
empty
(
$skuInfo
[
'canal'
]))
{
$invalidSkuIds
[]
=
$skuId
;
continue
;
}
$supplierCode
=
$skuInfo
[
'canal'
];
//获取对应的cp_time限制
if
(
!
isset
(
$supplierCpTimeMap
[
$supplierCode
]))
{
$invalidSkuIds
[]
=
$skuId
;
$invalidSkuIds
[]
=
[
'sku_id'
=>
$skuId
,
'supplier_code'
=>
$supplierCode
,
'cp_time_limit'
=>
''
,
];
continue
;
}
$cpTimeLimit
=
$isFutures
?
$supplierCpTimeMap
[
$supplierCode
][
'futures_cp_time_day'
]
:
$supplierCpTimeMap
[
$supplierCode
][
'cp_time_day'
];
// -1表示不限制
if
(
$cpTimeLimit
==
-
1
)
{
continue
;
...
...
@@ -381,19 +387,29 @@ class SkuService extends BaseService
//计算允许的最大cp_time(当前时间+限制天数)
$maxCpTime
=
$now
+
(
$cpTimeLimit
*
86400
);
//获取传入的cp_time(从请求中获取,这里假设传入的是2051193600)
$inputCpTime
=
$data
[
'cp_time'
];
//验证cp_time是否超过限制
if
(
!
$inputCpTime
)
{
$inputCpTime
=
100000000000
;
}
$inputCpTime
=
strtotime
(
$inputCpTime
);
if
(
$inputCpTime
>
$maxCpTime
)
{
$invalidSkuIds
[]
=
$skuId
;
$invalidSkuIds
[]
=
[
'sku_id'
=>
$skuId
,
'supplier_code'
=>
$supplierCode
,
'cp_time_limit'
=>
$cpTimeLimit
,
];
}
}
//如果有不符合要求的SKU,全部拒绝
if
(
!
empty
(
$invalidSkuIds
))
{
return
new
Exception
(
"以下SKU的cp_time超过限制:"
.
implode
(
'</br>'
,
$invalidSkuIds
));
$errorMessages
=
[];
foreach
(
$invalidSkuIds
as
$invalidSku
)
{
$errorMessages
[]
=
"SKU ID:
{
$invalidSku
[
'sku_id'
]
}
, 供应商编码:
{
$invalidSku
[
'supplier_code'
]
}
, 过期时间限制:
{
$invalidSku
[
'cp_time_limit'
]
}
天"
;
}
return
"以下SKU的过期时间超过限制:"
.
implode
(
'</br>'
,
$errorMessages
);
}
}
$supplierCodes
=
explode
(
','
,
$data
[
'supplier_codes'
]);
...
...
@@ -424,9 +440,6 @@ class SkuService extends BaseService
}
QueueService
::
publishQueueSecond
(
$queueName
,
$queueData
);
}
catch
(
\Exception
$exception
)
{
return
$exception
;
}
return
true
;
}
...
...
resources/views/script/BatchUpdateSkuStatusScript.blade.php
View file @
3a670845
...
...
@@ -51,7 +51,7 @@
success
:
function
(
res
)
{
if
(
res
.
err_code
===
0
)
{
admin
.
closeThisDialog
();
parent
.
layer
.
msg
(
res
.
err_msg
,
{
icon
:
6
});
layer
.
msg
(
res
.
err_msg
,
{
icon
:
6
});
}
else
{
layer
.
msg
(
res
.
err_msg
,
{
icon
:
5
});
}
...
...
resources/views/script/SkuListScript.blade.php
View file @
3a670845
...
...
@@ -396,7 +396,7 @@
if
(
status
!==
'offshelf'
)
{
layer
.
open
({
type
:
2
,
area
:
[
'
6
00px'
,
'500px'
],
area
:
[
'
8
00px'
,
'500px'
],
offset
:
'100px'
,
fixed
:
false
,
//不固定
maxmin
:
true
,
...
...
@@ -425,14 +425,14 @@
success
:
function
(
res
)
{
console
.
log
(
res
);
if
(
res
.
err_code
===
0
)
{
layer
.
msg
(
res
.
err_msg
,
{
icon
:
6
});
parent
.
layer
.
msg
(
res
.
err_msg
,
{
icon
:
6
});
table
.
reload
(
'skuList'
,
{
page
:
{
curr
:
currentPage
},
});
}
else
{
layer
.
msg
(
res
.
err_msg
,
{
icon
:
5
});
parent
.
layer
.
msg
(
res
.
err_msg
,
{
icon
:
5
});
return
false
;
}
}
...
...
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