Exemplo n.º 1
0
Arquivo: day.go Projeto: tangseng/gtt
func (this *DayController) Add() {
	this.info = &map[string]string{
		"post": "所有信息必须填写",
		"day":  "添加今天的工作内容失败(day)",
		"work": "添加今天的工作内容失败(work)",
		"plan": "没有这个工作计划",
		"err":  "操作失败",
		"ok":   "操作成功",
	}
	this.prefixInit()
	content := this.GetString("content")
	startTime, _ := this.GetInt("startTime")
	endTime, _ := this.GetInt("endTime")
	status, _ := this.GetInt8("status")
	planId, _ := this.GetInt("planId")
	appId, _ := this.GetInt("appId")
	if len(content) == 0 || startTime == 0 || endTime == 0 || status == 0 {
		this.error("post")
		return
	}
	if planId != 0 {
		planOption := models.NewPlanOption()
		plan, err := planOption.Read(planId)
		if err != nil {
			this.error("plan")
			return
		}
		plan.Status = status
		if plan.Status == 100 {
			plan.RealTime = this.Today.Unix()
		}
		planOption.Update(plan)
	}
	dayOption := models.NewDayOption()
	day, err := dayOption.ReadDay(this.user.Id, this.Y, this.M, this.D)
	if err != nil {
		day = models.NewDay(this.user.Id, this.Y, this.M, this.D)
		_, err = dayOption.Insert(day)
		if err != nil {
			this.error("day")
			return
		}
	}
	workid, err := dayOption.InsertWork(models.NewDayWork(content, startTime, endTime, status, day, planId))
	if err != nil {
		this.error("work")
		return
	}
	if appId > 0 {
		models.NewAppOption().Insert(models.NewApp(this.user.Id, appId, content))
	}
	this.success(map[string]interface{}{"id": workid})
}
Exemplo n.º 2
0
Arquivo: app.go Projeto: tangseng/gtt
func (this *AppController) Add() {
	if !this.check() {
		return
	}
	this.info = &map[string]string{
		"post": "内容必须填写",
		"err":  "操作失败",
		"ok":   "操作成功",
	}
	appid, _ := this.GetInt("appid")
	desc := this.GetString("desc")
	if len(desc) == 0 {
		this.error("post")
		return
	}
	id, err := models.NewAppOption().Insert(models.NewApp(this.user.Id, appid, desc))
	if err != nil {
		this.error("err")
		return
	}
	this.success(map[string]interface{}{"id": id})
}