|
@@ -0,0 +1,680 @@
|
|
|
+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(66)
|
|
|
+ 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)
|
|
|
+ var keyword4 string
|
|
|
+ if req.PeerPeopleId != "" {
|
|
|
+ keyword4 = req.ArriveDate + "至" + req.ReturnDate + "," + req.Transportation + "前往" + req.Province + req.City + "," + "同行人" + req.PeerPeopleName
|
|
|
+ } else {
|
|
|
+ keyword4 = req.ArriveDate + "至" + req.ReturnDate + "," + 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(66)
|
|
|
+ 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)
|
|
|
+ var keyword4 string
|
|
|
+ if req.PeerPeopleId != "" {
|
|
|
+ keyword4 = req.ArriveDate + "至" + req.ReturnDate + "," + req.Transportation + "前往" + req.Province + req.City + "," + "同行人" + req.PeerPeopleName
|
|
|
+ } else {
|
|
|
+ keyword4 = req.ArriveDate + "至" + req.ReturnDate + "," + 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
|
|
|
+ }
|
|
|
+ //删除系统消息
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除系统消息
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ this.OkDetailed(item, "获取成功")
|
|
|
+}
|