mirror of https://github.com/rocboss/paopao-ce
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.
59 lines
1.3 KiB
59 lines
1.3 KiB
2 years ago
|
// Copyright 2022 ROC. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package broker
|
||
3 years ago
|
|
||
|
import (
|
||
2 years ago
|
"github.com/rocboss/paopao-ce/internal/core"
|
||
3 years ago
|
"time"
|
||
|
|
||
3 years ago
|
"github.com/gin-gonic/gin"
|
||
3 years ago
|
"github.com/rocboss/paopao-ce/internal/conf"
|
||
3 years ago
|
"github.com/rocboss/paopao-ce/pkg/errcode"
|
||
3 years ago
|
)
|
||
|
|
||
|
type RechargeReq struct {
|
||
|
Amount int64 `json:"amount" form:"amount" binding:"required"`
|
||
|
}
|
||
|
|
||
2 years ago
|
func GetRechargeByID(id int64) (*core.WalletRecharge, error) {
|
||
3 years ago
|
return ds.GetRechargeByID(id)
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
func CreateRecharge(userID, amount int64) (*core.WalletRecharge, error) {
|
||
3 years ago
|
return ds.CreateRecharge(userID, amount)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
func FinishRecharge(ctx *gin.Context, id int64, tradeNo string) error {
|
||
3 years ago
|
if ok, _ := conf.Redis.SetNX(ctx, "PaoPaoRecharge:"+tradeNo, 1, time.Second*5).Result(); ok {
|
||
3 years ago
|
recharge, err := ds.GetRechargeByID(id)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
if recharge.TradeStatus != "TRADE_SUCCESS" {
|
||
|
|
||
|
// 标记为已付款
|
||
3 years ago
|
err := ds.HandleRechargeSuccess(recharge, tradeNo)
|
||
3 years ago
|
defer conf.Redis.Del(ctx, "PaoPaoRecharge:"+tradeNo)
|
||
3 years ago
|
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
2 years ago
|
func BuyPostAttachment(post *core.Post, user *core.User) error {
|
||
3 years ago
|
if user.Balance < post.AttachmentPrice {
|
||
|
return errcode.InsuffientDownloadMoney
|
||
|
}
|
||
|
|
||
|
// 执行购买
|
||
3 years ago
|
return ds.HandlePostAttachmentBought(post, user)
|
||
3 years ago
|
}
|