智慧食堂
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

97 rindas
2.5 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. 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. Name string `json:"name" label:"姓名"`
  51. EnterpriseName string `json:"enterprise_name" label:"企业名"`
  52. EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"`
  53. Kind int `json:"kind" label:"身份类型"`
  54. }{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, Name: v1.UserIdentity.Name, EnterpriseName: v1.Enterprise.Name, EnterpriseKind: v1.Enterprise.Kind, Kind: v1.UserIdentity.Kind})
  55. }
  56. resp.List = append(resp.List, temp)
  57. }
  58. return
  59. }
  60. func UserUpdate(req md.UserList) (err error) {
  61. userDb := db.UserDb{}
  62. userDb.Set()
  63. user, err := userDb.GetUser(req.Id)
  64. if err != nil {
  65. return err
  66. }
  67. if user == nil {
  68. return errors.New("未获取到用户信息记录")
  69. }
  70. for _, v := range req.BindUserIdentity {
  71. //获取用户身份信息
  72. userIdentityDb := db.UserIdentityDb{}
  73. userIdentityDb.Set(v.Id)
  74. identity, err1 := userIdentityDb.GetUserIdentity(v.Id)
  75. if err1 != nil {
  76. err = err1
  77. return
  78. }
  79. if user == nil {
  80. return errors.New("未获取到用户身份信息记录")
  81. }
  82. identity.Name = v.Name
  83. identity.IdNo = v.IdNo
  84. _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
  85. if err2 != nil {
  86. err = err2
  87. return
  88. }
  89. }
  90. return
  91. }