蛋蛋星球 后台端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

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