|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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) {
- var userId int64
- if req.Phone != "" {
- var user model.User
- get, err := db.DbIm.Where("phone_number = ?", req.Phone).Get(&user)
- if err != nil {
- return err, resp
- }
- if get {
- userId = user.Id
- }
- }
-
- sess := db.DbIm.Where("1=1")
- if req.Memo != "" {
- sess.And("memo LIKE ?", "%"+req.Memo+"%")
- }
- if req.State != 0 {
- sess.And("state = ?", req.State)
- }
- if userId != 0 {
- sess.And("uid = ?", userId)
- }
-
- 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,
- UpdateTime: v.UpdateTime,
- })
- }
- 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.Now().Format("2006-01-02 15:04:05"),
- UpdateTime: time.Now().Format("2006-01-02 15:04:05"),
- }
- _, 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
- }
|