智慧食堂
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

98 wiersze
2.6 KiB

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. "errors"
  7. )
  8. func UserList(req md.UserListReq) (resp md.UserListResp, err error) {
  9. var m []model.User
  10. userDb := db.UserDb{}
  11. userDb.Set()
  12. sess := userDb.Db.Join("LEFT", "user_identity", "user.id = user_identity.uid").
  13. Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").Limit(req.Limit, (req.Page-1)*req.Limit)
  14. sess.Where("1=1")
  15. if req.Phone != "" {
  16. sess.And("user.phone like ?", "%"+req.Phone+"%")
  17. }
  18. if req.Nickname != "" {
  19. sess.And("user.nickname like ?", "%"+req.Nickname+"%")
  20. }
  21. if req.CreateTimeStart != "" {
  22. sess.And("user.create_at >= ?", req.CreateTimeStart)
  23. }
  24. if req.CreateTimeEnd != "" {
  25. sess.And("user.create_at <= ?", req.CreateTimeEnd)
  26. }
  27. resp.Total, err = sess.Desc("user.id").FindAndCount(&m)
  28. if err != nil {
  29. return
  30. }
  31. for _, v := range m {
  32. //获取用户身份信息
  33. userIdentityDb := db.UserIdentityDb{}
  34. userIdentityDb.Set(v.Id)
  35. identity, err1 := userIdentityDb.FindUserIdentity()
  36. if err1 != nil {
  37. err = err1
  38. return
  39. }
  40. var temp = md.UserList{
  41. Id: v.Id,
  42. Nickname: v.Nickname,
  43. Phone: v.Phone,
  44. Avatar: v.Avatar,
  45. CreateAt: v.CreateAt,
  46. }
  47. for _, v1 := range *identity {
  48. temp.BindUserIdentity = append(temp.BindUserIdentity, struct {
  49. Id int `json:"id" label:"id"`
  50. IdNo string `json:"id_no" label:"身份证号"`
  51. Name string `json:"name" label:"姓名"`
  52. EnterpriseName string `json:"enterprise_name" label:"企业名"`
  53. EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"`
  54. Kind int `json:"kind" label:"身份类型"`
  55. }{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, Name: v1.UserIdentity.Name, EnterpriseName: v1.Enterprise.Name, EnterpriseKind: v1.Enterprise.Kind, Kind: v1.UserIdentity.Kind})
  56. }
  57. resp.List = append(resp.List, temp)
  58. }
  59. return
  60. }
  61. func UserUpdate(req md.UserList) (err error) {
  62. userDb := db.UserDb{}
  63. userDb.Set()
  64. user, err := userDb.GetUser(req.Id)
  65. if err != nil {
  66. return err
  67. }
  68. if user == nil {
  69. return errors.New("未获取到用户信息记录")
  70. }
  71. for _, v := range req.BindUserIdentity {
  72. //获取用户身份信息
  73. userIdentityDb := db.UserIdentityDb{}
  74. userIdentityDb.Set(v.Id)
  75. identity, err1 := userIdentityDb.GetUserIdentity(v.Id)
  76. if err1 != nil {
  77. err = err1
  78. return
  79. }
  80. if user == nil {
  81. return errors.New("未获取到用户身份信息记录")
  82. }
  83. identity.Name = v.Name
  84. identity.IdNo = v.IdNo
  85. _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
  86. if err2 != nil {
  87. err = err2
  88. return
  89. }
  90. }
  91. return
  92. }