func (this *PlanController) Update() { this.prefixInit() if !this.checkForm(false) { return } id, _ := this.GetInt("id") if id == 0 { this.error("id") return } planOption := models.NewPlanOption() plan, err := planOption.Read(id) if err != nil { this.error("id") return } if plan.Uid != this.user.Id { this.error("auth") return } plan.Content = this.Content plan.StartTime = this.StartTime plan.EndTime = this.EndTime _, err = planOption.Update(plan) if err != nil { this.error("err") return } this.success("ok") }
func (this *PlanController) Delete() { this.info = &map[string]string{ "auth": "该计划你没有权限删除", "id": "不存在该计划", "err": "操作失败", "ok": "操作成功", } id, _ := this.GetInt("id") if id == 0 { this.error("id") return } planOption := models.NewPlanOption() plan, err := planOption.Read(id) if err != nil { this.error("id") return } if plan.Uid != this.user.Id { this.error("auth") return } err = planOption.Delete(id) if err != nil { this.error("err") return } this.success("ok") }
func (this *MonthController) Plan() { this.info = &map[string]string{ "diff": "所请求的时间大于一个月的时间", } startTime, _ := this.GetInt64("start") endTime, _ := this.GetInt64("end") if endTime-startTime > 32*24*3600 { this.error("diff") return } isAdmin := this.IsAdmin() planOption := models.NewPlanOption() var plans []models.Plan if isAdmin { plans = planOption.ReadInMonth(startTime, endTime) } else { persons := models.NewPersonOption().ReadByGroup(this.user.Group) uids := make([]int, 0) for _, person := range persons { uids = append(uids, person.Id) } plans = planOption.ReadByUidsInMonth(uids, startTime, endTime) } this.success(plans) }
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}) }
func (this *PlanController) Add() { this.prefixInit() if !this.checkForm(true) { return } planOption := models.NewPlanOption() id, err := planOption.Insert(models.NewPlan(this.user.Id, this.Content, this.StartTime, this.EndTime)) if err != nil { this.error("err") return } this.success(map[string]interface{}{"id": id}) }
func (this *DayController) Update() { if !this.prefixCheck() { return } content := this.GetString("content") startTime, _ := this.GetInt("startTime") endTime, _ := this.GetInt("endTime") status, _ := this.GetInt8("status") if len(content) == 0 || startTime == 0 || endTime == 0 || status == 0 { this.error("post") return } date, _ := this.GetInt64("date") timer := time.Unix(date, 0) y := timer.Year() m := int(timer.Month()) d := timer.Day() dayOption := models.NewDayOption() id, _ := this.GetInt("id") dayWork, err := dayOption.ReadDayWork(id) if err != nil { this.error("id") return } planId := dayWork.PlanId if planId != 0 { planOption := models.NewPlanOption() plan, err := planOption.Read(planId) if err == nil && plan != nil { plan.Status = status if plan.Status == 100 { plan.RealTime = this.Today.Unix() } planOption.Update(plan) } } oldDay, _ := dayOption.ReadDayById(dayWork.Day.Id, false) day, err := dayOption.ReadDay(oldDay.Uid, y, m, d) if err != nil { day = models.NewDay(oldDay.Uid, y, m, d) _, err = dayOption.Insert(day) if err != nil { this.error("day") return } } dayWork.Content = content dayWork.StartTime = startTime dayWork.EndTime = endTime dayWork.Status = status dayWork.Day = day dayWork.Time = uint64(date) _, err = dayOption.UpdateDayWork(dayWork, "") if err != nil { this.error("err") return } this.success("ok") }
func (this *PlanController) GetComplete() { plans := models.NewPlanOption().ReadByUidOfComplete(this.user.Id, 10) this.success(plans) }
func (this *PlanController) Get() { plans := models.NewPlanOption().ReadByUid(this.user.Id) this.success(plans) }