refactor platform menus and entity statuses
This commit is contained in:
@@ -133,7 +133,7 @@ func GetOrCreateOwnerWallet(ctx *gin.Context) {
|
||||
return err
|
||||
}
|
||||
candidate := models.WalletBasic{
|
||||
Entity: models.Entity{Identity: models.NewIdentity(), Status: "enabled", Version: 1},
|
||||
Entity: models.Entity{Identity: models.NewIdentity(), Status: common.StatusEnable, Version: 1},
|
||||
OwnerType: ownerType, OwnerID: ownerID, OwnerIdentity: ownerIdentity,
|
||||
}
|
||||
if err := tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&candidate).Error; err != nil {
|
||||
@@ -169,9 +169,10 @@ func resolveWalletOwner(ownerType, ownerIdentity string) (uint64, error) {
|
||||
|
||||
func UpdateWalletBasicStatus(ctx *gin.Context) {
|
||||
var request struct {
|
||||
Status string `json:"status" binding:"required"`
|
||||
Status int `json:"status" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || (request.Status != "enabled" && request.Status != "disabled") {
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil ||
|
||||
(request.Status != common.StatusEnable && request.Status != common.StatusDisable && request.Status != common.StatusFrozen) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
@@ -209,7 +210,7 @@ func RechargeWalletBasic(ctx *gin.Context) {
|
||||
}
|
||||
updates := map[string]any{"balance": gorm.Expr("balance + ?", request.Amount)}
|
||||
query := tx.Model(&models.WalletBasic{}).
|
||||
Where("id = ? AND status = ? AND balance <= ?", wallet.ID, "enabled", math.MaxInt64-request.Amount)
|
||||
Where("id = ? AND status = ? AND balance <= ?", wallet.ID, common.StatusEnable, math.MaxInt64-request.Amount)
|
||||
if request.Withdrawable {
|
||||
updates["withdrawal_balance"] = gorm.Expr("withdrawal_balance + ?", request.Amount)
|
||||
query = query.Where("withdrawal_balance <= ?", math.MaxInt64-request.Amount)
|
||||
@@ -226,7 +227,7 @@ func RechargeWalletBasic(ctx *gin.Context) {
|
||||
}
|
||||
now := time.Now()
|
||||
record = models.WalletRecord{
|
||||
Entity: models.Entity{Identity: models.NewIdentity(), Status: "posted", Version: 1},
|
||||
Entity: models.Entity{Identity: models.NewIdentity(), Status: common.StatusPosted, Version: 1},
|
||||
WalletBasicID: wallet.ID, RecordNo: models.NewIdentity(), RequestNo: request.RequestNo,
|
||||
Direction: "income", TradeType: "recharge", Amount: request.Amount,
|
||||
BalanceAfter: wallet.Balance, WithdrawalBalanceAfter: wallet.WithdrawalBalance,
|
||||
@@ -250,14 +251,14 @@ func RechargeWalletBasic(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func ApproveWalletApplyCash(ctx *gin.Context) {
|
||||
reviewWalletApplyCash(ctx, "approved")
|
||||
reviewWalletApplyCash(ctx, common.StatusApproved)
|
||||
}
|
||||
|
||||
func RejectWalletApplyCash(ctx *gin.Context) {
|
||||
reviewWalletApplyCash(ctx, "rejected")
|
||||
reviewWalletApplyCash(ctx, common.StatusRejected)
|
||||
}
|
||||
|
||||
func reviewWalletApplyCash(ctx *gin.Context, targetStatus string) {
|
||||
func reviewWalletApplyCash(ctx *gin.Context, targetStatus int) {
|
||||
if !common.RequirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
@@ -278,11 +279,11 @@ func reviewWalletApplyCash(ctx *gin.Context, targetStatus string) {
|
||||
if application.Status == targetStatus {
|
||||
return nil
|
||||
}
|
||||
if application.Status != "pending" {
|
||||
if application.Status != common.StatusPending {
|
||||
return errors.New("cash application is not pending")
|
||||
}
|
||||
now := time.Now()
|
||||
if targetStatus == "rejected" {
|
||||
if targetStatus == common.StatusRejected {
|
||||
result := tx.Model(&models.WalletBasic{}).
|
||||
Where("id = ? AND withdrawal_balance <= ?", application.WalletBasicID, math.MaxInt64-application.Amount).
|
||||
Update("withdrawal_balance", gorm.Expr("withdrawal_balance + ?", application.Amount))
|
||||
|
||||
Reference in New Issue
Block a user