ziwen 1 éve
szülő
commit
74398f82f3
2 módosított fájl, 126 hozzáadás és 7 törlés
  1. 114 6
      controllers/yanxuan_special.go
  2. 12 1
      models/cygx_yanxuan_special.go

+ 114 - 6
controllers/yanxuan_special.go

@@ -114,12 +114,6 @@ func (this *YanxuanSpecialController) Detail() {
 	if item.MyCollectNum > 0 {
 		item.IsCollect = 1
 	}
-	if item.Status != 3 && item.Status != 2 {
-		br.Msg = "获取失败,专栏未发布"
-		br.ErrMsg = "获取失败, 专栏未发布"
-		br.Ret = 200
-		return
-	}
 
 	br.Data = item
 	br.Ret = 200
@@ -852,3 +846,117 @@ func (this *YanxuanSpecialController) AuthorHeadImg() {
 	br.Success = true
 	br.Msg = "保存成功"
 }
+
+// ResourceUpload 上传文件
+// @Title 上传文件
+// @Description 上传文件
+// @Param   MenuId  query  int  true  "目录ID"
+// @Param   File	query  file  true  "文件"
+// @Success 200 Ret=200 操作成功
+// @router /doc/upload [post]
+//func (this *YanxuanSpecialController) ResourceUpload() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//
+//	originName := this.GetString("OriginName", "")
+//	if originName == "" {
+//		br.Msg = "请上传文件名"
+//		return
+//	}
+//	if !strings.Contains(originName, ".") {
+//		br.Msg = "文件名有误"
+//		return
+//	}
+//	f, h, e := this.GetFile("file")
+//	if e != nil {
+//		br.Msg = "获取资源信息失败"
+//		br.ErrMsg = "获取资源信息失败, Err:" + e.Error()
+//		return
+//	}
+//	defer func() {
+//		_ = f.Close()
+//	}()
+//
+//	extIndex := strings.LastIndex(originName, ".")
+//	fileName := originName[:extIndex]
+//	ext := path.Ext(h.Filename)
+//
+//	// 重名校验
+//	existItem := new(models.CloudDiskResource)
+//	existCond := ` AND resource_name = ? AND menu_id = ? `
+//	existPars := make([]interface{}, 0)
+//	existPars = append(existPars, fileName, menuId)
+//	if e := existItem.GetItemByCondition(existCond, existPars); e != nil && e.Error() != utils.ErrNoRow() {
+//		br.Msg = "操作失败"
+//		br.ErrMsg = "获取重名文件失败, Err: " + e.Error()
+//		return
+//	}
+//	if existItem != nil && existItem.MenuId > 0 {
+//		br.Msg = fmt.Sprintf("文件名%s已存在", fileName)
+//		return
+//	}
+//
+//	uploadDir := utils.STATIC_DIR + "hongze/" + time.Now().Format("20060102")
+//	if e = os.MkdirAll(uploadDir, 766); e != nil {
+//		br.Msg = "存储目录创建失败"
+//		br.ErrMsg = "存储目录创建失败, Err:" + e.Error()
+//		return
+//	}
+//	ossFileName := utils.GetRandStringNoSpecialChar(28) + ext
+//	filePath := uploadDir + "/" + ossFileName
+//	if e = this.SaveToFile("file", filePath); e != nil {
+//		br.Msg = "文件保存失败"
+//		br.ErrMsg = "文件保存失败, Err:" + e.Error()
+//		return
+//	}
+//	defer func() {
+//		_ = os.Remove(filePath)
+//	}()
+//	// 上传到阿里云
+//	ossDir := "static/cloud_disk/"
+//	resourceUrl, e := services.UploadAliyunToDir(ossFileName, filePath, ossDir, "")
+//	if e != nil {
+//		br.Msg = "文件上传失败"
+//		br.ErrMsg = "文件上传失败, Err:" + e.Error()
+//		return
+//	}
+//
+//	// 新增云盘资源
+//	extMap := services.GetCloudDiskResourceFileTypeExtMap()
+//	resourceIcon := extMap[ext]
+//	if resourceIcon == "" {
+//		resourceIcon = models.CloudDiskResourceFileTypeIconUnknown
+//	}
+//	resourceItem := &models.CloudDiskResource{
+//		MenuId:         menuId,
+//		ResourceName:   fileName,
+//		ResourceSuffix: ext,
+//		ResourceUrl:    resourceUrl,
+//		ResourceIcon:   resourceIcon,
+//		AdminId:        this.SysUser.AdminId,
+//		AdminName:      this.SysUser.RealName,
+//		Size:           h.Size,
+//		CreateTime:     time.Now().Local(),
+//		ModifyTime:     time.Now().Local(),
+//	}
+//	if e = resourceItem.Create(); e != nil {
+//		br.Msg = "上传失败"
+//		br.ErrMsg = "新增云盘资源失败, Err: " + e.Error()
+//		return
+//	}
+//
+//	// 更新目录大小
+//	go func() {
+//		if e = services.UpdateCloudDiskMenuSize(menuId); e != nil {
+//			alarm_msg.SendAlarmMsg("更新云盘目录大小失败, Err: "+e.Error(), 3)
+//		}
+//	}()
+//
+//	br.Msg = "上传成功"
+//	br.Ret = 200
+//	br.Success = true
+//	br.Data = resourceItem
+//}

+ 12 - 1
models/cygx_yanxuan_special.go

@@ -49,6 +49,18 @@ type CygxYanxuanSpecialItem struct {
 	ContentHasImg int //正文是否包含图片 1包含 0不包含
 }
 
+type CygxYanxuanSpecialResp struct {
+	CygxYanxuanSpecialItem
+	Docs []Doc
+}
+
+type Doc struct {
+	DocName   string
+	DocSuffix string
+	DocUrl    string
+	DocIcon   string
+}
+
 func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
@@ -148,4 +160,3 @@ func CancelPublishYanxuanSpecial(id int) (err error) {
 	_, err = o.Raw(sql, id).Exec()
 	return
 }
-