fix: 合伙人提现

master
howell 3 years ago
parent c3ce77d246
commit 02dd1cd2a7

@ -46,7 +46,7 @@ func PlanMonitorTradeSucOrderTask() {
func PlanMonitorExpireOrderTask() {
now := time.Now()
var expireOrderList []order.Information
dbc.DB.Find(&expireOrderList, "status = 0 AND expire_time <= ?", now)
dbc.DB.Find(&expireOrderList, "status = 0 AND expire_time <= ? and order_type = 1", now)
for _, v := range expireOrderList {
err := CancelOrExpireOrder(&v, false)

@ -27,6 +27,13 @@ func (o Proxy) List(c *gin.Context) {
}
func (o Proxy) Count(c *gin.Context) {
id, _ := common.GetAppUserId(c)
back.Suc(c, "ok", gin.H{
"count": msg.Logic.Count(id),
})
}
func (o Proxy) Read(c *gin.Context) {
var args msg.MessageReq
if err := tools.ParseParams(&args, c); err != nil {

@ -686,24 +686,52 @@ func (o logic) CompanyApply(args company.Apply) error {
var wallet user.RecookUserWalletModel
mysql.Db.First(&wallet, "user_id = ?", args.UserID)
var apply []company.Apply
mysql.Db.Find(&apply, "user_id = ? and state = 1", args.UserID)
applied := decimal.Zero
for _, v := range apply {
applied = applied.Add(v.Amount)
}
if args.Amount.Add(applied).GreaterThan(wallet.Balance) {
return fmt.Errorf("余额不足,已申请%f, 全部%f", applied.BigFloat(), wallet.Balance.BigFloat())
var a company.Apply
mysql.Db.Where("state in (1, 2)").First(&a, "user_id = ?", args.UserID) // 带审核提现
if a.ID > 0 {
return errors.New("有待审核的记录,不需要重试")
}
res := o.CompanyAllAmount(uint(args.UserID))
args.Balance = res.Balance
args.Withdrawal = res.Withdrawal
args.TaxAmount = res.TaxAmount
args.ActualAmount = res.ActualAmount
var company company.Info
mysql.Db.First(&company, "user_id = ?", args.UserID)
args.CompanyID = int(company.ID)
return mysql.Db.Create(&args).Error
return mysql.Db.Transaction(func(tx *gorm.DB) error {
if e := tx.Create(&args).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 {
return e
}
return nil
})
}
type Data struct {
Balance decimal.Decimal `json:"balance"`
TaxAmount decimal.Decimal `json:"tax_amount"`
Withdrawal decimal.Decimal `json:"withdrawal"`
ActualAmount decimal.Decimal `json:"actual_amount"`
}
func (o logic) CompanyAllAmount(id uint) error {
return nil
func (o logic) CompanyAllAmount(id uint) (res Data) {
var record []user.RecookUserWalletBalanceListModel
mysql.Db.Where("user_id = ?", id).Where("statsu = 0").Find(&record)
for _, v := range record {
res.Balance = res.Balance.Add(v.Amount)
}
res.TaxAmount = res.Balance.
Div(decimal.NewFromFloat(1.13)).
Mul(decimal.NewFromFloat(0.13)).
Mul(decimal.NewFromFloat(1.12)).Round(2)
res.Withdrawal = res.Balance.Sub(res.ActualAmount)
res.ActualAmount = res.Withdrawal.Mul(decimal.NewFromFloat(1.06)).Round(2)
return
}

@ -1,7 +1,11 @@
package jyy
import (
"errors"
"recook/internal/model/order"
jpush2 "recook/internal/v2/lib/jpush"
"recook/internal/v2/model/jpush"
"recook/internal/v2/model/jyy"
"git.oa00.com/go/mysql"
"github.com/shopspring/decimal"
@ -15,15 +19,35 @@ type ArgsLogisticsFee struct {
func (o logic) SetFee(args ArgsLogisticsFee) error {
return mysql.Db.Transaction(func(tx *gorm.DB) error {
if e := tx.Table((&order.Information{}).TableName()).
var od order.Information
tx.First(&od, "id = ?", args.ID)
if row := tx.Table((&order.Information{}).TableName()).
Where("id = ?", args.ID).
Where("can_pay = 0").Updates(map[string]interface{}{
"can_pay": true,
"express_total_fee": args.Fee.Abs(),
"actual_total_amount": gorm.Expr("actual_total_amount + ?", args.Fee.Abs()),
}).RowsAffected; row == 0 {
return errors.New("更新失败")
}
message := "已录入订单物流费用"
if e := tx.Create(&jyy.AppUserMessage{
UserID: int(od.UserID),
Message: message,
Kind: jyy.Order,
IsRead: false,
SubID: uint64(od.ID),
}).Error; e != nil {
return e
}
// 确认收益
var ju jpush.JPush
mysql.Db.First(&ju, "user_id = ?", od.UserID)
if ju.RegistrationId != "" {
client := jpush2.GetClient()
client.PushMsgWithRegister(ju.RegistrationId, "收益到账", message)
}
return nil
})
}

@ -59,13 +59,30 @@ type ArgsWithdrawalApply struct {
func (o logic) WithdrawalApply(args ArgsWithdrawalApply) error {
now := time.Now()
return mysql.Db.Table((&company.Apply{}).TableName()).
Where("state=1").Where("id = ?", args.ID).Updates(company.Apply{
State: args.Apply,
ApplyUserID: args.ManageUserID,
ApplyTime: &now,
Content: args.Content,
}).Error
return mysql.Db.Transaction(func(tx *gorm.DB) error {
var a company.Apply
if e := tx.First(&a, "id = ?", args.ID).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,
ApplyUserID: args.ManageUserID,
ApplyTime: &now,
Content: args.Content,
}).Error; e != nil {
return e
}
// 拒绝
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 {
return e
}
}
return nil
})
}
type ArgsWithdrawalPass struct {
@ -96,7 +113,7 @@ func (o logic) WithdrawPass(args ArgsWithdrawalPass) error {
return e
}
if row := tx.Model(&w).Where("version = ?", w.Version).Updates(map[string]interface{}{
"balance": gorm.Expr("balance - ?", record.Amount),
"balance": gorm.Expr("balance - ?", record.Balance),
"version": gorm.Expr("version + 1"),
}).RowsAffected; row != 1 {
return errors.New("更新失败")
@ -104,17 +121,25 @@ func (o logic) WithdrawPass(args ArgsWithdrawalPass) error {
if e := tx.Create(&user.RecookUserWalletBalanceListModel{
UserId: uint(record.UserID),
IncomeType: user.RecookUserWalletBalanceListIncomeTypeWithdraw,
Amount: record.Amount.Neg(),
Title: fmt.Sprintf("提现%f", record.Amount.BigFloat()),
Amount: record.Balance.Neg(),
Title: fmt.Sprintf("提现%f", record.ActualAmount.BigFloat()),
Comment: "提现",
OrderId: 0,
OrderGoodsId: 0,
OrderTime: formatime.Second{},
CreatedAt: formatime.NewSecondNow(),
ProfitID: 0,
Status: 2,
}).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

@ -25,6 +25,12 @@ func (o logic) List(args MessageReq) (data []jyy.AppUserMessage, total int64) {
return
}
func (o logic) Count(id uint) (total int64) {
query := mysql.Db.Table((&jyy.AppUserMessage{}).TableName()).Where("is_read=0").Where("user_id=?", id)
query.Count(&total)
return
}
func (o logic) Read(args MessageReq) error {
query := mysql.Db.Table((&jyy.AppUserMessage{}).TableName()).Where("user_id = ?", args.UserID)
if !args.IsAll {

@ -148,6 +148,10 @@ type Apply struct {
User *user.Information `json:"-" gorm:"foreignKey:UserID"`
Mobile string `json:"mobile" gorm:"-"`
Nickname string `json:"nickname" gorm:"-"`
Balance decimal.Decimal `json:"balance"`
TaxAmount decimal.Decimal `json:"tax_amount"`
Withdrawal decimal.Decimal `json:"withdrawal"`
ActualAmount decimal.Decimal `json:"actual_amount"`
}
func (o Apply) TableName() string {

@ -1,9 +1,10 @@
package user
import (
"recook/internal/v2/lib/db"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
"recook/internal/v2/lib/db"
)
const (
@ -27,6 +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"`
}
// TableName sets the insert table name for this struct type

@ -287,6 +287,7 @@ func routerApp(appRouter *gin.RouterGroup) {
proxy := msg.Proxy{}
{
messageController.POST("list", proxy.List)
messageController.POST("count", proxy.Count)
messageController.POST("read", proxy.Read)
messageController.POST("read_all", proxy.ReadAll)
}

Loading…
Cancel
Save