rai_data_summary.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package statistic_report
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models/company"
  6. )
  7. // 时间区间数据结构
  8. type DateInterval struct {
  9. StartDate string `description:"合同开始日期"`
  10. EndDate string `description:"合同结束日期"`
  11. }
  12. type RaiDataSummaryListResp struct {
  13. List []*RaiDataSummaryResp
  14. }
  15. type RaiDataSummaryResp struct {
  16. DataType string `description:"时间区间"`
  17. DataList []*RaiDataSummaryDetail
  18. }
  19. type RaiDataSummaryDetail struct {
  20. IsServerSeller bool `description:"是否属于服务组销售"`
  21. SellerId string `description:"销售id"`
  22. SellerName string `description:"销售名称"`
  23. AddTrialCount string `description:"新增试用"`
  24. NewContractData string `description:"新签合同(金额/数量)"`
  25. ExpiredContractData string `description:"到期合同(金额/数量)"`
  26. RenewedContractData string `description:"续约合同(金额/数量)"`
  27. RenewalRateData string `description:"续约率(金额/数量)"`
  28. ConfirmedNoRenewalContractData string `description:"确认不续约合同(金额/数量)"`
  29. ConfirmNonRenewalRateData string `description:"确认不续约率(金额/数量)"`
  30. SignedClientCount string `description:"签约客户数量"`
  31. AverageRevenueCount string `description:"客单价"`
  32. InvoiceAmountCount string `description:"开票金额"`
  33. PaymentReceivedCount string `description:"到款金额"`
  34. UnpaidRatioCount string `description:"未到款比例"`
  35. NewCustomerInvoicingCount string `description:"新客开票"`
  36. NewCustomerPaymentsReceivedCount string `description:"新客到款"`
  37. }
  38. // 增量客户统计报表列表数据结构
  39. type IncrementalList struct {
  40. CompanyContractId int `description:"合同id"`
  41. ContractType string `description:"合同类型"`
  42. CompanyId int `description:"企业客户id"`
  43. CompanyName string `description:"企业客户名称"`
  44. ProductId int `description:"产品id"`
  45. ProductName string `description:"产品名称"`
  46. ProductStatus string `description:"产品名称"`
  47. CompanyProductId int `description:"客户购买产品授权id"`
  48. ContractCode string `description:"合同编码"`
  49. StartDate string `description:"合同开始日期"`
  50. EndDate string `description:"合同结束日期"`
  51. Money float64 `description:"合同金额"`
  52. PayMethod string `description:"付款方式"`
  53. PayChannel string `description:"付款渠道"`
  54. ImgUrl string `description:"合同图片"`
  55. CreateTime string `description:"合同创建时间"`
  56. ModifyTime string `description:"合同修改时间"`
  57. Status string `description:"合同审批状态,0:待审批,1:已审批;默认:1"`
  58. RegionType string `description:"企业客户所属区域;可选范围:国内,海外"`
  59. SellerId int `description:"归属销售id"`
  60. SellerName string `description:"归属销售名称"`
  61. SellerNameLast string `description:"合同到期之前最后所属归属销售名称"`
  62. ShareSeller string `description:"合同到期之前最后所属共享销售员"`
  63. ShareSellerLast string `description:"共享销售员"`
  64. ExpireDay string `description:"剩余可用天数"`
  65. PermissionList []*company.CompanyReportPermission `description:"产品权限"`
  66. Count int `json:"-" description:"合同数"`
  67. RenewalReason string `description:"未续约说明"`
  68. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  69. PackageDifference string `description:"和上一份合同的区别"`
  70. AscribeContent string `description:"归因标签说明"`
  71. IsShowNoRenewedNote bool `description:"是否展示未续约备注按钮"`
  72. Content string `description:"归因内容说明"`
  73. PermissionName string `description:"权限名"`
  74. PermissionNameExport string `description:"权限名导出时使用"`
  75. PermissionNameStatus string `description:"权限状态"`
  76. CompanyProductStatus string `description:"客户状态"`
  77. //CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  78. IsUserMaker int `description:"近四周之内是否包含决策人互动过 ,0否,1是"`
  79. SellerNameInit string `description:"权益初始化销售"`
  80. SellerIdInit int `description:"权益初始化销售ID"`
  81. SellerIdLast int `description:"合同到期之前最后所属销售ID"`
  82. ShareSellerIdInit int `description:"共享销售员"`
  83. ShareSellerIdLast int `description:"合同到期之前最后共享销售员ID"`
  84. SysRealName string `description:"操作者名称"`
  85. Operation string `description:"操作"`
  86. RaiContractType string `description:"权益合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  87. InheritEndDate string `description:"所继承上一份合同的结束日期,权益自定义续约合同统计使用"`
  88. }
  89. // GetRaiDataSummaryList 获取增量客户报表列表数据(根据合同来展示)
  90. func GetRaiDataSummaryList(condition string, pars []interface{}) (items []*IncrementalList, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT a.start_date,
  93. a.end_date,
  94. a.company_contract_id,
  95. a.money,
  96. a.company_id,
  97. a.rai_contract_type,
  98. a.seller_id_init,
  99. a.seller_name_init,
  100. a.share_seller_init,
  101. a.share_seller_id_init,
  102. a.seller_id_last,
  103. a.seller_name_last,
  104. a.share_seller_last,
  105. a.share_seller_id_last
  106. FROM company_contract a
  107. JOIN company b ON a.company_id = b.company_id
  108. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  109. if condition != "" {
  110. sql += condition
  111. }
  112. sql += ` group by a.company_contract_id order by a.start_date desc,a.company_id desc `
  113. _, err = o.Raw(sql, pars).QueryRows(&items)
  114. return
  115. }
  116. // GetRaiDataSummaryList 获取增量客户报表列表数据(根据合同来展示)
  117. func GetRaiDataSummaryInheritList(condition string, pars []interface{}) (items []*IncrementalList, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT a.start_date,
  120. a.end_date,
  121. a.inherit_end_date,
  122. a.company_contract_id,
  123. a.money,
  124. a.company_id,
  125. a.rai_contract_type,
  126. a.seller_id_init,
  127. a.seller_name_init,
  128. a.share_seller_init,
  129. a.share_seller_id_init,
  130. a.seller_id_last,
  131. a.seller_name_last,
  132. a.share_seller_last,
  133. a.share_seller_id_last
  134. FROM company_contract a
  135. JOIN company b ON a.company_id = b.company_id
  136. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  137. if condition != "" {
  138. sql += condition
  139. }
  140. sql += ` group by a.company_contract_id order by a.start_date desc,a.company_id desc `
  141. _, err = o.Raw(sql, pars).QueryRows(&items)
  142. return
  143. }
  144. type RaiDataSummaryPopupTypeResp struct {
  145. CompanyNum int `description:"企业客户数量"`
  146. CompanyMultiple int `description:"户有多份合同的企业客户数量"`
  147. Paging *paging.PagingItem `description:"分页数据"`
  148. List []*RaiDataSummaryDetailResp `description:"列表"`
  149. }
  150. // 增量客户统计报表列表数据结构
  151. type RaiDataSummaryDetailResp struct {
  152. CompanyId int `description:"企业客户ID"`
  153. CompanyName string `description:"企业客户名称"`
  154. SellerName string `description:"归属销售名称"`
  155. AddType string `description:"新增类型"`
  156. CreateTime string `description:"创建时间"`
  157. StartDate string `description:"合同开始日期"`
  158. EndDate string `description:"合同结束日期"`
  159. Money float64 `description:"合同金额"`
  160. PermissionName string `description:"权限名"`
  161. RenewedContractMoney string `description:"续约金额"`
  162. ExpiredContractMoney string `description:"到期金额"`
  163. RenewalRate string `description:"续约率"`
  164. RenewedContractCompany int `description:"续约客户数"`
  165. RenewedContract int `description:"续约合同数"`
  166. NewContractCompany int `description:"新签客户数"`
  167. NewContract int `description:"新签合同数"`
  168. ContractMoney string `description:"签约总金额"`
  169. ContractNum int `description:"签约客户数"`
  170. ContractCode string `description:"合同编号"`
  171. InvoicedAmount float64 ` description:"开票金额"`
  172. PaymentAmount float64 ` description:"到款金额"`
  173. NotReceivedtAmount float64 ` description:"未到账金额"`
  174. TbaleNameAText string ` description:"表格A列占位符"` //配合前端渲染使用,没有啥实际意义
  175. }