company_product.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package company_product
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyProduct struct {
  7. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  8. CompanyId int `description:"客户id"`
  9. ProductId int `description:"产品id"`
  10. ProductName string `description:"产品名称"`
  11. CompanyName string `description:"客户名称"`
  12. Source string `description:"来源"`
  13. Reasons string `description:"新增理由"`
  14. Status string `description:"客户状态"`
  15. InitStatus string `description:"客户初始化状态(目前用来处理权益的永续客户使用)"`
  16. IndustryId int `description:"行业id"`
  17. IndustryName string `description:"行业名称"`
  18. SellerId int `description:"销售id"`
  19. SellerName string `description:"销售名称"`
  20. GroupId int `description:"销售分组id"`
  21. DepartmentId int `description:"销售部门id"`
  22. IsSuspend int `description:"1:暂停,0:启用"`
  23. SuspendTime time.Time `description:"暂停启用时间"`
  24. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  25. FreezeTime time.Time `description:"冻结时间"`
  26. Remark string `description:"备注信息"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"修改时间"`
  29. StartDate string `description:"开始日期"`
  30. EndDate string `description:"结束日期"`
  31. ContractEndDate time.Time `description:"合同结束日期"`
  32. LoseReason string `description:"流失原因"`
  33. LossTime time.Time `description:"流失时间"`
  34. CompanyType string `description:"客户类型"`
  35. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  36. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  37. }
  38. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT b.* FROM company AS a
  41. INNER JOIN company_product AS b ON a.company_id=b.company_id
  42. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  43. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  44. return
  45. }
  46. // 更新客户产品信息
  47. func (companyProduct *CompanyProduct) Update(cols []string) (err error) {
  48. o := orm.NewOrm()
  49. _, err = o.Update(companyProduct, cols...)
  50. return
  51. }
  52. // CompanyProductItem
  53. // @Description: 客户品种
  54. type CompanyProductItem struct {
  55. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  56. CompanyId int `description:"客户id"`
  57. ProductId int `description:"产品id"`
  58. ProductName string `description:"产品名称"`
  59. CompanyName string `description:"客户名称"`
  60. Source string `description:"来源"`
  61. Reasons string `description:"新增理由"`
  62. Status string `description:"客户状态"`
  63. IndustryId int `description:"行业id"`
  64. IndustryName string `description:"行业名称"`
  65. SellerId int `description:"销售id"`
  66. SellerName string `description:"销售名称"`
  67. GroupId int `description:"销售分组id"`
  68. DepartmentId int `description:"销售部门id"`
  69. IsSuspend int `description:"1:暂停,0:启用"`
  70. SuspendTime time.Time `description:"暂停启用时间"`
  71. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  72. FreezeTime time.Time `description:"冻结时间"`
  73. Remark string `description:"备注信息"`
  74. CreateTime time.Time `description:"创建时间"`
  75. ModifyTime time.Time `description:"修改时间"`
  76. StartDate string `description:"开始日期"`
  77. EndDate string `description:"结束日期"`
  78. ContractEndDate string `description:"合同结束日期"`
  79. LoseReason string `description:"流失原因"`
  80. LossTime time.Time `description:"流失时间"`
  81. CompanyType string `description:"客户类型"`
  82. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  83. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  84. ViewTotal int `description:"总阅读次数"`
  85. RoadShowTotal int `description:"累计路演次数"`
  86. LastViewTime time.Time `description:"最后一次阅读时间"`
  87. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  88. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  89. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  90. TodoCreateTime time.Time `description:"任务创建时间"`
  91. TodoApproveTime time.Time `description:"任务审批时间"`
  92. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  93. IsShare int `description:"0:非共享用户,1:共享客户"`
  94. ShareSeller string `description:"共享销售员"`
  95. ShareSellerId int `description:"共享销售员id"`
  96. }
  97. // GetCompanyProductItemByCompanyId
  98. // @Description: 根据客户ID获取客户产品列表
  99. // @author: Roc
  100. // @datetime 2023-12-07 11:06:58
  101. // @param companyIdList []int
  102. // @param productId int
  103. // @return items []*CompanyProductItem
  104. // @return err error
  105. func GetCompanyProductItemByCompanyId(companyId int, productId int) (items *CompanyProductItem, err error) {
  106. o := orm.NewOrm()
  107. sql := `SELECT a.*,b.is_share,b.share_seller,b.share_seller_id FROM company_product as a
  108. JOIN company b on a.company_id=b.company_id
  109. WHERE a.company_id = ? AND a.product_id = ? `
  110. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  111. return
  112. }
  113. // 获取权益用户客户数量
  114. func GetCompanyProductRaiForeverCount(companyId int) (count int, err error) {
  115. sqlCount := ` SELECT COUNT(1) AS count FROM company_product WHERE 1= 1 AND product_id = 2 AND status = '永续' AND company_id = ? `
  116. o := orm.NewOrm()
  117. err = o.Raw(sqlCount, companyId).QueryRow(&count)
  118. return
  119. }
  120. // 获取列表
  121. func GetCompanyProductList(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  122. o := orm.NewOrm()
  123. sql := `SELECT * FROM company_product WHERE 1= 1 `
  124. if condition != "" {
  125. sql += condition
  126. }
  127. _, err = o.Raw(sql, pars).QueryRows(&items)
  128. return
  129. }