浏览代码

Merge branch 'aj_business_trip'

tuoling805 2 年之前
父节点
当前提交
001fe6e3e1

+ 117 - 10
controllers/business_trip/business_apply.go

@@ -86,7 +86,7 @@ func (this *BusinessTrip) ApplyAdd() {
 
 	//校验出差日期冲突
 	{
-		businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", sysUser.AdminId, 0)
+		businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
 		if err != nil {
 			this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyDate!Err:"+err.Error())
 			return
@@ -99,7 +99,7 @@ func (this *BusinessTrip) ApplyAdd() {
 
 	//校验申请人,是否被邀请为同行人,并且出差日期冲突
 	{
-		peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", sysUser.AdminId, 0)
+		peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
 		if err != nil {
 			this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
 			return
@@ -125,7 +125,7 @@ func (this *BusinessTrip) ApplyAdd() {
 					return
 				}
 
-				peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", peerId, 0)
+				peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", peerId, 0)
 				if err != nil {
 					this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
 					return
@@ -301,7 +301,7 @@ func (this *BusinessTrip) ApplyEdit() {
 
 	//校验出差日期冲突
 	{
-		businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", sysUser.AdminId, req.BusinessApplyId)
+		businessApplyCount, err := business_trip.CheckBusinessApplyDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, req.BusinessApplyId)
 		if err != nil {
 			this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyDate!Err:"+err.Error())
 			return
@@ -314,7 +314,7 @@ func (this *BusinessTrip) ApplyEdit() {
 
 	//校验申请人,是否被邀请为同行人,并且出差日期冲突
 	{
-		peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", sysUser.AdminId, 0)
+		peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", sysUser.AdminId, 0)
 		if err != nil {
 			this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
 			return
@@ -340,7 +340,7 @@ func (this *BusinessTrip) ApplyEdit() {
 					return
 				}
 
-				peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已审批'", peerId, req.BusinessApplyId)
+				peerCount, err := business_trip.CheckBusinessApplyPeerDate(req.ArriveDate, req.ReturnDate, "'待审批','已通过'", peerId, req.BusinessApplyId)
 				if err != nil {
 					this.FailWithMessage("时间冲突检测失败", "时间冲突检测失败-CheckBusinessApplyPeerDate!Err:"+err.Error())
 					return
@@ -371,8 +371,8 @@ func (this *BusinessTrip) ApplyEdit() {
 		return
 	}
 
-	if businessApplyItem.Status == "已审批" {
-		this.FailWithMessage("已审批,不可进行重新申请操作!", "已审批,不可进行重新申请操作!")
+	if businessApplyItem.Status == "已通过" {
+		this.FailWithMessage("已通过,不可进行重新申请操作!", "已通过,不可进行重新申请操作!")
 		return
 	} else if businessApplyItem.Status == "已过期" {
 		this.FailWithMessage("已过期,不可进行重新申请操作!", "已过期,不可进行重新申请操作!")
@@ -581,6 +581,13 @@ func (this *BusinessTrip) Delete() {
 		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("删除成功")
@@ -616,8 +623,8 @@ func (this *BusinessTrip) Back() {
 		return
 	}
 
-	if businessApplyItem.Status == "已审批" {
-		this.FailWithMessage("已审批,不可进行撤回操作!", "已审批,不可进行撤回操作!")
+	if businessApplyItem.Status == "已通过" {
+		this.FailWithMessage("已通过,不可进行撤回操作!", "已通过,不可进行撤回操作!")
 		return
 	} else if businessApplyItem.Status == "已驳回" {
 		this.FailWithMessage("已驳回,不可进行撤回操作!", "已驳回,不可进行撤回操作!")
@@ -645,6 +652,23 @@ func (this *BusinessTrip) Back() {
 		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)
 
@@ -678,3 +702,86 @@ func (this *BusinessTrip) ApplyDetail() {
 	}
 	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
+	}
+
+	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
+	}
+
+	{
+		//系统消息
+		sourceType := 10
+		content := businessApplyItem.ApplyRealName + " " + businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请已关闭"
+		go services.AddCompanyApprovalMessage(sysUserId, businessApplyItem.ApplyAdminId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 1, "", content, content, "", "")
+	}
+
+	//模板消息
+	{
+		status := "已关闭"
+		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
+		go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, applyItem.Mobile)
+	}
+	this.OkWithMessage("关闭成功")
+}

+ 6 - 6
controllers/business_trip/business_approve.go

@@ -5,6 +5,7 @@ import (
 	"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"
@@ -53,7 +54,7 @@ func (this *BusinessTrip) ApproveList() {
 
 	if status != "" {
 		if status == "已审批" {
-			condition += ` AND status IN('已审批','已驳回') `
+			condition += ` AND status IN('已通过','已驳回','已关闭') `
 		} else {
 			condition += ` AND status=? `
 			pars = append(pars, status)
@@ -124,13 +125,11 @@ func (this *BusinessTrip) ApplyApprove() {
 
 	whereParams["business_apply_id"] = req.BusinessApplyId
 
-	var status, applyStatus string
+	var status string
 	if req.ApproveStatus == 1 {
-		status = "已审批"
-		applyStatus = "已通过"
+		status = "已通过"
 	} else {
 		status = "已驳回"
-		applyStatus = "已驳回"
 	}
 	updateParams["status"] = status
 	updateParams["refuse_reason"] = req.RefuseReason
@@ -148,6 +147,7 @@ func (this *BusinessTrip) ApplyApprove() {
 		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)
 	}
 
 	//模板消息
@@ -155,7 +155,7 @@ func (this *BusinessTrip) ApplyApprove() {
 		applyItem, _ := admin.GetAdminById(businessApplyItem.ApplyAdminId)
 		wxAppPath := "pages-approve/businessTrip/detail?id=" + strconv.Itoa(req.BusinessApplyId)
 		first := "您的出差申请已被审批"
-		keyword1 := businessApplyItem.Reason + "出差申请" + applyStatus
+		keyword1 := businessApplyItem.Reason + "出差申请" + status
 		keyword2 := status
 		var remark string
 		if status == "已驳回" {

+ 2 - 2
controllers/business_trip/business_calendar.go

@@ -30,10 +30,10 @@ func (this *BusinessTrip) BusinessTripCalendar() {
 	}
 
 	if sysUserId == 66 {
-		condition += ` AND status IN('待审批','已审批') `
+		condition += ` AND status IN('待审批','已通过') `
 	} else {
 		condition += ` AND status=? `
-		pars = append(pars, "已审批")
+		pars = append(pars, "已通过")
 	}
 
 	if tripDate != "" {

+ 21 - 0
models/tables/business_trip/business_apply.go

@@ -24,6 +24,8 @@ type BusinessApply struct {
 	RefuseReason    string    `description:"拒绝理由"`
 	RefuseTime      time.Time `description:"拒绝时间"`
 	ApproveTime     time.Time `description:"审批时间"`
+	CloseReason     string    `description:"关闭理由"`
+	CloseTime       time.Time `description:"关闭时间"`
 	CreateTime      time.Time `description:"创建时间"`
 	ModifyTime      time.Time `description:"修改时间"`
 }
@@ -70,6 +72,8 @@ type BusinessApplyView struct {
 	CreateTime      string `description:"创建时间"`
 	ModifyTime      string `description:"修改时间"`
 	IsApprove       bool   `description:"是否审批人,true:是,false:否"`
+	CloseReason     string `description:"关闭理由"`
+	CloseTime       string `description:"关闭时间"`
 }
 
 func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {
@@ -215,3 +219,20 @@ func CheckBusinessApplyPeerDate(startDateTime, endDateTime, status string, apply
 	calendarCount, err = CheckBusinessApplyPeerDateCount(condition, pars)
 	return
 }
+
+type BusinessApplyCloseReq struct {
+	BusinessApplyId int    `description:"出差申请id"`
+	CloseReason     string `description:"关闭原因"`
+}
+
+// 更新
+func UpdateBusinessApplyPeer(where, updateParams map[string]interface{}) error {
+	o := orm.NewOrm()
+	ptrStructOrTableName := "business_apply_peer"
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Update(updateParams)
+	return err
+}

+ 9 - 0
models/tables/company_approval_message/company_approval_message.go

@@ -195,3 +195,12 @@ func DeleteCompanyApprovalMessage(companyApprovalId, sourceType int) (err error)
 	_, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
 	return
 }
+
+// CancelCompanyApprovalMessage 消息作废
+func IsReadCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() 
+WHERE company_approval_id=? AND source_type=?  AND message_type=1 AND operation_status=1 `
+	_, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -34,6 +34,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/business_trip:BusinessTrip"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/business_trip:BusinessTrip"],
+        beego.ControllerComments{
+            Method: "Close",
+            Router: `/apply/close`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/business_trip:BusinessTrip"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/business_trip:BusinessTrip"],
         beego.ControllerComments{
             Method: "Delete",