|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package svc
-
- import (
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/db/model"
- "errors"
- )
-
- func UserList(req md.UserListReq) (resp md.UserListResp, err error) {
- var m []model.User
- userDb := db.UserDb{}
- userDb.Set()
- sess := userDb.Db.Limit(req.Limit, (req.Page-1)*req.Limit)
- sess.Where("1=1")
- if req.Phone != "" {
- sess.And("phone like ?", "%"+req.Phone+"%")
- }
- if req.Nickname != "" {
- sess.And("nickname like ?", "%"+req.Nickname+"%")
- }
- if req.CreateTimeStart != "" {
- sess.And("create_at >= ?", req.CreateTimeStart)
- }
- if req.CreateTimeEnd != "" {
- sess.And("create_at <= ?", req.CreateTimeEnd)
- }
- resp.Total, err = sess.Desc("user.id").FindAndCount(&m)
- if err != nil {
- return
- }
-
- for _, v := range m {
- //获取用户身份信息
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(v.Id)
- identity, err1 := userIdentityDb.FindUserIdentity()
- if err1 != nil {
- err = err1
- return
- }
- var temp = md.UserList{
- Id: v.Id,
- Nickname: v.Nickname,
- Phone: v.Phone,
- Avatar: v.Avatar,
- CreateAt: v.CreateAt,
- }
- for _, v1 := range *identity {
- temp.BindUserIdentity = append(temp.BindUserIdentity, struct {
- Id int `json:"id" label:"id"`
- IdNo string `json:"id_no" label:"身份证号"`
- CertType int `json:"cert_type" label:"证件类型"`
- Name string `json:"name" label:"姓名"`
- EnterpriseName string `json:"enterprise_name" label:"企业名"`
- EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"`
- Kind int `json:"kind" label:"身份类型"`
- }{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})
- }
- resp.List = append(resp.List, temp)
- }
- return
- }
-
- func UserUpdate(req md.UserList) (err error) {
- userDb := db.UserDb{}
- userDb.Set()
- user, err := userDb.GetUser(req.Id)
- if err != nil {
- return err
- }
- if user == nil {
- return errors.New("未获取到用户信息记录")
- }
-
- for _, v := range req.BindUserIdentity {
- //获取用户身份信息
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(v.Id)
- identity, err1 := userIdentityDb.GetUserIdentity(v.Id)
- if err1 != nil {
- err = err1
- return
- }
- if user == nil {
- return errors.New("未获取到用户身份信息记录")
- }
- identity.Name = v.Name
- identity.IdNo = v.IdNo
- identity.CertType = v.CertType
- _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
- if err2 != nil {
- err = err2
- return
- }
- }
- return
- }
|