蛋蛋星球 后台端
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.

svc_customer_service.go 3.6 KiB

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