|
- 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.Join("LEFT", "user_identity", "user.id = user_identity.uid").
- Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").Limit(req.Limit, (req.Page-1)*req.Limit)
- sess.Where("1=1")
- if req.Phone != "" {
- sess.And("user.phone like ?", "%"+req.Phone+"%")
- }
- if req.Nickname != "" {
- sess.And("user.nickname like ?", "%"+req.Nickname+"%")
- }
- if req.CreateTimeStart != "" {
- sess.And("user.create_at >= ?", req.CreateTimeStart)
- }
- if req.CreateTimeEnd != "" {
- sess.And("user.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.Format("2006-01-02 15:04:05"),
- }
- for _, v1 := range *identity {
- temp.BindUserIdentity = append(temp.BindUserIdentity, struct {
- Id int `json:"id" label:"id"`
- IdNo string `json:"id_no" 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, 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
- _, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no")
- if err2 != nil {
- err = err2
- return
- }
- }
- return
- }
|