statistic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package kf
  2. import (
  3. "fmt"
  4. "github.com/silenceper/wechat/v2/util"
  5. )
  6. const (
  7. // getCorpStatisticURL 获取「客户数据统计」企业汇总数据
  8. getCorpStatisticURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=%s"
  9. // getServicerStatisticURL 获取「客户数据统计」接待人员明细数据
  10. getServicerStatisticURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/get_servicer_statistic?access_token=%s"
  11. )
  12. // GetCorpStatisticRequest 获取「客户数据统计」企业汇总数据请求
  13. type GetCorpStatisticRequest struct {
  14. OpenKfID string `json:"open_kfid"`
  15. StartTime int64 `json:"start_time"`
  16. EndTime int64 `json:"end_time"`
  17. }
  18. // GetCorpStatisticResponse 获取「客户数据统计」企业汇总数据响应
  19. type GetCorpStatisticResponse struct {
  20. util.CommonError
  21. StatisticList []CorpStatisticList `json:"statistic_list"`
  22. }
  23. // CorpStatisticList 企业汇总统计数据列表
  24. type CorpStatisticList struct {
  25. StatTime int64 `json:"stat_time"`
  26. Statistic CorpStatistic `json:"statistic"`
  27. }
  28. // CorpStatistic 企业汇总统计一天的统计数据
  29. type CorpStatistic struct {
  30. SessionCnt int64 `json:"session_cnt"`
  31. CustomerCnt int64 `json:"customer_cnt"`
  32. CustomerMsgCnt int64 `json:"customer_msg_cnt"`
  33. UpgradeServiceCustomerCnt int64 `json:"upgrade_service_customer_cnt"`
  34. AiSessionReplyCnt int64 `json:"ai_session_reply_cnt"`
  35. AiTransferRate float64 `json:"ai_transfer_rate"`
  36. AiKnowledgeHitRate float64 `json:"ai_knowledge_hit_rate"`
  37. MsgRejectedCustomerCnt int64 `json:"msg_rejected_customer_cnt"`
  38. }
  39. // GetCorpStatistic 获取「客户数据统计」企业汇总数据
  40. // see https://developer.work.weixin.qq.com/document/path/95489
  41. func (r *Client) GetCorpStatistic(req *GetCorpStatisticRequest) (*GetCorpStatisticResponse, error) {
  42. var (
  43. accessToken string
  44. err error
  45. )
  46. if accessToken, err = r.ctx.GetAccessToken(); err != nil {
  47. return nil, err
  48. }
  49. var response []byte
  50. if response, err = util.PostJSON(fmt.Sprintf(getCorpStatisticURL, accessToken), req); err != nil {
  51. return nil, err
  52. }
  53. result := &GetCorpStatisticResponse{}
  54. err = util.DecodeWithError(response, result, "GetCorpStatistic")
  55. return result, err
  56. }
  57. // GetServicerStatisticRequest 获取「客户数据统计」接待人员明细数据请求
  58. type GetServicerStatisticRequest struct {
  59. OpenKfID string `json:"open_kfid"`
  60. ServicerUserID string `json:"servicer_userid"`
  61. StartTime int64 `json:"start_time"`
  62. EndTime int64 `json:"end_time"`
  63. }
  64. // GetServicerStatisticResponse 获取「客户数据统计」接待人员明细数据响应
  65. type GetServicerStatisticResponse struct {
  66. util.CommonError
  67. StatisticList []ServicerStatisticList `json:"statistic_list"`
  68. }
  69. // ServicerStatisticList 接待人员明细统计数据列表
  70. type ServicerStatisticList struct {
  71. StatTime int64 `json:"stat_time"`
  72. Statistic ServicerStatistic `json:"statistic"`
  73. }
  74. // ServicerStatistic 接待人员明细统计一天的统计数据
  75. type ServicerStatistic struct {
  76. SessionCnt int64 `json:"session_cnt"`
  77. CustomerCnt int64 `json:"customer_cnt"`
  78. CustomerMsgCnt int64 `json:"customer_msg_cnt"`
  79. ReplyRate float64 `json:"reply_rate"`
  80. FirstReplyAverageSec float64 `json:"first_reply_average_sec"`
  81. SatisfactionInvestgateCnt int64 `json:"satisfaction_investgate_cnt"`
  82. SatisfactionParticipationRate float64 `json:"satisfaction_participation_rate"`
  83. SatisfiedRate float64 `json:"satisfied_rate"`
  84. MiddlingRate float64 `json:"middling_rate"`
  85. DissatisfiedRate float64 `json:"dissatisfied_rate"`
  86. UpgradeServiceCustomerCnt int64 `json:"upgrade_service_customer_cnt"`
  87. UpgradeServiceMemberInviteCnt int64 `json:"upgrade_service_member_invite_cnt"`
  88. UpgradeServiceMemberCustomerCnt int64 `json:"upgrade_service_member_customer_cnt"`
  89. UpgradeServiceGroupChatInviteCnt int64 `json:"upgrade_service_groupchat_invite_cnt"`
  90. UpgradeServiceGroupChatCustomerCnt int64 `json:"upgrade_service_groupchat_customer_cnt"`
  91. MsgRejectedCustomerCnt int64 `json:"msg_rejected_customer_cnt"`
  92. }
  93. // GetServicerStatistic 获取「客户数据统计」接待人员明细数据
  94. // see https://developer.work.weixin.qq.com/document/path/95490
  95. func (r *Client) GetServicerStatistic(req *GetServicerStatisticRequest) (*GetServicerStatisticResponse, error) {
  96. var (
  97. accessToken string
  98. err error
  99. )
  100. if accessToken, err = r.ctx.GetAccessToken(); err != nil {
  101. return nil, err
  102. }
  103. var response []byte
  104. if response, err = util.PostJSON(fmt.Sprintf(getServicerStatisticURL, accessToken), req); err != nil {
  105. return nil, err
  106. }
  107. result := &GetServicerStatisticResponse{}
  108. err = util.DecodeWithError(response, result, "GetServicerStatistic")
  109. return result, err
  110. }