company.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. 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.NewOrmUsingDB("weekly_report")
  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 GetCompanyPermission(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. func GetCompanyPermissionName(companyId int) (permission string, err error) {
  86. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name 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.NewOrmUsingDB("weekly_report")
  96. err = o.Raw(sql, companyId).QueryRow(&permission)
  97. return
  98. }
  99. func GetCompanyPermissionByUser(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. type PermissionItem struct {
  114. ChartPermissionId int `description:"权限id"`
  115. PermissionName string `description:"权限名称"`
  116. IsUpgrade int `description:"是否升级,1是,0否"`
  117. Remark string `description:"备注区分主观客观"`
  118. }
  119. func GetCompanyPermissionList(companyId int) (items []*PermissionItem, err error) {
  120. sql := ` SELECT b.chart_permission_id,b.permission_name,b.remark,a.is_upgrade
  121. FROM company_report_permission AS a
  122. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  123. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  124. WHERE a.company_id=?
  125. AND c.is_suspend=0
  126. AND b.cygx_auth=1
  127. AND c.status IN('正式','试用','永续')
  128. AND a.status IN('正式','试用','永续') ORDER BY b.sort ASC `
  129. o := orm.NewOrmUsingDB("weekly_report")
  130. _, err = o.Raw(sql, companyId).QueryRows(&items)
  131. return
  132. }
  133. // 获取用户权限不限制状态
  134. func GetCompanyPermissionByUserNoStatus(companyId int) (permission string, err error) {
  135. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  136. FROM company_report_permission AS a
  137. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  138. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  139. WHERE a.company_id=?
  140. AND c.is_suspend=0
  141. AND b.cygx_auth=1`
  142. o := orm.NewOrmUsingDB("weekly_report")
  143. err = o.Raw(sql, companyId).QueryRow(&permission)
  144. return
  145. }
  146. // 获取正式权限
  147. func GetCompanyPermissionByUserZhengShi(companyId int) (permission string, err error) {
  148. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  149. FROM company_report_permission AS a
  150. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  151. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  152. WHERE a.company_id=?
  153. AND c.is_suspend=0
  154. AND b.cygx_auth=1
  155. AND a.status IN('正式') `
  156. o := orm.NewOrmUsingDB("weekly_report")
  157. err = o.Raw(sql, companyId).QueryRow(&permission)
  158. return
  159. }
  160. func GetCompanyPermissionByName(name string) (permission string, err error) {
  161. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR '/') AS permission
  162. FROM company_report_permission AS a
  163. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  164. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  165. INNER JOIN company AS cm ON cm.company_id=c.company_id
  166. WHERE cm.company_name=?
  167. AND b.product_id = 2 `
  168. o := orm.NewOrmUsingDB("weekly_report")
  169. err = o.Raw(sql, name).QueryRow(&permission)
  170. return
  171. }
  172. func GetCompanyDetailAllById(companyId int) (item *CompanyDetail, err error) {
  173. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile
  174. FROM company AS a
  175. INNER JOIN company_product AS b ON a.company_id=b.company_id
  176. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  177. INNER JOIN chart_permission AS cp ON cp.chart_permission_id=p.chart_permission_id
  178. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  179. WHERE a.company_id=? AND cp.cygx_auth=1
  180. OR (a.company_id = ? AND cp.permission_name = '策略' )` // 兼容永续状态
  181. //WHERE a.company_id=? AND b.status IN('正式','试用','永续')`
  182. o := orm.NewOrmUsingDB("weekly_report")
  183. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  184. return
  185. }
  186. // 获取对应销售以及销售的手机号
  187. func GetSellerDetailAllByCompanyId(companyId int) (item *CompanyDetail, err error) {
  188. sql := ` SELECT c.mobile ,c.real_name as seller_name
  189. FROM
  190. company AS a
  191. INNER JOIN company_product AS b ON a.company_id = b.company_id
  192. INNER JOIN admin AS c ON b.seller_id = c.admin_id
  193. WHERE
  194. b.product_id = 2
  195. AND a.company_id = ? LIMIT 1`
  196. o := orm.NewOrmUsingDB("weekly_report")
  197. err = o.Raw(sql, companyId).QueryRow(&item)
  198. return
  199. }
  200. func GetCompanySellerName(companyId int) (sellerName string, err error) {
  201. sql := ` SELECT
  202. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS sellerName
  203. FROM
  204. company_product AS p
  205. WHERE
  206. p.company_id = ? `
  207. o := orm.NewOrmUsingDB("weekly_report")
  208. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  209. return
  210. }
  211. type CompanyProductStatus struct {
  212. IsSuspend int `description:"1:暂停,0:启用"`
  213. }
  214. type CompanyProductDetial struct {
  215. IsSuspend int `description:"1:暂停,0:启用"`
  216. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  217. }
  218. // 获取对应销售以及销售的手机号
  219. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetial, err error) {
  220. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  221. o := orm.NewOrmUsingDB("weekly_report")
  222. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  223. return
  224. }
  225. // 获取公司详情详情
  226. func GetCompanyByName(companyName string) (item *Company, err error) {
  227. o := orm.NewOrmUsingDB("weekly_report")
  228. sql := `SELECT * FROM company WHERE company_name = ? LIMIT 1`
  229. err = o.Raw(sql, companyName).QueryRow(&item)
  230. return
  231. }
  232. // 获取公司详情详情
  233. func GetCompanyById(companyId int) (item *Company, err error) {
  234. o := orm.NewOrmUsingDB("weekly_report")
  235. sql := `SELECT * FROM company WHERE company_id = ? LIMIT 1`
  236. err = o.Raw(sql, companyId).QueryRow(&item)
  237. return
  238. }
  239. // 获取公司详情详情
  240. func GetCompanyByThirdName(tripartiteCompanyCode string) (item *Company, err error) {
  241. o := orm.NewOrmUsingDB("weekly_report")
  242. sql := `SELECT * FROM company WHERE tripartite_company_code = ? LIMIT 1`
  243. err = o.Raw(sql, tripartiteCompanyCode).QueryRow(&item)
  244. return
  245. }
  246. // 更新机构互动量
  247. func UpdateComapanyInteractionNum(interactionNum, interactionNumSeller, companyId int) (err error) {
  248. o := orm.NewOrmUsingDB("weekly_report")
  249. sql := `UPDATE company SET interaction_num = ? , interaction_num_seller = ? WHERE company_id=? `
  250. _, err = o.Raw(sql, interactionNum, interactionNumSeller, companyId).Exec()
  251. return
  252. }
  253. // 获取有机构互动量的公司
  254. func GetCompanyInteractionNumList() (items []*Company, err error) {
  255. o := orm.NewOrmUsingDB("weekly_report")
  256. sql := `SELECT * FROM company WHERE interaction_num > 0 `
  257. _, err = o.Raw(sql).QueryRows(&items)
  258. return
  259. }
  260. func GetCompanyProductCount(companyId, productId int) (count int, err error) {
  261. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = ? AND company_id > 1 `
  262. o := orm.NewOrmUsingDB("weekly_report")
  263. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  264. return
  265. }