user_password.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 买方研选网页版用户设置登录密码
  7. type CygxUserPassword struct {
  8. UserPasswordId int `orm:"column(user_password_id);pk";comment:"主键ID"`
  9. UserId int `comment:"用户ID"`
  10. Mobile string `comment:"手机号"`
  11. RealName string `comment:"用户实际名称"`
  12. Password string `comment:"密码"`
  13. CreateTime time.Time `comment:"创建时间"`
  14. ModifyTime time.Time `comment:"修改时间"`
  15. }
  16. type SetUserPasswordReq struct {
  17. Mobile string `comment:"手机号"`
  18. VCode string `description:"验证码"`
  19. Password string `comment:"密码"`
  20. }
  21. type UpdateUserPasswordReq struct {
  22. OldPassword string `comment:"旧密码"`
  23. NewPassword string `comment:"新密码"`
  24. }
  25. // 获取数量
  26. func GetCygxUserPasswordCountByMobile(mobile string) (count int, err error) {
  27. o := orm.NewOrm()
  28. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_password WHERE mobile = ? `
  29. err = o.Raw(sqlCount, mobile).QueryRow(&count)
  30. return
  31. }
  32. // 获取数量
  33. func GetCygxUserPasswordCountByMobileAdnPss(mobile, password string) (count int, err error) {
  34. o := orm.NewOrm()
  35. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_password WHERE mobile = ? AND password = ?`
  36. err = o.Raw(sqlCount, mobile, password).QueryRow(&count)
  37. return
  38. }
  39. // 添加
  40. func AddCygxUserPassword(item *CygxUserPassword) (err error) {
  41. o := orm.NewOrm()
  42. _, err = o.Insert(item)
  43. return
  44. }
  45. // 根据手机号修改密码
  46. func UpdateCygxUserPassword(mobile, password string) (err error) {
  47. o := orm.NewOrm()
  48. updateParams := make(map[string]interface{})
  49. updateParams["Password"] = password
  50. updateParams["ModifyTime"] = time.Now()
  51. ptrStructOrTableName := "cygx_user_password"
  52. whereParam := map[string]interface{}{"mobile": mobile}
  53. qs := o.QueryTable(ptrStructOrTableName)
  54. for expr, exprV := range whereParam {
  55. qs = qs.Filter(expr, exprV)
  56. }
  57. _, err = qs.Update(updateParams)
  58. if err != nil {
  59. return
  60. }
  61. return
  62. }