|
|
@@ -10,6 +10,8 @@ import ( |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_system_rules.git" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" |
|
|
|
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" |
|
|
|
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc/sys_cfg" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" |
|
|
@@ -69,7 +71,6 @@ func EggFinWithdrawApplyDataConsume(queue md.MqQueue) { |
|
|
|
if err1 != nil { |
|
|
|
// 无法解析 直接将[]byte推进队列 |
|
|
|
data.Ext = res.Body |
|
|
|
|
|
|
|
} else { |
|
|
|
// 解析成功 |
|
|
|
err2 := copier.Copy(&data, &msg) |
|
|
@@ -97,19 +98,44 @@ func handleEggFinWithdrawApplyDataConsume(msgData []byte, client *alipay.Client) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
applyDb := implement.NewFinWithdrawApplyDb(db.Db) |
|
|
|
apply, err := applyDb.FinWithdrawApplyGet(msg.Id) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if apply == nil { |
|
|
|
return errors.New("提现记录不存在~") |
|
|
|
} |
|
|
|
|
|
|
|
// 如果不在队列处理阶段或不是自动处理订单,直接返回 |
|
|
|
if msg.State != 4 && msg.Type != 2 { |
|
|
|
return nil |
|
|
|
if apply.State != 4 && apply.Type != 2 { |
|
|
|
return errors.New("提现记录无需处理~") |
|
|
|
} |
|
|
|
|
|
|
|
session := db.Db.NewSession() |
|
|
|
defer func() { |
|
|
|
session.Close() |
|
|
|
if err := recover(); err != nil { |
|
|
|
_ = logx.Error(err) |
|
|
|
} |
|
|
|
}() |
|
|
|
session.Begin() |
|
|
|
// 2.3 更新 apply 信息 |
|
|
|
apply.State = 2 |
|
|
|
affected, err2 := applyDb.UpdateFinWithdrawApplyBySession(session, apply, "state") |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
if affected == 0 { |
|
|
|
return errors.New("更新 apply 状态失败") |
|
|
|
} |
|
|
|
|
|
|
|
applyDb := implement.NewFinWithdrawApplyDb(db.Db) |
|
|
|
if msg.WithdrawKind == 1 { |
|
|
|
// 2.支付宝提现 |
|
|
|
// 2.1 提现 |
|
|
|
// 3.支付宝提现 |
|
|
|
alipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db) |
|
|
|
userInfo, err := alipayUserInfoDb.GetAlipayUserInfo(msg.Uid) |
|
|
|
userInfo, err1 := alipayUserInfoDb.GetAlipayUserInfo(msg.Uid) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err1 |
|
|
|
} |
|
|
|
bm := make(gopay.BodyMap) |
|
|
|
bm.Set("out_biz_no", msg.Id). |
|
|
@@ -122,23 +148,54 @@ func handleEggFinWithdrawApplyDataConsume(msgData []byte, client *alipay.Client) |
|
|
|
}) |
|
|
|
_, err = client.FundTransUniTransfer(context.Background(), bm) |
|
|
|
if err != nil { |
|
|
|
//TODO::处理提现失败 |
|
|
|
err = dealFinWithdrawApplyStateForBad(apply) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
} else if msg.WithdrawKind == 2 { |
|
|
|
|
|
|
|
// 2.3 更新 apply 信息 |
|
|
|
affected, err := applyDb.UpdateFinWithdrawApply(&model.FinWithdrawApply{State: 2}, "state") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if affected == 0 { |
|
|
|
return errors.New("更新 apply 状态失败") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if msg.WithdrawKind == 2 { |
|
|
|
return session.Begin() |
|
|
|
} |
|
|
|
|
|
|
|
func dealFinWithdrawApplyStateForBad(finWithdrawApply *model.FinWithdrawApply) error { |
|
|
|
session := db.Db.NewSession() |
|
|
|
defer session.Close() |
|
|
|
session.Begin() |
|
|
|
|
|
|
|
finWithdrawApplyDb := implement.NewFinWithdrawApplyDb(db.Db) |
|
|
|
finWithdrawApply.State = int(enum.FinWithdrawApplyStateForBad) |
|
|
|
updateAffected, err1 := finWithdrawApplyDb.UpdateFinWithdrawApplyBySession(session, finWithdrawApply, "state") |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
if updateAffected <= 0 { |
|
|
|
return errors.New("更新提现单状态失败") |
|
|
|
} |
|
|
|
dealUserWalletReq := md3.DealUserWalletReq{ |
|
|
|
Direction: "sub", |
|
|
|
Kind: int(enum.UserWithdrawBad), |
|
|
|
Title: enum.UserWithdrawBad.String(), |
|
|
|
Uid: finWithdrawApply.Uid, |
|
|
|
Amount: utils2.StrToFloat64(finWithdrawApply.Amount), |
|
|
|
} |
|
|
|
|
|
|
|
err := rule.DealUserWallet(session, dealUserWalletReq) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
err = session.Commit() |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
} |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
type InitAlipayStruct struct { |
|
|
|