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.

db_merchant.go 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package db
  2. import (
  3. "applet/app/e"
  4. "applet/app/utils"
  5. "applet/app/utils/logx"
  6. "applet/supply/db/model"
  7. "errors"
  8. "fmt"
  9. "reflect"
  10. "xorm.io/xorm"
  11. )
  12. // MerchantFindByParams 通过传入的参数查询数据(多条)
  13. func MerchantFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.Merchant, error) {
  14. var m []model.Merchant
  15. if params["key"] == nil {
  16. //查询全部数据
  17. err := Db.Find(&m)
  18. if err != nil {
  19. return nil, logx.Error(err)
  20. }
  21. return &m, nil
  22. } else {
  23. if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
  24. //指定In查询
  25. if err := Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
  26. return nil, logx.Warn(err)
  27. }
  28. return &m, nil
  29. } else {
  30. var query = fmt.Sprintf("%s =?", params["key"])
  31. err := Db.Where(query, params["value"]).Find(&m)
  32. if err != nil {
  33. return nil, logx.Error(err)
  34. }
  35. return &m, nil
  36. }
  37. }
  38. }
  39. // MerchantProfileFindByParams 通过传入的参数查询数据(多条)
  40. func MerchantProfileFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.MerchantProfile, error) {
  41. var m []model.MerchantProfile
  42. if params["key"] == nil {
  43. //查询全部数据
  44. err := Db.Find(&m)
  45. if err != nil {
  46. return nil, logx.Error(err)
  47. }
  48. return &m, nil
  49. } else {
  50. if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
  51. //指定In查询
  52. if err := Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
  53. return nil, logx.Warn(err)
  54. }
  55. return &m, nil
  56. } else {
  57. var query = fmt.Sprintf("%s =?", params["key"])
  58. err := Db.Where(query, params["value"]).Find(&m)
  59. if err != nil {
  60. return nil, logx.Error(err)
  61. }
  62. return &m, nil
  63. }
  64. }
  65. }
  66. func GetMerchantById(eg *xorm.Engine, id int) (*model.Merchant, error) {
  67. var m model.Merchant
  68. get, err := eg.ID(id).Get(&m)
  69. if err != nil {
  70. return nil, err
  71. }
  72. if !get {
  73. return nil, errors.New("账号不存在")
  74. }
  75. return &m, nil
  76. }
  77. func GetSystemMerchant(eg *xorm.Engine) (bool, *model.Merchant, error) {
  78. var m model.Merchant
  79. get, err := eg.Where("is_system = 1").Get(&m)
  80. if err != nil {
  81. return get, nil, err
  82. }
  83. return get, &m, nil
  84. }
  85. func GetMerchantByIdWithSession(session *xorm.Session, id int) (*model.Merchant, error) {
  86. var m model.Merchant
  87. get, err := session.ID(id).Get(&m)
  88. if err != nil {
  89. return nil, err
  90. }
  91. if !get {
  92. return nil, errors.New("账号不存在")
  93. }
  94. return &m, nil
  95. }
  96. func GetMerchantByPhone(eg *xorm.Engine, phone string) (*model.Merchant, error) {
  97. var m model.Merchant
  98. get, err := eg.Where("phone=?", phone).Get(&m)
  99. if err != nil {
  100. return nil, err
  101. }
  102. if !get {
  103. return nil, e.NewErr(e.ERR_ITEM_NOT_FOUND, "手机号不存在")
  104. }
  105. return &m, nil
  106. }
  107. func CheckMerchantPhoneExists(eg *xorm.Engine, phone string) (bool, error) {
  108. exist, err := eg.Where("phone=?", phone).Exist(&model.Merchant{})
  109. if err != nil {
  110. return false, err
  111. }
  112. return exist, nil
  113. }
  114. func GetMerchantApplyById(eg *xorm.Engine, id interface{}) (*model.MerchantProfile, error) {
  115. var m model.MerchantProfile
  116. get, err := eg.ID(id).Get(&m)
  117. if err != nil {
  118. return nil, err
  119. }
  120. if !get {
  121. return nil, e.NewErr(e.ERR_ITEM_NOT_FOUND, "该申请不存在")
  122. }
  123. return &m, nil
  124. }