You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.5 KiB
72 lines
2.5 KiB
package pay
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/log"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// @Summary 获取商品列表 v2
|
|
// @Description 获取商品列表(读管理后台「应用商品配置」,按应用隔离)
|
|
// @Tags Pay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param order body pb.PayGetGoodssV2Req true "获取商品列表 v2"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.PayGetGoodssV2Resp} "商品列表"
|
|
// @Router /api/home/pay_getgoodssv2 [post]
|
|
//
|
|
// GetGoodssV2 与 v1(GetGoodss)返回结构完全一致,差别只有商品来源:
|
|
// v1 读**各业务库自己的 goods 表**,v2 读**管理后台的应用商品配置**
|
|
// (console 公共库 app_goods,按 comm.AppName() 隔离),与支付通知 v2 的发货口径同源——
|
|
// 后台「应用商品配置」页改完即生效,多区域部署共用一份,不必再逐个业务库同步。
|
|
//
|
|
// 只下发已上架(Enable)的商品,顺序按后台配置的 sort;后台一个商品都没配时返回空列表,
|
|
// 不报错——让客户端表现为「暂无商品」,而不是弹错误。
|
|
func (this *apiComp) GetGoodssV2(session comm.IUserSession, req *pb.PayGetGoodssV2Req) (resp *pb.PayGetGoodssV2Resp, errdata *pb.ErrorData) {
|
|
var (
|
|
allgoodss []*comm.AppGoods
|
|
goodss []*pb.DBGoods
|
|
err error
|
|
)
|
|
if allgoodss, err = this.module.model.appGoodss(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("GetGoodssV2 失败!",
|
|
log.Field{Key: "app", Value: comm.AppName()},
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
goodss = make([]*pb.DBGoods, 0, len(allgoodss))
|
|
for _, v := range allgoodss {
|
|
if !v.Enable {
|
|
continue
|
|
}
|
|
goodss = append(goodss, dbGoodsOfAppGoods(v))
|
|
}
|
|
resp = &pb.PayGetGoodssV2Resp{
|
|
Goodss: goodss,
|
|
}
|
|
return
|
|
}
|
|
|
|
// dbGoodsOfAppGoods 把后台商品配置转成客户端认识的 DBGoods。
|
|
// id 取 GoodsId(下单时写进订单 product_id 的那个标识,不是后台自增主键 Id),
|
|
// localname 原样透传(同一份 JSON 形态,多语言由客户端按 lang 取)。
|
|
func dbGoodsOfAppGoods(g *comm.AppGoods) *pb.DBGoods {
|
|
return &pb.DBGoods{
|
|
Id: g.GoodsId,
|
|
Enable: g.Enable,
|
|
Name: g.Name,
|
|
Localname: g.Localname,
|
|
Price: g.Price,
|
|
Usagetype: pb.UsageType(g.Usagetype),
|
|
Ainum: g.Ainum,
|
|
Meetnum: g.Meetnum,
|
|
Tradenum: g.Tradenum,
|
|
Viptime: g.Viptime,
|
|
}
|
|
}
|
|
|