Commit d2cb5033 by wang

增加接口:获取分类信息,暂时放开流量控制

parent 6fa45fa7
......@@ -18,5 +18,10 @@ cmd.exe~
/cmd/http/http
/doc/spuTest
/doc/test3
/cmd/test
/doc/redisLock
/controller/testLua.go
/controller/test.lua
/open/redisLock
/tests
......@@ -4,6 +4,7 @@ port = 60006
mode = debug
[sku_server]
api_domain = http://192.168.1.237:60014
;api_domain = http://192.168.1.237:60014
api_domain = http://localhost:60014
[pool_class]
user_name = root
password = root
host = 192.168.2.250
database = liexin_pool_class
table_prefix =lie_
type = mysql
\ No newline at end of file
;redis连接信息
[default_redis_read]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 5000
idle_timeout = 20
[default_redis_write]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 5000
idle_timeout = 20
;存放redis所有键
[redis_all]
;redis连接信息
[default_redis_read]
host = 192.168.2.129:6379
password = ws123678
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 5000
idle_timeout = 20
[default_redis_write]
host = 192.168.2.129:6379
password = ws123678
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 5000
idle_timeout = 20
......
......@@ -78,7 +78,7 @@ func Error_Middleware(logPaths ...string) gin.HandlerFunc {
}else{
errMsg:=fmt.Sprintf("%s",err)
fmt.Println(errMsg)
common.NResponse("service err",500).SetLogHandel(errlogHandle(logPath)).OpenParamLog().OutPut(ctx)
common.NResponse("service error",500).SetLogHandel(errlogHandle(logPath)).OpenParamLog().OutPut(ctx)
}
ctx.Abort()
}
......
package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"golang_open_platform/model"
"golang_open_platform/open"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/e"
"golang_open_platform/service"
......@@ -47,3 +50,19 @@ func GetSkuListPrice(ctx *gin.Context) {
common.NResponse("",0,rsp).OutPut(ctx)
}
/**
用goods_id 获取sku列表价格库存字段
*/
func GetClassList(ctx *gin.Context) {
parent_id:= ctx.Request.FormValue("parent_id")
if(parent_id==""){
common.NResponse("parent_id 必填",open.PARAM1,nil).OutPut(ctx)
return
}
fmt.Printf(parent_id)
rsp,err:=service.NewClassService().GetClassList(gconv.Int(parent_id))
e.CheckError(err)
common.NResponse("",0,rsp).OutPut(ctx)
}
package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/e"
"golang_open_platform/pkg/gredis"
)
func TestRequest(ctx *gin.Context) {
ctx.JSON(200,nil)
ctx.JSON(200,nil)
}
func LuaTest() {
}
func LockTest(ctx *gin.Context) {
defer delOnlyLock("test_lock")
addOnlyLock("test_lock")
err:=addOnlyLock("test_lock")
if(err!=nil){
common.PrintStdout().Printf("加锁失败")
return
}
num,err:=getRedisFlowNum("abc")
fmt.Println(num)
if(err!=nil){
common.PrintStdout().Printf(err.Error())
}
if(num>=2100){
common.PrintStdout().Printf("频率限制")
ctx.JSON(200,"频率限制")
return
}
num,err=incrRedisFlowNum("abc")
if(err!=nil){
common.PrintStdout().Printf("新增报错")
}
common.PrintStdout().Printf("新增后的值"+string(num))
ctx.JSON(200,"锁测试")
}
func incrRedisFlowNum(key string) (num int,err error){
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
num,err= redis.Int(redisWriteConn.Do("INCR", key))
if(err!=nil){
common.PrintStdout().Printf("INCR redis "+key+"错误")
//return 0,e.NewApiError("service error",FLOWERR1)
}
return num,nil
}
func abc() {
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
}
//如果锁不存在并设置锁
func addOnlyLock(key string){
func addOnlyLock(key string)error{
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
name:="flow_lock_"+key
//common.PrintStdout().Printf("加锁 key:%s",name)
for{
s, err:= redisWriteConn.Do("SET", name, "1", "EX", "10","NX")//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
//for{
r, err:= redisWriteConn.Do("SET", name, "1", "EX", "100","NX")//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if(err!=nil){
common.PrintStdout().Printf("读取redis 锁 key:%d 报错",key)
}
if(s!=nil){
//common.PrintStdout().Printf("加锁完成 key :%s",name)
break
if(r!=nil){
return nil
}
}
//}
incrRedisFlowNum("err_num")
//common.PrintStdout().Printf("没读到")
return fmt.Errorf("请重试")
}
//删除锁
......@@ -46,5 +99,15 @@ func delOnlyLock(key string){
if(err!=nil){
println(err.Error())
}
//common.PrintStdout().Printf("解锁完成")
common.PrintStdout().Printf("解锁完成")
}
func getRedisFlowNum(key string) (num int,err error){
redisReadConn := gredis.Conn("search_r")
defer redisReadConn.Close()
num,err= redis.Int(redisReadConn.Do("Get", key))
if(err!=nil && err!=redis.ErrNil){
common.PrintStdout().Printf("读取redis "+key+"错误"+err.Error())
return 0,e.NewApiError("service error",80000)
}
return num,nil
}
\ No newline at end of file
package dao
import (
"fmt"
"golang_open_platform/model"
"golang_open_platform/pkg/mysql"
)
/**
获取相似商品
@param parentId 父类ID
*/
func GetClassList(parentId int) (QueryClassRspS []model.QueryClassRsp,err error) {
dbSpu:= mysql.Conn("pool_class") //spu实例化链接
QueryClassRspS = make([]model.QueryClassRsp, 0)
whereStr:="parent_id =? and status=1"
err= dbSpu.Table("lie_class").Where(whereStr,parentId).Find(&QueryClassRspS)
if(err!=nil){
return QueryClassRspS,fmt.Errorf("method:GetClassList,"+err.Error())
}
return QueryClassRspS,nil
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package dao
import (
"golang_open_platform/model"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
......@@ -19,6 +20,7 @@ func GetMongoOpenSku(classId int,page int) (mongoSkuOpen *model.MongoSkuOpen,err
if(err == mgo.ErrNotFound){
return mongoSkuOpen,nil
}
common.PrintStdout().Printf("根据class id 获取mongo sku error:"+err.Error())
return
}
return
......
......@@ -21,6 +21,7 @@ var(
GetSkuListByClass ="GetSkuListByClass"
GetSkuListFull ="GetSkuListFull"
GetSkuListPrice ="GetSkuListPrice"
GetClassList ="GetClassList"
//redis 表key
openWhiteList ="openWhiteList"//白名单
......@@ -104,6 +105,11 @@ func businessInterfaceList() {
"minMaxNum":2000,
"totalMaxNum":10000,
},
jdToken+"_"+GetClassList: map[string]interface{}{
"dayMaxNum":6100,
"minMaxNum":2000,
"totalMaxNum":10000,
},
/*baiduToken+"_"+getSkuListByClass: map[string]interface{}{
"dayMaxNum":100,
"minMaxNum":500,
......
package model
//根据class获取sku列表 返回参数
type QueryClassRsp struct {
ClassId int `json:"class_id"`
ClassName string `json:"class_name"`
ParentId int `json:"parent_id"`
}
\ No newline at end of file
......@@ -34,6 +34,7 @@ func filterData(remoteData RemoteSkuData,filterField []string)(data RemoteSkuDat
newItem[field]=filterLadder(info[field])
}
}else{
newItem[field]=""
//common.PrintStdout().Printf("skuId:%s,字段:%s 不存在",string(skuId),field)
}
}
......@@ -49,7 +50,7 @@ func filterData(remoteData RemoteSkuData,filterField []string)(data RemoteSkuDat
func filterLadder(ladder interface{}) interface{}{
var newLadderS = []map[string]interface{}{}
fileds:=[]string{"purchases","price_us","price_cn"}
fileds:=[]string{"purchases"/*,"price_us"*/,"price_cn"}
if ladderSlice,ok:=ladder.([]interface{});ok{
......
......@@ -11,7 +11,7 @@ type QuerySkuCreq struct {
type QuerySkuCrsp struct {
Count int `json:"count"`
SkuData map[string]interface{} `json:"sku_data"`
Limit int `json:"limit"`
PageSize int `json:"page_size"`
Page int `json:"page"`
}
......
......@@ -23,10 +23,17 @@ const (
FLOWERR3 = 814406//触发分钟级流量限制
FLOWERR4 = 814407//触发天级流量限制
//lock===========815=========
LOCKERR1 =815407 //没读到锁,请重试
//sku接口===================================== 80开头 获取sku错误码
PARAM1 = 80001 //参数问题(缺失or数据格式不对)
OTHERERROR = 80500 //其他错误,比如读取redis出错
REMOTESKUINFO = 80501 //调用远程商详接口报错
//class
CLASSDBERR = 80504 //获取class mysql报错
)
......@@ -32,7 +32,7 @@ func (this *business) GetInterfaceConfig(interfaceName string) (configOne *inter
} else{
str,err:=this.dao.GetbusinessInterface(this.token,interfaceName)
if(err!=nil){
return configOne,nil
return configOne,err
}
if(str==""){
common.PrintStdout().Printf(strconv.Itoa(BUSINESSCONFIG2)+":平台没有设置此商家的接口配置")
......
......@@ -20,7 +20,7 @@ func (this *Dao) getOpenWhiteList()(whitestr string,err error){
defer redisReadConn.Close()
whitestr,err=redis.String(redisReadConn.Do("Get","openWhiteList"))
if(err!=nil && err!=redis.ErrNil){
common.PrintStdout().Printf(strconv.Itoa(WHILTREDISEERR1)+":读取redis 白名单错误"+err.Error())
common.PrintStdout().Printf(strconv.Itoa(WHILTREDISEERR1)+":读取redis "+err.Error())
return "",e.NewApiError("white err",WHILTREDISEERR1)
}
return whitestr,nil
......@@ -59,7 +59,7 @@ func (this *Dao) getRedisFlowNum(key string) (num int,err error){
num,err= redis.Int(redisReadConn.Do("Get", key))
if(err!=nil && err!=redis.ErrNil){
common.PrintStdout().Printf("读取redis "+key+"错误"+err.Error())
return 0,e.NewApiError("service err",FLOWERR1)
return 0,e.NewApiError("service error",FLOWERR1)
}
return num,nil
}
......@@ -71,7 +71,7 @@ func (this *Dao) setRedisFlowEx(key string,expire interface{}) error{
_, err:= redisWriteConn.Do("SET", key, "0", "EX", expire)
if(err!=nil){
common.PrintStdout().Printf("设置redis "+key+"错误")
return e.NewApiError("service err",FLOWERR1)
return e.NewApiError("service error",FLOWERR1)
}
return nil
}
......@@ -82,7 +82,7 @@ func (this *Dao)incrRedisFlowNum(key string) (num int,err error){
num,err= redis.Int(redisWriteConn.Do("INCR", key))
if(err!=nil){
common.PrintStdout().Printf("INCR redis "+key+"错误")
return 0,e.NewApiError("service err",FLOWERR1)
return 0,e.NewApiError("service error",FLOWERR1)
}
return num,nil
}
package open
import (
logger "github.com/ichunt2019/log"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/e"
"golang_open_platform/pkg/gredis"
......@@ -87,10 +88,17 @@ func (this *flowmeter) compare(maxNum int64) (error,bool){
验证
*/
func (this *flowmeter) checkout(business *business) error{
return nil
interfaceConfig,err:=business.GetInterfaceConfig(this.interfaceName)//商家接口配置,包含一小时最大流量,一天最大流量
key,_:=this.getFlowKeyAndEx()
defer this.delOnlyLock(key)
this.addOnlyLock(key)//加锁
err=this.addOnlyLock(key)//加锁
if(err!=nil){
common.PrintStdout().Printf("加锁失败")
this.dao.incrRedisFlowNum("err_num")
return err
}
//lock.Lock()
//defer lock.Unlock()
......@@ -101,6 +109,7 @@ func (this *flowmeter) checkout(business *business) error{
return err
}
if(err!=nil){
logger.Error("sku_query","比较失败")
return err
}
if(isPass==false){
......@@ -120,18 +129,19 @@ func (this *flowmeter) checkout(business *business) error{
//增加分钟计数
err=this.incr()
if(err!=nil){
common.PrintStdout().Printf("增加fen分计数报错")
return nil
}
//增加天计数
this.setFlowKey(INCRTYPEDAY)
err=this.incr()
if(err!=nil){
common.PrintStdout().Printf("增加天计数报错")
return err
}
return nil
}
//自增
func (this *flowmeter)incr() (err error) {
key,_:=this.getFlowKeyAndEx()
......@@ -146,22 +156,22 @@ func (this *flowmeter)incr() (err error) {
//如果锁不存在并设置锁
func (this *flowmeter)addOnlyLock(key string){
func (this *flowmeter)addOnlyLock(key string)error{
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
name:="flow_lock_"+key
//common.PrintStdout().Printf("加锁 key:%s",name)
for{
s, err:= redisWriteConn.Do("SET", name, "1", "EX", "10","NX")//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if(err!=nil){
common.PrintStdout().Printf("读取redis 锁 key:%d 报错",key)
}
if(s!=nil){
//common.PrintStdout().Printf("加锁完成 key :%s",name)
break
}
s, err:= redisWriteConn.Do("SET", name, "1", "EX", "100","NX")//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if(err!=nil){
common.PrintStdout().Printf("读取redis 锁 key:%d 报错",key)
}
if(s!=nil){//读到了
//common.PrintStdout().Printf("加锁完成 key :%s",name)
return nil
}
common.PrintStdout().Printf("没读到")
return e.NewApiError("请重试",LOCKERR1)
}
//删除锁
......@@ -171,6 +181,7 @@ func (this *flowmeter) delOnlyLock(key string){
name:="flow_lock_"+key
_, err:= redisWriteConn.Do("DEL", name)
if(err!=nil){
logger.Error("sku_query","删除锁失败")
println(err.Error())
}
//common.PrintStdout().Printf("解锁完成")
......
......@@ -13,118 +13,15 @@ type BaseDatabase struct {
//多数据库配置
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{
"spu": {
UserName: Get("spu.user_name").String(),
Password: Get("spu.password").String(),
Host: Get("spu.host").String(),
Database: Get("spu.database").String(),
Prefix: Get("spu.table_prefix").String(),
},
"supp": {
UserName: Get("supp.user_name").String(),
Password: Get("supp.password").String(),
Host: Get("supp.host").String(),
Database: Get("supp.database").String(),
Prefix: Get("supp.table_prefix").String(),
},
"cms": {
UserName: Get("cms.user_name").String(),
Password: Get("cms.password").String(),
Host: Get("cms.host").String(),
Database: Get("cms.database").String(),
Prefix: Get("cms.table_prefix").String(),
},
"liexin_data": {
UserName: Get("liexin_data.user_name").String(),
Password: Get("liexin_data.password").String(),
Host: Get("liexin_data.host").String(),
Database: Get("liexin_data.database").String(),
Prefix: Get("liexin_data.table_prefix").String(),
},
"wms": {
UserName: Get("wms.user_name").String(),
Password: Get("wms.password").String(),
Host: Get("wms.host").String(),
Database: Get("wms.database").String(),
Prefix: Get("wms.table_prefix").String(),
},
"szlc": {
UserName: Get("szlc.user_name").String(),
Password: Get("szlc.password").String(),
Host: Get("szlc.host").String(),
Database: Get("szlc.database").String(),
Prefix: Get("szlc.table_prefix").String(),
},
"sku_0": {
UserName: Get("sku_0.user_name").String(),
Password: Get("sku_0.password").String(),
Host: Get("sku_0.host").String(),
Database: Get("sku_0.database").String(),
Prefix: Get("sku_0.table_prefix").String(),
},
"sku_1": {
UserName: Get("sku_1.user_name").String(),
Password: Get("sku_1.password").String(),
Host: Get("sku_1.host").String(),
Database: Get("sku_1.database").String(),
Prefix: Get("sku_1.table_prefix").String(),
},
"sku_2": {
UserName: Get("sku_2.user_name").String(),
Password: Get("sku_2.password").String(),
Host: Get("sku_2.host").String(),
Database: Get("sku_2.database").String(),
Prefix: Get("sku_2.table_prefix").String(),
},
"sku_3": {
UserName: Get("sku_3.user_name").String(),
Password: Get("sku_3.password").String(),
Host: Get("sku_3.host").String(),
Database: Get("sku_3.database").String(),
Prefix: Get("sku_3.table_prefix").String(),
},
"sku_4": {
UserName: Get("sku_4.user_name").String(),
Password: Get("sku_4.password").String(),
Host: Get("sku_4.host").String(),
Database: Get("sku_4.database").String(),
Prefix: Get("sku_4.table_prefix").String(),
},
"sku_5": {
UserName: Get("sku_5.user_name").String(),
Password: Get("sku_5.password").String(),
Host: Get("sku_5.host").String(),
Database: Get("sku_5.database").String(),
Prefix: Get("sku_5.table_prefix").String(),
},
"sku_6": {
UserName: Get("sku_6.user_name").String(),
Password: Get("sku_6.password").String(),
Host: Get("sku_6.host").String(),
Database: Get("sku_6.database").String(),
Prefix: Get("sku_6.table_prefix").String(),
},
"sku_7": {
UserName: Get("sku_7.user_name").String(),
Password: Get("sku_7.password").String(),
Host: Get("sku_7.host").String(),
Database: Get("sku_7.database").String(),
Prefix: Get("sku_7.table_prefix").String(),
},
"sku_8": {
UserName: Get("sku_8.user_name").String(),
Password: Get("sku_8.password").String(),
Host: Get("sku_8.host").String(),
Database: Get("sku_8.database").String(),
Prefix: Get("sku_8.table_prefix").String(),
},
"sku_9": {
UserName: Get("sku_9.user_name").String(),
Password: Get("sku_9.password").String(),
Host: Get("sku_9.host").String(),
Database: Get("sku_9.database").String(),
Prefix: Get("sku_9.table_prefix").String(),
"pool_class": {
UserName: Get("pool_class.user_name").String(),
Password: Get("pool_class.password").String(),
Host: Get("pool_class.host").String(),
Database: Get("pool_class.database").String(),
Prefix: Get("pool_class.table_prefix").String(),
},
}
}
......@@ -16,7 +16,22 @@ func InitRouter() *gin.Engine {
r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata",controller.Hbsdata)
//用classId获取sku列表
rsku:=r.Group("/sku")
{
//用classId获取sku列表
rsku.GET("/GetSkuListByClass",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListByClass"),controller.GetSkuListByClass)
//获取sku列表完整字段
rsku.GET("/GetSkuListFull",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListFull"),controller.GetSkuListFull)
//获取sku列表 价格库存相关字段
rsku.GET("/GetSkuListPrice",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListPrice"),controller.GetSkuListPrice)
rsku.GET("/GetClassList",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetClassList"),controller.GetClassList)
}
/*//用classId获取sku列表
r.GET("GetSkuListByClass",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListByClass"),controller.GetSkuListByClass)
//获取sku列表完整字段
......@@ -24,9 +39,11 @@ func InitRouter() *gin.Engine {
controller.Open_Middleware("GetSkuListFull"),controller.GetSkuListFull)
//获取sku列表 价格库存相关字段
r.GET("GetSkuListPrice",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListPrice"),controller.GetSkuListPrice)
controller.Open_Middleware("GetSkuListPrice"),controller.GetSkuListPrice)*/
//
r.GET("Test",controller.Error_Middleware("sku_query"),controller.TestRequest)
r.GET("LockTest",controller.Error_Middleware("sku_query"),controller.LockTest)
//r.GET("Test",controller.Error_Middleware("sku_query"),controller.TestRequest)
//r.GET("LockTest",controller.Error_Middleware("sku_query"),controller.LockTest)
//r.GET("TestLua",controller.Error_Middleware("sku_query"),controller.TestLua)
//r.GET("ScriptKill",controller.Error_Middleware("sku_query"),controller.ScriptKill)
return r
}
package service
import (
"golang_open_platform/dao"
"golang_open_platform/model"
"golang_open_platform/open"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/e"
)
type ClassService struct {
}
//获取sku列表完整字段
func (this *ClassService) GetClassList(parentId int)(rsp []model.QueryClassRsp,err error) {
//skuIds:=strings.Replace(req.GoodsIds," ",",",-1)
//skuIds
rsp,err=dao.GetClassList(parentId)
if(err!=nil){
common.PrintStdout().Printf(err.Error())
return rsp,e.NewApiError("service error",open.CLASSDBERR)
}
return
}
func NewClassService()*ClassService{
return &ClassService{}
}
\ No newline at end of file
......@@ -25,20 +25,20 @@ func NewSkuService() *SkuService{
func (this *SkuService)GetSkuListByClass(req *model.QuerySkuCreq) (rsp *model.QuerySkuCrsp,err error ){
pageData,err:=dao.GetMongoOpenSku(req.ClassId,0)
if(err!=nil){
return nil,e.NewApiError("service err",open.OTHERERROR)
return nil,e.NewApiError("service error",open.OTHERERROR)
}
rsp=&model.QuerySkuCrsp{Count:pageData.Count,Limit:10,Page:req.Page}
rsp=&model.QuerySkuCrsp{Count:pageData.Count,PageSize:10,Page:req.Page}
if(pageData.Count<=0){//没数据
return
}
if(req.Page>0){
//验证下page是否有效
if(math.Ceil(float64(pageData.Count/rsp.Limit))<float64(req.Page)){
if(math.Ceil(float64(pageData.Count/rsp.PageSize))<float64(req.Page)){
return nil,e.NewApiError("page invalid",open.PARAM1)
}
mongoOpenSku,err:=dao.GetMongoOpenSku(req.ClassId,req.Page)
if(err!=nil){
return nil,e.NewApiError("service err",open.OTHERERROR)
return nil,e.NewApiError("service error",open.OTHERERROR)
}
if(mongoOpenSku.SkuIds==""){
if(rsp.Count>0){
......@@ -50,8 +50,8 @@ func (this *SkuService)GetSkuListByClass(req *model.QuerySkuCreq) (rsp *model.Qu
//skuIds
remoteData,err:=this.getRemoteSku(skuIds)
if(err!=nil){
common.PrintStdout().Printf("获取远程商详接口报错 msg:"+err.Error())
return nil,e.NewApiError("service err",open.REMOTESKUINFO)
common.PrintStdout().Printf(err.Error())
return rsp,e.NewApiError("service error",open.REMOTESKUINFO)
}
field:=[]string{"goods_id","spu_id","brand_id","brand_name","goods_name", "stock","moq","mpq",
"class_id1","class_id2","class_id1_name","class_id2_name","attrs","ladder_price",}
......@@ -68,6 +68,10 @@ func (this *SkuService) GetSkuListFull(req * model.QuerySkuReq)(rsp *model.Query
//skuIds
rsp=&model.QuerySkuRsp{}
remoteData,err:=this.getRemoteSku(req.GoodsIds)
if(err!=nil){
common.PrintStdout().Printf(err.Error())
return rsp,e.NewApiError("service error",open.REMOTESKUINFO)
}
//"class_id1": 10014,
// "class_id2": 10031,
// "class_id1_name": "处理器及微控制器",
......@@ -80,6 +84,10 @@ func (this *SkuService) GetSkuListFull(req * model.QuerySkuReq)(rsp *model.Query
//获取sku列表 价格库存相关字段
func (this *SkuService) GetSkuListPrice(req * model.QuerySkuReq)(rsp model.QuerySkuRsp,err error) {
remoteData,err:=this.getRemoteSku(req.GoodsIds)
if(err!=nil){
common.PrintStdout().Printf(err.Error())
return rsp,e.NewApiError("service error",open.REMOTESKUINFO)
}
field:=[]string{"goods_id","stock","ladder_price"}
rsp.SkuData=model.SkuFilter(*remoteData,field)
return
......@@ -90,7 +98,7 @@ func (this *SkuService) getRemoteSku(ids string) (remoteData *model.RemoteSkuDa
resStr:=""
err=gout.POST(config.Get("sku_server.api_domain").String()+"/synchronization")/*.Debug(true)*/.SetForm(gout.H{"goods_id": ids}).BindBody(&resStr).Do()
if(err!=nil){
return remoteData,err
return remoteData,fmt.Errorf("调用远端商详接口报错:"+err.Error())
}
gjsonRes:=gjson.Parse(resStr)
if(gjsonRes.Exists()==false){
......
package main
import (
"fmt"
"github.com/syyongx/php2go"
)
func main() {
var a = []string{"3923"}
var b = 3923
fmt.Println(php2go.InArray(b,a))
}
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