Feat: vas for score

This commit is contained in:
HFO4
2020-02-17 09:48:39 +08:00
parent e38a60ea44
commit ca0f244109
7 changed files with 39 additions and 17 deletions

View File

@@ -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)
}
// 创建订单记录

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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,
},
}
}