company_renewal_record.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package models
  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. // GetUnusualRenewCompanyList 获取销售未续约数据
  21. func GetUnusualRenewCompanyList(startDate, endDate time.Time, productId int) (list []*CompanyRenewalRecord, err error) {
  22. o := orm.NewOrm()
  23. sql := ` SELECT
  24. a.seller_id,a.share_seller_id,
  25. count(
  26. DISTINCT ( a.company_id )) num,
  27. GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids
  28. FROM
  29. company_renewal_record as a
  30. WHERE
  31. a.modify_time BETWEEN ?
  32. AND ?
  33. AND a.source = 1
  34. AND a.product_id = ?
  35. GROUP BY
  36. a.seller_id;
  37. `
  38. _, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
  39. return
  40. }
  41. // MultiAddCompanyRenewalRecord
  42. // @Description: 批量添加续约用户记录
  43. // @author: Roc
  44. // @datetime 2023-12-07 11:17:26
  45. // @param list []*CompanyRenewalRecord
  46. // @return err error
  47. func MultiAddCompanyRenewalRecord(list []*CompanyRenewalRecord) (err error) {
  48. num := len(list)
  49. if num <= 0 {
  50. return
  51. }
  52. o := orm.NewOrm()
  53. _, err = o.InsertMulti(num, list)
  54. return
  55. }
  56. // Add
  57. // @Description: 添加续约用户记录
  58. // @author: Roc
  59. // @datetime 2023-12-07 14:16:37
  60. // @param item *CompanyRenewalRecord
  61. // @return err error
  62. func (item *CompanyRenewalRecord) Add() (err error) {
  63. o := orm.NewOrm()
  64. lastId, err := o.Insert(item)
  65. if err != nil {
  66. return
  67. }
  68. item.Id = int(lastId)
  69. return
  70. }