Ejemplo n.º 1
0
func (c App) DoCheckLeave(id int, action string) revel.Result {
	//检查权限
	leaveTransfer := new(models.LeaveTransfer)
	has, _ := app.Engine.Where("leave_id=? and assign_to=?", id, c.User.Id).Get(leaveTransfer)
	if !has {
		return c.Redirect("/")
	}

	leave := new(models.Leave)
	app.Engine.Id(id).Get(leave)

	//获取请假人信息
	userProfile := new(models.UserProfiles)
	app.Engine.Id(leave.UserId).Get(userProfile)

	if action == "agree" {
		err := c.getLeaveInchargeProfile(userProfile, leave, true)
		if err != nil {
			c.Flash.Error(err.Error())
			c.FlashParams()
		}

		if leaveTransfer.IsAgree == utils.LEAVE_CHECKING {
			leaveTransfer.IsAgree = utils.LEAVE_CHECK_OK
			app.Engine.Cols("is_agree").Update(leaveTransfer)
		}

		app.Engine.Cols("in_charge_user_id").Cols("status").Cols("updated_at").Update(leave)

		if leave.Status != utils.LEAVE_STATUS_CANCEL_OK && leave.InChargeUserId > 0 {
			transfer := new(models.LeaveTransfer)
			transfer.LeaveId = leave.Id
			transfer.AssignFr = leave.UserId
			transfer.AssignTo = leave.InChargeUserId
			transfer.IsAgree = 0
			transfer.CreatedAt = time.Now()
			transfer.UpdatedAt = transfer.CreatedAt
			app.Engine.Insert(transfer)
		}
	} else {
		err := c.getLeaveInchargeProfile(userProfile, leave, false)
		if err != nil {
			c.Flash.Error(err.Error())
			c.FlashParams()
		}

		if leaveTransfer.IsAgree == utils.LEAVE_CHECKING {
			leaveTransfer.IsAgree = utils.LEAVE_CHECK_FAIL
			app.Engine.Cols("is_agree").Update(leaveTransfer)
		}

		app.Engine.Cols("in_charge_user_id").Cols("status").Cols("updated_at").Update(leave)
	}

	return c.Redirect("viewCheckDetail?id=" + fmt.Sprintf("%d", id))
}
Ejemplo n.º 2
0
func (c App) DoAddLeave(reason string, leave_type int, startdate, enddate time.Time, address string, onway_date int, filepath string) revel.Result {

	leave := new(models.Leave)
	leave.UserId = c.User.Id
	leave.Status = utils.LEAVE_STATUS_ASKING
	leave.LeaveType = leave_type
	leave.Reason = reason
	leave.Address = address
	leave.OnwayDate = onway_date
	leave.Filepath = filepath
	leave.Startdate = startdate
	leave.Enddate = enddate
	leave.Duration = fmt.Sprintf("%.1f", enddate.Sub(startdate).Seconds()/86400)
	leave.CreatedAt = time.Now()
	leave.UpdatedAt = leave.CreatedAt
	revel.INFO.Println("DoAddLeave", startdate, enddate)

	leave.FlowId = c.getLeaveFlowId(c.UserProfile, leave)
	leave.StepId = "0" //第0步,
	err := c.getLeaveInchargeProfile(c.UserProfile, leave, true)

	if err != nil {
		c.Flash.Error(err.Error())
		c.FlashParams()
		return c.Redirect("/app/addLeave")
	}

	app.Engine.Insert(leave)

	transfer := new(models.LeaveTransfer)
	transfer.LeaveId = leave.Id
	transfer.AssignFr = leave.UserId
	transfer.AssignTo = leave.InChargeUserId
	transfer.IsAgree = 0
	transfer.CreatedAt = time.Now()
	transfer.UpdatedAt = transfer.CreatedAt

	app.Engine.Insert(transfer)
	//获取处理负责人

	return c.Redirect("/app/listLeave")
}