|
|
|
@ -1,12 +1,16 @@
|
|
|
|
|
package jyy
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"recook/internal/libs/bean"
|
|
|
|
|
"recook/internal/v2/model/company"
|
|
|
|
|
"recook/internal/v2/model/recook/user"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"git.oa00.com/go/mysql"
|
|
|
|
|
"github.com/golangkit/formatime"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -64,3 +68,57 @@ func (o logic) WithdrawalApply(args ArgsWithdrawalApply) error {
|
|
|
|
|
Content: args.Content,
|
|
|
|
|
}).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ArgsWithdrawalPass struct {
|
|
|
|
|
ID int `json:"id" validate:"required"`
|
|
|
|
|
Proof string `json:"proof"`
|
|
|
|
|
ManageUserID int `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o logic) WithdrawPass(args ArgsWithdrawalPass) error {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
var record company.Apply
|
|
|
|
|
if e := tx.First(&record, "id = ?", args.ID).Error; e != nil {
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if e := tx.Table((&company.Apply{}).TableName()).
|
|
|
|
|
Where("state=2").Where("id = ?", args.ID).Updates(company.Apply{
|
|
|
|
|
State: 3,
|
|
|
|
|
ProcessUserID: args.ManageUserID,
|
|
|
|
|
ProcessTime: &now,
|
|
|
|
|
Proof: args.Proof,
|
|
|
|
|
}).Error; e != nil {
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
var w user.RecookUserWalletModel
|
|
|
|
|
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.Amount),
|
|
|
|
|
"version": gorm.Expr("version + 1"),
|
|
|
|
|
}).RowsAffected; row != 1 {
|
|
|
|
|
return errors.New("更新失败")
|
|
|
|
|
}
|
|
|
|
|
if e := tx.Create(&user.RecookUserWalletBalanceListModel{
|
|
|
|
|
UserId: uint(record.UserID),
|
|
|
|
|
IncomeType: user.RecookUserWalletBalanceListIncomeTypeWithdraw,
|
|
|
|
|
Amount: record.Amount.Neg(),
|
|
|
|
|
Title: fmt.Sprintf("提现%f", record.Amount.BigFloat()),
|
|
|
|
|
Comment: "提现",
|
|
|
|
|
OrderId: 0,
|
|
|
|
|
OrderGoodsId: 0,
|
|
|
|
|
OrderTime: formatime.Second{},
|
|
|
|
|
CreatedAt: formatime.NewSecondNow(),
|
|
|
|
|
ProfitID: 0,
|
|
|
|
|
}).Error; e != nil {
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|