o2o公共业务代码
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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