o2o公共业务代码
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 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package db
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/db/model"
  4. "errors"
  5. "xorm.io/xorm"
  6. )
  7. func UpdateMerchant(engine *xorm.Engine, merchant *model.O2oMerchant) error {
  8. update, err := engine.ID(merchant.Id).AllCols().Update(merchant)
  9. if err != nil || update == 0 {
  10. if err == nil {
  11. err = errors.New("更新数据异常!")
  12. }
  13. return err
  14. }
  15. return nil
  16. }
  17. func MerchantExistByPhoneAndPassword(Db *xorm.Engine, username string, password string) (bool, error) {
  18. has, err := Db.Where("phone = ? AND password = ?", username, password).Exist(&model.O2oMerchant{})
  19. if err != nil {
  20. return false, err
  21. }
  22. return has, nil
  23. }
  24. func MerchantFindByMobileOrId(Db *xorm.Engine, mobileOrId string) (*model.O2oMerchant, error) {
  25. var m model.O2oMerchant
  26. if has, err := Db.Where("(phone = ? OR id = ?)", mobileOrId, mobileOrId).
  27. Get(&m); err != nil || has == false {
  28. return nil, err
  29. }
  30. return &m, nil
  31. }
  32. func MerchantUpdateWithSession(sess *xorm.Session, merchant *model.O2oMerchant, forceCols ...string) (int64, error) {
  33. var (
  34. affected int64
  35. err error
  36. )
  37. if forceCols != nil {
  38. affected, err = sess.Where("id = ?", merchant.Id).Cols(forceCols...).Update(merchant)
  39. } else {
  40. affected, err = sess.Where("id = ?", merchant.Id).Update(merchant)
  41. }
  42. if err != nil {
  43. return 0, err
  44. }
  45. return affected, nil
  46. }
  47. func MerchantFindByUId(Db *xorm.Engine, uid string) (*model.O2oMerchant, error) {
  48. var m model.O2oMerchant
  49. if has, err := Db.Where("uid = ?", uid).
  50. Get(&m); err != nil || has == false {
  51. return nil, err
  52. }
  53. return &m, nil
  54. }
  55. // UserisExistByMobile is exist
  56. func MerchantExistByMobile(Db *xorm.Engine, n string) (bool, error) {
  57. has, err := Db.Where("phone = ?", n).Exist(&model.O2oMerchant{})
  58. if err != nil {
  59. return false, err
  60. }
  61. return has, nil
  62. }
  63. // MerchantGetByMobileIgnoreDelete search merchant by mobile ignore delete
  64. func MerchantGetByMobileIgnoreDelete(Db *xorm.Engine, mobile string) (*model.O2oMerchant, bool, error) {
  65. m := new(model.O2oMerchant)
  66. has, err := Db.Where("phone = ?", mobile).Get(m)
  67. if err != nil {
  68. return nil, false,err
  69. }
  70. return m, has, nil
  71. }
  72. func MerchantUpdate(Db *xorm.Engine, merchant *model.O2oMerchant, forceCols ...string) (int64, error) {
  73. var (
  74. affected int64
  75. err error
  76. )
  77. if forceCols != nil {
  78. affected, err = Db.ID(merchant.Id).Cols(forceCols...).Update(merchant)
  79. } else {
  80. affected, err = Db.ID(merchant.Id).Update(merchant)
  81. }
  82. if err != nil {
  83. return 0, err
  84. }
  85. return affected, nil
  86. }
  87. //MerchantInsert is insert user
  88. func MerchantInsert(Db *xorm.Engine, user *model.O2oMerchant) (int64, error) {
  89. affected, err := Db.Insert(user)
  90. if err != nil {
  91. return 0, err
  92. }
  93. return affected, nil
  94. }
  95. // MerchantDelete is delete user
  96. func MerchantDelete(Db *xorm.Engine, uid interface{}) (int64, error) {
  97. return Db.ID(uid).Delete(model.O2oMerchant{})
  98. }