Commit e570ea22 by wang

存档

parent b02d98af
......@@ -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(saveLogHandle).OutPut(ctx)
common.NResponse(err.Error()).SetLogHandel(zySaveLogHandle).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(saveLogHandle).OpenParamLog().OutPut(ctx)
common.NResponse(err.ErrMsg,err.Code).SetLogHandel(zySaveLogHandle).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)
}
......@@ -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")
......
......@@ -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 zySkuEntityS,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
}
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
}
package model
package model
//php
/**
......
......@@ -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
......
......@@ -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.InsertDbGoods(zySkuEntity)
affected, err:=dao.UpdateDbGoods(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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment