business_approve.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package business_trip
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mobile_admin/models/tables/business_trip"
  6. "hongze/hongze_mobile_admin/services"
  7. "hongze/hongze_mobile_admin/utils"
  8. "time"
  9. )
  10. // @Title 出差审批列表
  11. // @Description 出差申请列表接口
  12. // @Param PageSize query int true "每页数据条数"
  13. // @Param CurrentIndex query int true "当前页页码,从1开始"
  14. // @Param Status query string true "状态"
  15. // @Success 200 {object} business_trip.BusinessApplyListResp
  16. // @router /approve/list [get]
  17. func (this *BusinessTrip) ApproveList() {
  18. sysUser := this.AdminWx
  19. sysUserId := sysUser.AdminId
  20. pageSize, _ := this.GetInt("PageSize")
  21. currentIndex, _ := this.GetInt("CurrentIndex")
  22. var total int
  23. page := paging.GetPaging(currentIndex, pageSize, total)
  24. var startSize int
  25. if pageSize <= 0 {
  26. pageSize = utils.PageSize10
  27. }
  28. if currentIndex <= 0 {
  29. currentIndex = 1
  30. }
  31. startSize = paging.StartIndex(currentIndex, pageSize)
  32. reason := this.GetString("Reason")
  33. status := this.GetString("Status")
  34. var condition string
  35. var pars []interface{}
  36. condition += ` AND approve_id=? `
  37. pars = append(pars, sysUserId)
  38. if reason != "" {
  39. condition += ` AND reason=? `
  40. pars = append(pars, reason)
  41. }
  42. if status != "" {
  43. if status == "已审批" {
  44. condition += ` AND status IN('已审批','已驳回') `
  45. } else {
  46. condition += ` AND status=? `
  47. pars = append(pars, status)
  48. }
  49. }
  50. condition += ` AND status IN('待审批','已审批') `
  51. resp := new(business_trip.BusinessApplyListResp)
  52. total, err := business_trip.GetBusinessApplyListCount(condition, pars)
  53. if err != nil && err.Error() != utils.ErrNoRow() {
  54. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  55. return
  56. }
  57. dataList, err := business_trip.GetBusinessApplyList(condition, pars, startSize, pageSize)
  58. if err != nil {
  59. this.FailWithMessage("获取指标信息失败!", "获取数据失败,GetBusinessApplyList,Err:"+err.Error())
  60. return
  61. }
  62. page = paging.GetPaging(currentIndex, pageSize, total)
  63. resp.Paging = page
  64. resp.List = dataList
  65. this.OkDetailed(resp, "获取成功")
  66. }
  67. // @Title 出差申请,审批接口
  68. // @Description 出差申请,审批接口
  69. // @Param request body business_trip.BusinessApplyApproveReq true "type json string"
  70. // @Success Ret=200 保存成功
  71. // @router /apply/approve [post]
  72. func (this *BusinessTrip) ApplyApprove() {
  73. sysUser := this.AdminWx
  74. sysUserId := sysUser.AdminId
  75. var req business_trip.BusinessApplyApproveReq
  76. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  77. if err != nil {
  78. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  79. return
  80. }
  81. if req.BusinessApplyId <= 0 {
  82. this.FailWithMessage("参数错误!", "参数错误")
  83. return
  84. }
  85. if req.ApproveStatus != 1 && req.ApproveStatus != 2 {
  86. this.FailWithMessage("审批状态错误!", "审批状态错误")
  87. return
  88. }
  89. if req.ApproveStatus == 2 && req.RefuseReason == "" {
  90. this.FailWithMessage("请填写驳回理由!", "请填写驳回理由")
  91. return
  92. }
  93. businessApplyItem, err := business_trip.GetBusinessApplyById(req.BusinessApplyId)
  94. if err != nil {
  95. if err.Error() == utils.ErrNoRow() {
  96. this.FailWithMessage("出差申请已被删除,请刷新页面!", "出差申请已被删除,请刷新页面")
  97. return
  98. }
  99. this.FailWithMessage("获取数据失败!", "获取数据失败!GetBusinessApplyById:"+err.Error())
  100. return
  101. }
  102. whereParams := make(map[string]interface{})
  103. updateParams := make(map[string]interface{})
  104. whereParams["business_apply_id"] = req.BusinessApplyId
  105. var status string
  106. if req.ApproveStatus == 1 {
  107. status = "已审批"
  108. } else {
  109. status = "已驳回"
  110. }
  111. updateParams["status"] = "已驳回"
  112. updateParams["refuse_reason"] = req.RefuseReason
  113. updateParams["modify_time"] = time.Now()
  114. updateParams["approve_time"] = time.Now()
  115. err = business_trip.UpdateBusinessApply(whereParams, updateParams)
  116. if err != nil {
  117. this.FailWithMessage("审批失败!", "审批失败!UpdateBusinessApply:"+err.Error())
  118. return
  119. }
  120. {
  121. //系统消息
  122. sourceType := 10
  123. content := businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请" + status
  124. go services.AddCompanyApprovalMessage(sysUserId, businessApplyItem.ApplyAdminId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 2, "", content, content, "", "")
  125. }
  126. this.OkWithMessage("审批成功")
  127. }