ソースを参照

文章列表页面的开发

xiaoming_global 5 年 前
コミット
49d3258da9

+ 49 - 1
controllers/article/article_controller.go ファイルの表示

@@ -6,12 +6,14 @@ import (
6 6
 	"SCRM/controllers"
7 7
 	"SCRM/service/article_service"
8 8
 	"SCRM/enums"
9
+	"SCRM/models"
9 10
 )
10 11
 
11 12
 func ArticleRouters() {
12 13
 
13 14
 	beego.Router("/api/acticle/createacticle",&ArticleManage{},"Get:CreateArticle")
14 15
 	beego.Router("/api/acticle/getArticleType",&ArticleManage{},"Get:GetArticleType")
16
+	beego.Router("/api/acticle/getAllArticles",&ArticleManage{},"Get:GetAllArticles")
15 17
 }
16 18
 
17 19
 type ArticleManage struct {
@@ -20,8 +22,25 @@ type ArticleManage struct {
20 22
 }
21 23
 
22 24
 func (this *ArticleManage) CreateArticle(){
25
+	adminUserInfo := this.GetAdminUserInfo()
26
+	userOrgID := int64(adminUserInfo.CurrentOrgId)
23 27
 	actname := this.GetString("act_name")
24
-	fmt.Println("姓名:",actname)
28
+	actcontent := this.GetString("act_content")
29
+	orglogo := this.GetString("org_logo")
30
+	acttype, _ := this.GetInt64("act_type")
31
+	fmt.Println("姓名:",actname,"文章内容",actcontent,"图片",orglogo,"文章类型",acttype,userOrgID)
32
+	articles := models.Articles{
33
+				Title: actname,
34
+				Content: actcontent,
35
+				Imgs: orglogo,
36
+				ClassId: acttype,
37
+				UserOrgId:userOrgID,
38
+		}
39
+		err := article_service.AddAritcle(articles)
40
+		if err !=nil{
41
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "插入文章失败")
42
+			return
43
+		}
25 44
 }
26 45
 
27 46
 func (this *ArticleManage) GetArticleType(){
@@ -39,3 +58,32 @@ func (this *ArticleManage) GetArticleType(){
39 58
 	return
40 59
 }
41 60
 
61
+func (this *ArticleManage) GetAllArticles()  {
62
+	page, _ := this.GetInt("page", 1)
63
+	limit, _ := this.GetInt64("limit", 10)
64
+	searchKey := this.GetString("search", "")
65
+	classId,_ := this.GetInt64("classid",0)
66
+    fmt.Println("页面",page,"限制",limit,"关键字",searchKey,"分类号",classId)
67
+
68
+	if page <= 0 {
69
+		page = 1
70
+	}
71
+	if limit <= 0 {
72
+		limit = 10
73
+	}
74
+	adminUserInfo := this.GetAdminUserInfo()
75
+	userOrgID := adminUserInfo.CurrentOrgId
76
+
77
+	articles, total, err := article_service.FindAllArticle(userOrgID, page,limit, searchKey, classId)
78
+	fmt.Println("文章内容是是么",articles)
79
+	if err !=nil{
80
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章列表失败")
81
+		return
82
+	}
83
+	this.ServeSuccessJSON(map[string]interface{}{
84
+		"articles":articles,
85
+		"total":total,
86
+	})
87
+	return
88
+}
89
+

+ 2 - 1
controllers/base_view_controller.go ファイルの表示

@@ -1,9 +1,10 @@
1 1
 package controllers
2
-
3 2
 type BaseViewController struct {
4 3
 	BaseController
5 4
 }
6 5
 
6
+
7
+
7 8
 // 设置模板
8 9
 // 第一个参数模板,第二个参数为layout
9 10
 func (this *BaseViewController) SetTpl(template ...string) {

+ 2 - 2
controllers/members/members_controller.go ファイルの表示

@@ -8,7 +8,7 @@ import (
8 8
 	"SCRM/utils"
9 9
 	"reflect"
10 10
 	"time"
11
-
11
+    "fmt"
12 12
 	"encoding/json"
13 13
 
14 14
 	"github.com/astaxie/beego"
@@ -33,7 +33,7 @@ func (c *MembersAPIController) GetMembers() {
33 33
 	source, _ := c.GetInt64("source", 0)
34 34
 	tag, _ := c.GetInt64("tag", 0)
35 35
 	init, _ := c.GetInt64("init", 0)
36
-
36
+	fmt.Println("level",level,"source",source)
37 37
 	if page <= 0 {
38 38
 		page = 1
39 39
 	}

+ 69 - 0
models/article_models.go ファイルの表示

@@ -18,3 +18,72 @@ type ArticleCategory struct{
18 18
 func (ArticleCategory) TableName() string  {
19 19
 	return "sgj_patient_articles_menu"
20 20
 }
21
+
22
+type Articles struct {
23
+	ID            int64     `gorm:"column:id" json:"id"`
24
+	Title         string    `gorm:"column:title" json:"title"`
25
+	Summary       string    `gorm:"column:summary" json:"summary"`
26
+	Content       string    `gorm:"column:content" json:"content"`
27
+	Type          int       `gorm:"column:type" json:"type"`
28
+	Num           int       `gorm:"column:num" json:"num"`
29
+	Mtime         int64     `gorm:"column:mtime" json:"mtime"`
30
+	Ctime         int64     `gorm:"column:ctime" json:"ctime"`
31
+	ClassId       int64     `gorm:"column:class_id" json:"class_id"`
32
+	Author        string    `gorm:"column:author" json:"author"`
33
+	Status        int       `gorm:"column:status" json:"status"`
34
+	Reason        string    `gorm:"column:reason" json:"reason"`
35
+	StarNum       int       `gorm:"column:star_num" json:"star_num"`
36
+	CommentNum    int       `gorm:"column:comment_num" json:"comment_num"`
37
+	UserOrgId     int64     `gorm:"column:user_org_id" json:"user_org_id"`
38
+	ArticleStatus int64     `gorm:"column:article_status" json:"article_status"`
39
+	Imgs          string    `gorm:"column:imgs" json:"imgs"`
40
+	VideoUrl      string    `gorm:"column:video_url" json:"video_url"`
41
+	Cover         string    `gorm:"-" json:"cover"`
42
+	PublicTime    string    `gorm:"-" json:"publicTime"`
43
+	Comments      []Comment `gorm:"ForeignKey:ArticleId"`
44
+	ArticleId	  int64		 `gorm:"-"`
45
+}
46
+
47
+func (Articles) TableName() string {
48
+	return "sgj_patient_articles"
49
+}
50
+
51
+type Comment struct {
52
+	ID                int64  `gorm:"column:id" json:"id"`
53
+	ArticleId         int64  `gorm:"column:article_id" json:"article_id"`
54
+	CommentUserId     int64  `gorm:"column:comment_user_id" json:"comment_user_id"`
55
+	ParentId          int64  `gorm:"column:parent_id" json:"parent_id"`
56
+	Content           string `gorm:"column:content" json:"content"`
57
+	Ctime             int64  `gorm:"column:ctime" json:"ctime"`
58
+	Mtime             int64  `gorm:"column:mtime" json:"mtime"`
59
+	Status            int64  `gorm:"column:status" json:"status"`
60
+	StarNum           int64  `gorm:"column:star_num" json:"star_num"`
61
+	CommentNum        int64  `gorm:"column:comment_num" json:"comment_num"`
62
+	CommentId         int64  `gorm:"column:comment_id" json:"comment_id"`
63
+	CommentUserName   string `gorm:"column:comment_user_name" json:"comment_user_name"`
64
+	CommentUserAvater string `gorm:"column:comment_user_avater" json:"comment_user_avater"`
65
+	CommentTime       string `gorm:"-" json:"commentTime"`
66
+	Article           Articles
67
+	Parent            Parents
68
+}
69
+
70
+type Parents struct {
71
+	ID                int64  `gorm:"-" json:"id"`
72
+	ArticleId         int64  `gorm:"-" json:"article_id"`
73
+	CommentUserId     int64  `gorm:"-" json:"comment_user_id"`
74
+	ParentId          int64  `gorm:"-" json:"parent_id"`
75
+	Content           string `gorm:"-" json:"content"`
76
+	Ctime             int64  `gorm:"-" json:"ctime"`
77
+	Mtime             int64  `gorm:"-" json:"mtime"`
78
+	Status            int64  `gorm:"-" json:"status"`
79
+	StarNum           int64  `gorm:"-" json:"star_num"`
80
+	CommentNum        int64  `gorm:"-" json:"comment_num"`
81
+	CommentId         int64  `gorm:"-" json:"comment_id"`
82
+	CommentUserName   string `gorm:"-" json:"comment_user_name"`
83
+	CommentUserAvater string `gorm:"-" json:"comment_user_avater"`
84
+	CommentTime       string `gorm:"-" json:"commentTime"`
85
+}
86
+
87
+func (Comment) TableName() string {
88
+	return "sgj_patient_articles_comment"
89
+}

+ 28 - 1
service/article_service/article_category_service.go ファイルの表示

@@ -5,8 +5,35 @@ import (
5 5
 	"SCRM/service"
6 6
 )
7 7
 
8
-func FindArticleCategoryType(userOrgId int64)(*[]models.ArticleCategory,error){
8
+func FindArticleCategoryType (userOrgId int64)(*[]models.ArticleCategory,error){
9 9
    cartegory :=	&[]models.ArticleCategory{}
10 10
 	err := service.PatientReadDB().Where("status = ? AND user_org_id = ? ", 1, userOrgId).Find(cartegory).Error
11 11
 	return  cartegory,err
12 12
 }
13
+
14
+func AddAritcle(articles models.Articles) error {
15
+	err := service.PatientWriteDB().Create(&articles).Error
16
+	return  err
17
+}
18
+
19
+func FindAllArticle(orgID int64, page, limit, searchKey string, classId int64) (articles *[]models.Articles,total int64, err error) {
20
+
21
+	db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
22
+	if(orgID>0){
23
+		db.Where("a.user_org_id = ?" ,orgID)
24
+	}
25
+
26
+	if(classId>0){
27
+	  db = db.Joins("JOIN sgj_patient_articles_menu as s ON s.id = a.class_id AND s.status=1 AND user_org_id = ?")
28
+	}
29
+
30
+	if len(searchKey) > 0 {
31
+		searchKey = "%" + searchKey + "%"
32
+		db = db.Where("a.title LIKE ?", searchKey)
33
+	}
34
+
35
+	//err = db.Select("a.id,a.title,a.summary,a.content,a.type,a.num,a.mtime,a.real_read_num,a.ctime,a.class_id,a.author,a.status,a.reason" +
36
+	//	"a.star_num,a.comment_num,a.user_org_id,a.article_status,a.imgs,a.video_url,a.source,a.category_id,a.ttid,a.ttype,a.toid").Count(&total).Find(&articles).Error
37
+
38
+		return
39
+}

+ 1 - 0
service/member_service/models.go ファイルの表示

@@ -34,3 +34,4 @@ type CustomerIllness struct {
34 34
 func (CustomerIllness) TableName() string {
35 35
 	return "sgj_user_customer_illness"
36 36
 }
37
+