智慧食堂
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 2.6 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 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. resp.Total, err = sess.Desc("user.id").FindAndCount(&m)
  27. if err != nil {
  28. return
  29. }
  30. for _, v := range m {
  31. //获取用户身份信息
  32. userIdentityDb := db.UserIdentityDb{}
  33. userIdentityDb.Set(v.Id)
  34. identity, err1 := userIdentityDb.FindUserIdentity()
  35. if err1 != nil {
  36. err = err1
  37. return
  38. }
  39. var temp = md.UserList{
  40. Id: v.Id,
  41. Nickname: v.Nickname,
  42. Phone: v.Phone,
  43. Avatar: v.Avatar,
  44. CreateAt: v.CreateAt,
  45. }
  46. for _, v1 := range *identity {
  47. temp.BindUserIdentity = append(temp.BindUserIdentity, struct {
  48. Id int `json:"id" label:"id"`
  49. IdNo string `json:"id_no" label:"身份证号"`
  50. CertType int `json:"cert_type" 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, CertType: v1.UserIdentity.CertType, 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. identity.CertType = v.CertType
  86. _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
  87. if err2 != nil {
  88. err = err2
  89. return
  90. }
  91. }
  92. return
  93. }