瀏覽代碼

Merge branch 'needs/trip_close'

hsun 1 年之前
父節點
當前提交
91f6b46594
共有 2 個文件被更改,包括 32 次插入5 次删除
  1. 31 5
      controllers/business_trip/business_apply.go
  2. 1 0
      models/tables/business_trip/business_apply.go

+ 31 - 5
controllers/business_trip/business_apply.go

@@ -699,9 +699,16 @@ func (this *BusinessTrip) ApplyDetail() {
 		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, "获取成功")
 }
 
@@ -734,9 +741,18 @@ func (this *BusinessTrip) Close() {
 		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)
+	//fmt.Println(req.BusinessApplyId)
+	//fmt.Println(req.CloseReason)
 
 	whereParams := make(map[string]interface{})
 	updateParams := make(map[string]interface{})
@@ -767,23 +783,33 @@ func (this *BusinessTrip) Close() {
 		return
 	}
 
+	// 审批人关闭时, 发送消息给申请人
+	// 若为申请人自己关闭, 则消息发送给审批人
+	receiveUserId := businessApplyItem.ApplyAdminId
+	if isApply {
+		receiveUserId = businessApplyItem.ApproveId
+	}
 	{
 		//系统消息
 		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, "", "")
+		go services.AddCompanyApprovalMessage(sysUserId, receiveUserId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 1, "", content, content, "", "")
 	}
 
 	//模板消息
 	{
 		status := "已关闭"
-		applyItem, _ := admin.GetAdminById(businessApplyItem.ApplyAdminId)
+		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, applyItem.Mobile)
+		go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, receiver.Mobile)
 	}
 	this.OkWithMessage("关闭成功")
 }

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

@@ -74,6 +74,7 @@ type BusinessApplyView struct {
 	IsApprove       bool   `description:"是否审批人,true:是,false:否"`
 	CloseReason     string `description:"关闭理由"`
 	CloseTime       string `description:"关闭时间"`
+	IsClose         bool   `description:"true,可关闭,false,不可关闭"`
 }
 
 func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {