蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

127 lines
3.2 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/im/model"
  5. md "applet/app/md/im"
  6. "errors"
  7. "time"
  8. )
  9. func PageCustomerService(req md.PageCustomerServiceReq) (err error, resp md.PageCustomerServiceResp) {
  10. sess := db.DbIm.Where("1=1")
  11. if req.Memo != "" {
  12. sess.And("memo LIKE ?", "%"+req.Memo+"%")
  13. }
  14. if req.State != 0 {
  15. sess.And("memo = ?", req.State)
  16. }
  17. var mm []*model.CustomerService
  18. resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("id").FindAndCount(&mm)
  19. if err != nil {
  20. return
  21. }
  22. resp.Page = req.Page
  23. resp.PageSize = req.PageSize
  24. for _, v := range mm {
  25. var user model.User
  26. _, err = db.DbIm.Where("`id`=?", v.Uid).Get(&user)
  27. if err != nil {
  28. return
  29. }
  30. resp.List = append(resp.List, struct {
  31. Id int64 `json:"id"` //记录id
  32. Phone string `json:"phone" example:"手机号"`
  33. Nickname string `json:"nickname" example:"昵称"`
  34. Weight int32 `json:"weight"` // 权重
  35. State int32 `json:"state"` // 状态
  36. HaasUserNums int `json:"has_user_nums"` // 拥有用户数量
  37. Memo string `json:"memo" example:"备注"` // 备注
  38. CreateTime string `json:"create_time" example:"创建时间"` // 创建时间
  39. UpdateTime string `json:"update_time" example:"更新时间"` // 更新时间
  40. }{
  41. Id: v.Id,
  42. Phone: user.PhoneNumber,
  43. Nickname: user.Nickname,
  44. Weight: v.Weight,
  45. State: v.State,
  46. HaasUserNums: v.HasUserNums,
  47. Memo: v.Memo,
  48. CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
  49. UpdateTime: v.UpdateTime.Format("2006-01-02 15:04:05"),
  50. })
  51. }
  52. return
  53. }
  54. func AddCustomerService(req md.AddCustomerServiceReq) (err error) {
  55. var user model.User
  56. has, err := db.DbIm.Where("`phone_number`=?", req.Phone).Get(&user)
  57. if err != nil {
  58. return
  59. }
  60. if !has {
  61. return errors.New("未查询到对应手机号账号记录")
  62. }
  63. var customerService model.CustomerService
  64. has, err = db.DbIm.Where("`uid`=?", user.Id).Get(&customerService)
  65. if err != nil {
  66. return
  67. }
  68. if has {
  69. return errors.New("该账号已是客服!")
  70. }
  71. cfg := model.CustomerService{
  72. Uid: user.Id,
  73. Weight: req.Weight,
  74. State: 1,
  75. HasUserNums: 0,
  76. Memo: req.Memo,
  77. CreateTime: time.Time{},
  78. UpdateTime: time.Time{},
  79. }
  80. _, err = db.DbIm.InsertOne(&cfg)
  81. if err != nil {
  82. return
  83. }
  84. return
  85. }
  86. func SetCustomerServiceState(req md.SetCustomerServiceStateReq) (err error) {
  87. var customerService model.CustomerService
  88. has, err := db.DbIm.ID(req.Id).Get(&customerService)
  89. if err != nil {
  90. return
  91. }
  92. if has {
  93. return errors.New("未查询到对应记录!")
  94. }
  95. customerService.State = req.State
  96. _, err = db.DbIm.ID(req.Id).Cols("state").Update(&customerService)
  97. if err != nil {
  98. return
  99. }
  100. return
  101. }
  102. func UpdateCustomerServiceMemo(req md.UpdateCustomerServiceMemoReq) (err error) {
  103. var customerService model.CustomerService
  104. has, err := db.DbIm.ID(req.Id).Get(&customerService)
  105. if err != nil {
  106. return
  107. }
  108. if has {
  109. return errors.New("未查询到对应记录!")
  110. }
  111. customerService.Memo = req.Memo
  112. _, err = db.DbIm.ID(req.Id).Cols("memo").Update(&customerService)
  113. if err != nil {
  114. return
  115. }
  116. return
  117. }