123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type ChartResultApi struct {
- Data []ChartResultApidate `json:"data"`
- Code int `json:"code"`
- Msg string `json:"msg"`
- }
- type ChartFavoritesResultApi struct {
- Data []ChartInfo `json:"data"`
- Code int `json:"code"`
- Msg string `json:"msg"`
- Pagination Pagination `json:"pagination"`
- }
- type Pagination struct {
- Total int `json:"total"`
- Page int `json:"id"`
- PageSize int `json:"page_size"`
- PageTotal int `json:"page_total"`
- }
- type ChartInfo struct {
- ChartInfo *ChartResultApidate `json:"chart_info"`
- ChartId int `json:"chart_id"`
- CreateDate string `json:"add_favorites_time"`
- }
- type ChartResultApidate struct {
- ChartId int `json:"id"`
- PtagId int `json:"ptag_id"`
- CtagId int `json:"ctag_id"`
- Title string `json:"title"`
- TitleEn string `json:"title_en"`
- CreateDate string `json:"create_date"`
- UpdateDate string `json:"update_date"`
- PublishStatus int `json:"publish_status"`
- Cover string `json:"cover"`
- Iframe string `json:"iframe"`
- Ptag Ptag `json:"ptag"`
- Ctag Ptag `json:"ctag"`
- PtagTwo Ptag `json:"ptag1"`
- CtagTwo Ptag `json:"ctag1"`
- }
- type Ptag struct {
- Id int `json:"id"`
- Name string `json:"name"`
- Description string `json:"description"`
- }
- type Ctag struct {
- Id int `json:"id"`
- Name string `json:"name"`
- Description string `json:"description"`
- PtagId int `json:"ptag_id"`
- }
- type CygxChart struct {
- Id int `orm:"column(id);pk"`
- ChartId int `description:"图表id"`
- PtagId int `description:"图表父类分类id"`
- CtagId int `description:"图表子类分类id"`
- PtagIdTwo int `description:"图表父类分类id"`
- CtagIdTwo int `description:"图表子类分类id"`
- Title string `description:"标题"`
- TitleEn string `description:"英文标题 "`
- CreateDate string `description:"本地创建时间"`
- CreateDateApi time.Time `description:"图表创建时间"`
- PublishStatus int `description:"发布状态"`
- PtagName string `description:"父类名称"`
- CtagName string `description:"子类名称"`
- Cover string `description:"图表图片"`
- Iframe string `description:"图表详情跳转地址"`
- PtagNameTwo string `description:"父类名称"`
- CtagNameTwo string `description:"子类名称"`
- }
- type CygxChartDetail struct {
- ChartId int `description:"图表id"`
- Title string `description:"标题"`
- TitleEn string `description:"英文标题 "`
- IsCollection bool `description:"是否收藏 "`
- CollectionNum int `description:"本人收藏数量 "`
- HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
- }
- func GetChartCountById(chartId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM cygx_chart WHERE chart_id = ? `
- err = o.Raw(sql, chartId).QueryRow(&count)
- return
- }
- // 新增图表
- func AddCygxChart(item *CygxChart) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // 标签分类
- type ChartPtagResultApi struct {
- Data []ChartPtagResultApidate `json:"data"`
- Code int `json:"code"`
- Msg string `json:"msg"`
- }
- type ChartPtagResultApidate struct {
- ChartPermissionId int `json:"id"`
- ChartPermissionName string `json:"name"`
- Ctag []Ctag `json:"ctag"`
- }
- type ChartPtagResp struct {
- ChartPermissionId int `description:"分类ID"`
- PermissionName string `description:"分类名称"`
- List []*CtagResp `description:"子分类"`
- }
- type CtagResp struct {
- CtagId int `description:"子分类ID"`
- Name string `description:"子分类名称"`
- }
- type ChartUserTokenResult struct {
- AccessToken string `json:"access_token"`
- }
- type ChartUserTokenResultApi struct {
- Data ChartUserTokenResult `json:"data"`
- Code int `json:"code"`
- Msg string `json:"msg"`
- }
- type HomeChartListItem struct {
- IsBindingMobile bool `description:"是否绑定过手机号"`
- Paging *paging.PagingItem
- List []*HomeChartListResp `description:"图表列表"`
- }
- type ChartCollectReq struct {
- ChartId int `description:"图表ID"`
- }
- // 获取图表列表
- func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY create_date DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // 获取所有同步过来的图表
- func GetChartListAll() (items []*HomeChartListResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT chart_id FROM cygx_chart `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- ////获取图表列表
- //func GetChartCtagIds(ctagId int ) (items []*HomeChartListResp, err error) {
- // o := orm.NewOrm()
- // sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 AND ctag_id = 1 ORDER BY create_date DESC LIMIT 2 `
- // _, err = o.Raw(sql,ctagId).QueryRows(&items)
- // return
- //}
- // 获取图表列表
- func GetChartListCollection(condition string, pars []interface{}, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT a.*,
- t.create_time AS t_create_time,
- c.create_time AS c_create_time,
- ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS is_top,
- ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
- FROM
- cygx_chart AS a
- LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
- LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id
- WHERE
- a.publish_status = 1 ` + condition + `
-
- GROUP BY
- a.chart_id
- ORDER BY
- t_create_time DESC,
- c_create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // 获取图表列表本地
- func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- a.*,
- t.create_time AS t_create_time,
- c.create_time AS c_create_time,
- ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
- ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
- FROM
- cygx_chart_collect AS c
- INNER JOIN cygx_chart AS a ON c.chart_id = a.chart_id
- LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
- WHERE
- a.publish_status = 1
- AND c.user_id =?
- GROUP BY
- a.chart_id
- ORDER BY
- t_create_time DESC,
- c_create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, userId, userId, userId, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetChartListConfig() (items []*HomeChartListResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 AND ctag_id IN (7,8,9,10) GROUP BY ctag_id ORDER BY create_date DESC LIMIT 4 `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取图表数量
- func GetChartCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count
- FROM cygx_chart AS a
- WHERE a.publish_status=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- // 获取图表数量
- func GetChartCollentCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count
- FROM cygx_chart_all AS a
- WHERE a.publish_status=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
- o := orm.NewOrm()
- sql := `SELECT * ,( SELECT COUNT( 1 ) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS collection_num
- FROM
- cygx_chart_all as a
- WHERE
- a.chart_id =? `
- err = o.Raw(sql, uid, chartId).QueryRow(&item)
- return
- }
|