send_company_user.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyJson struct {
  7. CompanyName string `json:"name"` //公司名称
  8. ShortName string `json:"short_name"` //公司简称
  9. CreditCode string `json:"social"` //社会信用代码
  10. City string `json:"city"` //所在地级市或直辖市
  11. SignType string `json:"sign_type"` //客户重要度(A类、B类、C类、D类)
  12. Fe string `json:"f_e"` //客户类型(FICC、权益、策略)
  13. IndustryName string `json:"industry"` //所属行业(公募、私募、券商资管、保险、海外、其他类型)
  14. Mobile string `json:"sale_phone"` //所属销售(销售手机号)
  15. Status string `json:"status"` //客户状态(正式、试用)
  16. //Permission string `json:"permissions"` //客户权限(医药,科技,智造,消费,策略,专家,路演服务,研选)
  17. StartDate string `json:"start_time"` //服务期限开始时间
  18. EndDate string `json:"end_time"` //服务期限结束时间
  19. Info string `json:"info"` //简介
  20. CreatedTime string `json:"create_time"` //创建时间
  21. PermissionData []*PermissionData `json:"permission_data"` //创建时间
  22. //CreatedTimes string //创建时间
  23. EndDateTime time.Time //创建时间
  24. Cid int // 公司ID
  25. }
  26. type PermissionDataList struct {
  27. PermissionData []*PermissionData
  28. }
  29. type PermissionData struct {
  30. PermissionName string `json:"permission_name"` //权限名称
  31. StartTime string `json:"start_time"` //权限开始时间
  32. EndTime string `json:"end_time"` //权限结束时间
  33. IsTryOut int `json:"is_try_out"` //权限是否试用:0=否,1=是
  34. Money int `json:"money"` //权限是否试用:0=否,1=是
  35. }
  36. type UserJson struct {
  37. CreditCode string `json:"social"` //社会信用代码
  38. RealName string `json:"name"` //昵称
  39. Mobile string `json:"phone"` //手机号1
  40. CountryCode string `json:"area_code"` //国家号1(+86..)
  41. OutboundMobile string `json:"phone2"` //手机号2
  42. OutboundCountryCode string `json:"area_code2"` //国家号2(+86..)
  43. Telephone string `json:"machine"` //座机
  44. MachineAreaCode string `json:"machine_area_code"` //座机国家号(+86..)
  45. Sex string `json:"sex"` //性别(男、女)
  46. Email string `json:"email"` //电子邮箱,比如 example@qq.com
  47. Department string `json:"department"` //部门
  48. Position string `json:"position"` //职位
  49. Level string `json:"level"` //职位等级(研究员、基金经理、部门总监)
  50. IsMaker string `json:"policymakers"` //是否决策人(是、否)
  51. CreatedTime string `json:"create_time"` //创建时间
  52. }
  53. type CompanyJsonList struct {
  54. SyncData *[]CompanyJson `json:"sync_data"`
  55. }
  56. type CompanyUnJsonList struct {
  57. SyncData []CompanyJson `json:"sync_data"`
  58. }
  59. // 删除用户
  60. type ShangHaiCrmUserDeleteResp struct {
  61. Social string `json:"social"`
  62. Mobile string `json:"phone"`
  63. Name string `json:"name"`
  64. }
  65. // 获取公司
  66. func GetSendCompanyList(condition string) (items []*CompanyJson, err error) {
  67. o := orm.NewOrmUsingDB("weekly_report")
  68. sql := ` SELECT
  69. c.company_name,
  70. c.company_id as cid,
  71. c.credit_code,
  72. c.city,
  73. p.industry_name,
  74. am.real_name,
  75. am.mobile,
  76. p.status,
  77. p.end_date as end_date_time,
  78. UNIX_TIMESTAMP( p.start_date ) AS start_date,
  79. UNIX_TIMESTAMP( p.end_date ) AS end_date,
  80. UNIX_TIMESTAMP( a.created_time ) AS created_time,
  81. (SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',')
  82. FROM company_report_permission AS a
  83. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  84. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  85. WHERE a.company_id=cid
  86. AND c.enabled = 1
  87. AND b.cygx_auth=1
  88. AND a.STATUS IN ( '正式', '试用', '永续' )) AS permission
  89. FROM
  90. company_report_permission AS a
  91. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  92. INNER JOIN company_product AS p ON a.company_id = p.company_id
  93. INNER JOIN company AS c ON c.company_id = a.company_id
  94. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  95. AND a.product_id = p.product_id
  96. WHERE
  97. 1 = 1
  98. AND c.enabled = 1
  99. AND b.cygx_auth = 1
  100. AND p.STATUS IN ( '正式', '试用','冻结','流失' ,'流失', '永续' )
  101. AND( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
  102. AND p.product_id = 2 ` + condition +
  103. `GROUP BY
  104. c.company_id `
  105. _, err = o.Raw(sql).QueryRows(&items)
  106. return
  107. }
  108. type PermissionDataResp struct {
  109. CompanyId int `description:"公司ID"`
  110. PermissionName string `description:"行业名称"`
  111. Status string `description:"状态"`
  112. StartDate time.Time `description:"行业名称"`
  113. EndDate time.Time `description:"行业名称"`
  114. }
  115. func GetSendCompanyPermissionDataList(condition string, pars []interface{}) (items []*PermissionDataResp, err error) {
  116. o := orm.NewOrmUsingDB("weekly_report")
  117. sql := ` SELECT
  118. company_id,
  119. c.permission_name,
  120. cp.status,
  121. cp.end_date,
  122. cp.start_date
  123. FROM
  124. company_report_permission AS cp
  125. INNER JOIN chart_permission AS c ON cp.chart_permission_id = c.chart_permission_id
  126. WHERE
  127. 1 = 1
  128. AND cp.STATUS IN ( '正式', '试用', '永续' )
  129. AND c.enabled = 1
  130. AND c.chart_permission_name IN ( '医药', '消费', '科技', '智造', '策略', '研选订阅', '研选扣点包', '专家', '路演服务','固收','周期' ) ` + condition + ` GROUP BY c.permission_name, cp.company_id `
  131. _, err = o.Raw(sql, pars).QueryRows(&items)
  132. return
  133. }
  134. // 不做正式,试用,永续权限的校验
  135. func GetSendCompanyPermissionDataListNoChekcStatus(condition string, pars []interface{}) (items []*PermissionDataResp, err error) {
  136. o := orm.NewOrmUsingDB("weekly_report")
  137. sql := ` SELECT
  138. company_id,
  139. c.permission_name,
  140. cp.status,
  141. cp.end_date,
  142. cp.start_date
  143. FROM
  144. company_report_permission AS cp
  145. INNER JOIN chart_permission AS c ON cp.chart_permission_id = c.chart_permission_id
  146. WHERE
  147. 1 = 1
  148. AND cp.STATUS NOT IN ( '正式', '试用', '永续' )
  149. AND c.chart_permission_name IN ( '医药', '消费', '科技', '智造', '策略', '研选扣点包', '专家', '路演服务' ,'固收','周期' ) ` + condition + ` GROUP BY c.permission_name, cp.company_id `
  150. _, err = o.Raw(sql, pars).QueryRows(&items)
  151. return
  152. }
  153. // 获取FICC公司
  154. func GetSendCompanyFiccList(condition string) (items []*CompanyJson, err error) {
  155. o := orm.NewOrmUsingDB("weekly_report")
  156. sql := ` SELECT
  157. c.company_name,
  158. c.company_id AS cid,
  159. c.credit_code,
  160. c.city,
  161. p.industry_name,
  162. am.real_name,
  163. am.mobile,
  164. p.status,
  165. p.end_date AS end_date_time,
  166. UNIX_TIMESTAMP( p.start_date ) AS start_date,
  167. UNIX_TIMESTAMP( p.end_date ) AS end_date,
  168. UNIX_TIMESTAMP( a.created_time ) AS created_time,
  169. (
  170. SELECT
  171. GROUP_CONCAT( DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',' )
  172. FROM
  173. company_report_permission AS a
  174. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  175. INNER JOIN company_product AS c ON a.company_id = c.company_id
  176. AND a.product_id = c.product_id
  177. WHERE
  178. a.company_id = cid
  179. AND c.enabled = 1
  180. AND b.cygx_auth = 1
  181. AND a.STATUS IN ( '正式', '试用', '永续' )) AS permission
  182. FROM
  183. company_report_permission AS a
  184. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  185. INNER JOIN company_product AS p ON a.company_id = p.company_id
  186. INNER JOIN company AS c ON c.company_id = a.company_id
  187. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  188. AND a.product_id = p.product_id
  189. WHERE
  190. 1 = 1
  191. AND c.enabled = 1
  192. AND b.cygx_auth = 1
  193. AND p.STATUS IN ( '正式', '试用','冻结','流失' )
  194. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
  195. AND p.product_id = 1 ` + condition +
  196. `AND c.company_id NOT IN (
  197. SELECT
  198. c.company_id
  199. FROM
  200. company_report_permission AS a
  201. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  202. INNER JOIN company_product AS p ON a.company_id = p.company_id
  203. INNER JOIN company AS c ON c.company_id = a.company_id
  204. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  205. AND a.product_id = p.product_id
  206. WHERE
  207. 1 = 1
  208. AND c.enabled = 1
  209. AND b.cygx_auth = 1
  210. AND p.STATUS IN ( '正式', '试用' ,'冻结','流失', '永续')
  211. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
  212. AND p.product_id = 2
  213. GROUP BY
  214. c.company_id
  215. )
  216. GROUP BY
  217. c.company_id `
  218. _, err = o.Raw(sql).QueryRows(&items)
  219. return
  220. }
  221. // 获取用户
  222. func GetSendUserList(condition string) (items []*UserJson, err error) {
  223. o := orm.NewOrmUsingDB("weekly_report")
  224. sql := ` SELECT
  225. c.credit_code,
  226. u.real_name,
  227. u.mobile,
  228. u.country_code,
  229. u.outbound_mobile,
  230. u.outbound_country_code,
  231. u.telephone,
  232. u.sex,
  233. u.is_maker,
  234. c.company_id,
  235. UNIX_TIMESTAMP( us.create_time ) AS created_time
  236. FROM
  237. wx_user AS u
  238. INNER JOIN company AS c ON c.company_id = u.company_id
  239. INNER JOIN user_seller_relation AS us ON us.user_id = u.user_id
  240. WHERE
  241. 1 = 1
  242. AND u.company_id IN (
  243. SELECT
  244. c.company_id
  245. FROM
  246. company_report_permission AS a
  247. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  248. INNER JOIN company_product AS p ON a.company_id = p.company_id
  249. INNER JOIN company AS c ON c.company_id = a.company_id
  250. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  251. AND a.product_id = p.product_id
  252. WHERE
  253. 1 = 1
  254. AND c.enabled = 1
  255. AND b.cygx_auth = 1
  256. AND p.STATUS IN ( '正式', '试用','冻结','流失','流失', '永续' )
  257. AND us.create_time != '' ` + condition +
  258. `GROUP BY
  259. c.company_id
  260. )
  261. AND us.create_time != ''
  262. AND u.real_name != ''
  263. AND u.mobile != ''
  264. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' ) GROUP BY u.user_id ORDER BY c.company_id DESC `
  265. _, err = o.Raw(sql).QueryRows(&items)
  266. return
  267. }
  268. type WxUserOpLogResp struct {
  269. CompanyId int `description:"客户ID"`
  270. UserId int `description:"用户ID"`
  271. Mobile string `description:"用户ID"`
  272. }
  273. type WxUserOpLogDeleteResp struct {
  274. CompanyId int `description:"客户ID"`
  275. UserId int `description:"用户ID"`
  276. Mobile string `description:"用户ID"`
  277. OriginalUserInfo string `description:"用户详情"`
  278. CreditCode string `description:"社会信用码"`
  279. RealName string `description:"真实姓名"`
  280. }
  281. // 获取指定时间内更新的用户
  282. func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
  283. o := orm.NewOrmUsingDB("weekly_report")
  284. sql := ` SELECT
  285. u.company_id
  286. FROM
  287. wx_user_op_log AS l
  288. INNER JOIN wx_user AS u ON u.mobile = l.mobile
  289. WHERE
  290. l.create_time >= '` + createTime + `' GROUP BY u.company_id `
  291. _, err = o.Raw(sql).QueryRows(&items)
  292. return
  293. }
  294. // 获取指定时间内删除的用户
  295. func GetWxUserOpLogDelete(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  296. o := orm.NewOrmUsingDB("weekly_report")
  297. sql := `SELECT
  298. l.*,
  299. c.credit_code
  300. FROM
  301. wx_user_op_log AS l
  302. INNER JOIN company AS c ON c.company_id = l.company_id WHERE l.log_type = 'delete' AND l.create_time >= '` + createTime + `'`
  303. _, err = o.Raw(sql).QueryRows(&items)
  304. return
  305. }
  306. // 获取指定时间内被暂停的客户
  307. func GetWxUserOpLogSuspend(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  308. o := orm.NewOrmUsingDB("weekly_report")
  309. sql := `SELECT
  310. *
  311. FROM
  312. company_operation_record AS p
  313. WHERE
  314. remark = '暂停'
  315. AND p.id IN ( SELECT MAX( p.id ) AS max_id FROM company_operation_record AS p WHERE 1 = 1 AND p.create_time > '` + createTime + `' ) `
  316. _, err = o.Raw(sql).QueryRows(&items)
  317. return
  318. }
  319. // 获取指定时间内被移动的客户
  320. func GetCompanyOperationRecord(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  321. o := orm.NewOrmUsingDB("weekly_report")
  322. sql := `SELECT
  323. *
  324. FROM
  325. company_operation_record AS p
  326. WHERE
  327. 1=1
  328. AND p.create_time > '` + createTime + `' GROUP BY company_id `
  329. _, err = o.Raw(sql).QueryRows(&items)
  330. return
  331. }
  332. // 获取指定时间内试用转冻结,冻结转流失的客户
  333. func GetCompanyFreezeAndLoss(createTime string) (items []*WxUserOpLogResp, err error) {
  334. o := orm.NewOrmUsingDB("weekly_report")
  335. sql := ` SELECT * FROM company_operation_record WHERE status IN ('冻结','流失') AND create_time > '` + createTime + `' GROUP BY company_id `
  336. _, err = o.Raw(sql).QueryRows(&items)
  337. return
  338. }
  339. // 获取指定时间内被移动的用户
  340. func GetWxUserOpLogList(startDate, endDate string) (items []*WxUserOpLogResp, err error) {
  341. o := orm.NewOrmUsingDB("weekly_report")
  342. sql := ` SELECT company_id,user_id,mobile FROM wx_user_op_log WHERE log_type IN ('move','add') AND create_time >= '` + startDate + `' AND create_time <= '` + endDate + `' GROUP BY user_id `
  343. _, err = o.Raw(sql).QueryRows(&items)
  344. return
  345. }
  346. // 获取指定时间内被删除的用户
  347. func GetWxUserOpLogDeleteList(startDate, endDate string) (items []*WxUserOpLogResp, err error) {
  348. o := orm.NewOrmUsingDB("weekly_report")
  349. sql := ` SELECT company_id,user_id,mobile FROM wx_user_op_log WHERE log_type IN ('delete') AND create_time >= '` + startDate + `' AND create_time <= '` + endDate + `' GROUP BY user_id `
  350. _, err = o.Raw(sql).QueryRows(&items)
  351. return
  352. }