Browse Source

修改消息数据

tuoling805 2 years ago
parent
commit
2d0c86fc6d

+ 6 - 1
controllers/business_trip/business_apply.go

@@ -238,6 +238,7 @@ func (this *BusinessTrip) ApplyEdit() {
 	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)
@@ -452,7 +453,8 @@ func (this *BusinessTrip) Back() {
 // @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))
@@ -467,5 +469,8 @@ func (this *BusinessTrip) ApplyDetail() {
 		this.FailWithMessage("获取数据失败", "获取数据失败:"+err.Error())
 		return
 	}
+	if item.ApproveId == sysUserId {
+		item.IsApply = true
+	}
 	this.OkDetailed(item, "获取成功")
 }

+ 26 - 6
controllers/business_trip/business_approve.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_mobile_admin/models/tables/business_trip"
+	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/utils"
 	"time"
 )
@@ -84,8 +85,8 @@ func (this *BusinessTrip) ApproveList() {
 // @Success Ret=200 保存成功
 // @router /apply/approve [post]
 func (this *BusinessTrip) ApplyApprove() {
-	//sysUser := this.AdminWx
-	//sysUserId := sysUser.AdminId
+	sysUser := this.AdminWx
+	sysUserId := sysUser.AdminId
 	var req business_trip.BusinessApplyApproveReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -108,25 +109,44 @@ func (this *BusinessTrip) ApplyApprove() {
 		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
+	}
+
 	whereParams := make(map[string]interface{})
 	updateParams := make(map[string]interface{})
 
 	whereParams["business_apply_id"] = req.BusinessApplyId
 
+	var status string
 	if req.ApproveStatus == 1 {
-		updateParams["status"] = "已审批"
+		status = "已审批"
 	} else {
-		updateParams["status"] = "已驳回"
-		updateParams["refuse_reason"] = req.RefuseReason
+		status = "已驳回"
 	}
+	updateParams["status"] = "已驳回"
+	updateParams["refuse_reason"] = req.RefuseReason
 	updateParams["modify_time"] = time.Now()
 	updateParams["approve_time"] = time.Now()
 
 	err = business_trip.UpdateBusinessApply(whereParams, updateParams)
-
 	if err != nil {
 		this.FailWithMessage("审批失败!", "审批失败!UpdateBusinessApply:"+err.Error())
 		return
 	}
+
+	{
+		//系统消息
+		sourceType := 10
+		content := businessApplyItem.Province + businessApplyItem.City + businessApplyItem.Reason + "出差申请" + status
+		go services.AddCompanyApprovalMessage(sysUserId, businessApplyItem.ApplyAdminId, 0, businessApplyItem.BusinessApplyId, 1, sourceType, 2, "", content, content, "", "")
+	}
+
 	this.OkWithMessage("审批成功")
 }

+ 11 - 0
controllers/message.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_mobile_admin/models/response/message"
+	"hongze/hongze_mobile_admin/models/tables/business_trip"
 	"hongze/hongze_mobile_admin/models/tables/company_approval"
 	"hongze/hongze_mobile_admin/models/tables/company_approval_message"
 	"hongze/hongze_mobile_admin/models/tables/contract_approval"
@@ -297,6 +298,16 @@ func (c *MessageCommon) MessageList() {
 				approvalInfo.ApplyTime = companyApproval.CreateTime
 				approvalInfo.ApprovalTime = companyApproval.ApproveTime
 			}
+		} else if messageInfo.SourceType == 10 {
+			applyId := messageInfo.CompanyApprovalId
+			if applyId > 0 {
+				bt, err := business_trip.GetBusinessApplyById(applyId)
+				if err != nil && err.Error() != utils.ErrNoRow() {
+					c.FailWithMessage("获取失败", "获取信息失败,GetBusinessApplyById,Err:"+err.Error())
+					return
+				}
+				messageInfo.BusinessTripInfo = bt
+			}
 		} else {
 			if newApproval, ok := newApprovalMap[messageInfo.CompanyApprovalId]; ok {
 				approvalInfo.Type = newApproval.ApplyContent

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

@@ -69,6 +69,7 @@ type BusinessApplyView struct {
 	ApproveTime     string `description:"审批时间"`
 	CreateTime      string `description:"创建时间"`
 	ModifyTime      string `description:"修改时间"`
+	IsApply         bool   `description:"是否审批人,true:是,false:否"`
 }
 
 func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {

+ 16 - 14
models/tables/company_approval_message/company_approval_message.go

@@ -2,6 +2,7 @@ package company_approval_message
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_mobile_admin/models/tables/business_trip"
 	"hongze/hongze_mobile_admin/utils"
 	"time"
 )
@@ -43,20 +44,21 @@ WHERE company_approval_id=? AND source_type=?  AND message_type=1 AND operation_
 
 // 消息列表结果
 type CompanyApprovalMessageList struct {
-	Id                int          `orm:"column(id);pk"`
-	CreateUserId      int          `description:"申请者id"`
-	MessageStatus     int          `description:"消息状态:0未读,1:已读,2:作废"`
-	MessageType       int          `description:"1:申请消息,2:审批结果,3:文字消息"`
-	ApprovalStatus    int          `description:"审批结果:1:待审批,2:已审批,3:已驳回"`
-	SourceType        int          `description:"消息来源类型,1:客户,2:合同,3:用印"`
-	Remark            string       `description:"备注信息"`
-	Content           string       `description:"消息内容"`
-	CompanyName       string       `description:"客户名称"`
-	CreateTime        time.Time    `description:"创建时间"`
-	RealName          string       `description:"销售名称"`
-	CompanyApprovalId int          `description:"审批单id"`
-	MessageInfo       string       `description:"消息主要内容,json数据" json:"-"`
-	ApprovalInfo      ApprovalInfo `description:"审批单信息"`
+	Id                int                              `orm:"column(id);pk"`
+	CreateUserId      int                              `description:"申请者id"`
+	MessageStatus     int                              `description:"消息状态:0未读,1:已读,2:作废"`
+	MessageType       int                              `description:"1:申请消息,2:审批结果,3:文字消息"`
+	ApprovalStatus    int                              `description:"审批结果:1:待审批,2:已审批,3:已驳回"`
+	SourceType        int                              `description:"消息来源类型,1:客户,2:合同,3:用印"`
+	Remark            string                           `description:"备注信息"`
+	Content           string                           `description:"消息内容"`
+	CompanyName       string                           `description:"客户名称"`
+	CreateTime        time.Time                        `description:"创建时间"`
+	RealName          string                           `description:"销售名称"`
+	CompanyApprovalId int                              `description:"审批单id"`
+	MessageInfo       string                           `description:"消息主要内容,json数据" json:"-"`
+	ApprovalInfo      ApprovalInfo                     `description:"审批单信息"`
+	BusinessTripInfo  *business_trip.BusinessApplyView `description:"出差申请信息"`
 }
 
 // 消息审批单信息