|
|
@@ -81,6 +81,30 @@ func handleZhiosGuideStoreOrderSuccess(msg []byte) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if canalMsg.Type == "down" { |
|
|
|
err := down(eg, canalMsg) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func down(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error { |
|
|
|
sess := eg.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Begin() |
|
|
|
//退积分 |
|
|
|
sum := canalMsg.DeductPrice |
|
|
|
//退积分 |
|
|
|
// 111商家发布商品扣除 112商家商品审核失败退回 113 商家删除商品退回 114商品退款退回 115商家商品下架退回 |
|
|
|
err := UpdateUserFinValidAndInterFlowFreezeSess(sess, |
|
|
|
utils.AnyToString(sum), "商品("+canalMsg.ItemId+")删除"+canalMsg.Stock+"个退回", "0", 1, utils.StrToInt(canalMsg.Uid), utils.StrToInt(canalMsg.CoinId), 113, utils.StrToInt64(utils.OrderUUID(utils.StrToInt(canalMsg.Uid)))) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
sess.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
func success(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error { |
|
|
@@ -160,6 +184,44 @@ func fail(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error { |
|
|
|
sess.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
func UpdateUserFinValidAndInterFlowFreezeSess(session *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error { |
|
|
|
UserVirtualAmount, err := db.UserVirtualAmountFindByIdWithSession(session, uid, coinId) |
|
|
|
if err != nil || UserVirtualAmount == nil { |
|
|
|
if err == nil { |
|
|
|
err = errors.New("获取用户余额信息失败") |
|
|
|
} |
|
|
|
return err |
|
|
|
} |
|
|
|
beforeAmount := UserVirtualAmount.Amount |
|
|
|
freezeBeforeAmount := UserVirtualAmount.FreezeAmount |
|
|
|
|
|
|
|
if types == 1 { |
|
|
|
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) + utils.StrToFloat64(money)) |
|
|
|
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money)) |
|
|
|
} else if types == 2 { |
|
|
|
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money)) |
|
|
|
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) + utils.StrToFloat64(money)) |
|
|
|
if utils.StrToFloat64(UserVirtualAmount.Amount) < 0 { |
|
|
|
return errors.New("额度不足") |
|
|
|
} |
|
|
|
} |
|
|
|
afterAmount := UserVirtualAmount.Amount |
|
|
|
freezeAfterAmount := UserVirtualAmount.FreezeAmount |
|
|
|
|
|
|
|
affected, err := db.UserVirtualAmountUpdateWithSession(session, uid, coinId, UserVirtualAmount, "amount,freeze_amount") |
|
|
|
if err != nil || affected == 0 { |
|
|
|
if err == nil { |
|
|
|
err = errors.New("更新用户余额信息失败") |
|
|
|
} |
|
|
|
return err |
|
|
|
} |
|
|
|
err = virtualCoinFlowInsert(session, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error { |
|
|
|
UserVirtualAmount, err := db.UserVirtualAmountFindById(sess, uid, coinId) |
|
|
|
if err != nil || UserVirtualAmount == nil { |
|
|
@@ -169,6 +231,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, |
|
|
|
return err |
|
|
|
} |
|
|
|
beforeAmount := UserVirtualAmount.Amount |
|
|
|
freezeBeforeAmount := UserVirtualAmount.FreezeAmount |
|
|
|
if types == 2 { |
|
|
|
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money)) |
|
|
|
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money)) |
|
|
@@ -177,6 +240,8 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, |
|
|
|
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money)) |
|
|
|
} |
|
|
|
afterAmount := UserVirtualAmount.Amount |
|
|
|
freezeAfterAmount := UserVirtualAmount.FreezeAmount |
|
|
|
|
|
|
|
affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "amount") |
|
|
|
if err != nil || affected == 0 { |
|
|
|
if err == nil { |
|
|
@@ -184,7 +249,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, |
|
|
|
} |
|
|
|
return err |
|
|
|
} |
|
|
|
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount) |
|
|
|
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
@@ -200,6 +265,8 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee |
|
|
|
return err |
|
|
|
} |
|
|
|
beforeAmount := UserVirtualAmount.Amount |
|
|
|
freezeBeforeAmount := UserVirtualAmount.FreezeAmount |
|
|
|
|
|
|
|
if types == 2 { |
|
|
|
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money)) |
|
|
|
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money)) |
|
|
@@ -208,6 +275,7 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee |
|
|
|
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money)) |
|
|
|
} |
|
|
|
afterAmount := UserVirtualAmount.Amount |
|
|
|
freezeAfterAmount := UserVirtualAmount.FreezeAmount |
|
|
|
affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "freeze_amount,use_amount") |
|
|
|
if err != nil || affected == 0 { |
|
|
|
if err == nil { |
|
|
@@ -215,28 +283,30 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee |
|
|
|
} |
|
|
|
return err |
|
|
|
} |
|
|
|
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount) |
|
|
|
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string) error { |
|
|
|
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string, freezeBeforeAmount string, freezeAfterAmount string) error { |
|
|
|
now := time.Now() |
|
|
|
if err := db.UserVirtualCoinFlowInsertOne( |
|
|
|
sess, |
|
|
|
&model.UserVirtualCoinFlow{ |
|
|
|
Uid: uid, |
|
|
|
OrdId: utils.Int64ToStr(ordId), |
|
|
|
CoinId: coinId, |
|
|
|
Direction: types, |
|
|
|
Title: ItemTitle, |
|
|
|
Amout: money, |
|
|
|
BeforeAmout: beforeAmount, |
|
|
|
AfterAmout: afterAmount, |
|
|
|
SysFee: SysFee, |
|
|
|
CreateTime: now, |
|
|
|
TransferType: transferType, |
|
|
|
Uid: uid, |
|
|
|
OrdId: utils.Int64ToStr(ordId), |
|
|
|
CoinId: coinId, |
|
|
|
Direction: types, |
|
|
|
Title: ItemTitle, |
|
|
|
Amout: money, |
|
|
|
FreezeBeforeAmout: freezeBeforeAmount, |
|
|
|
FreezeAfterAmout: freezeAfterAmount, |
|
|
|
BeforeAmout: beforeAmount, |
|
|
|
AfterAmout: afterAmount, |
|
|
|
SysFee: SysFee, |
|
|
|
CreateTime: now, |
|
|
|
TransferType: transferType, |
|
|
|
}); err != nil { |
|
|
|
_ = logx.Warn(err) |
|
|
|
return err |
|
|
|