智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

118 行
3.0 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.Limit(req.Limit, (req.Page-1)*req.Limit)
  13. sess.Where("1=1")
  14. if req.Phone != "" {
  15. sess.And("phone like ?", "%"+req.Phone+"%")
  16. }
  17. if req.Nickname != "" {
  18. sess.And("nickname like ?", "%"+req.Nickname+"%")
  19. }
  20. if req.CreateTimeStart != "" {
  21. sess.And("create_at >= ?", req.CreateTimeStart)
  22. }
  23. if req.CreateTimeEnd != "" {
  24. sess.And("create_at <= ?", req.CreateTimeEnd)
  25. }
  26. if req.UserIdentityName != "" {
  27. var mm []model.UserIdentity
  28. engine := db.Db.Where("name like ?", "%"+req.UserIdentityName+"%")
  29. if req.EnterpriseId != 0 {
  30. engine = engine.And("enterprise_id =? ", req.EnterpriseId)
  31. }
  32. err = engine.Find(&mm)
  33. if err != nil {
  34. return
  35. }
  36. if len(mm) > 0 {
  37. var userIds []int
  38. for _, v := range mm {
  39. userIds = append(userIds, v.Uid)
  40. }
  41. sess.In("id", userIds)
  42. }
  43. }
  44. resp.Total, err = sess.Desc("user.id").FindAndCount(&m)
  45. if err != nil {
  46. return
  47. }
  48. for _, v := range m {
  49. //获取用户身份信息
  50. userIdentityDb := db.UserIdentityDb{}
  51. userIdentityDb.Set(v.Id)
  52. identity, err1 := userIdentityDb.FindUserIdentity()
  53. if err1 != nil {
  54. err = err1
  55. return
  56. }
  57. var temp = md.UserList{
  58. Id: v.Id,
  59. Nickname: v.Nickname,
  60. Phone: v.Phone,
  61. Avatar: v.Avatar,
  62. CreateAt: v.CreateAt,
  63. }
  64. for _, v1 := range *identity {
  65. temp.BindUserIdentity = append(temp.BindUserIdentity, struct {
  66. Id int `json:"id" label:"id"`
  67. IdNo string `json:"id_no" label:"身份证号"`
  68. CertType int `json:"cert_type" label:"证件类型"`
  69. Name string `json:"name" label:"姓名"`
  70. EnterpriseName string `json:"enterprise_name" label:"企业名"`
  71. EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"`
  72. Kind int `json:"kind" label:"身份类型"`
  73. }{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, CertType: v1.UserIdentity.CertType, Name: v1.UserIdentity.Name, EnterpriseName: v1.Enterprise.Name, EnterpriseKind: v1.Enterprise.Kind, Kind: v1.UserIdentity.Kind})
  74. }
  75. resp.List = append(resp.List, temp)
  76. }
  77. return
  78. }
  79. func UserUpdate(req md.UserList) (err error) {
  80. userDb := db.UserDb{}
  81. userDb.Set()
  82. user, err := userDb.GetUser(req.Id)
  83. if err != nil {
  84. return err
  85. }
  86. if user == nil {
  87. return errors.New("未获取到用户信息记录")
  88. }
  89. for _, v := range req.BindUserIdentity {
  90. //获取用户身份信息
  91. userIdentityDb := db.UserIdentityDb{}
  92. userIdentityDb.Set(v.Id)
  93. identity, err1 := userIdentityDb.GetUserIdentity(v.Id)
  94. if err1 != nil {
  95. err = err1
  96. return
  97. }
  98. if user == nil {
  99. return errors.New("未获取到用户身份信息记录")
  100. }
  101. identity.Name = v.Name
  102. identity.IdNo = v.IdNo
  103. identity.CertType = v.CertType
  104. _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
  105. if err2 != nil {
  106. err = err2
  107. return
  108. }
  109. }
  110. return
  111. }