123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package models
- import (
- "fmt"
- "hongze/hongze_api/utils"
- "rdluck_tools/orm"
- "rdluck_tools/paging"
- )
- type HomeList struct {
- ClassifyId int `orm:"column(id)"`
- ClassifyName string `description:"分类名称"`
- Child []*HomeClassifyItem
- TitleType string `description:"标题类型,FICC或者权益"`
- }
- type HomeClassifyItem struct {
- ClassifyId int `orm:"column(id)"`
- ClassifyName string `description:"分类名称"`
- Child *Report
- }
- func ListHome(userId, maxPermission, userPermission int, permissionStr string) (items []*HomeList, err error) {
- o := orm.NewOrm()
- o.Using("rddp")
- sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 ORDER BY create_time ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- if err != nil {
- fmt.Println("Get classify Err:" + err.Error())
- return
- }
- lenItem := len(items)
- fmt.Println("lenItem:", lenItem)
- for i := 0; i < lenItem; i++ {
- item := items[i]
- subItems := make([]*HomeClassifyItem, 0)
- subWhere := ``
- if maxPermission < 15 && userPermission == 0 {
- if permissionStr != "" {
- subWhere = ` WHERE parent_id=? AND classify_name IN(` + permissionStr + `) `
- } else {
- subWhere = ` WHERE parent_id=? `
- }
- } else {
- subWhere = ` WHERE parent_id=? `
- }
- subSql := `SELECT id ,classify_name FROM classify `
- subSql += subWhere
- subSql += ` ORDER BY create_time ASC `
- _, err = o.Raw(subSql, item.ClassifyId).QueryRows(&subItems)
- if err != nil {
- fmt.Println("Sub Err:" + err.Error())
- return
- }
- lenSub := len(subItems)
- for k := 0; k < lenSub; k++ {
- subItem := subItems[k]
- reportSql := ` SELECT a.id,a.classify_name,b.*,
- (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
- CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
- FROM classify AS a
- INNER JOIN report AS b ON a.id=b.classify_id_second
- WHERE b.state=2 AND a.id=?
- ORDER BY b.publish_time DESC LIMIT 1 `
- report := new(Report)
- err = o.Raw(reportSql, userId, subItem.ClassifyId).QueryRow(&report)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- return
- } else {
- err = nil
- }
- }
- subItems[k].Child = report
- }
- items[i].Child = subItems
- }
- return
- }
- type PcHomeClassifyItem struct {
- ClassifyId int `orm:"column(id)"`
- ClassifyName string `description:"分类名称"`
- ReportInfo *PcReport
- }
- func PcListHomeCount(classifyId int) (count int, err error) {
- o := orm.NewOrm()
- o.Using("rddp")
- sql := `SELECT COUNT(1) AS count FROM classify WHERE parent_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyItem, err error) {
- o := orm.NewOrm()
- o.Using("rddp")
- subSql := ` SELECT id ,classify_name FROM classify WHERE parent_id=? `
- subSql += ` ORDER BY create_time ASC LIMIT ?,? `
- _, err = o.Raw(subSql, classifyId, startSize, pageSize).QueryRows(&items)
- if err != nil {
- fmt.Println("Sub Err:" + err.Error())
- return
- }
- lenSub := len(items)
- for k := 0; k < lenSub; k++ {
- subItem := items[k]
- reportSql := ` SELECT a.id,a.classify_name,b.*,c.*,
- CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
- FROM classify AS a
- INNER JOIN report AS b ON a.id=b.classify_id_second
- INNER JOIN report_author AS c ON b.author=c.report_author
- WHERE b.state=2 AND a.id=?
- ORDER BY b.publish_time DESC LIMIT 1 `
- report := new(PcReport)
- err = o.Raw(reportSql, subItem.ClassifyId).QueryRow(&report)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- return
- } else {
- err = nil
- }
- }
- items[k].ReportInfo = report
- }
- return
- }
- type PcListHomeResp struct {
- Paging *paging.PagingItem
- List []*PcHomeClassifyItem
- }
|