智慧食堂
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

svc_user.go 3.0 KiB

il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 8 mois
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }