company.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package models
  2. import "github.com/beego/beego/v2/client/orm"
  3. type CompanyDetail struct {
  4. CompanyId int `orm:"column(company_id);pk"`
  5. CompanyName string `description:"客户名称"`
  6. Status string `description:"客户状态"`
  7. SellerId int `description:"销售id"`
  8. SellerName string `description:"销售名称"`
  9. Mobile string `description:"销售手机号"`
  10. ProductId int `description:"1,FICC,2权益"`
  11. IsSuspend int `description:"1:暂停,0:启用"`
  12. }
  13. func GetCompanyDetailById(companyId int) (item *CompanyDetail, err error) {
  14. //sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile
  15. // FROM company AS a
  16. // INNER JOIN company_product AS b ON a.company_id=b.company_id
  17. // LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  18. // WHERE a.company_id=? AND b.product_id=2 `
  19. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile,p.product_id
  20. FROM company AS a
  21. INNER JOIN company_product AS b ON a.company_id=b.company_id
  22. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  23. INNER JOIN chart_permission AS cp ON cp.chart_permission_id=p.chart_permission_id
  24. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  25. WHERE a.company_id=? AND cp.cygx_auth=1
  26. OR (a.company_id = ? AND cp.permission_name = '策略' ) ORDER BY b.product_id DESC LIMIT 1` // 兼容永续状态
  27. o := orm.NewOrmUsingDB("weekly_report")
  28. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  29. return
  30. }
  31. func GetCompanyDetailByIdGroup(companyId int) (item *CompanyDetail, err error) {
  32. o := orm.NewOrmUsingDB("weekly_report")
  33. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile ,b.is_suspend
  34. FROM company AS a
  35. INNER JOIN company_product AS b ON a.company_id=b.company_id
  36. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  37. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  38. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  39. WHERE a.company_id=? AND b.product_id = 2
  40. OR (a.company_id = ? AND cp.permission_name = '策略' )
  41. ORDER BY b.product_id DESC LIMIT 0,1 `
  42. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  43. return
  44. }
  45. func GetCountCompanyDetailByIdGroup(companyId int) (count int, err error) {
  46. sql := ` SELECT COUNT(1) AS count
  47. FROM company AS a
  48. INNER JOIN company_product AS b ON a.company_id=b.company_id
  49. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  50. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  51. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  52. WHERE a.company_id=? AND b.product_id = 2 OR (a.company_id = ? AND cp.permission_name = '策略' ) `
  53. o := orm.NewOrmUsingDB("weekly_report")
  54. err = o.Raw(sql, companyId, companyId).QueryRow(&count)
  55. return
  56. }
  57. //原有权限叫校验,下方更改与2021-5.18
  58. //func GetCompanyPermission(companyId int) (permission string, err error) {
  59. // sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission
  60. // FROM company_report_permission AS a
  61. // INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  62. // INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  63. // WHERE a.company_id=?
  64. // AND a.product_id=2
  65. // AND b.show_type=1
  66. // AND c.status IN('正式','试用','永续') `
  67. // o := orm.NewOrm()
  68. // err = o.Raw(sql, companyId).QueryRow(&permission)
  69. // return
  70. //}
  71. func GetCompanyPermissionByUser(companyId int) (permission string, err error) {
  72. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  73. FROM company_report_permission AS a
  74. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  75. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  76. WHERE a.company_id=?
  77. AND c.is_suspend=0
  78. AND b.cygx_auth=1
  79. AND c.status IN('正式','试用','永续')
  80. AND a.status IN('正式','试用','永续') `
  81. o := orm.NewOrmUsingDB("weekly_report")
  82. err = o.Raw(sql, companyId).QueryRow(&permission)
  83. return
  84. }
  85. // 获取用户权限不限制状态
  86. func GetCompanyPermissionByUserNoStatus(companyId int) (permission string, err error) {
  87. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  88. FROM company_report_permission AS a
  89. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  90. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  91. WHERE a.company_id=?
  92. AND c.is_suspend=0
  93. AND b.cygx_auth=1`
  94. o := orm.NewOrmUsingDB("weekly_report")
  95. err = o.Raw(sql, companyId).QueryRow(&permission)
  96. return
  97. }
  98. // 获取正式权限
  99. func GetCompanyPermissionByUserZhengShi(companyId int) (permission string, err error) {
  100. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  101. FROM company_report_permission AS a
  102. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  103. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  104. WHERE a.company_id=?
  105. AND c.is_suspend=0
  106. AND b.cygx_auth=1
  107. AND c.status IN('正式')
  108. AND a.status IN('正式') `
  109. o := orm.NewOrmUsingDB("weekly_report")
  110. err = o.Raw(sql, companyId).QueryRow(&permission)
  111. return
  112. }
  113. func GetCompanyPermissionByName(name string) (permission string, err error) {
  114. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR '/') AS permission
  115. FROM company_report_permission AS a
  116. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  117. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  118. INNER JOIN company AS cm ON cm.company_id=c.company_id
  119. WHERE cm.company_name=?
  120. AND b.product_id = 2 `
  121. o := orm.NewOrmUsingDB("weekly_report")
  122. err = o.Raw(sql, name).QueryRow(&permission)
  123. return
  124. }
  125. func GetCompanyDetailAllById(companyId int) (item *CompanyDetail, err error) {
  126. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile
  127. FROM company AS a
  128. INNER JOIN company_product AS b ON a.company_id=b.company_id
  129. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  130. INNER JOIN chart_permission AS cp ON cp.chart_permission_id=p.chart_permission_id
  131. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  132. WHERE a.company_id=? AND cp.cygx_auth=1
  133. OR (a.company_id = ? AND cp.permission_name = '策略' )` // 兼容永续状态
  134. //WHERE a.company_id=? AND b.status IN('正式','试用','永续')`
  135. o := orm.NewOrmUsingDB("weekly_report")
  136. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  137. return
  138. }
  139. // 获取对应销售以及销售的手机号
  140. func GetSellerDetailAllByCompanyId(companyId int) (item *CompanyDetail, err error) {
  141. sql := ` SELECT c.mobile ,c.real_name as seller_name,a.company_name
  142. FROM
  143. company AS a
  144. INNER JOIN company_product AS b ON a.company_id = b.company_id
  145. INNER JOIN admin AS c ON b.seller_id = c.admin_id
  146. WHERE
  147. b.product_id = 2
  148. AND a.company_id = ? LIMIT 1`
  149. o := orm.NewOrmUsingDB("weekly_report")
  150. err = o.Raw(sql, companyId).QueryRow(&item)
  151. return
  152. }
  153. func GetCompanySellerName(companyId int) (sellerName string, err error) {
  154. sql := ` SELECT
  155. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS sellerName
  156. FROM
  157. company_product AS p
  158. WHERE
  159. p.company_id = ? `
  160. o := orm.NewOrmUsingDB("weekly_report")
  161. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  162. return
  163. }
  164. // 获取权益销售
  165. func GetCompanySellerNameRai(companyId int) (sellerName string, err error) {
  166. sql := ` SELECT
  167. seller_name AS sellerName
  168. FROM
  169. company_product AS p
  170. WHERE
  171. p.company_id = ? AND product_id = 2 `
  172. o := orm.NewOrmUsingDB("weekly_report")
  173. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  174. return
  175. }
  176. type CompanyProductStatus struct {
  177. IsSuspend int `description:"1:暂停,0:启用"`
  178. }
  179. type CompanyProductDetial struct {
  180. IsSuspend int `description:"1:暂停,0:启用"`
  181. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  182. }
  183. // 获取对应销售以及销售的手机号
  184. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetial, err error) {
  185. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  186. o := orm.NewOrmUsingDB("weekly_report")
  187. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  188. return
  189. }
  190. type PermissionItem struct {
  191. ChartPermissionId int `description:"权限id"`
  192. PermissionName string `description:"权限名称"`
  193. IsUpgrade int `description:"是否升级,1是,0否"`
  194. Remark string `description:"备注区分主观客观"`
  195. }
  196. func GetCompanyPermissionList(companyId int) (items []*PermissionItem, err error) {
  197. sql := ` SELECT b.chart_permission_id,b.permission_name,b.remark,a.is_upgrade
  198. FROM company_report_permission AS a
  199. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  200. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  201. WHERE a.company_id=?
  202. AND c.is_suspend=0
  203. AND b.cygx_auth=1
  204. AND c.status IN('正式','试用','永续')
  205. AND a.status IN('正式','试用','永续') ORDER BY b.sort ASC `
  206. o := orm.NewOrmUsingDB("weekly_report")
  207. _, err = o.Raw(sql, companyId).QueryRows(&items)
  208. return
  209. }
  210. func GetCompanyProductCount(companyId, productId int) (count int, err error) {
  211. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = ? AND company_id > 1 `
  212. o := orm.NewOrmUsingDB("weekly_report")
  213. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  214. return
  215. }