Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
go_supplier_sever
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
6cd9a63a
authored
May 21, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
线上测试
parent
e300fe09
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
8 deletions
app/dao/supplier.go
app/model/supplier.go
app/service/supplier_sku_mode.go
config/dev/config.toml
app/dao/supplier.go
View file @
6cd9a63a
...
@@ -263,6 +263,24 @@ func UpdateSupplierSkuLog(supplierId int, skuNum int) (err error) {
...
@@ -263,6 +263,24 @@ func UpdateSupplierSkuLog(supplierId int, skuNum int) (err error) {
return
return
}
}
// 修改sku_expired_in_days
func
UpdateSupplierSkuExpiredInDays
(
supplierId
,
skuExpiredInDays
int
)
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Get
(
supplier
)
if
supplier
.
SupplierId
==
0
{
return
err
}
if
err
!=
nil
{
return
err
}
supplier
.
SkuExpiredInDays
=
skuExpiredInDays
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
MustCols
(
"sku_expired_in_days"
)
.
Update
(
supplier
)
if
err
!=
nil
{
return
err
}
return
}
// 修改sku_mode
// 修改sku_mode
func
UpdateSupplierSkuMode
(
supplierId
,
skuMode
int
)
(
err
error
)
{
func
UpdateSupplierSkuMode
(
supplierId
,
skuMode
int
)
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
supplier
:=
new
(
model
.
Supplier
)
...
...
app/model/supplier.go
View file @
6cd9a63a
...
@@ -12,4 +12,5 @@ type Supplier struct {
...
@@ -12,4 +12,5 @@ type Supplier struct {
SkuCreateTime
int
SkuCreateTime
int
SkuUpdateTime
int
SkuUpdateTime
int
LastOrderTime
int
LastOrderTime
int
SkuExpiredInDays
int
}
}
app/service/supplier_sku_mode.go
View file @
6cd9a63a
...
@@ -2,18 +2,26 @@ package service
...
@@ -2,18 +2,26 @@ package service
import
(
import
(
"fmt"
"fmt"
"time"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/cfg/lib"
"github.com/imroc/req"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
)
)
//从ES统计出sku类型,然后写到供应商的sku_mode字段
//
从ES统计出sku类型,然后写到供应商的sku_mode字段
func
SaveSkuModeFromES
()
(
err
error
)
{
func
SaveSkuModeFromES
()
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
supplier
:=
new
(
model
.
Supplier
)
//先去根据供应商内部编码找出对应的supplierId
//先去根据供应商内部编码找出对应的supplierId
rows
,
err
:=
dao
.
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"is_type = ?"
,
0
)
.
OrderBy
(
"supplier_id desc"
)
.
Rows
(
supplier
)
rows
,
err
:=
dao
.
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
// Where("supplier_code = ?", "L0001175").
Where
(
"is_type = ?"
,
0
)
.
Where
(
"uploaded_sku = ?"
,
1
)
.
OrderBy
(
"supplier_id desc"
)
.
Rows
(
supplier
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -24,8 +32,9 @@ func SaveSkuModeFromES() (err error) {
...
@@ -24,8 +32,9 @@ func SaveSkuModeFromES() (err error) {
err
=
rows
.
Scan
(
supplier
)
err
=
rows
.
Scan
(
supplier
)
//去es查询sku数量
//去es查询sku数量
params
:=
req
.
Param
{
params
:=
req
.
Param
{
"status/condition"
:
1
,
"canal/condition"
:
supplier
.
SupplierCode
,
"canal/condition"
:
supplier
.
SupplierCode
,
"cp_time/sort"
:
"asc"
,
"cp_time/neq"
:
0
,
}
}
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
...
@@ -34,8 +43,9 @@ func SaveSkuModeFromES() (err error) {
...
@@ -34,8 +43,9 @@ func SaveSkuModeFromES() (err error) {
}
}
result
:=
resp
.
String
()
result
:=
resp
.
String
()
goodsIdArr
:=
gjson
.
Get
(
result
,
"data.goods_id"
)
.
Array
()
goodsIdArr
:=
gjson
.
Get
(
result
,
"data.goods_id"
)
.
Array
()
//fmt.Println("当前处理供应商为 : ", supplier.SupplierName)
//
fmt.Println("当前处理供应商为 : ", supplier.SupplierName)
if
len
(
goodsIdArr
)
>
0
{
if
len
(
goodsIdArr
)
>
0
{
fmt
.
Println
(
"存在商品"
)
//取一个goods_id就好
//取一个goods_id就好
goodsId
:=
goodsIdArr
[
0
]
.
String
()
goodsId
:=
goodsIdArr
[
0
]
.
String
()
//fmt.Println("skuId为 : " + goodsId)
//fmt.Println("skuId为 : " + goodsId)
...
@@ -57,11 +67,42 @@ func SaveSkuModeFromES() (err error) {
...
@@ -57,11 +67,42 @@ func SaveSkuModeFromES() (err error) {
return
err
return
err
}
}
}
}
//统计sku过期天数:ES已按cp_time升序排序,取第一个goods_id的cp_time即可
sku
:=
redisCon
.
HGet
(
"sku"
,
goodsId
)
.
String
()
skuExpiredInDays
:=
0
cpTime
:=
gjson
.
Get
(
sku
,
"cp_time"
)
.
Int
()
fmt
.
Println
(
"cpTime:"
,
cpTime
)
if
cpTime
>
0
{
//cp_time是时间戳,转成日期和当前日期对比计算天数
cpTimeDate
:=
time
.
Unix
(
cpTime
,
0
)
nowDate
:=
time
.
Now
()
//计算cp_time日期和当前日期的天数差
cpTimeDay
:=
time
.
Date
(
cpTimeDate
.
Year
(),
cpTimeDate
.
Month
(),
cpTimeDate
.
Day
(),
0
,
0
,
0
,
0
,
cpTimeDate
.
Location
())
nowDay
:=
time
.
Date
(
nowDate
.
Year
(),
nowDate
.
Month
(),
nowDate
.
Day
(),
0
,
0
,
0
,
0
,
nowDate
.
Location
())
daysDiff
:=
int
(
nowDay
.
Sub
(
cpTimeDay
)
.
Hours
()
/
24
)
//如果过期了(当前日期 > cp_time日期),则为正数,否则为0
if
daysDiff
>
0
{
skuExpiredInDays
=
daysDiff
}
}
if
skuExpiredInDays
>
0
{
fmt
.
Println
(
"sku过期天数 : "
,
skuExpiredInDays
)
}
err
=
dao
.
UpdateSupplierSkuExpiredInDays
(
supplier
.
SupplierId
,
skuExpiredInDays
)
if
err
!=
nil
{
return
err
}
}
else
{
}
else
{
err
=
dao
.
UpdateSupplierSkuMode
(
supplier
.
SupplierId
,
0
)
err
=
dao
.
UpdateSupplierSkuMode
(
supplier
.
SupplierId
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
//没有sku的那就是1000
err
=
dao
.
UpdateSupplierSkuExpiredInDays
(
supplier
.
SupplierId
,
1000
)
if
err
!=
nil
{
return
err
}
}
}
//time.Sleep(100 * time.Millisecond)
//time.Sleep(100 * time.Millisecond)
}
}
...
...
config/dev/config.toml
View file @
6cd9a63a
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
url
=
"amqp://guest:guest@192.168.1.252:5672/"
url
=
"amqp://guest:guest@192.168.1.252:5672/"
[es]
[es]
es_sku_url
=
"http://so.liexin.net/search/Es/searchSku"
es_sku_url
=
"https://icso.ichunt.com/search/es/searchSku"
\ No newline at end of file
\ No newline at end of file
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