chart.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models/company"
  6. "strconv"
  7. "time"
  8. )
  9. type ChartResultApi struct {
  10. Data []ChartResultApidate `json:"data"`
  11. Code int `json:"code"`
  12. Msg string `json:"msg"`
  13. }
  14. type ChartFavoritesResultApi struct {
  15. Data []ChartInfo `json:"data"`
  16. Code int `json:"code"`
  17. Msg string `json:"msg"`
  18. Pagination Pagination `json:"pagination"`
  19. }
  20. type Pagination struct {
  21. Total int `json:"total"`
  22. Page int `json:"id"`
  23. PageSize int `json:"page_size"`
  24. PageTotal int `json:"page_total"`
  25. }
  26. type ChartInfo struct {
  27. ChartInfo *ChartResultApidate `json:"chart_info"`
  28. ChartId int `json:"chart_id"`
  29. CreateDate string `json:"add_favorites_time"`
  30. }
  31. type ChartResultApidate struct {
  32. ChartId int `json:"id"`
  33. PtagId int `json:"ptag_id"`
  34. CtagId int `json:"ctag_id"`
  35. Title string `json:"title"`
  36. TitleEn string `json:"title_en"`
  37. CreateDate string `json:"create_date"`
  38. UpdateDate string `json:"update_date"`
  39. PublishStatus int `json:"publish_status"`
  40. Cover string `json:"cover"`
  41. Iframe string `json:"iframe"`
  42. Ptag Ptag `json:"ptag"`
  43. Ctag Ptag `json:"ctag"`
  44. PtagTwo Ptag `json:"ptag1"`
  45. CtagTwo Ptag `json:"ctag1"`
  46. }
  47. type Ptag struct {
  48. Id int `json:"id"`
  49. Name string `json:"name"`
  50. Description string `json:"description"`
  51. }
  52. type Ctag struct {
  53. Id int `json:"id"`
  54. Name string `json:"name"`
  55. Description string `json:"description"`
  56. PtagId int `json:"ptag_id"`
  57. }
  58. type CygxChart struct {
  59. Id int `orm:"column(id);pk"`
  60. ChartId int `description:"图表id"`
  61. PtagId int `description:"图表父类分类id"`
  62. CtagId int `description:"图表子类分类id"`
  63. PtagIdTwo int `description:"图表父类分类id"`
  64. CtagIdTwo int `description:"图表子类分类id"`
  65. Title string `description:"标题"`
  66. TitleEn string `description:"英文标题 "`
  67. CreateDate string `description:"本地创建时间"`
  68. CreateDateApi time.Time `description:"图表创建时间"`
  69. PublishStatus int `description:"发布状态"`
  70. PtagName string `description:"父类名称"`
  71. CtagName string `description:"子类名称"`
  72. Cover string `description:"图表图片"`
  73. Iframe string `description:"图表详情跳转地址"`
  74. PtagNameTwo string `description:"父类名称"`
  75. CtagNameTwo string `description:"子类名称"`
  76. }
  77. type CygxChartDetail struct {
  78. ChartId int `description:"图表id"`
  79. Title string `description:"标题"`
  80. TitleEn string `description:"英文标题 "`
  81. IsCollection bool `description:"是否收藏 "`
  82. CollectionNum int `description:"本人收藏数量 "`
  83. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  84. }
  85. func GetChartCountById(chartId int) (count int, err error) {
  86. o := orm.NewOrmUsingDB("hz_cygx")
  87. sql := `SELECT COUNT(1) AS count FROM cygx_chart WHERE chart_id = ? `
  88. err = o.Raw(sql, chartId).QueryRow(&count)
  89. return
  90. }
  91. // 标签分类
  92. type ChartPtagResultApi struct {
  93. Data []ChartPtagResultApidate `json:"data"`
  94. Code int `json:"code"`
  95. Msg string `json:"msg"`
  96. }
  97. type ChartPtagResultApidate struct {
  98. ChartPermissionId int `json:"id"`
  99. ChartPermissionName string `json:"name"`
  100. Ctag []Ctag `json:"ctag"`
  101. }
  102. type ChartPtagResp struct {
  103. ChartPermissionId int `description:"分类ID"`
  104. PermissionName string `description:"分类名称"`
  105. List []*CtagResp `description:"子分类"`
  106. }
  107. type CtagResp struct {
  108. CtagId int `description:"子分类ID"`
  109. Name string `description:"子分类名称"`
  110. }
  111. type ChartUserTokenResult struct {
  112. AccessToken string `json:"access_token"`
  113. }
  114. type ChartUserTokenResultApi struct {
  115. Data ChartUserTokenResult `json:"data"`
  116. Code int `json:"code"`
  117. Msg string `json:"msg"`
  118. }
  119. type HomeChartListResp struct {
  120. ChartId int `description:"图表ID"`
  121. Title string `description:"标题"`
  122. TitleEn string `description:"英文标题 "`
  123. CreateDate string `description:"创建时间"`
  124. PtagName string `description:"父类名称"`
  125. CtagName string `description:"子类名称"`
  126. PtagNameTwo string `description:"父类名称"`
  127. CtagNameTwo string `description:"子类名称"`
  128. CtagNamePc string `description:"Pc端所有的分类名称"`
  129. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  130. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  131. IsNeedJump bool `description:"是否需要跳转链接地址"`
  132. IsTop bool `description:"是否置顶"`
  133. NumTop int `description:"置顶数量"`
  134. Source int `description:"来源 1:文章, 2:图表"`
  135. }
  136. type HomeChartListItem struct {
  137. IsBindingMobile bool `description:"是否绑定过手机号"`
  138. Paging *paging.PagingItem
  139. List []*HomeChartListResp `description:"图表列表"`
  140. }
  141. type ChartCollectReq struct {
  142. ChartId int `description:"图表ID"`
  143. }
  144. // 获取图表列表
  145. func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  146. o := orm.NewOrmUsingDB("hz_cygx")
  147. sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
  148. if condition != "" {
  149. sql += condition
  150. }
  151. sql += ` ORDER BY create_date DESC LIMIT ?,? `
  152. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  153. return
  154. }
  155. // 获取图表列表
  156. func GetChartListCollection(chartIds string, userId, startSize, pageSize int) (items []*UserInteraction, err error) {
  157. o := orm.NewOrmUsingDB("hz_cygx")
  158. sql := ` SELECT a.*,
  159. t.create_time AS t_create_time,
  160. c.create_time AS c_create_time,
  161. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
  162. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  163. FROM
  164. cygx_chart AS a
  165. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  166. LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id
  167. WHERE
  168. 1=1
  169. AND a.chart_id IN (` + chartIds + `)
  170. GROUP BY
  171. a.chart_id
  172. ORDER BY
  173. t_create_time DESC,
  174. c_create_time DESC LIMIT ?,? `
  175. _, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  176. return
  177. }
  178. // 获取图表列表本地
  179. func GetChartListCollectionWithCygxByMobile(condition string, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  180. o := orm.NewOrmUsingDB("hz_cygx")
  181. sql := ` SELECT
  182. a.chart_id,a.title,a.title_en,a.ptag_name,a.ctag_name,a.cover,a.iframe,a.ptag_name_two,a.ctag_name_two,
  183. r.create_time AS create_date
  184. FROM
  185. cygx_chart_collect AS r
  186. INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
  187. WHERE 1 =1 ` + condition + `
  188. GROUP BY
  189. a.chart_id
  190. ORDER BY
  191. create_time DESC LIMIT ?,? `
  192. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  193. return
  194. }
  195. // 获取图表列表本地
  196. func GetChartListCollectionWithCygx(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  197. o := orm.NewOrmUsingDB("hz_cygx")
  198. sql := ` SELECT
  199. a.chart_id,a.title,a.title_en,a.ptag_name,a.ctag_name,a.cover,a.iframe,a.ptag_name_two,a.ctag_name_two,
  200. r.create_time AS create_time
  201. FROM
  202. cygx_chart_collect AS r
  203. INNER JOIN cygx_chart_all AS a ON r.chart_id = a.chart_id
  204. WHERE
  205. 1= 1 ` + condition +
  206. ` GROUP BY
  207. a.chart_id
  208. ORDER BY
  209. r.create_time DESC LIMIT ?,? `
  210. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  211. return
  212. }
  213. // 获取图表数量
  214. func GetChartCount(condition string, pars []interface{}) (count int, err error) {
  215. o := orm.NewOrmUsingDB("hz_cygx")
  216. sql := `SELECT COUNT(1) AS count
  217. FROM cygx_chart AS a
  218. WHERE a.publish_status=1 `
  219. if condition != "" {
  220. sql += condition
  221. }
  222. err = o.Raw(sql, pars).QueryRow(&count)
  223. return
  224. }
  225. func GetChartCountByUser(condition string) (count int, err error) {
  226. o := orm.NewOrmUsingDB("hz_cygx")
  227. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect as r INNER JOIN cygx_chart_all AS a ON r.chart_id = a.chart_id WHERE 1=1 ` + condition
  228. err = o.Raw(sql).QueryRow(&count)
  229. return
  230. }
  231. func GetChartCountByUserMobile(condition string) (count int, err error) {
  232. o := orm.NewOrmUsingDB("hz_cygx")
  233. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect as r INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id WHERE 1= 1 ` + condition
  234. err = o.Raw(sql).QueryRow(&count)
  235. return
  236. }
  237. type CygxChartCollect struct {
  238. Mobile string `description:"手机号"`
  239. UserId int `description:"手机号"`
  240. }
  241. // 获取图表列表
  242. func GetChartCollectList(condition string) (items []*UserInteraction, err error) {
  243. //o := orm.NewOrm()
  244. //sql := `SELECT u.mobile,u.user_id,u.real_name FROM cygx_chart_collect AS r
  245. // INNER JOIN wx_user AS u ON u.mobile = r.mobile
  246. // LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  247. // WHERE 1= 1 ` + condition + ` GROUP BY r.mobile ORDER BY ui.chart_count_num DESC `
  248. //_, err = o.Raw(sql).QueryRows(&items)
  249. o := orm.NewOrmUsingDB("hz_cygx")
  250. sql := `SELECT * FROM cygx_chart_collect AS r
  251. WHERE 1= 1 ` + condition + ` GROUP BY r.mobile `
  252. _, err = o.Raw(sql).QueryRows(&items)
  253. return
  254. }
  255. // 获取图表列表
  256. func GetChartCollectBycompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  257. o := orm.NewOrmUsingDB("hz_cygx")
  258. //sql := `SELECT u.mobile,u.user_id,u.real_name,r.company_name,
  259. // cp.seller_name FROM cygx_chart_collect AS r
  260. // INNER JOIN wx_user AS u ON u.user_id = r.user_id
  261. // INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  262. // LEFT JOIN company_product AS cp ON cp.company_id = r.company_id AND cp.product_id = 2
  263. // INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  264. // WHERE 1= 1 ` + condition + ` GROUP BY r.mobile ORDER BY ci.chart_count_num DESC , ui.chart_count_num DESC `
  265. sql := `SELECT r.*
  266. FROM cygx_chart_collect AS r
  267. WHERE 1= 1 ` + condition + ` GROUP BY r.mobile `
  268. if startSize > 0 || pageSize > 0 {
  269. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  270. }
  271. _, err = o.Raw(sql).QueryRows(&items)
  272. return
  273. }
  274. // 获取一共有多少用户收藏图表
  275. func GetChartCountByUserCount(condition string) (count int, err error) {
  276. o := orm.NewOrmUsingDB("hz_cygx")
  277. sql := ` SELECT
  278. COUNT( 1 ) AS count
  279. FROM
  280. (
  281. SELECT
  282. COUNT( 1 )
  283. FROM
  284. cygx_chart_collect AS r
  285. INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  286. INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  287. WHERE 1= 1 ` + condition + ` GROUP BY r.user_id ) AS count`
  288. err = o.Raw(sql).QueryRow(&count)
  289. return
  290. }
  291. func GetChartCountBySeller(condition string) (list []*company.CompanyReportRecordGroup, err error) {
  292. o := orm.NewOrmUsingDB("hz_cygx")
  293. sql := `SELECT
  294. count(
  295. DISTINCT ( r.company_id )) num,
  296. GROUP_CONCAT( DISTINCT r.company_id SEPARATOR ',' ) AS company_ids
  297. FROM
  298. cygx_chart_collect AS r
  299. INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
  300. WHERE
  301. 1 = 1 ` + condition
  302. _, err = o.Raw(sql).QueryRows(&list)
  303. return
  304. }