business_approve.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package business_trip
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/business_trip"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "time"
  13. )
  14. // @Title 出差审批列表
  15. // @Description 出差申请列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param Status query string true "状态"
  19. // @Success 200 {object} business_trip.BusinessApplyListResp
  20. // @router /approve/list [get]
  21. func (this *BusinessTrip) ApproveList() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. pageSize, _ := this.GetInt("PageSize")
  35. currentIndex, _ := this.GetInt("CurrentIndex")
  36. var total int
  37. page := paging.GetPaging(currentIndex, pageSize, total)
  38. var startSize int
  39. if pageSize <= 0 {
  40. pageSize = utils.PageSize10
  41. }
  42. if currentIndex <= 0 {
  43. currentIndex = 1
  44. }
  45. startSize = paging.StartIndex(currentIndex, pageSize)
  46. reason := this.GetString("Reason")
  47. status := this.GetString("Status")
  48. var condition string
  49. var pars []interface{}
  50. condition += ` AND approve_id=? `
  51. pars = append(pars, sysUser.AdminId)
  52. if reason != "" {
  53. condition += ` AND reason=? `
  54. pars = append(pars, reason)
  55. }
  56. if status != "" {
  57. condition += ` AND status=? `
  58. pars = append(pars, status)
  59. } else {
  60. condition += ` AND status IN('待审批','已通过','已驳回','已关闭') `
  61. }
  62. resp := new(business_trip.BusinessApplyListResp)
  63. total, err := business_trip.GetBusinessApplyListCount(condition, pars)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "获取信息失败"
  66. br.ErrMsg = "获取数据总数失败,GetCalendarListCount,Err:" + err.Error()
  67. return
  68. }
  69. dataList, err := business_trip.GetBusinessApplyList(condition, pars, startSize, pageSize)
  70. if err != nil {
  71. br.Msg = "获取指标信息失败"
  72. br.ErrMsg = "获取数据失败,GetBusinessApplyList,Err:" + err.Error()
  73. return
  74. }
  75. nowDate, _ := time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
  76. for _, v := range dataList {
  77. arriveDate, _ := time.ParseInLocation(utils.FormatDate, v.ArriveDate, time.Local)
  78. if v.Status == "已通过" && arriveDate.After(nowDate) {
  79. v.IsClose = true
  80. }
  81. }
  82. page = paging.GetPaging(currentIndex, pageSize, total)
  83. resp.Paging = page
  84. resp.List = dataList
  85. br.Ret = 200
  86. br.Success = true
  87. br.Msg = "获取成功"
  88. br.Data = resp
  89. }
  90. // @Title 出差申请,审批接口
  91. // @Description 出差申请,审批接口
  92. // @Param request body business_trip.BusinessApplyApproveReq true "type json string"
  93. // @Success Ret=200 保存成功
  94. // @router /apply/approve [post]
  95. func (this *BusinessTrip) ApplyApprove() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. sysUser := this.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.ErrMsg = "请登录,SysUser Is Empty"
  105. br.Ret = 408
  106. return
  107. }
  108. var req business_trip.BusinessApplyApproveReq
  109. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  110. if err != nil {
  111. br.Msg = "参数解析异常!"
  112. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  113. return
  114. }
  115. if req.BusinessApplyId <= 0 {
  116. br.Msg = "参数错误"
  117. br.ErrMsg = "参数错误"
  118. return
  119. }
  120. if req.ApproveStatus != 1 && req.ApproveStatus != 2 {
  121. br.Msg = "审批状态错误"
  122. return
  123. }
  124. if req.ApproveStatus == 2 && req.RefuseReason == "" {
  125. br.Msg = "请填写驳回理由"
  126. return
  127. }
  128. businessApplyItem, err := business_trip.GetBusinessApplyById(req.BusinessApplyId)
  129. if err != nil {
  130. if err.Error() == utils.ErrNoRow() {
  131. br.Msg = "出差申请已被删除,请刷新页面"
  132. return
  133. }
  134. br.Msg = "获取数据失败!"
  135. br.ErrMsg = "获取数据失败!GetBusinessApplyById:" + err.Error()
  136. return
  137. }
  138. // 审批权限-仅王沛
  139. if businessApplyItem.ApproveId != sysUser.AdminId {
  140. br.Msg = "无权审批"
  141. return
  142. }
  143. whereParams := make(map[string]interface{})
  144. updateParams := make(map[string]interface{})
  145. whereParams["business_apply_id"] = req.BusinessApplyId
  146. var status string
  147. if req.ApproveStatus == 1 {
  148. status = "已通过"
  149. } else {
  150. status = "已驳回"
  151. }
  152. updateParams["status"] = status
  153. updateParams["refuse_reason"] = req.RefuseReason
  154. updateParams["modify_time"] = time.Now()
  155. updateParams["approve_time"] = time.Now()
  156. err = business_trip.UpdateBusinessApply(whereParams, updateParams)
  157. if err != nil {
  158. br.Msg = "审批失败!"
  159. br.ErrMsg = "审批失败!UpdateBusinessApply:" + err.Error()
  160. return
  161. }
  162. {
  163. //系统消息
  164. sourceType := 10
  165. content := businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请" + status
  166. go services.AddCompanyApprovalMessage(sysUser.AdminId, businessApplyItem.ApplyAdminId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 2, "", content, content, "")
  167. go company.IsReadCompanyApprovalMessage(businessApplyItem.BusinessApplyId, sourceType)
  168. }
  169. //模板消息
  170. {
  171. applyItem, _ := system.GetSysUserById(businessApplyItem.ApplyAdminId)
  172. openIdObj := &system.OpenIdList{
  173. OpenId: applyItem.OpenId,
  174. AdminId: applyItem.AdminId,
  175. }
  176. openIdList := make([]*system.OpenIdList, 0)
  177. openIdList = append(openIdList, openIdObj)
  178. var remark string
  179. if status == "已驳回" {
  180. remark = req.RefuseReason
  181. }
  182. var wxAppPath string
  183. if utils.RunMode == "debug" {
  184. wxAppPath = "pages/index/index"
  185. } else {
  186. wxAppPath = "pages-approve/businessTrip/detail?id=" + strconv.Itoa(req.BusinessApplyId)
  187. }
  188. first := "您的出差申请已被审批"
  189. keyword1 := businessApplyItem.Reason + "出差申请" + status
  190. keyword2 := status
  191. if status == `已驳回` {
  192. keyword2 = status + `(` + req.RefuseReason + `)`
  193. }
  194. go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, openIdList)
  195. }
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "审批成功"
  199. br.IsAddLog = true
  200. }