company_activity_trip.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package models
  2. import "github.com/beego/beego/v2/client/orm"
  3. func GetCountCompanyDetailByIdGroupTrip(companyId int) (count int, err error) {
  4. o := orm.NewOrmUsingDB("weekly_report")
  5. sql := ` SELECT
  6. COUNT( 1 ) AS count
  7. FROM
  8. company AS a
  9. INNER JOIN company_product AS b ON a.company_id = b.company_id
  10. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  11. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  12. LEFT JOIN admin AS c ON b.seller_id = c.admin_id
  13. WHERE
  14. a.company_id = ?
  15. AND b.product_id = 2
  16. AND b.status = '正式'
  17. AND p.is_upgrade = 1
  18. OR (
  19. a.company_id = ?
  20. AND b.product_id = 2
  21. AND b.status = '永续') `
  22. err = o.Raw(sql, companyId, companyId).QueryRow(&count)
  23. return
  24. }
  25. func GetCompanyDetailByIdGroupTrip(companyId int) (item *CompanyDetail, err error) {
  26. o := orm.NewOrmUsingDB("weekly_report")
  27. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile ,b.is_suspend
  28. FROM company AS a
  29. INNER JOIN company_product AS b ON a.company_id=b.company_id
  30. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  31. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  32. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  33. WHERE a.company_id=? AND b.product_id = 2
  34. ORDER BY b.product_id DESC LIMIT 0,1 `
  35. err = o.Raw(sql, companyId).QueryRow(&item)
  36. return
  37. }
  38. func GetCompanyPermissionByUserTrip(companyId int) (permission string, err error) {
  39. o := orm.NewOrmUsingDB("weekly_report")
  40. sql := ` SELECT
  41. GROUP_CONCAT( DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',' ) AS permission
  42. FROM
  43. company_report_permission AS a
  44. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  45. INNER JOIN company_product AS c ON a.company_id = c.company_id
  46. AND a.product_id = c.product_id
  47. WHERE
  48. a.company_id = ?
  49. AND c.is_suspend = 0
  50. AND b.cygx_auth = 1
  51. AND a.is_upgrade = 1
  52. AND c.STATUS IN ( '正式' )
  53. OR ( a.company_id = ? AND c.is_suspend = 0 AND b.cygx_auth = 1 AND c.STATUS IN ( '永续' ) )
  54. OR ( a.company_id = ? AND c.is_suspend = 0 AND b.cygx_auth = 1 AND b.chart_permission_name = '策略' AND c.STATUS IN ( '正式' ) )`
  55. err = o.Raw(sql, companyId, companyId, companyId).QueryRow(&permission)
  56. return
  57. }
  58. // 获取正式权限
  59. func GetCompanyPermissionByUserZhengShiTrip(companyId int) (permission string, err error) {
  60. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission
  61. FROM company_report_permission AS a
  62. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  63. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  64. WHERE a.company_id=?
  65. AND c.is_suspend=0
  66. AND b.cygx_auth=1
  67. AND ( a.is_upgrade = 1 AND c.STATUS = '正式' OR c.STATUS = '永续' ) `
  68. o := orm.NewOrmUsingDB("weekly_report")
  69. err = o.Raw(sql, companyId).QueryRow(&permission)
  70. return
  71. }
  72. // GetCompanyReportPermissionUpgrade 获取升级的权限类型
  73. func GetCompanyReportPermissionUpgrade(companyId, productId int) (items []*CompanyReportPermission, err error) {
  74. o := orm.NewOrmUsingDB("weekly_report")
  75. sql := `SELECT
  76. re.*
  77. FROM
  78. company_report_permission as re
  79. INNER JOIN chart_permission as c ON c.chart_permission_id = re.chart_permission_id
  80. WHERE
  81. re.company_id = ?
  82. AND re.product_id = ?
  83. AND re.is_upgrade = 1
  84. AND c.permission_type = 1
  85. AND STATUS = '正式' `
  86. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  87. return
  88. }
  89. // GetChartPermissionByIds 主键获取权限
  90. func GetChartPermissionByIds(permissionIds []string) (list []*ChartPermission, err error) {
  91. qb, _ := orm.NewQueryBuilder("mysql")
  92. // 构建查询对象
  93. qb.Select("*").From("chart_permission").
  94. Where("chart_permission_id").In(permissionIds...)
  95. // 导出 SQL 语句
  96. sql := qb.String()
  97. // 执行 SQL 语句
  98. o := orm.NewOrmUsingDB("weekly_report")
  99. _, err = o.Raw(sql).QueryRows(&list)
  100. return
  101. }
  102. // GetCompanyPermissionNameCheck 通过名称判断客户是否开了某一类型的权限
  103. func GetCompanyPermissionNameCheck(companyId, productId int, permissionName string) (count int, err error) {
  104. o := orm.NewOrmUsingDB("weekly_report")
  105. sql := `SELECT
  106. COUNT( 1 ) AS count
  107. FROM
  108. company_report_permission AS a
  109. INNER JOIN chart_permission as c ON c.chart_permission_id = a.chart_permission_id
  110. WHERE
  111. a.company_id = ?
  112. AND a.STATUS = '正式'
  113. AND a.product_id = ?
  114. AND c.chart_permission_name = ? `
  115. err = o.Raw(sql, companyId, productId, permissionName).QueryRow(&count)
  116. return
  117. }
  118. // GetCompanyReportPermissionByCompanyIdAndProductId 获取权限类型
  119. func GetCompanyReportPermissionByCompanyIdAndProductId(companyId, productId int) (items []*CompanyReportPermission, err error) {
  120. o := orm.NewOrmUsingDB("weekly_report")
  121. sql := `SELECT
  122. re.*
  123. FROM
  124. company_report_permission as re
  125. INNER JOIN chart_permission as c ON c.chart_permission_id = re.chart_permission_id
  126. WHERE
  127. re.company_id = ?
  128. AND re.product_id = ?
  129. AND STATUS = '正式' `
  130. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  131. return
  132. }