Browse Source

新增关闭接口

tuoling805 2 years ago
parent
commit
6dfdf5f0c3

+ 80 - 0
controllers/business_trip/business_apply.go

@@ -678,3 +678,83 @@ 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
+	}
+
+	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("关闭成功")
+}

+ 2 - 0
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"
@@ -148,6 +149,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)
 	}
 
 	//模板消息

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

@@ -215,3 +215,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",