Browse Source

新增审批权限

tuoling805 2 năm trước cách đây
mục cha
commit
1506fa9402

+ 5 - 0
controllers/admin.go

@@ -78,6 +78,11 @@ func (c *AdminCommon) Login() {
 	resp.ProductName = productName
 	resp.Authority = adminWx.Authority
 	resp.Headimgurl = adminWx.Headimgurl
+	if utils.RunMode == "release" {
+		if adminWx.AdminId == 66 {
+			resp.IsBusinessTrip = true
+		}
+	}
 	c.OkDetailed(resp, "登录成功")
 }
 

+ 74 - 1
controllers/business_trip/business_apply.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -110,6 +111,39 @@ func (this *BusinessTrip) ApplyAdd() {
 		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
@@ -247,6 +281,45 @@ func (this *BusinessTrip) ApplyEdit() {
 		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())
@@ -470,7 +543,7 @@ func (this *BusinessTrip) ApplyDetail() {
 		return
 	}
 	if item.ApproveId == sysUserId {
-		item.IsApply = true
+		item.IsApprove = true
 	}
 	this.OkDetailed(item, "获取成功")
 }

+ 1 - 1
controllers/business_trip/business_approve.go

@@ -41,7 +41,7 @@ func (this *BusinessTrip) ApproveList() {
 	var condition string
 	var pars []interface{}
 
-	condition += ` AND apply_admin_id=? `
+	condition += ` AND approve_id=? `
 	pars = append(pars, sysUserId)
 
 	if reason != "" {

+ 1 - 0
models/db_init.go

@@ -157,5 +157,6 @@ func InitDb() {}
 func initBusinessTrip() {
 	orm.RegisterModel(
 		new(business_trip.BusinessApply),
+		new(business_trip.BusinessApplyPeer),
 	)
 }

+ 1 - 0
models/response/admin/admin.go

@@ -11,4 +11,5 @@ type LoginResp struct {
 	GroupName      string `description:"所属分组"`
 	ProductName    string `description:"产品名称:admin,ficc,权益"`
 	Authority      int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员"`
+	IsBusinessTrip bool   `description:"是否出差审批:true,审批,false:无审批"`
 }

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

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

+ 42 - 0
models/tables/business_trip/business_apply_peer.go

@@ -0,0 +1,42 @@
+package business_trip
+
+import "time"
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type BusinessApplyPeer struct {
+	BusinessApplyPeerId int       `orm:"column(business_apply_peer_id);pk;auto" description:"ID"`
+	BusinessApplyId     int       `description:"出差申请id"`
+	ArriveDate          string    `description:"到达日期"`
+	ReturnDate          string    `description:"返程日期"`
+	Province            string    `description:"目的地省"`
+	City                string    `description:"目的地市"`
+	Status              string    `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
+	PeerPeopleId        int       `description:"同行人id"`
+	PeerPeopleName      string    `description:"同行人姓名"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+}
+
+// 添加出差申请随行人
+func AddBusinessApplyPeer(items []*BusinessApplyPeer) (err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	if err != nil {
+		return
+	}
+	return
+}
+
+// 删除
+func DeleteBusinessApplyPeer(businessApplyId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM business_apply_peer WHERE business_apply_id=? `
+	_, err = o.Raw(sql, businessApplyId).Exec()
+	if err != nil {
+		return err
+	}
+	return err
+}

+ 4 - 5
models/tables/business_trip/business_calendar.go

@@ -43,19 +43,18 @@ type BusinessTripCalendarResp struct {
 	GroupList []*BusinessTripCalendarGroup
 }
 
-func GetBusinessTripList(adminId int, startDate, endDate string) (list []*BusinessApplyView, err error) {
+func GetBusinessTripList(adminId, startDate, endDate string) (list []*BusinessApplyView, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT *
 			FROM  business_apply AS a
 			WHERE a.status IN('待审批','已审批')
 			AND ((a.arrive_date>=? AND a.arrive_date<=?) OR (a.return_date>=? AND a.return_date<=?)) `
-	if adminId > 0 {
-		sql += ` AND a.apply_admin_id=? `
+	if adminId != "" {
+		sql += ` AND a.apply_admin_id IN  (` + adminId + `)`
 		sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
-		_, err = o.Raw(sql, startDate, endDate, adminId).QueryRows(&list)
 	} else {
 		sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
-		_, err = o.Raw(sql, startDate, endDate, startDate, endDate).QueryRows(&list)
 	}
+	_, err = o.Raw(sql, startDate, endDate, startDate, endDate).QueryRows(&list)
 	return
 }