company_product.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package models
  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. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  24. FreezeTime time.Time `description:"冻结时间"`
  25. Remark string `description:"备注信息"`
  26. CreateTime time.Time `description:"创建时间"`
  27. ModifyTime time.Time `description:"修改时间"`
  28. StartDate string `description:"开始日期"`
  29. EndDate string `description:"结束日期"`
  30. LoseReason string `description:"流失原因"`
  31. LossTime time.Time `description:"流失时间"`
  32. CompanyType string `description:"客户类型"`
  33. ViewTotal int `description:"总阅读次数"`
  34. LastViewTime time.Time `description:"最后一次阅读时间"`
  35. }
  36. //判断客户权限总数
  37. func GetCompanyProductPermissionCount(companyId, productId int) (count int, err error) {
  38. sql := ` SELECT COUNT(DISTINCT c.chart_permission_id) AS COUNT FROM company AS a
  39. INNER JOIN company_product AS b ON a.company_id=b.company_id
  40. INNER JOIN company_report_permission AS c ON a.company_id=c.company_id
  41. WHERE b.company_id=? AND b.product_id=?
  42. AND b.status IN('正式','试用','永续')
  43. AND c.product_id=? `
  44. o := orm.NewOrm()
  45. err = o.Raw(sql, companyId, productId, productId).QueryRow(&count)
  46. return
  47. }
  48. type CompanyProductDetail struct {
  49. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  50. CompanyId int `description:"客户id"`
  51. ProductId int `description:"产品id"`
  52. ProductName string `description:"产品名称"`
  53. CompanyName string `description:"客户名称"`
  54. Source string `description:"来源"`
  55. Reasons string `description:"新增理由"`
  56. Status string `description:"客户状态"`
  57. IndustryId int `description:"行业id"`
  58. IndustryName string `description:"行业名称"`
  59. SellerId int `description:"销售id"`
  60. SellerName string `description:"销售名称"`
  61. GroupId int `description:"销售分组id"`
  62. DepartmentId int `description:"销售部门id"`
  63. IsSuspend int `description:"1:暂停,0:启用"`
  64. SuspendTime time.Time `description:"暂停启用时间"`
  65. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  66. FreezeTime time.Time `description:"冻结时间"`
  67. Remark string `description:"备注信息"`
  68. CreateTime time.Time `description:"创建时间"`
  69. ModifyTime time.Time `description:"修改时间"`
  70. StartDate string `description:"开始日期"`
  71. EndDate string `description:"结束日期"`
  72. LoseReason string `description:"流失原因"`
  73. LossTime time.Time `description:"流失时间"`
  74. }
  75. func GetCompanyProductsByUserId(userId int) (items []*CompanyProductDetail, err error) {
  76. sql := ` SELECT a.* FROM company_product AS a
  77. INNER JOIN wx_user AS b ON a.company_id=b.company_id
  78. WHERE b.user_id=? `
  79. o := orm.NewOrm()
  80. _, err = o.Raw(sql, userId).QueryRows(&items)
  81. return
  82. }
  83. // GetTacticsPermissionIdByCompanyId 获取客户的策略权限
  84. func GetTacticsPermissionIdByCompanyId(companyId, productId int) (count int, err error) {
  85. sql := `SELECT COUNT(DISTINCT crp.chart_permission_id) AS COUNT from chart_permission cp
  86. INNER JOIN company_report_permission AS crp ON cp.chart_permission_id = crp.chart_permission_id
  87. WHERE crp.company_id=? AND crp.product_id=? AND cp.permission_name="策略"`
  88. o := orm.NewOrm()
  89. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  90. return
  91. }
  92. // UpdateCompanyProductViewData 更新客户产品的阅读记录(阅读时间、总阅读次数)
  93. func UpdateCompanyProductViewData(companyId, productId int, lastViewTime string) (err error) {
  94. sql := ` update company_product set view_total=view_total+1,last_view_time=? WHERE company_id=? and product_id =? `
  95. o := orm.NewOrm()
  96. _, err = o.Raw(sql, lastViewTime, companyId, productId).Exec()
  97. return
  98. }