Feat: vas for score
This commit is contained in:
parent
e38a60ea44
commit
ca0f244109
7 changed files with 39 additions and 17 deletions
|
@ -160,6 +160,7 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti
|
|||
{Name: "temp_path", Value: "temp", Type: "path"},
|
||||
{Name: "score_enabled", Value: "1", Type: "score"},
|
||||
{Name: "share_score_rate", Value: "80", Type: "score"},
|
||||
{Name: "score_price", Value: "1", Type: "score"},
|
||||
{Name: "home_view_method", Value: "icon", Type: "view"},
|
||||
{Name: "share_view_method", Value: "list", Type: "view"},
|
||||
{Name: "cron_garbage_collect", Value: "@hourly", Type: "cron"},
|
||||
|
|
|
@ -10,6 +10,8 @@ const (
|
|||
PackOrderType = iota
|
||||
// GroupOrderType 用户组订单
|
||||
GroupOrderType
|
||||
// ScoreOrderType 积分充值订单
|
||||
ScoreOrderType
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -58,16 +58,21 @@ func NewOrder(pack *serializer.PackProduct, group *serializer.GroupProducts, num
|
|||
title string
|
||||
price int
|
||||
)
|
||||
if pack == nil {
|
||||
if pack != nil {
|
||||
orderType = model.PackOrderType
|
||||
productID = pack.ID
|
||||
title = pack.Name
|
||||
price = pack.Price
|
||||
} else if group != nil {
|
||||
orderType = model.GroupOrderType
|
||||
productID = group.ID
|
||||
title = group.Name
|
||||
price = group.Price
|
||||
} else {
|
||||
orderType = model.PackOrderType
|
||||
productID = pack.ID
|
||||
title = pack.Name
|
||||
price = pack.Price
|
||||
orderType = model.ScoreOrderType
|
||||
productID = 0
|
||||
title = fmt.Sprintf("%d 积分", num)
|
||||
price = model.GetIntSetting("score_price", 1)
|
||||
}
|
||||
|
||||
// 创建订单记录
|
||||
|
|
|
@ -53,12 +53,19 @@ func GiveGroup(user *model.User, groupInfo *serializer.GroupProducts, num int) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// GiveScore 积分充值
|
||||
func GiveScore(user *model.User, num int) error {
|
||||
user.AddScore(num)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GiveProduct “发货”
|
||||
func GiveProduct(user *model.User, pack *serializer.PackProduct, group *serializer.GroupProducts, num int) error {
|
||||
if pack != nil {
|
||||
return GivePack(user, pack, num)
|
||||
} else if group != nil {
|
||||
return GiveGroup(user, group, num)
|
||||
} else {
|
||||
return GiveScore(user, num)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ func (pay *ScorePayment) Create(order *model.Order, pack *serializer.PackProduct
|
|||
}
|
||||
|
||||
// 创建订单记录
|
||||
order.Status = model.OrderPaid
|
||||
if _, err := order.Create(); err != nil {
|
||||
return nil, ErrInsertOrder.WithError(err)
|
||||
}
|
||||
|
|
|
@ -68,17 +68,18 @@ type GroupProducts struct {
|
|||
}
|
||||
|
||||
// BuildProductResponse 构建增值服务商品响应
|
||||
func BuildProductResponse(groups []GroupProducts, packs []PackProduct, alipay, payjs bool) Response {
|
||||
func BuildProductResponse(groups []GroupProducts, packs []PackProduct, alipay, payjs bool, scorePrice int) Response {
|
||||
// 隐藏响应中的用户组ID
|
||||
for i := 0; i < len(groups); i++ {
|
||||
groups[i].GroupID = 0
|
||||
}
|
||||
return Response{
|
||||
Data: map[string]interface{}{
|
||||
"packs": packs,
|
||||
"groups": groups,
|
||||
"alipay": alipay,
|
||||
"payjs": payjs,
|
||||
"packs": packs,
|
||||
"groups": groups,
|
||||
"alipay": alipay,
|
||||
"payjs": payjs,
|
||||
"score_price": scorePrice,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ type GeneralVASService struct {
|
|||
|
||||
// CreateOrderService 创建订单服务
|
||||
type CreateOrderService struct {
|
||||
Action string `json:"action" binding:"required,eq=group|eq=pack"`
|
||||
Action string `json:"action" binding:"required,eq=group|eq=pack|eq=score"`
|
||||
Method string `json:"method" binding:"required,eq=alipay|eq=score|eq=payjs"`
|
||||
ID int64 `json:"id" binding:"required"`
|
||||
Num int `json:"num" binding:"required,min=1,max=99"`
|
||||
Num int `json:"num" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// Create 创建新订单
|
||||
|
@ -40,7 +40,7 @@ func (service *CreateOrderService) Create(c *gin.Context, user *model.User) seri
|
|||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if service.Action == "pack" {
|
||||
for _, v := range packs {
|
||||
if v.ID == service.ID {
|
||||
pack = &v
|
||||
|
@ -48,8 +48,12 @@ func (service *CreateOrderService) Create(c *gin.Context, user *model.User) seri
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 购买积分
|
||||
if pack == nil && group == nil {
|
||||
return serializer.Err(serializer.CodeNotFound, "商品不存在", nil)
|
||||
if service.Method == "score" {
|
||||
return serializer.Err(serializer.CodeNotFound, "不支持此支付方式", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 创建订单
|
||||
|
@ -64,13 +68,14 @@ func (service *CreateOrderService) Create(c *gin.Context, user *model.User) seri
|
|||
|
||||
// Products 获取商品信息
|
||||
func (service *GeneralVASService) Products(c *gin.Context, user *model.User) serializer.Response {
|
||||
options := model.GetSettingByNames("alipay_enabled", "payjs_enabled")
|
||||
options := model.GetSettingByNames("alipay_enabled", "payjs_enabled", "score_price")
|
||||
scorePrice := model.GetIntSetting("score_price", 0)
|
||||
packs, groups, err := decodeProductInfo()
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeInternalSetting, "无法解析商品设置", err)
|
||||
}
|
||||
|
||||
return serializer.BuildProductResponse(groups, packs, options["alipay_enabled"] == "1", options["payjs_enabled"] == "1")
|
||||
return serializer.BuildProductResponse(groups, packs, options["alipay_enabled"] == "1", options["payjs_enabled"] == "1", scorePrice)
|
||||
}
|
||||
|
||||
func decodeProductInfo() ([]serializer.PackProduct, []serializer.GroupProducts, error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue