123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- package article_service
-
- import (
- "SCRM/models"
- "SCRM/service"
- "fmt"
- "github.com/jinzhu/gorm"
-
- "time"
- )
-
- func FindArticleCategoryType (userOrgId int64)(*[]models.ArticleCategory,error){
- cartegory := &[]models.ArticleCategory{}
- err := service.PatientReadDB().Where("status = ? AND user_org_id = ? ", 1, userOrgId).Find(cartegory).Error
- return cartegory,err
- }
-
- func FindCategoryList(orgID int64)(cate []*models.ArticleCategory,err error) {
- err = service.PatientReadDB().Model(&models.ArticleCategory{}).Where("user_org_id =? AND status =?", orgID, 1).Order("id asc").Find(&cate).Error
- return
- }
-
- func AddAritcle(articles models.Articles) error {
- err := service.PatientWriteDB().Create(&articles).Error
- return err
- }
-
- func FindAllArticle(orgID int64, page int64,limit int64, searchKey string,classId int64) (articles []*models.Articles,total int64, err error) {
- fmt.Println("机构ID",orgID,"搜搜索",searchKey)
- db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
- if(orgID>0){
- db = db.Where("a.user_org_id=?" ,orgID)
- }
-
- if(classId > 0){
- db = db.Where("class_id = ?",classId)
- }
-
- if len(searchKey) > 0 {
- searchKey = "%" + searchKey + "%"
- db = db.Where("a.title LIKE ?", searchKey)
- }
-
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Preload("Comments", func(db *gorm.DB) *gorm.DB {
- return db.Where(" status = ?",1)
- }).Where("article_status <> ?",3).
- 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,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").Find(&articles).Error
- fmt.Println("err是啥呢?",err)
- if err != nil {
- return
- }
- return
- }
-
- func AddCategory(category models.ArticleCategory) error {
- err := service.PatientWriteDB().Create(&category).Error
- return err
- }
-
- func GetCategorys(page int64,limit int64,orgID int64) ( categorys []*models.ArticleCategory,total int64,err error) {
- db := service.PatientReadDB().Table("sgj_patient_articles_menu as a").Where("a.status=1")
- if(orgID > 0){
- db = db.Where("a.user_org_id=?" ,orgID)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Select("a.id,a.name,a.order,a.status,a.summary,a.type,a.user_org_id,a.mtime,a.ctime,a.num").Find(&categorys).Error
- if err != nil {
- return
- }
- return
- }
-
- func GetCategorysByID(orgID int64,id int64)(categorys []*models.ArticleCategory,err error){
- err = service.PatientReadDB().Where("user_org_id = ? AND id =? AND status =1", orgID, id).Find(&categorys).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return categorys,err
- }
-
- func EditCategory(cat *models.ArticleCategory,orgID int64,id int64){
- service.PatientWriteDB().Model(cat).Where("user_org_id =? AND id =? AND status = ?", orgID, id, 1).Update(map[string]interface{}{"Name": cat.Name, "Summary": cat.Summary, "Order": cat.Order, "mtime": cat.Mtime})
- }
-
- func DeleteCategorys(orgID int64,ids[] int64)(err error){
- if len(ids) ==1{
- err = service.PatientWriteDB().Model(&models.ArticleCategory{}).Where( "id=? and user_org_id = ?",ids[0],orgID).Update(map[string]interface{}{"Status":0,"mtime":time.Now().Unix()}).Error
- }else {
- err = service.PatientWriteDB().Model(&models.ArticleCategory{}).Where("id IN (?) and user_org_id = ?",ids,orgID).Update(map[string]interface{}{"Status":0,"mtime":time.Now().Unix()}).Error
- }
- return
- }
-
- func AddVido(articles models.Articles) error {
- err := service.PatientWriteDB().Create(&articles).Error
- return err
- }
-
- func AddPrviewArticle(articles models.Articles)(err error) {
- err = service.PatientWriteDB().Create(&articles).Error
- return err
- }
-
- func GetArtilcePreview(OrgID int64)(models.Articles,error) {
- article := models.Articles{}
- err := service.PatientReadDB().Where("user_org_id = ? AND article_status = ? AND type = ?", OrgID, 3, 1).Last(&article).Error
- return article, err
- }
-
- func AddDraft(articles models.Articles) error {
- err := service.PatientReadDB().Create(&articles).Error
- return err
- }
-
- func GetPublished(orgID int64,page int64,limit int64, searchKey string)(articles []*models.Articles,total int64, err error) {
- db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
- if (orgID > 0) {
- db = db.Where("a.user_org_id=? AND article_status = ?", orgID,1)
- }
- if len(searchKey) > 0 {
- searchKey = "%" + searchKey + "%"
- db = db.Where("a.title LIKE ?", searchKey)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Preload("Comments", func(db *gorm.DB) *gorm.DB {
- return db.Where(" status = ?",1)
- }).Where("status = ?",1).
- 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,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").Find(&articles).Error
- fmt.Println("err是啥呢?",err)
- if err != nil {
- return
- }
- return
- }
-
- func GetDraftbox(orgID int64,page int64,limit int64, searchKey string)(articles []*models.Articles,total int64, err error) {
- db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
- if (orgID > 0) {
- db = db.Where("a.user_org_id=? AND article_status = ?", orgID,2)
- }
- if len(searchKey) > 0 {
- searchKey = "%" + searchKey + "%"
- db = db.Where("a.title LIKE ?", searchKey)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Preload("Comments", func(db *gorm.DB) *gorm.DB {
- return db.Where(" status = ?",1)
- }).Where("article_status = ? AND status = ?",2,1).
- 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,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").Find(&articles).Error
- fmt.Println("err是啥呢?",err)
- if err != nil {
- return
- }
- return
- }
-
- func GetNoPass(orgID int64,page int64,limit int64, searchKey string)(articles []*models.Articles,total int64, err error) {
- db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
- if (orgID > 0) {
- db = db.Where("a.user_org_id=? AND article_status = ?", orgID,4)
- }
- if len(searchKey) > 0 {
- searchKey = "%" + searchKey + "%"
- db = db.Where("a.title LIKE ?", searchKey)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Preload("Comments", func(db *gorm.DB) *gorm.DB {
- return db.Where(" status = ?",1)
- }).Where("article_status = ? AND status = ?",4,1).
- 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,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").Find(&articles).Error
- fmt.Println("err是啥呢?",err)
- if err != nil {
- return
- }
- return
- }
-
- func GetArticleInfo(orgID int64,id int64)(articles models.Articles,err error){
- err = service.PatientReadDB().Where("user_org_id = ? AND id = ? AND status = ?", orgID, id, 1).Find(&articles).Error
- return articles,err
- }
-
- func DeleteArticle(ids[] int64,orgID int64)(err error) {
- if len(ids) ==1{
- err = service.PatientWriteDB().Model(&models.Articles{}).Where( "id=? and user_org_id = ?",ids[0],orgID).Update(map[string]interface{}{"status":0,"mtime":time.Now().Unix()}).Error
- }else {
- err = service.PatientWriteDB().Model(&models.Articles{}).Where("id IN (?) and user_org_id = ?",ids,orgID).Update(map[string]interface{}{"status":0,"mtime":time.Now().Unix()}).Error
- }
- return
- }
-
- func GetMenus(OrgID int64)(categorys []*models.ArticleCategory,err error) {
- err = service.PatientReadDB().Where("user_org_id = ?", OrgID).Find(&categorys).Error
- return categorys ,err
- }
-
- func UpdataArticleInfo(art *models.Articles,orgID int64,id int64){
- service.PatientWriteDB().Model(art).Where("user_org_id = ? AND id = ? AND status = ?",orgID,id,1).Update(map[string]interface{}{"title":art.Title,"content":art.Content,"imgs":art.Imgs,"class_id":art.ClassId,"mtime":art.Mtime})
-
- }
-
- func PreviewEditArticle(art models.Articles,orgID int64,id int64) {
- service.PatientWriteDB().Model(art).Where("user_org_id = ? AND id = ? AND status = ?",orgID,id,1).Update(map[string]interface{}{"title":art.Title,"content":art.Content,"imgs":art.Imgs,"class_id":art.ClassId,"mtime":art.Mtime,"article_status":art.ArticleStatus})
- }
-
- func GetPreviewInfo(orgID int64)(models.Articles,error) {
- article := models.Articles{}
- err := service.PatientReadDB().Where("user_org_id = ? AND article_status = ? AND type = ?", orgID, 3, 1).Last(&article).Error
- return article, err
- }
-
- func GetAllComment(page int64,limit int64,orgID int64)(articles []*models.Articles,total int64, err error) {
- db := service.PatientReadDB().Table("sgj_patient_articles as a ").Where("a.status=1")
- if (orgID > 0) {
- db = db.Where("a.user_org_id=? AND article_status = ?", orgID,1)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
- Preload("Comments", func(db *gorm.DB) *gorm.DB {
- return db.Where(" status = ?",1)
- }).
- 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,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").Find(&articles).Error
- fmt.Println("err是啥呢?",err)
- if err != nil {
- return
- }
- return
- }
-
- func GetArticleCommentDetail(articleId int64,orgID int64)(*models.Articles, error){
- article := &models.Articles{}
- err :=service.PatientReadDB().Where("id = ? AND user_org_id = ? AND status = ?", articleId, orgID,1).Find(article).Error
- tm := time.Unix(article.Ctime, 0)
- article.PublicTime = tm.Format("2006-01-02 15:04:05")
- return article, err
- }
|