附近小店
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.

db_user_fin_flow.go 3.7 KiB

3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. // GetFinUserFlowByID is 用户流水记录
  8. func GetFinUserFlowByID(Db *xorm.Engine, id interface{}) (*model.FinUserFlow, error) {
  9. var m model.FinUserFlow
  10. if has, err := Db.Where("id = ?", id).Get(&m); err != nil || !has {
  11. return nil, logx.Warn(err)
  12. }
  13. return &m, nil
  14. }
  15. // GetFinUserFlowByID is 用户流水记录
  16. func GetFinUserFlowByUIDANDOID(Db *xorm.Engine, types, uid, ordId string) (*model.FinUserFlow, error) {
  17. var m model.FinUserFlow
  18. if has, err := Db.Where("uid = ? and ord_id = ? and type = ?", uid, ordId, types).Get(&m); err != nil || !has {
  19. return nil, logx.Warn(err)
  20. }
  21. return &m, nil
  22. }
  23. func GetFinUserFlowByUIDANDOIDTOORDTYPE(Db *xorm.Engine, types, uid, ordId string) (*model.FinUserFlow, error) {
  24. var m model.FinUserFlow
  25. if has, err := Db.Where("uid = ? and ord_id = ? and ord_type = ?", uid, ordId, types).Get(&m); err != nil || !has {
  26. return nil, logx.Warn(err)
  27. }
  28. return &m, nil
  29. }
  30. // GetFinUserFlowByID is 用户流水记录
  31. func GetFinUserFlowByOIDANDORDTYPE(Db *xorm.Engine, types, ordId, ordType string) (*model.FinUserFlow, error) {
  32. var m model.FinUserFlow
  33. if has, err := Db.Where("ord_id = ? and ord_action = ? and ord_type= ?", ordId, types, ordType).Get(&m); err != nil || !has {
  34. return nil, logx.Warn(err)
  35. }
  36. return &m, nil
  37. }
  38. //FinUserFlowInsertOne is 插入一条流水记录
  39. func FinUserFlowInsertOne(Db *xorm.Engine, m *model.FinUserFlow) error {
  40. _, err := Db.InsertOne(m)
  41. if err != nil {
  42. return err
  43. }
  44. return nil
  45. }
  46. //FinUserFlowInsertOne is 插入一条流水记录
  47. func FinUserFlowWithSessionInsertOne(session *xorm.Session, m *model.FinUserFlow) error {
  48. _, err := session.InsertOne(m)
  49. if err != nil {
  50. return err
  51. }
  52. return nil
  53. }
  54. // FinUserFlowByUID is 用户流水
  55. func FinUserFlowInputByUID(Db *xorm.Engine, uid interface{}, time string, limit, start int) ([]*model.FinUserFlow, error) {
  56. var m []*model.FinUserFlow
  57. if err := Db.Where("uid = ? AND create_at like ? and (amount> ? or ord_type=?)", uid, time+"%", "0", "fast_return").In("type", "0").Desc("create_at").Limit(limit, start).Find(&m); err != nil {
  58. return nil, logx.Warn(err)
  59. }
  60. return m, nil
  61. }
  62. func FinUserFlowInputByUIDWithAmount(Db *xorm.Engine, uid interface{}, types, before_amount, after_amount string) (*model.FinUserFlow, error) {
  63. var m model.FinUserFlow
  64. if has, err := Db.Where("uid = ? and ord_type='withdraw' and ord_action = ? and before_amount= ? and after_amount = ?", uid, types, before_amount, after_amount).Get(&m); err != nil || !has {
  65. return nil, logx.Warn(err)
  66. }
  67. return &m, nil
  68. }
  69. // FinUserFlowByUIDByOrderAction is 用户流水 by OrderAction
  70. func FinUserFlowInputByUIDByOrderActionByTime(Db *xorm.Engine, uid, oa interface{}, time string, limit, start int) ([]*model.FinUserFlow, error) {
  71. var m []*model.FinUserFlow
  72. if err := Db.Where("uid = ? AND create_at like ? and amount>0", uid, time+"%").In("ord_action", oa).Desc("create_at").Limit(limit, start).Find(&m); err != nil {
  73. return nil, logx.Warn(err)
  74. }
  75. return m, nil
  76. }
  77. // FinUserFlowByUIDByOrderAction is 用户流水 by OrderAction
  78. func FinUserFlowInputByUIDByTypeByTime(Db *xorm.Engine, uid int, time string, limit, start int) ([]*model.FinUserFlow, error) {
  79. var m []*model.FinUserFlow
  80. if err := Db.Where("uid = ? AND type = 1 AND create_at like ? and (amount>0 or ord_type=? or ord_action=?)", uid, time+"%", "fast_return", 101).Desc("create_at").Limit(limit, start).Find(&m); err != nil {
  81. return nil, logx.Warn(err)
  82. }
  83. return m, nil
  84. }
  85. // 在事务中使用,插入一条流水记录
  86. func FinUserFlowInsertOneWithSession(session *xorm.Session, m *model.FinUserFlow) error {
  87. _, err := session.InsertOne(m)
  88. if err != nil {
  89. return err
  90. }
  91. return nil
  92. }