package xianmai import ( "github.com/codinl/go-logger" "strconv" ) func GameCassetteList(keyword string, pageNum, pageSize int) ([]Cassette, int, error) { paraMap := map[string]interface{}{ "keyword": keyword, "pageNum": pageNum, "pageSize": pageSize, } games := make([]Cassette, 0) resp := &GameCassetteListResp{} err := GetXianClient().post("game/cassetteList", paraMap, resp) if err != nil { logger.Error("err:", err) return games, 0, err } for i, _ := range resp.Data1.List { cassette := Cassette{ GoodsId: resp.Data1.List[i].GoodsId, GoodsName: resp.Data1.List[i].GoodsName, GoodsImg: resp.Data1.List[i].GoodsImg, Keyword: resp.Data1.List[i].Keyword, } games = append(games, cassette) } return games, resp.Data1.Pages, nil } type GameCheckGoodsReq struct { GoodsId uint32 `json:"goods_id"` } func (m *GameCheckGoodsReq) Get() (*XMCheckGoods, error) { paraMap := map[string]interface{}{ "goodsId": m.GoodsId, } var xmGoods *XMCheckGoods resp := &GameCheckGoodsResp{} err := GetXianClient().post("game/check/goods", paraMap, resp) if err != nil { logger.Error("err:", err) return xmGoods, err } xmGoods = &XMCheckGoods{ GoodsId: resp.Data1.GoodsId, GoodsName: resp.Data1.GoodsName, GoodsImg: resp.Data1.GoodsImg, } skus := make([]XMSkuTitle, 0) problems := make([]XMProblemTitle, 0) for i, _ := range resp.Data1.SkuTitleVos { details := make([]XMSkuDetail, 0) skuTitle := XMSkuTitle{ ProblemId: resp.Data1.SkuTitleVos[i].ProblemId, ProblemName: resp.Data1.SkuTitleVos[i].ProblemName, } for _, vo := range resp.Data1.SkuTitleVos[i].SkuDetailVoList { skuDetail := XMSkuDetail{ ProblemValueId: vo.ProblemValueId, ProblemValueName: vo.ProblemValueName, } details = append(details, skuDetail) } skuTitle.List = details skus = append(skus, skuTitle) } for i, _ := range resp.Data1.ProblemTitleVos { details := make([]XMSkuDetail, 0) problemTitle := XMProblemTitle{ ProblemId: resp.Data1.ProblemTitleVos[i].ProblemId, ProblemName: resp.Data1.ProblemTitleVos[i].ProblemName, } for _, vo := range resp.Data1.ProblemTitleVos[i].ProblemDetailVoList { skuDetail := XMSkuDetail{ ProblemValueId: vo.ProblemValueId, ProblemValueName: vo.ProblemValueName, } details = append(details, skuDetail) } problemTitle.List = details problems = append(problems, problemTitle) } xmGoods.Skus = skus xmGoods.Problems = problems return xmGoods, nil } type GameEvaluationReq struct { GoodsId int `json:"goods_id"` GoodsName string `json:"goods_name"` GoodsImg string `json:"goods_img"` Keyword string `json:"keyword"` StoreId uint32 `json:"store_id"` ProblemAttrList []struct { ProblemAttrName string `json:"problem_attr_name"` ProblemAttrId int `json:"problem_attr_id"` ProblemAttrValueName string `json:"problem_attr_value_name"` ProblemAttrValueId int `json:"problem_attr_value_id"` } `json:"problem_attr_list"` SkuList []struct { ProblemAttrName string `json:"problem_attr_name"` ProblemAttrId int `json:"problem_attr_id"` ProblemAttrValueName string `json:"problem_attr_value_name"` ProblemAttrValueId int `json:"problem_attr_value_id"` } `json:"sku_list"` } func (m *GameEvaluationReq) Evaluation() (int, error) { paraMap := map[string]interface{}{ "goodsId": m.GoodsId, } problems := make([]XMProblemAttr, 0) skus := make([]XMProblemAttr, 0) for i, _ := range m.ProblemAttrList { attr := XMProblemAttr{ ProblemAttrId: strconv.Itoa(m.ProblemAttrList[i].ProblemAttrId), ProblemAttrValueId: strconv.Itoa(m.ProblemAttrList[i].ProblemAttrValueId), } problems = append(problems, attr) } for i, _ := range m.SkuList { attr := XMProblemAttr{ ProblemAttrId: strconv.Itoa(m.SkuList[i].ProblemAttrId), ProblemAttrValueId: strconv.Itoa(m.SkuList[i].ProblemAttrValueId), } skus = append(skus, attr) } paraMap["problemAttrList"] = problems paraMap["skuList"] = skus resp := &GameEvaluationResp{} err := GetXianClient().post("game/evaluation", paraMap, resp) if err != nil { logger.Error("err:", err) return 0, err } return resp.Data, nil } type SmBrandListReq struct { CategoryId uint32 `json:"categoryId"` } type SmBrandListResp struct { Flag bool `json:"flag"` Code int `json:"code"` Message string `json:"message"` Data1 interface{} `json:"data1"` Data []struct { Id int `json:"id"` CategoryId int `json:"categoryId"` Name string `json:"name"` Img string `json:"img"` Status int `json:"status"` CreateTime string `json:"createTime"` UpdateTime string `json:"updateTime"` Deleted int `json:"deleted"` CategoryName interface{} `json:"categoryName"` Tindex int `json:"tindex"` } `json:"data"` } func (m *SmBrandListReq) List() (*SmBrandListResp, error) { paraMap := map[string]interface{}{ "categoryId": m.CategoryId, } resp := &SmBrandListResp{} err := GetSanMaiClient().post("/openapi/order/queryBrandList", paraMap, resp) if err != nil { logger.Error("post err:", err) return resp, err } return resp, nil } type SmGoodsListReq struct { BrandId int `json:"brandId"` PageNum int `json:"pageNum"` PageSize int `json:"pageSize"` CategoryId int `json:"categoryId"` GoodsName string `json:"goodsName"` } type SmGoodsListResp struct { Flag bool `json:"flag"` Code int `json:"code"` Message string `json:"message"` Data1 struct { Records []struct { Id int `json:"id"` Name string `json:"name"` CategoryId int `json:"categoryId"` BrandId int `json:"brandId"` Status int `json:"status"` Gallery string `json:"gallery"` Keyword string `json:"keyword"` CreateTime string `json:"createTime"` UpdateTime string `json:"updateTime"` Deleted int `json:"deleted"` Price int `json:"price"` PriceHigh int `json:"priceHigh"` PriceAvg int `json:"priceAvg"` PriceCycle int `json:"priceCycle"` OverdueDays int `json:"overdueDays"` PriceAdjustmentTime string `json:"priceAdjustmentTime"` TemlateId int `json:"temlateId"` TemplateName string `json:"templateName"` BrandName string `json:"brandName"` CategoryName string `json:"categoryName"` IsBindCoupon bool `json:"isBindCoupon"` Tindex int `json:"tindex"` } `json:"records"` Total int `json:"total"` Size int `json:"size"` Current int `json:"current"` Orders []interface{} `json:"orders"` SearchCount bool `json:"searchCount"` Pages int `json:"pages"` } `json:"data1"` Data interface{} `json:"data"` } func (m *SmGoodsListReq) List() (*SmGoodsListResp, error) { paraMap := map[string]interface{}{ "brandId": m.BrandId, "pageNum": m.PageNum, "pageSize": m.PageSize, "goodsName": m.GoodsName, } resp := &SmGoodsListResp{} err := GetSanMaiClient().post("/openapi/order/queryGoodsList", paraMap, resp) if err != nil { logger.Error("post err:", err) return resp, err } return resp, nil } type SmExternal struct { ParaMap interface{} `json:"para_map"` ApiRoute string `json:"api_route"` WechatId string `json:"wechat_id"` WechatMobile string `json:"wechat_mobile"` RequestType string `json:"request_type"` //Resp interface{} } func (m *SmExternal) Pulling(resp interface{}) error { err := GetSanMaiClient().post(m.ApiRoute, m.ParaMap, resp) if err != nil { logger.Error("post err:", err) return err } return nil } func (m *SmExternal) EoPulling(resp interface{}) error { maiToken, err := EoSanMaiToken(m.WechatId, m.WechatMobile, m.RequestType) if err != nil { logger.Error("EoSanMaiToken err:", err) return err } sanMaiClient = &SanMaiClient{ Authentication: maiToken, BaseURL: SmBaseURL, } err = sanMaiClient.post(m.ApiRoute, m.ParaMap, resp) if err != nil { logger.Error("post err:", err) return err } return nil }