MCPcopy Index your code
hub / github.com/TruthHun/DocHub / DocEdit

Method DocEdit

controllers/HomeControllers/UserController.go:629–704  ·  view source on GitHub ↗

文档编辑

()

Source from the content-addressed store, hash-verified

627
628//文档编辑
629func (this *UserController) DocEdit() {
630
631 if this.IsLogin == 0 {
632 this.Redirect("/user", 302)
633 }
634
635 docId, _ := this.GetInt(":doc")
636 if docId == 0 {
637 this.Redirect("/user", 302)
638 }
639
640 info := models.DocumentInfo{Id: docId}
641 err := orm.NewOrm().Read(&info)
642 if err != nil {
643 helper.Logger.Error(err.Error())
644 this.Redirect("/user", 302)
645 }
646
647 if info.Uid != this.IsLogin { // 文档所属用户id与登录的用户id不一致
648 this.Redirect("/user", 302)
649 }
650
651 doc := models.Document{Id: docId}
652
653 // POST
654 if this.Ctx.Request.Method == "POST" {
655 ruels := map[string][]string{
656 "Title": {"required", "unempty"},
657 "Chanel": {"required", "gt:0", "int"},
658 "Pid": {"required", "gt:0", "int"},
659 "Cid": {"required", "gt:0", "int"},
660 "Tags": {"required"},
661 "Intro": {"required"},
662 "Price": {"required", "int"},
663 }
664 params, errs := helper.Valid(this.Ctx.Request.Form, ruels)
665 if len(errs) > 0 {
666 this.ResponseJson(false, "参数错误")
667 }
668 doc.Title = params["Title"].(string)
669 doc.Keywords = params["Tags"].(string)
670 doc.Description = params["Intro"].(string)
671 info.Pid = params["Pid"].(int)
672 info.Cid = params["Cid"].(int)
673 info.ChanelId = params["Chanel"].(int)
674 info.Price = params["Price"].(int)
675 info.TimeUpdate = int(time.Now().Unix())
676 orm.NewOrm().Update(&doc, "Title", "Keywords", "Description")
677 orm.NewOrm().Update(&info, "Pid", "Cid", "ChanelId", "Price")
678 //原分类-1
679 models.Regulate(models.GetTableCategory(), "Cnt", -1, fmt.Sprintf("Id in(%v,%v,%v)", info.ChanelId, info.Cid, info.Pid))
680 //新分类+1
681 models.Regulate(models.GetTableCategory(), "Cnt", 1, fmt.Sprintf("Id in(%v,%v,%v)", params["Chanel"], params["Cid"], params["Pid"]))
682 this.ResponseJson(true, "文档编辑成功")
683 }
684
685 // GET
686 err = orm.NewOrm().Read(&doc)

Callers

nothing calls this directly

Calls 4

UpdateMethod · 0.80
UserListMethod · 0.80
ResponseJsonMethod · 0.45
GetByIdMethod · 0.45

Tested by

no test coverage detected