company.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.NewOrm()
  28. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  29. return
  30. }
  31. func GetCompanyDetailByIdGroup(companyId int) (item *CompanyDetail, err error) {
  32. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile ,b.is_suspend
  33. FROM company AS a
  34. INNER JOIN company_product AS b ON a.company_id=b.company_id
  35. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  36. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  37. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  38. WHERE a.company_id=? AND b.product_id = 2
  39. OR (a.company_id = ? AND cp.permission_name = '策略' )
  40. ORDER BY b.product_id DESC LIMIT 0,1 `
  41. o := orm.NewOrm()
  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.NewOrm()
  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 GetCompanyPermission(companyId int) (permission string, err error) {
  72. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name 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.NewOrm()
  82. err = o.Raw(sql, companyId).QueryRow(&permission)
  83. return
  84. }
  85. func GetCompanyPermissionByUser(companyId int) (permission string, err error) {
  86. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  87. FROM company_report_permission AS a
  88. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  89. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  90. WHERE a.company_id=?
  91. AND c.is_suspend=0
  92. AND b.cygx_auth=1
  93. AND c.status IN('正式','试用','永续')
  94. AND a.status IN('正式','试用','永续') `
  95. o := orm.NewOrm()
  96. err = o.Raw(sql, companyId).QueryRow(&permission)
  97. return
  98. }
  99. //获取正式权限
  100. func GetCompanyPermissionByUserZhengShi(companyId int) (permission string, err error) {
  101. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  102. FROM company_report_permission AS a
  103. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  104. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  105. WHERE a.company_id=?
  106. AND c.is_suspend=0
  107. AND b.cygx_auth=1
  108. AND c.status IN('正式')
  109. AND a.status IN('正式') `
  110. o := orm.NewOrm()
  111. err = o.Raw(sql, companyId).QueryRow(&permission)
  112. return
  113. }
  114. func GetCompanyPermissionByName(name string) (permission string, err error) {
  115. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR '/') AS permission
  116. FROM company_report_permission AS a
  117. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  118. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  119. INNER JOIN company AS cm ON cm.company_id=c.company_id
  120. WHERE cm.company_name=?
  121. AND b.product_id = 2 `
  122. o := orm.NewOrm()
  123. err = o.Raw(sql, name).QueryRow(&permission)
  124. return
  125. }
  126. func GetCompanyDetailAllById(companyId int) (item *CompanyDetail, err error) {
  127. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile
  128. FROM company AS a
  129. INNER JOIN company_product AS b ON a.company_id=b.company_id
  130. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  131. INNER JOIN chart_permission AS cp ON cp.chart_permission_id=p.chart_permission_id
  132. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  133. WHERE a.company_id=? AND cp.cygx_auth=1
  134. OR (a.company_id = ? AND cp.permission_name = '策略' )` // 兼容永续状态
  135. //WHERE a.company_id=? AND b.status IN('正式','试用','永续')`
  136. o := orm.NewOrm()
  137. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  138. return
  139. }
  140. //获取对应销售以及销售的手机号
  141. func GetSellerDetailAllByCompanyId(companyId int) (item *CompanyDetail, err error) {
  142. sql := ` SELECT c.mobile ,c.real_name as seller_name
  143. FROM
  144. company AS a
  145. INNER JOIN company_product AS b ON a.company_id = b.company_id
  146. INNER JOIN admin AS c ON b.seller_id = c.admin_id
  147. WHERE
  148. b.product_id = 2
  149. AND a.company_id = ? LIMIT 1`
  150. o := orm.NewOrm()
  151. err = o.Raw(sql, companyId).QueryRow(&item)
  152. return
  153. }
  154. func GetCompanySellerName(companyId int) (sellerName string, err error) {
  155. sql := ` SELECT
  156. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS sellerName
  157. FROM
  158. company_product AS p
  159. WHERE
  160. p.company_id = ? `
  161. o := orm.NewOrm()
  162. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  163. return
  164. }
  165. type CompanyProductStatus struct {
  166. IsSuspend int `description:"1:暂停,0:启用"`
  167. }
  168. type CompanyProductDetial struct {
  169. IsSuspend int `description:"1:暂停,0:启用"`
  170. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  171. }
  172. //获取对应销售以及销售的手机号
  173. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetial, err error) {
  174. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  175. o := orm.NewOrm()
  176. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  177. return
  178. }
  179. //获取公司详情详情
  180. func GetCompanyByName(companyName string) (item *Company, err error) {
  181. o := orm.NewOrm()
  182. sql := `SELECT * FROM company WHERE company_name = ? LIMIT 1`
  183. err = o.Raw(sql, companyName).QueryRow(&item)
  184. return
  185. }
  186. //获取公司详情详情
  187. func GetCompanyByThirdName(tripartiteCompanyCode string) (item *Company, err error) {
  188. o := orm.NewOrm()
  189. sql := `SELECT * FROM company WHERE tripartite_company_code = ? LIMIT 1`
  190. err = o.Raw(sql, tripartiteCompanyCode).QueryRow(&item)
  191. return
  192. }