更新分类的图标
()
| 991 | |
| 992 | // 更新分类的图标 |
| 993 | func (this *ManagerController) UpdateCateIcon() { |
| 994 | var err error |
| 995 | id, _ := this.GetInt("id") |
| 996 | if id == 0 { |
| 997 | this.JsonResult(1, "参数不正确") |
| 998 | } |
| 999 | |
| 1000 | data := make(map[string]interface{}) |
| 1001 | model := new(models.Category) |
| 1002 | if cate := model.Find(id); cate.Id > 0 { |
| 1003 | cate.Icon = strings.TrimLeft(cate.Icon, "/") |
| 1004 | f, h, err1 := this.GetFile("icon") |
| 1005 | if err1 != nil { |
| 1006 | err = err1 |
| 1007 | } |
| 1008 | defer f.Close() |
| 1009 | |
| 1010 | tmpFile := fmt.Sprintf("uploads/icons/%v%v"+filepath.Ext(h.Filename), id, time.Now().Unix()) |
| 1011 | os.MkdirAll(filepath.Dir(tmpFile), os.ModePerm) |
| 1012 | if err = this.SaveToFile("icon", tmpFile); err == nil { |
| 1013 | switch utils.StoreType { |
| 1014 | case utils.StoreOss: |
| 1015 | store.ModelStoreOss.MoveToOss(tmpFile, tmpFile, true, false) |
| 1016 | store.ModelStoreOss.DelFromOss(cate.Icon) |
| 1017 | data["icon"] = utils.ShowImg(tmpFile) |
| 1018 | case utils.StoreLocal: |
| 1019 | store.ModelStoreLocal.DelFiles(cate.Icon) |
| 1020 | data["icon"] = "/" + tmpFile |
| 1021 | } |
| 1022 | err = model.UpdateByField(cate.Id, "icon", "/"+tmpFile) |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if err != nil { |
| 1027 | this.JsonResult(1, err.Error()) |
| 1028 | } |
| 1029 | this.JsonResult(0, "更新成功", data) |
| 1030 | } |
| 1031 | |
| 1032 | // 友情链接 |
| 1033 | func (this *ManagerController) FriendLink() { |
nothing calls this directly
no test coverage detected