business_approve.go 5.2 KB

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