fix: withdrawal

master
howell 3 years ago
parent 798d94de98
commit 70c5566db1

@ -685,13 +685,10 @@ func (o logic) CompanyApply(args company.Apply) error {
}
var wallet user.RecookUserWalletModel
mysql.Db.First(&wallet, "user_id = ?", args.UserID)
var a company.Apply
mysql.Db.Where("state in (1, 2)").First(&a, "user_id = ?", args.UserID) // 带审核提现
if a.ID > 0 {
return errors.New("有待审核的记录,不需要重试")
if e := mysql.Db.First(&wallet, "user_id = ?", args.UserID).Error; e != nil {
return e
}
res := o.CompanyAllAmount(uint(args.UserID))
args.Balance = res.Balance
args.Withdrawal = res.Withdrawal
@ -705,8 +702,13 @@ func (o logic) CompanyApply(args company.Apply) error {
if e := tx.Create(&args).Error; e != nil {
return e
}
if e := tx.Model(&wallet).Update("balance", gorm.Expr("balance - ?", args.Balance)).Error; e != nil {
return e
}
if e := tx.Table((&user.RecookUserWalletBalanceListModel{}).TableName()).
Where("user_id = ?", args.UserID).Where("statsu = 0").Update("status", 1).Error; e != nil {
Where("user_id = ?", args.UserID).
Where("statsu = 0").
Update("apply_id", args.ID).Error; e != nil {
return e
}
return nil

@ -1,7 +1,6 @@
package jyy
import (
"errors"
"fmt"
"recook/internal/libs/bean"
"recook/internal/v2/model/company"
@ -64,6 +63,13 @@ func (o logic) WithdrawalApply(args ArgsWithdrawalApply) error {
if e := tx.First(&a, "id = ?", args.ID).Error; e != nil {
return e
}
if a.State != 1 {
return nil
}
var wallet user.RecookUserWalletModel
if e := mysql.Db.First(&wallet, "user_id = ?", a.UserID).Error; e != nil {
return e
}
if e := tx.Table((&company.Apply{}).TableName()).
Where("state=1").Where("id = ?", args.ID).Updates(company.Apply{
State: args.Apply,
@ -76,7 +82,10 @@ func (o logic) WithdrawalApply(args ArgsWithdrawalApply) error {
// 拒绝
if args.Apply == 99 {
if e := tx.Table((&user.RecookUserWalletBalanceListModel{}).TableName()).
Where("user_id = ?", a.UserID).Where("statsu = 1").Update("status", 0).Error; e != nil {
Where("user_id = ?", a.UserID).Where("apply_id = ?", a.ID).Update("status", 0).Error; e != nil {
return e
}
if e := tx.Model(&wallet).Update("balance", gorm.Expr("balance + ?", a.Balance)).Error; e != nil {
return e
}
}
@ -112,12 +121,12 @@ func (o logic) WithdrawPass(args ArgsWithdrawalPass) error {
if e := tx.First(&w, "user_id = ?", record.UserID).Error; e != nil {
return e
}
if row := tx.Model(&w).Where("version = ?", w.Version).Updates(map[string]interface{}{
"balance": gorm.Expr("balance - ?", record.Balance),
"version": gorm.Expr("version + 1"),
}).RowsAffected; row != 1 {
return errors.New("更新失败")
}
// if row := tx.Model(&w).Where("version = ?", w.Version).Updates(map[string]interface{}{
// "balance": gorm.Expr("balance - ?", record.Balance),
// "version": gorm.Expr("version + 1"),
// }).RowsAffected; row != 1 {
// return errors.New("更新失败")
// }
if e := tx.Create(&user.RecookUserWalletBalanceListModel{
UserId: uint(record.UserID),
IncomeType: user.RecookUserWalletBalanceListIncomeTypeWithdraw,
@ -129,17 +138,10 @@ func (o logic) WithdrawPass(args ArgsWithdrawalPass) error {
OrderTime: formatime.Second{},
CreatedAt: formatime.NewSecondNow(),
ProfitID: 0,
Status: 2,
ApplyID: record.ID,
}).Error; e != nil {
return e
}
// 通过
if e := tx.Table((&user.RecookUserWalletBalanceListModel{}).TableName()).
Where("user_id = ?", record.UserID).
Where("statsu = 1").
Update("status", 2).Error; e != nil {
return e
}
return nil
}); err != nil {
return err

@ -28,7 +28,7 @@ type RecookUserWalletBalanceListModel struct {
OrderTime formatime.Second `gorm:"column:order_time" json:"orderTime,omitempty"`
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt,omitempty"`
ProfitID uint `json:"profit_id"`
Status int `json:"status"`
ApplyID int `json:"apply_id"`
}
// TableName sets the insert table name for this struct type

@ -299,7 +299,8 @@ func routerApp(appRouter *gin.RouterGroup) {
companyController.POST("info", proxy.CompanyInfo)
companyController.POST("apply/list", proxy.CompanyApplyList) // 提现列表
companyController.POST("apply/all_amount", proxy.CompanyAllAmount)
companyController.POST("apply", proxy.CompanyApply) // 提现
companyController.POST("apply", proxy.CompanyApply) // 提现
companyController.POST("deposit", proxy.CompanyDespoit) // 充值
companyController.POST("deposit/list", proxy.DespoitInfo) // 充值列表
companyController.POST("record/list", proxy.RecordInfo) // 钱包记录

Loading…
Cancel
Save