golang 的 rabbitmq 消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_refund.go 2.2 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "time"
  8. "xorm.io/xorm"
  9. )
  10. //公共处理记录
  11. func DealMoneyWithEg(eg *xorm.Engine, uid int, paidPrice string, orderAction int, ordId int64, id int64, goodsId int, ItemTitle string, ordType string, is_reduce int) {
  12. if utils.StrToFloat64(paidPrice) == 0 {
  13. return
  14. }
  15. //TODO 暂时退到余额
  16. session := eg.NewSession()
  17. userProfile, err := db.UserProfileFindByIdWithSession(session, uid)
  18. if err != nil || userProfile == nil {
  19. _ = session.Rollback()
  20. return
  21. }
  22. // 更新用户余额
  23. beforeAmount := userProfile.FinValid
  24. var types = 0
  25. if is_reduce == 1 {
  26. types = 1
  27. userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) - utils.StrToFloat64(paidPrice))
  28. } else {
  29. userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) + utils.StrToFloat64(paidPrice))
  30. }
  31. userProfile.FinTotal = userProfile.FinTotal + utils.StrToFloat32(paidPrice)
  32. affected, err := db.UserProfileUpdateWithSession(session, uid, userProfile, "fin_valid", "fin_total")
  33. if affected == 0 {
  34. _ = session.Rollback()
  35. return
  36. }
  37. if err != nil {
  38. _ = session.Rollback()
  39. return
  40. }
  41. // 开始写入流水
  42. FlowInsert(eg, uid, paidPrice, orderAction, ordId, id, goodsId, ItemTitle, ordType, types, beforeAmount, userProfile.FinValid)
  43. }
  44. // 开始写入流水
  45. func FlowInsert(eg *xorm.Engine, uid int, paidPrice string, orderAction int, ordId int64, id int64, goodsId int, ItemTitle string, ordType string, types int, beforeAmount string, afterAmount string) {
  46. session := eg.NewSession()
  47. now := time.Now()
  48. if err := db.FinUserFlowInsertOneWithSession(
  49. session,
  50. &model.FinUserFlow{
  51. Type: types,
  52. Uid: uid,
  53. Amount: paidPrice,
  54. BeforeAmount: beforeAmount,
  55. AfterAmount: afterAmount,
  56. OrdType: ordType,
  57. OrdId: utils.Int64ToStr(ordId),
  58. OrdAction: orderAction,
  59. OrdDetail: utils.IntToStr(goodsId),
  60. State: 2,
  61. OtherId: id,
  62. OrdTitle: ItemTitle,
  63. OrdTime: int(now.Unix()),
  64. CreateAt: now,
  65. UpdateAt: now,
  66. }); err != nil {
  67. _ = session.Rollback()
  68. _ = logx.Warn(err)
  69. return
  70. }
  71. }