diff --git a/rule/user_amount.go b/rule/user_amount.go index 16e6615..98c04b7 100644 --- a/rule/user_amount.go +++ b/rule/user_amount.go @@ -55,26 +55,27 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { } else if req.Kind == "sub" { userVirtualCoinFlow.Direction = 2 userVirtualCoinFlow.AfterAmout = coinAmountValue.Sub(amountValue).RoundFloor(4).String() + if zhios_order_relate_utils.StrToFloat64(userVirtualCoinFlow.AfterAmout) < 0 { + var coin model.VirtualCoin + _, err = session.Where("id = ?", req.CoinId).Get(&coin) + if err != nil { + return err + } + zhios_order_relate_utils.FilePutContents("virtual_coin_not", zhios_order_relate_utils.SerializeStr(map[string]interface{}{ + "uid": userVirtualCoinFlow.Uid, + "amount": userVirtualCoinFlow.Amout, + "before_amount": userVirtualCoinFlow.BeforeAmout, + "after_amount": userVirtualCoinFlow.AfterAmout, + "coin_id": userVirtualCoinFlow.CoinId, + })) + return errors.New("用户" + zhios_order_relate_utils.IntToStr(userVirtualCoinFlow.Uid) + "的" + coin.Name + "不足") + //userVirtualCoinFlow.AfterAmout = "0" + } } else { err = errors.New("错误的kind类型") return err } - if zhios_order_relate_utils.StrToFloat64(userVirtualCoinFlow.AfterAmout) < 0 { - var coin model.VirtualCoin - _, err = session.Where("id = ?", req.CoinId).Get(&coin) - if err != nil { - return err - } - zhios_order_relate_utils.FilePutContents("virtual_coin_not", zhios_order_relate_utils.SerializeStr(map[string]interface{}{ - "uid": userVirtualCoinFlow.Uid, - "amount": userVirtualCoinFlow.Amout, - "before_amount": userVirtualCoinFlow.BeforeAmout, - "after_amount": userVirtualCoinFlow.AfterAmout, - "coin_id": userVirtualCoinFlow.CoinId, - })) - return errors.New("用户" + zhios_order_relate_utils.IntToStr(userVirtualCoinFlow.Uid) + "的" + coin.Name + "不足") - //userVirtualCoinFlow.AfterAmout = "0" - } + //3、插入 `user_virtual_coin_flow` 记录 _, err = db.UserVirtualCoinFlowInsert(session, &userVirtualCoinFlow) if err != nil {