Commit 9e4a418b by mushishixian

修复

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