company_renewal_record.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CompanyRenewalRecord
  7. // @Description: 客户续约状态记录表
  8. type CompanyRenewalRecord struct {
  9. Id int `orm:"column(id);pk"`
  10. CompanyId int `description:"客户id"`
  11. ProductId int `description:"产品id"`
  12. Source int `description:"类型,枚举值,1:续约异常客户;2:续约正常客户;3:超时续约客户"`
  13. SellerId int `description:"销售id"`
  14. SellerName string `description:"销售名称"`
  15. ShareSellerId int `description:"共享销售id"`
  16. ShareSellerName string `description:"共享销售名称"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. }
  20. type UnusualRenewCompanyGroup struct {
  21. SellerId int `description:"所属销售id"`
  22. ShareSellerId int `description:"所属共享销售id"`
  23. //AdminName string `description:"所属销售名称"`
  24. Num int `description:"汇总次数"`
  25. CompanyIds string `description:"客户id字符串"`
  26. }
  27. // GetUnusualRenewCompanyList 获取销售未续约数据
  28. func GetUnusualRenewCompanyList(startDate, endDate time.Time, productId int) (list []*UnusualRenewCompanyGroup, err error) {
  29. o := orm.NewOrm()
  30. sql := ` SELECT
  31. a.seller_id,a.share_seller_id,
  32. count(
  33. DISTINCT ( a.company_id )) num,
  34. GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids
  35. FROM
  36. company_renewal_record as a
  37. WHERE
  38. a.modify_time BETWEEN ?
  39. AND ?
  40. AND a.source = 1
  41. AND a.product_id = ?
  42. GROUP BY
  43. a.seller_id;
  44. `
  45. _, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
  46. return
  47. }
  48. // Add
  49. // @Description: 添加续约用户记录
  50. // @author: Roc
  51. // @datetime 2023-12-07 14:16:37
  52. // @param item *CompanyRenewalRecord
  53. // @return err error
  54. func (item *CompanyRenewalRecord) Add() (err error) {
  55. o := orm.NewOrm()
  56. lastId, err := o.Insert(item)
  57. if err != nil {
  58. return
  59. }
  60. item.Id = int(lastId)
  61. return
  62. }