iedc-go/app/question.go

88 lines
2.2 KiB
Go
Raw Permalink Normal View History

2022-10-30 15:44:05 +00:00
package app
import (
2022-10-30 17:18:19 +00:00
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
2022-10-30 15:44:05 +00:00
"fmt"
"time"
//"strings"
)
var Question = Ctr{
//获取个人信息
"update": func(this *Context) {
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
questionCompanyId := ObjToInt(this.Req.FormValue("id"))
if questionCompanyId == 0 {
this.Display(3, "参数错误")
return
}
data := this.Req.FormValue("question_data")
if data == "" {
this.Display(3, "没有上传数据")
return
}
status := ObjToInt(this.Req.FormValue("status"))
re := this.Db.Update("question_company", Map{"question_data": data, "status": status}, Map{"id": questionCompanyId})
if re == 0 {
//this.Display(4, "没有更新信息!")
fmt.Println(4, "没有更新信息!")
//return
}
this.Display(0, "更新成功")
},
//获取列表
"list": func(this *Context) {
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
t := time.Now().Unix()
questions := this.Db.Select("question", "*", Map{"AND": Map{"org_id": user.GetCeilInt("org_id"), "start_time[>=]": t, "end_time[<=]": t, "state": 0}})
re := []Map{}
for _, v := range questions {
questionCompany := this.Db.Get("question_company", "*", Map{"AND": Map{"question_id": v.GetCeilInt("id"), "company_id": user.GetCeilInt("company_id")}})
if questionCompany == nil {
questionCompany = Map{
"name": v.GetString("name"),
"question_data": v.GetString("question_data"),
"org_id": v.GetString("org_id"),
"question_id": v.GetString("id"),
"company_id": user.GetCeilInt("company_id"),
"user_id": user.GetString("id"),
"create_time": t,
"modify_time": t,
"status": 0,
"state": 0,
}
questionCompany["id"] = this.Db.Insert("question_company", questionCompany)
if questionCompany.GetCeilInt("id") == 0 {
this.Display(4, "无法创建调查数据")
return
}
}
delete(v, "question")
questionCompany["question"] = v
re = append(re, questionCompany)
}
//user["questions"]=re
this.Display(0, re)
},
}