company_product.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package company
  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. IndustryId int `description:"行业id"`
  16. IndustryName string `description:"行业名称"`
  17. SellerId int `description:"销售id"`
  18. SellerName string `description:"销售名称"`
  19. GroupId int `description:"销售分组id"`
  20. DepartmentId int `description:"销售部门id"`
  21. IsSuspend int `description:"1:暂停,0:启用"`
  22. SuspendTime time.Time `description:"暂停启用时间"`
  23. TryOutTime time.Time `description:"正式转试用时间"`
  24. RenewalReason string `description:"正式转试用后的续约情况说明"`
  25. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  26. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  27. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  28. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  29. FreezeTime time.Time `description:"冻结时间"`
  30. FreezeReason time.Time `description:"冻结理由"`
  31. Remark string `description:"备注信息"`
  32. CreateTime time.Time `description:"创建时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. StartDate string `description:"开始日期"`
  35. EndDate string `description:"结束日期"`
  36. ContractEndDate time.Time `description:"合同结束日期"`
  37. LoseReason string `description:"流失原因"`
  38. LossTime time.Time `description:"流失时间"`
  39. CompanyType string `description:"客户类型"`
  40. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  41. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  42. ViewTotal int `description:"总阅读次数"`
  43. RoadShowTotal int `description:"累计路演次数"`
  44. LastViewTime time.Time `description:"最后一次阅读时间"`
  45. PackageType int `description:"套餐类型"`
  46. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  47. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  48. TodoCreateTime time.Time `description:"任务创建时间"`
  49. TodoApproveTime time.Time `description:"任务审批时间"`
  50. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  51. TryOutDayTotal int `description:"客户总试用天数"`
  52. CloseReason string `description:"关闭原因"`
  53. CloseTime time.Time `description:"关闭时间"`
  54. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  55. IsOverseas int `description:"是否显示在海外客户0:显示,1:不显示"`
  56. ShareSeller string `description:"共享销售员"`
  57. ShareSellerId int `description:"共享销售员id"`
  58. }
  59. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  60. o := orm.NewOrmUsingDB("weekly_report")
  61. sql := `SELECT b.* FROM company AS a
  62. INNER JOIN company_product AS b ON a.company_id=b.company_id
  63. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  64. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  65. return
  66. }
  67. func GetCompanyProductCount(companyId, productId int) (count int, err error) {
  68. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = ? `
  69. o := orm.NewOrmUsingDB("weekly_report")
  70. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  71. return
  72. }
  73. func GetCompanyProductDetailByCompanyId(companyId, productId int) (item *CompanyProduct, err error) {
  74. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  75. o := orm.NewOrmUsingDB("weekly_report")
  76. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  77. return
  78. }
  79. func GetCompanyProductAaiServeCount(companyId, groupId int) (count int, err error) {
  80. o := orm.NewOrmUsingDB("weekly_report")
  81. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = 2 AND (group_id = ? OR share_group_id = ?) `
  82. err = o.Raw(sql, companyId, groupId, groupId).QueryRow(&count)
  83. return
  84. }
  85. // 获取列表
  86. func GetCompanyProductAndCompanyListByCondition(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  87. o := orm.NewOrmUsingDB("weekly_report")
  88. sql := ` SELECT
  89. p.company_id,
  90. p.seller_id,
  91. p.seller_name,
  92. p.start_date,
  93. p.end_date,
  94. p.share_seller_id,
  95. p.share_seller,
  96. p.status,
  97. c.company_name
  98. FROM
  99. company_product AS p
  100. INNER JOIN company AS c ON c.company_id = p.company_id
  101. WHERE
  102. 1 = 1 `
  103. if condition != "" {
  104. sql += condition
  105. }
  106. _, err = o.Raw(sql, pars).QueryRows(&items)
  107. return
  108. }