Эх сурвалжийг харах

Merge branch 'debug' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 жил өмнө
parent
commit
d195cc18a4

+ 156 - 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,159 @@ 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
+//}
+
+// @Title 删除专栏
+// @Description 删除专栏
+// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /del [post]
+func (this *YanxuanSpecialController) Delete() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req models.EnableCygxYanxuanSpecialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Id <= 0 {
+		br.Msg = "文章id错误"
+		return
+	}
+
+	if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
+		br.Msg = "删除失败"
+		br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
+		return
+	}
+
+	br.Msg = "删除成功"
+	br.Ret = 200
+	br.Success = true
+}

+ 23 - 0
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 := ``
@@ -149,3 +161,14 @@ func CancelPublishYanxuanSpecial(id int) (err error) {
 	return
 }
 
+type DelCygxYanxuanSpecialReq struct {
+	Id     int    // 文章id
+}
+
+func DelYanxuanSpecial(id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -1762,6 +1762,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "Delete",
+            Router: `/del`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "Detail",