template.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**********************************************
  2. ** @Des: 公共文档设置
  3. ** @Author: haodaquan
  4. ** @Date: 2018-01-16 17:48:30
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2018-01-16 17:48:30
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "strings"
  11. "time"
  12. "github.com/astaxie/beego"
  13. "wuyebaoxiuapi/models/backgroundm"
  14. )
  15. var ()
  16. type TemplateController struct {
  17. BaseController
  18. }
  19. func (self *TemplateController) List() {
  20. self.Data["pageTitle"] = "模板管理"
  21. self.display()
  22. }
  23. func (self *TemplateController) Table() {
  24. //列表
  25. page, err := self.GetInt("page")
  26. if err != nil {
  27. page = 1
  28. }
  29. limit, err := self.GetInt("limit")
  30. if err != nil {
  31. limit = 30
  32. }
  33. TemplateName := strings.TrimSpace(self.GetString("TemplateName"))
  34. self.pageSize = limit
  35. //查询条件
  36. filters := make([]interface{}, 0)
  37. filters = append(filters, "status", 1)
  38. if TemplateName != "" {
  39. filters = append(filters, "template_name__icontains", TemplateName)
  40. }
  41. result, count := backgroundm.TemplateGetList(page, self.pageSize, filters...)
  42. list := make([]map[string]interface{}, len(result))
  43. for k, v := range result {
  44. row := make(map[string]interface{})
  45. row["id"] = v.Id
  46. row["template_name"] = v.TemplateName
  47. row["detail"] = v.Detail
  48. row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
  49. row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
  50. list[k] = row
  51. }
  52. self.ajaxList("成功", MSG_OK, count, list)
  53. }
  54. func (self *TemplateController) Add() {
  55. self.Data["pageTitle"] = "新增模板"
  56. self.display()
  57. }
  58. func (self *TemplateController) Edit() {
  59. id, _ := self.GetInt("id", 0)
  60. detail, _ := backgroundm.TemplateGetById(id)
  61. row := make(map[string]interface{})
  62. row["id"] = detail.Id
  63. row["template_name"] = detail.TemplateName
  64. row["detail"] = detail.Detail
  65. self.Data["pageTitle"] = "查看 " + detail.TemplateName
  66. self.Data["Detail"] = row
  67. self.display()
  68. }
  69. func (self *TemplateController) AjaxSave() {
  70. Pub_id, _ := self.GetInt("id")
  71. if Pub_id == 0 {
  72. Template := new(backgroundm.Template)
  73. Template.TemplateName = strings.TrimSpace(self.GetString("template_name"))
  74. Template.Detail = strings.TrimSpace(self.GetString("detail"))
  75. Template.CreateId = self.userId
  76. Template.UpdateId = self.userId
  77. Template.CreateTime = time.Now().Unix()
  78. Template.UpdateTime = time.Now().Unix()
  79. Template.Status = 1
  80. _, err := backgroundm.TemplateAdd(Template)
  81. if err != nil {
  82. self.ajaxMsg(err.Error(), MSG_ERR)
  83. }
  84. self.ajaxMsg("", MSG_OK)
  85. }
  86. //修改
  87. Template, _ := backgroundm.TemplateGetById(Pub_id)
  88. Template.Id, _ = self.GetInt("id")
  89. Template.TemplateName = strings.TrimSpace(self.GetString("template_name"))
  90. Template.Detail = strings.TrimSpace(self.GetString("detail"))
  91. Template.UpdateId = self.userId
  92. Template.UpdateTime = time.Now().Unix()
  93. Template.Status = 1
  94. if err := Template.Update(); err != nil {
  95. self.ajaxMsg(err.Error(), MSG_ERR)
  96. }
  97. self.ajaxMsg("", MSG_OK)
  98. }
  99. func (self *TemplateController) AjaxDel() {
  100. Pub_id, _ := self.GetInt("id")
  101. Api, _ := backgroundm.TemplateGetById(Pub_id)
  102. Api.UpdateTime = time.Now().Unix()
  103. Api.UpdateId = self.userId
  104. Api.Status = 0
  105. Api.Id = Pub_id
  106. //TODO 判断是否被使用
  107. if err := Api.Update(); err != nil {
  108. self.ajaxMsg(err.Error(), MSG_ERR)
  109. }
  110. self.ajaxMsg("", MSG_OK)
  111. }