Commit 9e4a418b by mushishixian

修复

parent 0b90376f
...@@ -26,7 +26,6 @@ func main() { ...@@ -26,7 +26,6 @@ func main() {
web.Handler(r), web.Handler(r),
web.Address(":"+port), web.Address(":"+port),
) )
if err := service.Init(); err != nil { if err := service.Init(); err != nil {
panic(err) panic(err)
} }
......
; 比如 sku_save,5000 路径 sku_save 即文件夹是 sku 文件名类似 是save_2020-12-10.log,5000代表队列的容量为5000 ; 比如 sku_save,5000 路径 sku_save 即文件夹是 sku 文件名类似 是save_2020-12-10.log,5000代表队列的容量为5000
[log_config] [log_config]
1=lysku_save,5000 1 = lysku_save,5000
2=sku_query,5000 2 = sku_query,5000
3=default_sku,5000 3 = default_sku,5000
...@@ -149,8 +149,8 @@ func Testr(ctx *gin.Context) { ...@@ -149,8 +149,8 @@ func Testr(ctx *gin.Context) {
redisConn.Close() redisConn.Close()
}() }()
goods_ids := ctx.Request.FormValue("goods_ids") goodsIds := ctx.Request.FormValue("goods_ids")
skuArr := gredis.Hmget("default_r", "sku", php2go.Explode(",", goods_ids)) skuArr := gredis.Hmget("default_r", "sku", php2go.Explode(",", goodsIds))
skustr, _ := json.Marshal(skuArr) skustr, _ := json.Marshal(skuArr)
time2 := time.Now().UnixNano() / 1e6 time2 := time.Now().UnixNano() / 1e6
......
...@@ -38,30 +38,28 @@ sku基本数据增加和修改 ...@@ -38,30 +38,28 @@ sku基本数据增加和修改
Attrs int `json:"attrs" ` Attrs int `json:"attrs" `
*/ */
func SaveSku(ctx *gin.Context) { func SaveSku(ctx *gin.Context) {
//参数验证 //参数验证
var lySaveRequest saveModel.LySaveRequest var lySaveRequest saveModel.LySaveRequest
if err := ctx.ShouldBindBodyWith(&lySaveRequest,binding.JSON); err != nil { if err := ctx.ShouldBindBodyWith(&lySaveRequest, binding.JSON); err != nil {
common.NResponse(err.Error()).SetLogHandel(saveLogHandle).OutPut(ctx) common.NResponse(err.Error()).SetLogHandel(saveLogHandle).OutPut(ctx)
return return
} }
//执行skuSave //执行skuSave
LySave:=service.LySaveService{} LySave := service.LySaveService{}
serviceErr,skuId:=LySave.SaveSku(lySaveRequest,ctx) serviceErr, skuId := LySave.SaveSku(lySaveRequest, ctx)
//错误处理 //错误处理
if(serviceErr!=nil){ if serviceErr != nil {
code:=10001 code := 10001
errMsg:=serviceErr.Error() errMsg := serviceErr.Error()
if err,ok:=serviceErr.(*e.ApiError);ok{ if err, ok := serviceErr.(*e.ApiError); ok {
code=err.Code code = err.Code
errMsg=err.ErrMsg errMsg = err.ErrMsg
} }
common.NResponse(errMsg,code).SetLogHandel(saveLogHandle).OpenParamLog().OutPut(ctx) common.NResponse(errMsg, code).SetLogHandel(saveLogHandle).OpenParamLog().OutPut(ctx)
}else {//执行成功 } else { //执行成功
res:=saveModel.LySaveResponse{0,"ok",gconv.Int64(skuId)} res := saveModel.LySaveResponse{0, "ok", gconv.Int64(skuId)}
fmt.Print("执行成功") fmt.Print("执行成功")
common.NResponse(&res).OutPut(ctx) common.NResponse(&res).OutPut(ctx)
} }
...@@ -69,36 +67,36 @@ func SaveSku(ctx *gin.Context) { ...@@ -69,36 +67,36 @@ func SaveSku(ctx *gin.Context) {
} }
//修改(暂时废弃,大数据那边没调用) //修改(暂时废弃,大数据那边没调用)
func SkuEdit(ctx *gin.Context) { func SkuEdit(ctx *gin.Context) {
//参数验证 //参数验证
var lyeditRequest saveModel.LyEditRequest var lyeditRequest saveModel.LyEditRequest
if err := ctx.ShouldBindBodyWith(&lyeditRequest,binding.JSON); err != nil { if err := ctx.ShouldBindBodyWith(&lyeditRequest, binding.JSON); err != nil {
common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx) common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx)
return return
} }
//执行skuSave //执行skuSave
LySave:=service.LySaveService{} LySave := service.LySaveService{}
serviceErr,skuId:=LySave.SkuEdit(lyeditRequest) serviceErr, skuId := LySave.SkuEdit(lyeditRequest)
//错误处理 //错误处理
if(serviceErr!=nil){ if serviceErr != nil {
if err,ok:=serviceErr.(*e.ApiError);ok{ if err, ok := serviceErr.(*e.ApiError); ok {
common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx) common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx)
}else{ } else {
common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx) common.NResponse(err.Error()).SetLogHandel(editLogHandle).OutPut(ctx)
} }
}else {//执行成功 } else { //执行成功
res:=saveModel.LySaveResponse{0,"ok",gconv.Int64(skuId)} res := saveModel.LySaveResponse{0, "ok", gconv.Int64(skuId)}
common.NResponse(&res).OutPut(ctx) common.NResponse(&res).OutPut(ctx)
} }
return return
} }
func saveLogHandle(errMsg string) { func saveLogHandle(errMsg string) {
logger.Select("lysku_save").Error(errMsg) logger.Select("lysku_save").Error(errMsg)
} }
func editLogHandle(errMsg string) { func editLogHandle(errMsg string) {
logger.Select("lysku_save").Error(errMsg) logger.Select("lysku_save").Error(errMsg)
} }
...@@ -2,9 +2,8 @@ package service ...@@ -2,9 +2,8 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger" "go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo" "go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2" "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
...@@ -21,16 +20,14 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) { ...@@ -21,16 +20,14 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
}() }()
spuIdInt, _ := strconv.Atoi(spuId) spuIdInt, _ := strconv.Atoi(spuId)
err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr) err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if err != nil && err != mgo.ErrNotFound { if err != nil && err != mgo.ErrNotFound {
fmt.Println("mongodb连接错误:") logger.Select("sku_query").Error(err.Error())
fmt.Println(err)
} }
if spuAttr.Attrs != "" { if spuAttr.Attrs != "" {
o := orderedmap.New() o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o) err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil { if err != nil {
logger.Error("%s", err) logger.Select("sku_query").Error(err.Error())
} }
for _, value := range o.Keys() { for _, value := range o.Keys() {
data := make(map[string]interface{}) data := make(map[string]interface{})
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
logger "github.com/ichunt2019/log"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
......
...@@ -4,12 +4,12 @@ import ( ...@@ -4,12 +4,12 @@ import (
"encoding/json" "encoding/json"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "github.com/iancoleman/orderedmap" _ "github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
_ "go_sku_server/pkg/mongo" _ "go_sku_server/pkg/mongo"
_ "gopkg.in/mgo.v2/bson" _ "gopkg.in/mgo.v2/bson"
"strings" "strings"
...@@ -89,7 +89,6 @@ type SpuAttr struct { ...@@ -89,7 +89,6 @@ type SpuAttr struct {
Attrs string `bson:"attrs"` Attrs string `bson:"attrs"`
} }
//H获取供应链标准品牌 //H获取供应链标准品牌
func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) { func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
...@@ -98,7 +97,7 @@ func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) { ...@@ -98,7 +97,7 @@ func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
if scmBrandId != 0 { if scmBrandId != 0 {
scmBrandData, err := redis.String(redisCon.Do("HGET", "pool_scm_brand", scmBrandId)) scmBrandData, err := redis.String(redisCon.Do("HGET", "pool_scm_brand", scmBrandId))
if err != nil { if err != nil {
logger.Error("%s", err) logger.Select("sku_query").Error(err.Error())
} }
scmBrand := make(map[string]interface{}) scmBrand := make(map[string]interface{})
scmBrand["erp_brand_name"] = gjson.Get(scmBrandData, "erp_brand_name").String() scmBrand["erp_brand_name"] = gjson.Get(scmBrandData, "erp_brand_name").String()
...@@ -198,7 +197,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -198,7 +197,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId)) ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId))
if ratio == "" { if ratio == "" {
logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId)) logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId))
return sku return sku
} }
...@@ -240,7 +239,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -240,7 +239,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
} }
} }
if !hasCoefficient && !hasDefault { if !hasCoefficient && !hasDefault {
logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId)) logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId))
return sku return sku
} }
...@@ -355,15 +354,13 @@ func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) { ...@@ -355,15 +354,13 @@ func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) {
//合并spu的信息 //合并spu的信息
func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku { func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
sku.UpdateTime = gjson.Get(spuStr,"update_time").Int() sku.UpdateTime = gjson.Get(spuStr, "update_time").Int()
sku.ClassID1 = int(gjson.Get(spuStr,"class_id1").Int()) sku.ClassID1 = int(gjson.Get(spuStr, "class_id1").Int())
sku.ClassID2 = int(gjson.Get(spuStr,"class_id2").Int()) sku.ClassID2 = int(gjson.Get(spuStr, "class_id2").Int())
sku.SpuName = gjson.Get(spuStr,"spu_name").String() sku.SpuName = gjson.Get(spuStr, "spu_name").String()
sku.SpuBrief =gjson.Get(spuStr,"spu_brief").String() sku.SpuBrief = gjson.Get(spuStr, "spu_brief").String()
sku.SpuDetail = gjson.Get(spuStr,"spu_detail").String() sku.SpuDetail = gjson.Get(spuStr, "spu_detail").String()
sku.Status = int(gjson.Get(spuStr,"status").Int()) sku.Status = int(gjson.Get(spuStr, "status").Int())
sku.Encap = gjson.Get(spuStr,"encap").String() sku.Encap = gjson.Get(spuStr, "encap").String()
return sku return sku
} }
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