mirror of https://github.com/cloudreve/Cloudreve
Feat: vas for score
parent
e38a60ea44
commit
ca0f244109
|
@ -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: "temp_path", Value: "temp", Type: "path"},
|
||||||
{Name: "score_enabled", Value: "1", Type: "score"},
|
{Name: "score_enabled", Value: "1", Type: "score"},
|
||||||
{Name: "share_score_rate", Value: "80", 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: "home_view_method", Value: "icon", Type: "view"},
|
||||||
{Name: "share_view_method", Value: "list", Type: "view"},
|
{Name: "share_view_method", Value: "list", Type: "view"},
|
||||||
{Name: "cron_garbage_collect", Value: "@hourly", Type: "cron"},
|
{Name: "cron_garbage_collect", Value: "@hourly", Type: "cron"},
|
||||||
|
|
|
@ -10,6 +10,8 @@ const (
|
||||||
PackOrderType = iota
|
PackOrderType = iota
|
||||||
// GroupOrderType 用户组订单
|
// GroupOrderType 用户组订单
|
||||||
GroupOrderType
|
GroupOrderType
|
||||||
|
// ScoreOrderType 积分充值订单
|
||||||
|
ScoreOrderType
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -58,16 +58,21 @@ func NewOrder(pack *serializer.PackProduct, group *serializer.GroupProducts, num
|
||||||
title string
|
title string
|
||||||
price int
|
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
|
orderType = model.GroupOrderType
|
||||||
productID = group.ID
|
productID = group.ID
|
||||||
title = group.Name
|
title = group.Name
|
||||||
price = group.Price
|
price = group.Price
|
||||||
} else {
|
} else {
|
||||||
orderType = model.PackOrderType
|
orderType = model.ScoreOrderType
|
||||||
productID = pack.ID
|
productID = 0
|
||||||
title = pack.Name
|
title = fmt.Sprintf("%d 积分", num)
|
||||||
price = pack.Price
|
price = model.GetIntSetting("score_price", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建订单记录
|
// 创建订单记录
|
||||||
|
|
|
@ -53,12 +53,19 @@ func GiveGroup(user *model.User, groupInfo *serializer.GroupProducts, num int) e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GiveScore 积分充值
|
||||||
|
func GiveScore(user *model.User, num int) error {
|
||||||
|
user.AddScore(num)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GiveProduct “发货”
|
// GiveProduct “发货”
|
||||||
func GiveProduct(user *model.User, pack *serializer.PackProduct, group *serializer.GroupProducts, num int) error {
|
func GiveProduct(user *model.User, pack *serializer.PackProduct, group *serializer.GroupProducts, num int) error {
|
||||||
if pack != nil {
|
if pack != nil {
|
||||||
return GivePack(user, pack, num)
|
return GivePack(user, pack, num)
|
||||||
} else if group != nil {
|
} else if group != nil {
|
||||||
return GiveGroup(user, group, num)
|
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 {
|
if _, err := order.Create(); err != nil {
|
||||||
return nil, ErrInsertOrder.WithError(err)
|
return nil, ErrInsertOrder.WithError(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,17 +68,18 @@ type GroupProducts struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildProductResponse 构建增值服务商品响应
|
// BuildProductResponse 构建增值服务商品响应
|
||||||
func BuildProductResponse(groups []GroupProducts, packs []PackProduct, alipay, payjs bool) Response {
|
func BuildProductResponse(groups []GroupProducts, packs []PackProduct, alipay, payjs bool, scorePrice int) Response {
|
||||||
// 隐藏响应中的用户组ID
|
// 隐藏响应中的用户组ID
|
||||||
for i := 0; i < len(groups); i++ {
|
for i := 0; i < len(groups); i++ {
|
||||||
groups[i].GroupID = 0
|
groups[i].GroupID = 0
|
||||||
}
|
}
|
||||||
return Response{
|
return Response{
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"packs": packs,
|
"packs": packs,
|
||||||
"groups": groups,
|
"groups": groups,
|
||||||
"alipay": alipay,
|
"alipay": alipay,
|
||||||
"payjs": payjs,
|
"payjs": payjs,
|
||||||
|
"score_price": scorePrice,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ type GeneralVASService struct {
|
||||||
|
|
||||||
// CreateOrderService 创建订单服务
|
// CreateOrderService 创建订单服务
|
||||||
type CreateOrderService struct {
|
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"`
|
Method string `json:"method" binding:"required,eq=alipay|eq=score|eq=payjs"`
|
||||||
ID int64 `json:"id" binding:"required"`
|
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 创建新订单
|
// Create 创建新订单
|
||||||
|
@ -40,7 +40,7 @@ func (service *CreateOrderService) Create(c *gin.Context, user *model.User) seri
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if service.Action == "pack" {
|
||||||
for _, v := range packs {
|
for _, v := range packs {
|
||||||
if v.ID == service.ID {
|
if v.ID == service.ID {
|
||||||
pack = &v
|
pack = &v
|
||||||
|
@ -48,8 +48,12 @@ func (service *CreateOrderService) Create(c *gin.Context, user *model.User) seri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 购买积分
|
||||||
if pack == nil && group == nil {
|
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 获取商品信息
|
// Products 获取商品信息
|
||||||
func (service *GeneralVASService) Products(c *gin.Context, user *model.User) serializer.Response {
|
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()
|
packs, groups, err := decodeProductInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return serializer.Err(serializer.CodeInternalSetting, "无法解析商品设置", err)
|
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) {
|
func decodeProductInfo() ([]serializer.PackProduct, []serializer.GroupProducts, error) {
|
||||||
|
|
Loading…
Reference in New Issue