1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package article_service
-
- import (
- "SCRM/models"
- "SCRM/service"
- "fmt"
- "github.com/jinzhu/gorm"
-
- )
-
- 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.Joins("JOIN sgj_patient_articles_menu as s ON s.id = a.class_id AND s.status=1 AND user_org_id=?",orgID)
- }
-
- 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)
- }).
- 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(category models.ArticleCategory)(err error) {
- err = service.PatientWriteDB().Save(&category).Error
- return err
- }
|