123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815 |
- package business_trip
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mobile_admin/controllers"
- "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"
- "strings"
- "time"
- )
- // 出差
- type BusinessTrip struct {
- controllers.BaseAuth
- }
- // @Title 出差申请接口
- // @Description 出差申请接口
- // @Param request body business_trip.BusinessApplyReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /apply/add [post]
- func (this *BusinessTrip) ApplyAdd() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("解析参数失败", "解析参数失败,Err:"+err.Error())
- return
- }
- if req.ArriveDate == "" {
- this.FailWithMessage("请填写到达日期", "请填写到达日期")
- return
- }
- if req.ReturnDate == "" {
- this.FailWithMessage("请填写返程日期", "请填写返程日期")
- return
- }
- if req.Province == "" {
- this.FailWithMessage("请填写目的地省", "请填写目的地省")
- return
- }
- if req.City == "" {
- this.FailWithMessage("请填写目的地市", "请填写目的地市")
- return
- }
- if req.Reason == "" {
- this.FailWithMessage("请填写出差事由", "请填写出差事由")
- return
- }
- if req.Transportation == "" {
- this.FailWithMessage("请填写交通工具", "请填写交通工具")
- return
- }
- startP, _ := time.ParseInLocation(utils.FormatDate, req.ArriveDate, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDate, req.ReturnDate, time.Local)
- nowDate, _ := time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
- if startP.Before(nowDate) {
- this.FailWithMessage("出差开始日期不能小于当前日期", "出差开始日期不能小于当前日期")
- return
- }
- if !endP.Equal(nowDate) && endP.Before(nowDate) {
- this.FailWithMessage("出差结束时间不能小于当前时间", "出差结束时间不能小于当前时间")
- return
- }
- if !startP.Equal(endP) && (startP.After(endP) || startP.Equal(endP)) {
- this.FailWithMessage("出差开始日期应小于结束日期", "出差开始日期应小于结束日期")
- return
- }
- //校验出差日期冲突
- {
- businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyDate!Err:"+err.Error())
- return
- }
- if businessApplyCount > 0 {
- this.FailWithMessage("日期已被占用", "日期已被占用-CheckBusinessApplyDate!")
- return
- }
- }
- //校验申请人,是否被邀请为同行人,并且出差日期冲突
- {
- peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
- return
- }
- if peerCount > 0 {
- this.FailWithMessage("所选日期您被设置为同行人,请重新选择!", "所选日期您被设置为同行人,请重新选择!")
- return
- }
- }
- //校验同行人,出差日期冲突
- {
- if req.PeerPeopleId != "" {
- var existPeerNameArr []string
- peerIdArr := strings.Split(req.PeerPeopleId, ",")
- peerNameArr := strings.Split(req.PeerPeopleName, ",")
- for k, v := range peerIdArr {
- peerId, err := strconv.Atoi(v)
- if err != nil {
- this.FailWithMessage("申请失败", "同行人id失败,Err:"+err.Error())
- return
- }
- peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", peerId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
- return
- }
- if peerCount > 0 {
- existPeerNameArr = append(existPeerNameArr, peerNameArr[k])
- }
- }
- if len(existPeerNameArr) > 0 {
- this.FailWithMessage(strings.Join(existPeerNameArr, ",")+"日期已被占用", "日期已被占用-CheckBusinessApplyDate!")
- return
- }
- }
- }
- approveItem, err := admin.GetAdminById(utils.ApproveUserId)
- if err != nil {
- this.FailWithMessage("获取审批人信息失败", "获取审批人信息失败,Err:"+err.Error())
- return
- }
- item := new(business_trip.BusinessApply)
- item.ApplyAdminId = sysUser.AdminId
- item.ApplyRealName = sysUser.RealName
- item.ArriveDate = req.ArriveDate
- item.ReturnDate = req.ReturnDate
- item.Province = req.Province
- item.City = req.City
- item.Reason = req.Reason
- item.Transportation = req.Transportation
- item.PeerPeopleId = req.PeerPeopleId
- item.PeerPeopleName = req.PeerPeopleName
- item.Status = "待审批"
- item.ApproveId = approveItem.AdminId
- item.ApproveName = approveItem.RealName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- applyId, err := business_trip.AddBusinessApply(item)
- if err != nil {
- this.FailWithMessage("申请失败", "申请失败,Err:"+err.Error())
- return
- }
- //新增随行人
- {
- if req.PeerPeopleId != "" {
- peerList := make([]*business_trip.BusinessApplyPeer, 0)
- peerIdArr := strings.Split(req.PeerPeopleId, ",")
- peerNameArr := strings.Split(req.PeerPeopleName, ",")
- for k, v := range peerIdArr {
- peerId, err := strconv.Atoi(v)
- if err != nil {
- this.FailWithMessage("申请失败", "同行人id失败,Err:"+err.Error())
- return
- }
- peerItem := new(business_trip.BusinessApplyPeer)
- peerItem.BusinessApplyId = int(applyId)
- peerItem.ArriveDate = req.ArriveDate
- peerItem.ReturnDate = req.ReturnDate
- peerItem.Province = req.Province
- peerItem.City = req.City
- peerItem.Status = "待审批"
- peerItem.PeerPeopleId = peerId
- peerItem.PeerPeopleName = peerNameArr[k]
- peerItem.CreateTime = time.Now()
- peerItem.ModifyTime = time.Now()
- peerList = append(peerList, peerItem)
- }
- err = business_trip.AddBusinessApplyPeer(peerList)
- if err != nil {
- this.FailWithMessage("申请失败", "新增同行人信息失败,Err:"+err.Error())
- return
- }
- }
- }
- {
- //系统消息
- sourceType := 10
- content := sysUser.RealName + " " + req.Province + req.City + req.Reason + "出差申请"
- go services.AddCompanyApprovalMessage(sysUserId, approveItem.AdminId, 0, int(applyId), 1, sourceType, 1, "", content, content, "", "")
- }
- //模板消息
- {
- var wxAppPath string
- if utils.RunMode == "debug" {
- wxAppPath = "pages/index/index"
- } else {
- wxAppPath = "pages-approve/businessTrip/detail?id=" + strconv.Itoa(int(applyId))
- }
- first := "您好,有新的申请待处理"
- keyword1 := sysUser.RealName
- keyword2 := "--" //sysUser.Mobile
- //keyword3 := time.Now().Format(utils.FormatDateTime)
- keyword3 := req.ArriveDate + "至" + req.ReturnDate
- var keyword4 string
- if req.PeerPeopleId != "" {
- keyword4 = req.Transportation + "前往" + req.Province + req.City + "," + "同行人:" + req.PeerPeopleName
- } else {
- keyword4 = req.Transportation + "前往" + req.Province + req.City
- }
- remark := "请尽快完成审批"
- go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, approveItem.Mobile)
- }
- this.OkWithMessage("保存成功")
- }
- // @Title 出差重新申请接口
- // @Description 出差重新申请接口
- // @Param request body business_trip.BusinessApplyEditReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /apply/edit [post]
- func (this *BusinessTrip) ApplyEdit() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("解析参数失败", "解析参数失败,Err:"+err.Error())
- return
- }
- if req.ArriveDate == "" {
- this.FailWithMessage("请填写到达日期", "请填写到达日期")
- return
- }
- if req.ReturnDate == "" {
- this.FailWithMessage("请填写返程日期", "请填写返程日期")
- return
- }
- if req.Province == "" {
- this.FailWithMessage("请填写目的地省", "请填写目的地省")
- return
- }
- if req.City == "" {
- this.FailWithMessage("请填写目的地市", "请填写目的地市")
- return
- }
- if req.Reason == "" {
- this.FailWithMessage("请填写出差事由", "请填写出差事由")
- return
- }
- if req.Transportation == "" {
- this.FailWithMessage("请填写交通工具", "请填写交通工具")
- return
- }
- startP, _ := time.ParseInLocation(utils.FormatDate, req.ArriveDate, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDate, req.ReturnDate, time.Local)
- nowDate, _ := time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
- if startP.Before(nowDate) {
- fmt.Println("出差开始日期不能小于当前日期!")
- return
- }
- if !endP.Equal(nowDate) && endP.Before(nowDate) {
- fmt.Println("出差结束时间不能小于当前时间!")
- return
- }
- if !startP.Equal(endP) && (startP.After(endP) || startP.Equal(endP)) {
- fmt.Println("出差开始日期应小于结束日期!")
- return
- }
- //校验出差日期冲突
- {
- businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, req.BusinessApplyId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyDate!Err:"+err.Error())
- return
- }
- if businessApplyCount > 0 {
- this.FailWithMessage("日期已被占用", "日期已被占用-CheckBusinessApplyDate!")
- return
- }
- }
- //校验申请人,是否被邀请为同行人,并且出差日期冲突
- {
- peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
- return
- }
- if peerCount > 0 {
- this.FailWithMessage("所选日期您被设置为同行人,请重新选择!", "所选日期您被设置为同行人,请重新选择!")
- return
- }
- }
- //校验同行人,出差日期冲突
- {
- if req.PeerPeopleId != "" {
- var existPeerNameArr []string
- peerIdArr := strings.Split(req.PeerPeopleId, ",")
- peerNameArr := strings.Split(req.PeerPeopleName, ",")
- for k, v := range peerIdArr {
- peerId, err := strconv.Atoi(v)
- if err != nil {
- this.FailWithMessage("申请失败", "同行人id失败,Err:"+err.Error())
- return
- }
- peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", peerId, req.BusinessApplyId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
- return
- }
- if peerCount > 0 {
- existPeerNameArr = append(existPeerNameArr, peerNameArr[k])
- }
- }
- if len(existPeerNameArr) > 0 {
- this.FailWithMessage(strings.Join(existPeerNameArr, ",")+"日期已被占用", "日期已被占用-CheckBusinessApplyDate!")
- return
- }
- }
- }
- if req.BusinessApplyId <= 0 {
- this.FailWithMessage("参数错误", "参数错误!BusinessApplyId:"+strconv.Itoa(req.BusinessApplyId))
- 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
- }
- if businessApplyItem.Status == "已通过" {
- this.FailWithMessage("已通过,不可进行重新申请操作!", "已通过,不可进行重新申请操作!")
- return
- } else if businessApplyItem.Status == "已过期" {
- this.FailWithMessage("已过期,不可进行重新申请操作!", "已过期,不可进行重新申请操作!")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["business_apply_id"] = req.BusinessApplyId
- updateParams["arrive_date"] = req.ArriveDate
- updateParams["return_date"] = req.ReturnDate
- updateParams["province"] = req.Province
- updateParams["city"] = req.City
- updateParams["reason"] = req.Reason
- updateParams["transportation"] = req.Transportation
- updateParams["peer_people_id"] = req.PeerPeopleId
- updateParams["peer_people_name"] = req.PeerPeopleName
- updateParams["status"] = "待审批"
- updateParams["refuse_reason"] = ""
- updateParams["create_time"] = time.Now()
- updateParams["modify_time"] = time.Now()
- err = business_trip.UpdateBusinessApply(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("重新申请失败", "重新申请失败,Err:"+err.Error())
- return
- }
- //新增随行人
- {
- if req.PeerPeopleId != "" {
- err = business_trip.DeleteBusinessApplyPeer(req.BusinessApplyId)
- if err != nil {
- this.FailWithMessage("申请失败", "删除同行人失败,Err:"+err.Error())
- return
- }
- peerList := make([]*business_trip.BusinessApplyPeer, 0)
- peerIdArr := strings.Split(req.PeerPeopleId, ",")
- peerNameArr := strings.Split(req.PeerPeopleName, ",")
- for k, v := range peerIdArr {
- peerId, err := strconv.Atoi(v)
- if err != nil {
- this.FailWithMessage("申请失败", "同行人id失败,Err:"+err.Error())
- return
- }
- peerItem := new(business_trip.BusinessApplyPeer)
- peerItem.BusinessApplyId = req.BusinessApplyId
- peerItem.ArriveDate = req.ArriveDate
- peerItem.ReturnDate = req.ReturnDate
- peerItem.Province = req.Province
- peerItem.City = req.City
- peerItem.Status = "待审批"
- peerItem.PeerPeopleId = peerId
- peerItem.PeerPeopleName = peerNameArr[k]
- peerItem.CreateTime = time.Now()
- peerItem.ModifyTime = time.Now()
- peerList = append(peerList, peerItem)
- }
- err = business_trip.AddBusinessApplyPeer(peerList)
- if err != nil {
- this.FailWithMessage("申请失败", "新增同行人信息失败,Err:"+err.Error())
- return
- }
- }
- }
- approveItem, err := admin.GetAdminById(utils.ApproveUserId)
- if err != nil {
- this.FailWithMessage("获取审批人信息失败!", "获取审批人信息失败,Err:"+err.Error())
- return
- }
- {
- //系统消息
- sourceType := 10
- content := sysUser.RealName + " " + req.Province + req.City + req.Reason + "出差申请"
- go services.AddCompanyApprovalMessage(sysUserId, approveItem.AdminId, 0, req.BusinessApplyId, 1, sourceType, 1, "", content, content, "", "")
- }
- //模板消息
- {
- var wxAppPath string
- if utils.RunMode == "debug" {
- wxAppPath = "pages/index/index"
- } else {
- wxAppPath = "pages-approve/businessTrip/detail?id=" + strconv.Itoa(req.BusinessApplyId)
- }
- first := "您好,有新的申请待处理"
- keyword1 := sysUser.RealName
- keyword2 := "--" //sysUser.Mobile
- //keyword3 := time.Now().Format(utils.FormatDateTime)
- keyword3 := req.ArriveDate + "至" + req.ReturnDate
- var keyword4 string
- if req.PeerPeopleId != "" {
- keyword4 = req.Transportation + "前往" + req.Province + req.City + "," + "同行人:" + req.PeerPeopleName
- } else {
- keyword4 = req.Transportation + "前往" + req.Province + req.City
- }
- remark := "请尽快完成审批"
- go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, approveItem.Mobile)
- }
- this.OkWithMessage("申请成功")
- }
- // @Title 出差申请列表
- // @Description 出差申请列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Reason query string true "出差事由"
- // @Param Status query string true "状态"
- // @Success 200 {object} business_trip.BusinessApplyListResp
- // @router /apply/list [get]
- func (this *BusinessTrip) ApplyList() {
- 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 apply_admin_id=? `
- pars = append(pars, sysUserId)
- if reason != "" {
- condition += ` AND reason=? `
- pars = append(pars, reason)
- }
- if status != "" {
- if status == "已处理" {
- condition += ` AND status <> '待审批' `
- } 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.BusinessApplyDeleteReq true "type json string"
- // @Success Ret=200 删除成功
- // @router /apply/delete [post]
- func (this *BusinessTrip) Delete() {
- //sysUser := this.AdminWx
- //sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.BusinessApplyId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!BusinessApplyId:"+strconv.Itoa(req.BusinessApplyId))
- 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
- }
- err = business_trip.DeleteBusinessApply(businessApplyItem.BusinessApplyId)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!DeleteBusinessApply:"+err.Error())
- return
- }
- if businessApplyItem.PeerPeopleId != "" {
- err = business_trip.DeleteBusinessApplyPeer(businessApplyItem.BusinessApplyId)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!DeleteBusinessApplyPeer:"+err.Error())
- return
- }
- }
- //删除系统消息
- go company_approval_message.DeleteCompanyApprovalMessage(req.BusinessApplyId, 10)
- this.OkWithMessage("删除成功")
- }
- // @Title 撤回出差申请接口
- // @Description 撤回出差申请接口
- // @Param request body business_trip.BusinessApplyBackReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /apply/back [post]
- func (this *BusinessTrip) Back() {
- //sysUser := this.AdminWx
- //sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyBackReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.BusinessApplyId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!BusinessApplyId:"+strconv.Itoa(req.BusinessApplyId))
- 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
- }
- if businessApplyItem.Status == "已通过" {
- this.FailWithMessage("已通过,不可进行撤回操作!", "已通过,不可进行撤回操作!")
- return
- } else if businessApplyItem.Status == "已驳回" {
- this.FailWithMessage("已驳回,不可进行撤回操作!", "已驳回,不可进行撤回操作!")
- return
- } else if businessApplyItem.Status == "已撤回" {
- this.FailWithMessage("已撤回,不可重复操作!", "已撤回,不可重复操作!")
- return
- } else if businessApplyItem.Status == "已过期" {
- this.FailWithMessage("已过期,不可进行重复操作!", "已过期,不可进行重复操作!")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["business_apply_id"] = req.BusinessApplyId
- updateParams["status"] = "已撤回"
- updateParams["modify_time"] = time.Now()
- err = business_trip.UpdateBusinessApply(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("撤回失败", "撤回失败!UpdateBusinessApply:"+err.Error())
- return
- }
- if businessApplyItem.PeerPeopleId != "" {
- peerWhereParams := make(map[string]interface{})
- peerUpdateParams := make(map[string]interface{})
- whereParams["business_apply_id"] = req.BusinessApplyId
- peerUpdateParams["status"] = "已撤回"
- peerUpdateParams["modify_time"] = time.Now()
- err = business_trip.UpdateBusinessApplyPeer(peerWhereParams, peerUpdateParams)
- if err != nil {
- this.FailWithMessage("撤回失败", "撤回失败!UpdateBusinessApplyPeer:"+err.Error())
- return
- }
- }
- //删除系统消息
- go company_approval_message.DeleteCompanyApprovalMessage(req.BusinessApplyId, 10)
- this.OkWithMessage("撤回成功")
- }
- // @Title 出差申请详情
- // @Description 出差申请详情接口
- // @Param BusinessApplyId query int true "出差申请id"
- // @Success 200 {object} business_trip.BusinessApplyView
- // @router /apply/detail [get]
- func (this *BusinessTrip) ApplyDetail() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- businessApplyId, _ := this.GetInt("BusinessApplyId")
- if businessApplyId <= 0 {
- this.FailWithMessage("参数错误", "出差申请id错误:"+strconv.Itoa(businessApplyId))
- return
- }
- item, err := business_trip.GetBusinessApplyById(businessApplyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- this.FailWithMessage("该出差申请已被删除", "该出差申请已被删除")
- return
- }
- this.FailWithMessage("获取数据失败", "获取数据失败:"+err.Error())
- return
- }
- if item.ApproveId == sysUserId {
- item.IsApprove = true
- }
- // 审批已通过且在出差日期之前时, 审批人/申请人均可关闭
- nowDate, _ := time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
- arriveDate, _ := time.ParseInLocation(utils.FormatDate, item.ArriveDate, time.Local)
- if item.Status == "已通过" && arriveDate.After(nowDate) && (sysUserId == item.ApproveId || sysUserId == item.ApplyAdminId) {
- item.IsClose = true
- }
- this.OkDetailed(item, "获取成功")
- }
- // @Title 关闭接口
- // @Description 关闭接口
- // @Param request body business_trip.BusinessApplyCloseReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /apply/close [post]
- func (this *BusinessTrip) Close() {
- sysUser := this.AdminWx
- sysUserId := sysUser.AdminId
- var req business_trip.BusinessApplyCloseReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.BusinessApplyId <= 0 {
- this.FailWithMessage("参数解析异常!", "参数错误!BusinessApplyId:"+strconv.Itoa(req.BusinessApplyId))
- return
- }
- businessApplyItem, err := business_trip.GetBusinessApplyById(req.BusinessApplyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- this.FailWithMessage("出差申请已被删除,请刷新页面!", "出差申请已被删除,请刷新页面:"+strconv.Itoa(req.BusinessApplyId))
- return
- }
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetBusinessApplyById:"+err.Error())
- return
- }
- if sysUser.AdminId != businessApplyItem.ApplyAdminId && sysUser.AdminId != businessApplyItem.ApproveId {
- this.FailWithMessage("无权操作", "无权操作")
- return
- }
- // 判断是申请人还是审批人操作的关闭
- isApply := false
- if sysUser.AdminId == businessApplyItem.ApplyAdminId {
- isApply = true
- }
- //fmt.Println(req.BusinessApplyId)
- //fmt.Println(req.CloseReason)
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["business_apply_id"] = req.BusinessApplyId
- updateParams["status"] = "已关闭"
- updateParams["close_reason"] = req.CloseReason
- updateParams["modify_time"] = time.Now()
- updateParams["close_time"] = time.Now()
- err = business_trip.UpdateBusinessApply(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("关闭失败!", "关闭失败!UpdateBusinessApply:"+err.Error())
- return
- }
- peerWhereParams := make(map[string]interface{})
- peerUpdateParams := make(map[string]interface{})
- peerWhereParams["business_apply_id"] = req.BusinessApplyId
- peerUpdateParams["status"] = "已关闭"
- peerUpdateParams["modify_time"] = time.Now()
- err = business_trip.UpdateBusinessApplyPeer(peerWhereParams, peerUpdateParams)
- if err != nil {
- this.FailWithMessage("关闭失败!", "关闭失败!UpdateBusinessApplyPeer:"+err.Error())
- return
- }
- // 审批人关闭时, 发送消息给申请人
- // 若为申请人自己关闭, 则消息发送给审批人
- receiveUserId := businessApplyItem.ApplyAdminId
- if isApply {
- receiveUserId = businessApplyItem.ApproveId
- }
- {
- //系统消息
- sourceType := 10
- content := businessApplyItem.ApplyRealName + " " + businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请已关闭"
- go services.AddCompanyApprovalMessage(sysUserId, receiveUserId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 1, "", content, content, "", "")
- }
- //模板消息
- {
- status := "已关闭"
- receiver, _ := admin.GetAdminById(receiveUserId)
- //applyItem, _ := admin.GetAdminById(businessApplyItem.ApplyAdminId)
- wxAppPath := "pages-approve/businessTrip/detail?id=" + strconv.Itoa(req.BusinessApplyId)
- first := "您的出差申请已被关闭"
- if isApply {
- first = fmt.Sprintf("%s的出差申请已关闭", businessApplyItem.ApplyRealName)
- }
- keyword1 := businessApplyItem.Reason + "出差申请" + status
- keyword2 := status
- var remark string
- go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, receiver.Mobile)
- }
- this.OkWithMessage("关闭成功")
- }
|