send_company_user.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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.chart_permission_name IN ( '医药', '消费', '科技', '智造', '策略', '买方研选', '专家', '路演服务' ) ` + condition + ` GROUP BY c.permission_name, cp.company_id `
  130. _, err = o.Raw(sql, pars).QueryRows(&items)
  131. return
  132. }
  133. // 获取FICC公司
  134. func GetSendCompanyFiccList(condition string) (items []*CompanyJson, err error) {
  135. o := orm.NewOrmUsingDB("weekly_report")
  136. sql := ` SELECT
  137. c.company_name,
  138. c.company_id AS cid,
  139. c.credit_code,
  140. c.city,
  141. p.industry_name,
  142. am.real_name,
  143. am.mobile,
  144. p.status,
  145. p.end_date AS end_date_time,
  146. UNIX_TIMESTAMP( p.start_date ) AS start_date,
  147. UNIX_TIMESTAMP( p.end_date ) AS end_date,
  148. UNIX_TIMESTAMP( a.created_time ) AS created_time,
  149. (
  150. SELECT
  151. GROUP_CONCAT( DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',' )
  152. FROM
  153. company_report_permission AS a
  154. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  155. INNER JOIN company_product AS c ON a.company_id = c.company_id
  156. AND a.product_id = c.product_id
  157. WHERE
  158. a.company_id = cid
  159. AND c.enabled = 1
  160. AND b.cygx_auth = 1
  161. AND a.STATUS IN ( '正式', '试用', '永续' )) AS permission
  162. FROM
  163. company_report_permission AS a
  164. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  165. INNER JOIN company_product AS p ON a.company_id = p.company_id
  166. INNER JOIN company AS c ON c.company_id = a.company_id
  167. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  168. AND a.product_id = p.product_id
  169. WHERE
  170. 1 = 1
  171. AND c.enabled = 1
  172. AND b.cygx_auth = 1
  173. AND p.STATUS IN ( '正式', '试用','冻结','流失' )
  174. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
  175. AND p.product_id = 1 ` + condition +
  176. `AND c.company_id NOT IN (
  177. SELECT
  178. c.company_id
  179. FROM
  180. company_report_permission AS a
  181. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  182. INNER JOIN company_product AS p ON a.company_id = p.company_id
  183. INNER JOIN company AS c ON c.company_id = a.company_id
  184. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  185. AND a.product_id = p.product_id
  186. WHERE
  187. 1 = 1
  188. AND c.enabled = 1
  189. AND b.cygx_auth = 1
  190. AND p.STATUS IN ( '正式', '试用' ,'冻结','流失')
  191. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
  192. AND p.product_id = 2
  193. GROUP BY
  194. c.company_id
  195. )
  196. GROUP BY
  197. c.company_id `
  198. _, err = o.Raw(sql).QueryRows(&items)
  199. return
  200. }
  201. // 获取用户
  202. func GetSendUserList(condition string) (items []*UserJson, err error) {
  203. o := orm.NewOrmUsingDB("weekly_report")
  204. sql := ` SELECT
  205. c.credit_code,
  206. u.real_name,
  207. u.mobile,
  208. u.country_code,
  209. u.outbound_mobile,
  210. u.outbound_country_code,
  211. u.telephone,
  212. u.sex,
  213. u.is_maker,
  214. c.company_id,
  215. UNIX_TIMESTAMP( us.create_time ) AS created_time
  216. FROM
  217. wx_user AS u
  218. INNER JOIN company AS c ON c.company_id = u.company_id
  219. INNER JOIN user_seller_relation AS us ON us.user_id = u.user_id
  220. WHERE
  221. 1 = 1
  222. AND u.company_id IN (
  223. SELECT
  224. c.company_id
  225. FROM
  226. company_report_permission AS a
  227. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  228. INNER JOIN company_product AS p ON a.company_id = p.company_id
  229. INNER JOIN company AS c ON c.company_id = a.company_id
  230. INNER JOIN admin AS am ON am.admin_id = p.seller_id
  231. AND a.product_id = p.product_id
  232. WHERE
  233. 1 = 1
  234. AND c.enabled = 1
  235. AND b.cygx_auth = 1
  236. AND p.STATUS IN ( '正式', '试用','冻结','流失')
  237. AND us.create_time != '' ` + condition +
  238. `GROUP BY
  239. c.company_id
  240. )
  241. AND us.create_time != ''
  242. AND u.real_name != ''
  243. AND u.mobile != ''
  244. AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' ) GROUP BY u.user_id ORDER BY c.company_id DESC `
  245. _, err = o.Raw(sql).QueryRows(&items)
  246. return
  247. }
  248. type WxUserOpLogResp struct {
  249. CompanyId int `description:"客户ID"`
  250. UserId int `description:"用户ID"`
  251. Mobile string `description:"用户ID"`
  252. }
  253. type WxUserOpLogDeleteResp struct {
  254. CompanyId int `description:"客户ID"`
  255. UserId int `description:"用户ID"`
  256. Mobile string `description:"用户ID"`
  257. OriginalUserInfo string `description:"用户详情"`
  258. CreditCode string `description:"社会信用码"`
  259. RealName string `description:"真实姓名"`
  260. }
  261. // 获取指定时间内更新的用户
  262. func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
  263. o := orm.NewOrmUsingDB("weekly_report")
  264. sql := ` SELECT
  265. u.company_id
  266. FROM
  267. wx_user_op_log AS l
  268. INNER JOIN wx_user AS u ON u.mobile = l.mobile
  269. WHERE
  270. l.create_time >= '` + createTime + `' GROUP BY u.company_id `
  271. _, err = o.Raw(sql).QueryRows(&items)
  272. return
  273. }
  274. // 获取指定时间内删除的用户
  275. func GetWxUserOpLogDelete(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  276. o := orm.NewOrmUsingDB("weekly_report")
  277. sql := `SELECT
  278. l.*,
  279. c.credit_code
  280. FROM
  281. wx_user_op_log AS l
  282. INNER JOIN company AS c ON c.company_id = l.company_id WHERE l.log_type = 'delete' AND l.create_time >= '` + createTime + `'`
  283. _, err = o.Raw(sql).QueryRows(&items)
  284. return
  285. }
  286. // 获取指定时间内被暂停的客户
  287. func GetWxUserOpLogSuspend(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  288. o := orm.NewOrmUsingDB("weekly_report")
  289. sql := `SELECT
  290. *
  291. FROM
  292. company_operation_record AS p
  293. WHERE
  294. remark = '暂停'
  295. 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 + `' ) `
  296. _, err = o.Raw(sql).QueryRows(&items)
  297. return
  298. }
  299. // 获取指定时间内被移动的客户
  300. func GetCompanyOperationRecord(createTime string) (items []*WxUserOpLogDeleteResp, err error) {
  301. o := orm.NewOrmUsingDB("weekly_report")
  302. sql := `SELECT
  303. *
  304. FROM
  305. company_operation_record AS p
  306. WHERE
  307. 1=1
  308. AND p.create_time > '` + createTime + `' GROUP BY company_id `
  309. _, err = o.Raw(sql).QueryRows(&items)
  310. return
  311. }
  312. // 获取指定时间内试用转冻结,冻结转流失的客户
  313. func GetCompanyFreezeAndLoss(createTime string) (items []*WxUserOpLogResp, err error) {
  314. o := orm.NewOrmUsingDB("weekly_report")
  315. sql := ` SELECT * FROM company_operation_record WHERE status IN ('冻结','流失') AND create_time > '` + createTime + `' GROUP BY company_id `
  316. _, err = o.Raw(sql).QueryRows(&items)
  317. return
  318. }
  319. // 获取指定时间内被移动的用户
  320. func GetWxUserOpLogList(startDate, endDate string) (items []*WxUserOpLogResp, err error) {
  321. o := orm.NewOrmUsingDB("weekly_report")
  322. 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 `
  323. _, err = o.Raw(sql).QueryRows(&items)
  324. return
  325. }
  326. // 获取指定时间内被删除的用户
  327. func GetWxUserOpLogDeleteList(startDate, endDate string) (items []*WxUserOpLogResp, err error) {
  328. o := orm.NewOrmUsingDB("weekly_report")
  329. 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 `
  330. _, err = o.Raw(sql).QueryRows(&items)
  331. return
  332. }