github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RUpdateMoveTopic.go (about)

     1  package root
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/insionng/makross"
     6  	
     7  	"github.com/insionng/yougam/models"
     8  )
     9  
    10  func GetRMoveTopicHandler(self *makross.Context) error {
    11  
    12  	
    13  
    14  	TplNames := "root/move_topic"
    15  	self.Set("catpage", "RMoveTopicHandler")
    16  	tid := self.Param("tid").MustInt64()
    17  	if tid <= 0 {
    18  		self.Flash.Error("非法参数!")
    19  		return self.Redirect("/root/read/topic/")
    20  
    21  	}
    22  
    23  	if tp, err := models.GetTopic(tid); tp != nil && err == nil {
    24  		self.Set("tp", *tp)
    25  
    26  		if nodes, err := models.GetNodes(0, 0, "id"); nodes != nil && err == nil {
    27  			self.Set("nodes", *nodes)
    28  		}
    29  
    30  	} else {
    31  		self.Flash.Error(fmt.Sprint(err))
    32  		return self.Render(TplNames)
    33  
    34  	}
    35  	return self.Render(TplNames)
    36  }
    37  
    38  func PostRMoveTopicHandler(self *makross.Context) error {
    39  	
    40  
    41  	nodeid := self.Args("nodeid").MustInt64()
    42  
    43  	tid := self.Param("tid").MustInt64()
    44  	if tid <= 0 || nodeid <= 0 {
    45  		self.Flash.Error("非法参数!")
    46  		return self.Redirect("/root/read/topic/")
    47  
    48  	}
    49  
    50  	tp, e := models.GetTopic(tid)
    51  	if e != nil || tp == nil {
    52  		self.Flash.Error("话题不存在!")
    53  		return self.Redirect("/root/read/topic/")
    54  
    55  	}
    56  
    57  	node, e := models.GetNode(nodeid)
    58  	if e != nil || node == nil {
    59  		self.Flash.Error("节点不存在!")
    60  		return self.Redirect("/root/read/topic/")
    61  	}
    62  
    63  	tp.Nid = node.Id
    64  	tp.Node = node.Title
    65  	if _, e := models.PutTopic(tid, tp); e == nil {
    66  		self.Flash.Success(fmt.Sprintf("移动话题[%v]成功!", tp.Title))
    67  	} else {
    68  		self.Flash.Error(fmt.Sprintf("移动话题[%v]失败!", tp.Title))
    69  	}
    70  	return self.Redirect(fmt.Sprintf("/root/update/topic/move/%v/", tid))
    71  
    72  }