company_product.go 5.6 KB

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