123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package business_trip
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mobile_admin/models/tables/admin"
- "hongze/hongze_mobile_admin/models/tables/business_trip"
- "hongze/hongze_mobile_admin/models/tables/company_approval_message"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "time"
- )
- // @Title 出差审批列表
- // @Description 出差申请列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query string true "状态"
- // @Success 200 {object} business_trip.BusinessApplyListResp
- // @router /approve/list [get]
- func (this *BusinessTrip) ApproveList() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- reason := this.GetString("Reason")
- status := this.GetString("Status")
- var condition string
- var pars []interface{}
- condition += ` AND approve_id=? `
- pars = append(pars, sysUserId)
- if reason != "" {
- condition += ` AND reason=? `
- pars = append(pars, reason)
- }
- if status != "" {
- if status == "已审批" {
- condition += ` AND status IN('已通过','已驳回','已关闭') `
- } else {
- condition += ` AND status=? `
- pars = append(pars, status)
- }
- }
- resp := new(business_trip.BusinessApplyListResp)
- total, err := business_trip.GetBusinessApplyListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
- return
- }
- dataList, err := business_trip.GetBusinessApplyList(condition, pars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取指标信息失败!", "获取数据失败,GetBusinessApplyList,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 出差申请,审批接口
- // @Description 出差申请,审批接口
- // @Param request body business_trip.BusinessApplyApproveReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /apply/approve [post]
- func (this *BusinessTrip) ApplyApprove() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyApproveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.BusinessApplyId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误")
- return
- }
- if req.ApproveStatus != 1 && req.ApproveStatus != 2 {
- this.FailWithMessage("审批状态错误!", "审批状态错误")
- return
- }
- if req.ApproveStatus == 2 && req.RefuseReason == "" {
- this.FailWithMessage("请填写驳回理由!", "请填写驳回理由")
- return
- }
- businessApplyItem, err := business_trip.GetBusinessApplyById(req.BusinessApplyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- this.FailWithMessage("出差申请已被删除,请刷新页面!", "出差申请已被删除,请刷新页面")
- return
- }
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetBusinessApplyById:"+err.Error())
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["business_apply_id"] = req.BusinessApplyId
- var status string
- if req.ApproveStatus == 1 {
- status = "已通过"
- } else {
- status = "已驳回"
- }
- updateParams["status"] = status
- updateParams["refuse_reason"] = req.RefuseReason
- updateParams["modify_time"] = time.Now()
- updateParams["approve_time"] = time.Now()
- err = business_trip.UpdateBusinessApply(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("审批失败!", "审批失败!UpdateBusinessApply:"+err.Error())
- return
- }
- {
- //系统消息
- sourceType := 10
- content := businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请" + status
- go services.AddCompanyApprovalMessage(sysUserId, businessApplyItem.ApplyAdminId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 2, "", content, content, "", "")
- go company_approval_message.IsReadCompanyApprovalMessage(businessApplyItem.BusinessApplyId, sourceType)
- }
- //模板消息
- {
- applyItem, _ := admin.GetAdminById(businessApplyItem.ApplyAdminId)
- wxAppPath := "pages-approve/businessTrip/detail?id=" + strconv.Itoa(req.BusinessApplyId)
- first := "您的出差申请已被审批"
- keyword1 := businessApplyItem.Reason + "出差申请" + status
- keyword2 := status
- var remark string
- if status == "已驳回" {
- remark = req.RefuseReason
- keyword2 = status + `(` + req.RefuseReason + `)`
- }
- go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, applyItem.Mobile)
- }
- this.OkWithMessage("审批成功")
- }
|