code.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**********************************************
  2. ** @Des: This file ...
  3. ** @Author: haodaquan
  4. ** @Date: 2017-09-09 12:53:05
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2017-09-25 18:50:54
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "fmt"
  11. "strings"
  12. "time"
  13. "github.com/astaxie/beego"
  14. "wuyebaoxiuapi/models/backgroundm"
  15. )
  16. type CodeController struct {
  17. BaseController
  18. }
  19. func (self *CodeController) List() {
  20. self.Data["pageTitle"] = "状态码设置"
  21. self.display()
  22. }
  23. func (self *CodeController) Add() {
  24. self.Data["pageTitle"] = "新增状态码"
  25. self.display()
  26. }
  27. func (self *CodeController) Edit() {
  28. self.Data["pageTitle"] = "编辑状态码"
  29. id, _ := self.GetInt("id", 0)
  30. Code, _ := backgroundm.CodeGetById(id)
  31. row := make(map[string]interface{})
  32. row["id"] = Code.Id
  33. row["code"] = Code.Code
  34. row["desc"] = Code.Desc
  35. row["detail"] = Code.Detail
  36. self.Data["code"] = row
  37. self.display()
  38. }
  39. func (self *CodeController) Table() {
  40. //列表
  41. page, err := self.GetInt("page")
  42. if err != nil {
  43. page = 1
  44. }
  45. limit, err := self.GetInt("limit")
  46. if err != nil {
  47. limit = 30
  48. }
  49. code := strings.TrimSpace(self.GetString("code"))
  50. self.pageSize = limit
  51. //查询条件
  52. filters := make([]interface{}, 0)
  53. filters = append(filters, "status", 1)
  54. if code != "" {
  55. filters = append(filters, "code", code)
  56. }
  57. result, count := backgroundm.CodeGetList(page, self.pageSize, filters...)
  58. list := make([]map[string]interface{}, len(result))
  59. for k, v := range result {
  60. row := make(map[string]interface{})
  61. row["id"] = v.Id
  62. row["code"] = v.Code
  63. row["detail"] = v.Detail
  64. row["desc"] = v.Desc
  65. row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
  66. row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
  67. list[k] = row
  68. }
  69. self.ajaxList("成功", MSG_OK, count, list)
  70. }
  71. func (self *CodeController) AjaxSave() {
  72. Code_id, _ := self.GetInt("id")
  73. if Code_id == 0 {
  74. Code := new(backgroundm.Code)
  75. Code.Code = strings.TrimSpace(self.GetString("code"))
  76. Code.Desc = strings.TrimSpace(self.GetString("desc"))
  77. Code.Detail = strings.TrimSpace(self.GetString("detail"))
  78. Code.CreateId = self.userId
  79. Code.UpdateId = self.userId
  80. Code.CreateTime = time.Now().Unix()
  81. Code.UpdateTime = time.Now().Unix()
  82. Code.Status = 1
  83. res, err := backgroundm.CodeGetByName(Code.Code)
  84. fmt.Println(res)
  85. if err == nil {
  86. self.ajaxMsg("状态码已经存在", MSG_ERR)
  87. }
  88. if _, err := backgroundm.CodeAdd(Code); err != nil {
  89. self.ajaxMsg(err.Error(), MSG_ERR)
  90. }
  91. self.ajaxMsg("", MSG_OK)
  92. }
  93. CodeUpdate, _ := backgroundm.CodeGetById(Code_id)
  94. // 修改
  95. CodeUpdate.Code = strings.TrimSpace(self.GetString("code"))
  96. CodeUpdate.Desc = strings.TrimSpace(self.GetString("desc"))
  97. CodeUpdate.Detail = strings.TrimSpace(self.GetString("detail"))
  98. CodeUpdate.UpdateId = self.userId
  99. CodeUpdate.UpdateTime = time.Now().Unix()
  100. CodeUpdate.Status = 1
  101. if err := CodeUpdate.Update(); err != nil {
  102. self.ajaxMsg(err.Error(), MSG_ERR)
  103. }
  104. self.ajaxMsg("", MSG_OK)
  105. }
  106. func (self *CodeController) AjaxDel() {
  107. Code_id, _ := self.GetInt("id")
  108. Code, _ := backgroundm.CodeGetById(Code_id)
  109. Code.UpdateTime = time.Now().Unix()
  110. Code.UpdateId = self.userId
  111. Code.Status = 0
  112. Code.Id = Code_id
  113. if err := Code.Update(); err != nil {
  114. self.ajaxMsg(err.Error(), MSG_ERR)
  115. }
  116. self.ajaxMsg("", MSG_OK)
  117. }