package svc import ( "applet/app/db" "applet/app/db/im/model" md "applet/app/md/im" "errors" "time" ) func PageCustomerService(req md.PageCustomerServiceReq) (err error, resp md.PageCustomerServiceResp) { sess := db.DbIm.Where("1=1") if req.Memo != "" { sess.And("memo LIKE ?", "%"+req.Memo+"%") } if req.State != 0 { sess.And("memo = ?", req.State) } var mm []*model.CustomerService resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("id").FindAndCount(&mm) if err != nil { return } resp.Page = req.Page resp.PageSize = req.PageSize for _, v := range mm { var user model.User _, err = db.DbIm.Where("`id`=?", v.Uid).Get(&user) if err != nil { return } resp.List = append(resp.List, struct { Id int64 `json:"id"` //记录id Phone string `json:"phone" example:"手机号"` Nickname string `json:"nickname" example:"昵称"` Weight int32 `json:"weight"` // 权重 State int32 `json:"state"` // 状态 HaasUserNums int `json:"has_user_nums"` // 拥有用户数量 Memo string `json:"memo" example:"备注"` // 备注 CreateTime string `json:"create_time" example:"创建时间"` // 创建时间 UpdateTime string `json:"update_time" example:"更新时间"` // 更新时间 }{ Id: v.Id, Phone: user.PhoneNumber, Nickname: user.Nickname, Weight: v.Weight, State: v.State, HaasUserNums: v.HasUserNums, Memo: v.Memo, CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"), UpdateTime: v.UpdateTime.Format("2006-01-02 15:04:05"), }) } return } func AddCustomerService(req md.AddCustomerServiceReq) (err error) { var user model.User has, err := db.DbIm.Where("`phone_number`=?", req.Phone).Get(&user) if err != nil { return } if !has { return errors.New("未查询到对应手机号账号记录") } var customerService model.CustomerService has, err = db.DbIm.Where("`uid`=?", user.Id).Get(&customerService) if err != nil { return } if has { return errors.New("该账号已是客服!") } cfg := model.CustomerService{ Uid: user.Id, Weight: req.Weight, State: 1, HasUserNums: 0, Memo: req.Memo, CreateTime: time.Time{}, UpdateTime: time.Time{}, } _, err = db.DbIm.InsertOne(&cfg) if err != nil { return } return } func SetCustomerServiceState(req md.SetCustomerServiceStateReq) (err error) { var customerService model.CustomerService has, err := db.DbIm.ID(req.Id).Get(&customerService) if err != nil { return } if has { return errors.New("未查询到对应记录!") } customerService.State = req.State _, err = db.DbIm.ID(req.Id).Cols("state").Update(&customerService) if err != nil { return } return } func UpdateCustomerServiceMemo(req md.UpdateCustomerServiceMemoReq) (err error) { var customerService model.CustomerService has, err := db.DbIm.ID(req.Id).Get(&customerService) if err != nil { return } if has { return errors.New("未查询到对应记录!") } customerService.Memo = req.Memo _, err = db.DbIm.ID(req.Id).Cols("memo").Update(&customerService) if err != nil { return } return }