Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
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
e570ea22
authored
Jan 06, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
存档
parent
b02d98af
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
123 additions
and
30 deletions
controller/sku_save_controller.go
dao/zy_brand.go
dao/zy_goods.go
dao/zy_history_price.go
model/zy_history_price.go
model/zy_sku.go
service/service_zy_save.go
controller/sku_save_controller.go
View file @
e570ea22
...
...
@@ -66,13 +66,13 @@ func SaveSku(ctx *gin.Context) {
}
}
//自营save_sku
func
SaveZySku
(
ctx
*
gin
.
Context
)
{
//参数验证
var
zySaveRequest
saveModel
.
ZySaveRequest
if
err
:=
ctx
.
ShouldBindBodyWith
(
&
zySaveRequest
,
binding
.
JSON
);
err
!=
nil
{
common
.
NResponse
(
err
.
Error
())
.
SetLogHandel
(
s
aveLogHandle
)
.
OutPut
(
ctx
)
common
.
NResponse
(
err
.
Error
())
.
SetLogHandel
(
zyS
aveLogHandle
)
.
OutPut
(
ctx
)
return
}
zySave
:=
service
.
ZySaveService
{}
...
...
@@ -80,7 +80,7 @@ func SaveZySku(ctx *gin.Context) {
//错误处理
if
(
serviceErr
!=
nil
){
if
err
,
ok
:=
serviceErr
.
(
*
e
.
ApiError
);
ok
{
common
.
NResponse
(
err
.
ErrMsg
,
err
.
Code
)
.
SetLogHandel
(
s
aveLogHandle
)
.
OpenParamLog
()
.
OutPut
(
ctx
)
common
.
NResponse
(
err
.
ErrMsg
,
err
.
Code
)
.
SetLogHandel
(
zyS
aveLogHandle
)
.
OpenParamLog
()
.
OutPut
(
ctx
)
return
}
}
...
...
@@ -119,6 +119,10 @@ func saveLogHandle(errMsg string) {
logger
.
Select
(
"lysku_save"
)
.
Error
(
errMsg
)
}
func
zySaveLogHandle
(
errMsg
string
)
{
logger
.
Select
(
"zysku_save"
)
.
Error
(
errMsg
)
}
func
editLogHandle
(
errMsg
string
)
{
logger
.
Select
(
"lysku_save"
)
.
Error
(
errMsg
)
}
dao/zy_brand.go
View file @
e570ea22
...
...
@@ -21,7 +21,6 @@ import (
查询BrandId,查询自营品牌映射(根据 supplier_id self_supplier_type self_supplier_id)
@param supplier_id 供应商ID
@param self_supplier_type 自采标记
@param self_supplier_id 自采供应商唯一商品ID(采集那边的id)
*/
func
GetBrandMappingId
(
supplierId
int
,
selfSupplierType
int
,
supplierBrandId
int
)
(
err
error
,
brandId
int64
)
{
redisReadConn
:=
gredis
.
Conn
(
"search_r"
)
...
...
dao/zy_goods.go
View file @
e570ea22
...
...
@@ -51,19 +51,18 @@ func GetSimilarGoods(selfSupplierType int,brandId int64) (zySkuEntity []model.Zy
whereStr
:=
"self_supplier_type =? and self_supplier_id ='' and brand_id=?"
err
=
dbSpu
.
Table
(
"lie_goods"
)
.
Where
(
whereStr
,
selfSupplierType
,
brandId
)
.
Find
(
&
zySkuEntityS
)
if
(
err
!=
nil
){
return
zySkuEntity
,
fmt
.
Errorf
(
"method:GetSimilarGoods,"
+
err
.
Error
())
return
zySkuEntity
S
,
fmt
.
Errorf
(
"method:GetSimilarGoods,"
+
err
.
Error
())
}
return
return
zySkuEntityS
,
nil
}
//插入自营sku到redis
func
InsertDbGoods
(
zySkuEntity
model
.
ZySkuEntity
)
(
affected
int64
,
err
error
)
{
//修改自营sku到mysql
func
UpdateDbGoods
(
zySkuEntity
model
.
ZySkuEntity
)
(
affected
int64
,
err
error
)
{
db
:=
mysql
.
Conn
(
"liexin_data"
)
//spu实例化链接
return
db
.
Table
(
"lie_goods"
)
.
Where
(
"goods_id=?"
,
zySkuEntity
.
GoodsId
)
.
Update
(
zySkuEntity
)
}
//插入自营sku到
mysql
//插入自营sku到
redis
func
InsertRedisGoods
(
zySkuEntity
model
.
ZySkuEntity
)
error
{
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
...
...
@@ -71,10 +70,24 @@ func InsertRedisGoods(zySkuEntity model.ZySkuEntity) error {
byte
,
err
:=
json
.
Marshal
(
zySkuEntity
)
if
(
err
!=
nil
){
return
fmt
.
Errorf
(
"method:InsertDbGoods,"
+
err
.
Error
())
return
fmt
.
Errorf
(
"method:InsertDbGoods,
对zySkuEntity json化出错,
"
+
err
.
Error
())
}
_
,
err
=
redisWriteConn
.
Do
(
"HSET"
,
"Self_SelfGoods"
,
zySkuEntity
.
GoodsId
,
string
(
byte
))
if
(
err
!=
nil
){
return
fmt
.
Errorf
(
"method:InsertRedisGoods,插入redis出错"
+
err
.
Error
())
}
return
err
}
//插入自营sku到DB
func
InsertDbGoods
(
zySkuEntity
model
.
ZySkuEntity
)
error
{
dbSpu
:=
mysql
.
Conn
(
"liexin_data"
)
//spu实例化链接
_
,
err
:=
dbSpu
.
Table
(
"lie_goods"
)
.
Insert
(
zySkuEntity
)
if
(
err
!=
nil
){
return
fmt
.
Errorf
(
"method:InsertDbGoods,"
+
err
.
Error
())
}
return
nil
}
dao/zy_history_price.go
0 → 100644
View file @
e570ea22
package
dao
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mysql"
)
//获取 redis hash Self_last_history_price
func
GetRedisHistoryPrice
(
goodsId
int
)
(
price
float64
,
err
error
)
{
redisReadConn
:=
gredis
.
Conn
(
"search_r"
)
defer
redisReadConn
.
Close
()
price
,
err
=
redis
.
Float64
(
redisReadConn
.
Do
(
"Hget"
,
"Self_last_history_price"
,
goodsId
))
if
(
err
!=
nil
){
if
(
err
==
redis
.
ErrNil
){
return
}
return
price
,
fmt
.
Errorf
(
"method:GetRedisHistoryPrice"
+
err
.
Error
())
}
return
}
//插入 redis hash Self_last_history_price
func
InsertRedisHistoryPrice
(
goodsId
int
,
price
float64
)
(
err
error
)
{
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
_
,
err
=
redisWriteConn
.
Do
(
"HSET"
,
"Self_last_history_price"
,
goodsId
,
price
)
if
(
err
!=
nil
){
if
(
err
==
redis
.
ErrNil
){
return
}
}
return
}
//插入历史价格到mysql
func
InsertDbHistoryPrice
(
zyHistoryPrice
model
.
ZyHistoryPrice
)
error
{
dbSpu
:=
mysql
.
Conn
(
"liexin_data"
)
//spu实例化链接
_
,
err
:=
dbSpu
.
Table
(
"lie_history_price"
)
.
Insert
(
zyHistoryPrice
)
if
(
err
!=
nil
){
return
fmt
.
Errorf
(
"method:GetDbBrand,"
+
err
.
Error
())
}
return
nil
}
model/zy_history_price.go
View file @
e570ea22
package
model
package
model
//php
/**
...
...
model/zy_sku.go
View file @
e570ea22
...
...
@@ -43,7 +43,7 @@ type ZySkuEntity struct {
GoodsName
string
`json:"goods_name" form:"goods_name" `
BrandId
int
`json:"brand_id" form:"brand_id" `
// 品牌ID
SupplierId
int
`json:"supplier_id" form:"supplier_id" `
//供应商ID
GoodsId
int
`json:"goods_id" form:"goods_id"`
GoodsId
int
`json:"goods_id" form:"goods_id"
xorm:"autoincr pk"
`
GoodsType
int
`json:"goods_type" form:"goods_type" `
//原厂条码,新增时默认goods_name
Barcode
string
`json:"barcode" form:"barcode" `
//原厂条码,新增时默认goods_name
PickType
int
`json:"pick_type" form:"pick_type"`
//供应商ID
...
...
service/service_zy_save.go
View file @
e570ea22
...
...
@@ -29,19 +29,16 @@ func (S *ZySaveService)SaveZySku(zySaveRequest saveModel.ZySaveRequest,ctx *gin.
zySkuEntity
,
err
:=
dao
.
GetZyGoodSInfoByCollect
(
zySaveRequest
.
SupplierId
,
zySaveRequest
.
SelfSupplierType
,
zySaveRequest
.
SelfSupplierId
)
e
.
CheckError
(
err
)
if
(
zySkuEntity
.
GoodsId
==
0
){
//参数验证(新增)
e
.
CheckError
(
S
.
addDataAlidator
(
zySaveRequest
))
//相似商品
e
.
CheckError
(
S
.
brandHandle
(
&
zySkuEntity
,
zySaveRequest
))
//查找相似商品必须要先获取到brandID
e
.
CheckError
(
S
.
brandHandle
(
&
zySkuEntity
,
&
zySaveRequest
))
//查找相似商品必须要先获取到brandID
SimilarGoods
,
err
:=
dao
.
GetSimilarGoods
(
zySaveRequest
.
SelfSupplierType
,
gconv
.
Int64
(
zySkuEntity
.
BrandId
))
e
.
CheckError
(
err
)
if
len
(
SimilarGoods
)
>
0
{
//
S
.
updateSimilarGoods
(
SimilarGoods
,
zySaveRequest
)
//修改相似商品
return
S
.
updateSimilarGoods
(
SimilarGoods
,
zySaveRequest
)
//修改相似商品
}
S
.
addGoods
(
zySkuEntity
,
zySaveRequest
)
//新增商品
}
else
{
//修改
S
.
updateGoods
(
zySkuEntity
,
zySaveRequest
)
//修改此商品
fmt
.
Print
(
"123123"
)
}
return
nil
}
...
...
@@ -63,9 +60,22 @@ func (S *ZySaveService) updateSimilarGoods(SimilarGoods []model.ZySkuEntity,zySa
/**
新增商品
*/
func
(
S
*
ZySaveService
)
addGoods
(
zySkuEntity
model
.
ZySkuEntity
,
zySaveRequest
saveModel
.
ZySaveRequest
)
{
fmt
.
Printf
(
"新增商品:%d"
,
777
)
//todo……
func
(
S
*
ZySaveService
)
addGoods
(
zySkuEntity
model
.
ZySkuEntity
,
zySaveRequest
saveModel
.
ZySaveRequest
)
error
{
err
:=
S
.
addDataAlidator
(
zySaveRequest
)
if
(
err
!=
nil
){
return
err
}
S
.
GoodsDataHandle
(
&
zySkuEntity
,
&
zySaveRequest
)
zySkuEntity
.
GoodsUnit
=
1
err
=
dao
.
InsertDbGoods
(
zySkuEntity
)
if
(
err
!=
nil
){
return
e
.
NewApiError
(
"新增sku 失败, msg:"
+
err
.
Error
(),
508002
)
}
err
=
dao
.
InsertRedisGoods
(
zySkuEntity
)
if
(
err
!=
nil
){
return
e
.
NewApiError
(
"新增sku 失败, msg:"
+
err
.
Error
(),
508002
)
}
return
nil
}
/**
...
...
@@ -74,7 +84,7 @@ func (S *ZySaveService)addGoods(zySkuEntity model.ZySkuEntity,zySaveRequest save
func
(
S
*
ZySaveService
)
updateGoods
(
zySkuEntity
model
.
ZySkuEntity
,
zySaveRequest
saveModel
.
ZySaveRequest
)
error
{
fmt
.
Printf
(
"修改商品:%d"
,
zySkuEntity
.
GoodsId
)
S
.
GoodsDataHandle
(
&
zySkuEntity
,
&
zySaveRequest
)
affected
,
err
:=
dao
.
Insert
DbGoods
(
zySkuEntity
)
affected
,
err
:=
dao
.
Update
DbGoods
(
zySkuEntity
)
if
(
err
!=
nil
)
{
return
e
.
NewApiError
(
"修改sku mysql数据失败 msg:"
+
err
.
Error
(),
508001
)
}
...
...
@@ -89,11 +99,12 @@ func (S *ZySaveService)updateGoods(zySkuEntity model.ZySkuEntity,zySaveRequest s
return
e
.
NewApiError
(
"修改sku redis数据失败 msg:"
+
err
.
Error
(),
508001
)
}
//存历史价格
S
.
historyPriceHandle
(
zySkuEntity
.
GoodsId
,
zySaveRequest
.
LadderPrice
)
if
(
err
!=
nil
){
return
e
.
NewApiError
(
"修改sku 历史价格出错 msg:"
+
err
.
Error
(),
508001
)
}
}
S
.
historyPriceHandle
(
zySkuEntity
.
GoodsId
,
zySaveRequest
.
LadderPrice
)
return
nil
//todo……
//获取映射品牌
}
...
...
@@ -106,7 +117,7 @@ func (S *ZySaveService) GoodsDataHandle(zySkuEntity *model.ZySkuEntity,zySaveReq
zySkuEntity
.
IsSelfName
=
1
zySkuEntity
.
IsPerfect
=
2
common
.
CopyStruct
(
&
zySaveRequest
,
zySkuEntity
)
common
.
CopyStruct
(
zySaveRequest
,
zySkuEntity
)
//品牌处理
e
.
CheckError
(
S
.
brandHandle
(
zySkuEntity
,
zySaveRequest
))
//分类处理
...
...
@@ -425,14 +436,31 @@ func (S *ZySaveService)addDataAlidator(Z saveModel.ZySaveRequest) error{
//历史价格处理 参照 项目 self_sku HistoryPriceModel.php 的 AddHistoryPrice(感觉是有问题,暂时按照PHP的业务来)
//
func
(
S
*
ZySaveService
)
historyPriceHandle
(
goodsId
int
,
LadderPrice
[]
model
.
LadderPrice
)
{
func
(
S
*
ZySaveService
)
historyPriceHandle
(
goodsId
int
,
LadderPrice
[]
model
.
LadderPrice
)
error
{
if
(
len
(
LadderPrice
)
>
0
){
sort
.
Sort
(
LadderPriceSorter
(
LadderPrice
))
ZyHistoryPrice
:=
model
.
ZyHistoryPrice
{}
ZyHistoryPrice
.
Price
=
LadderPrice
[
0
]
.
PriceCn
ZyHistoryPrice
.
Price
=
LadderPrice
[
0
]
.
PriceCn
//为啥第一个条数据的价格(不知道为啥是这个逻辑)
ZyHistoryPrice
.
GoodsId
=
goodsId
//todo 查 redis Self_last_history_price 的price 是否与此次 price相等,相等就不插入mysql,不相等就插入mysql(不知道为啥是这个逻辑)
//todo 插入mysql 的价格,只是排序后的阶梯价第一个条数据的价格(不知道为啥是这个逻辑)
//todo 查 redis Self_last_history_price(最后一次插入的历史价格) 的price 是否与阶梯价 price相等,
// 相等就不插入mysql,不相等就插入mysql(虽然知道这做法是防止重复插入,但只是防止最后一次插入不重复)
price
,
err
:=
dao
.
GetRedisHistoryPrice
(
goodsId
)
if
(
err
!=
nil
){
return
err
}
if
(
price
!=
ZyHistoryPrice
.
Price
){
//重复,不用插入(……)
err
:=
dao
.
InsertRedisHistoryPrice
(
goodsId
,
ZyHistoryPrice
.
Price
)
if
(
err
!=
nil
){
return
err
}
//todo 插入mysql 表 lie_history_price的价格
err
=
dao
.
InsertDbHistoryPrice
(
ZyHistoryPrice
)
if
(
err
!=
nil
){
return
err
}
}
}
return
nil
}
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