123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package youngee_talent_service
- import (
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/gtime"
- )
- // 添加脚本service
- func AddTaskScript(r *ghttp.Request) *TalentHttpResult {
- var scriptInfoReq *youngee_talent_model.AddTaskScriptRequest
- err := r.ParseForm(&scriptInfoReq)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- scriptInfo := model.YounggeeScriptInfo{
- TaskId: scriptInfoReq.TaskId,
- Title: scriptInfoReq.Title,
- Content: scriptInfoReq.Content,
- CreateAt: gtime.Now(),
- IsReview: 0,
- IsSubmit: 0,
- IsOk: 0,
- }
- // 查询该任务是否有未提交脚本,无则插入,有则更新
- res, err := g.DB().Model(model.YounggeeScriptInfo{}).Where("task_id = ? and is_submit = 0", scriptInfoReq.TaskId).Count()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YounggeeScriptInfo find failed"}
- }
- if res == 0 {
- _, err = g.DB().Model(model.YounggeeScriptInfo{}).Data(scriptInfo).Insert()
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "YounggeeScriptInfo insert failed"}
- }
- } else {
- _, err = g.DB().Model(model.YounggeeScriptInfo{}).Where("task_id = ? and is_submit = 0", scriptInfoReq.TaskId).Update(g.Map{"title": scriptInfoReq.Title, "content": scriptInfoReq.Content, "create_at": gtime.Now()})
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: "YounggeeScriptInfo update failed"}
- }
- }
- scriptStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("script_status").Where("task_id = ?", scriptInfoReq.TaskId).Value()
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
- }
- if scriptStatus.Int64() == 1 {
- _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", scriptInfoReq.TaskId).Update(g.Map{"script_status": 2})
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
- }
- } else if scriptStatus.Int64() == 3 {
- _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", scriptInfoReq.TaskId).Update(g.Map{"script_status": 4})
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success"}
- }
- // 提交脚本service
- func SubmitTaskScript(r *ghttp.Request) *TalentHttpResult {
- taskId, _ := r.Get("task_id").(string)
- taskInfo := model.YoungeeTaskInfo{}
- // 查询是否处于违约状态
- err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
- if err1 != nil {
- return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
- }
- if taskInfo.CurDefaultType == 1 || taskInfo.CurDefaultType == 9 {
- // 若处于违约状态则解除并更新企业应支付金额
- _, err1 = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "real_payment": taskInfo.AllPayment, "err_break_rate": 0}).Where("task_id = ?", taskId).Update()
- if err1 != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
- }
- // 更新违约记录表
- _, err1 = g.DB().Model(model.YoungeeContractInfo{}).Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", taskId, g.Slice{1, 3, 4}).Update()
- if err1 != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
- }
- }
- // 查询该任务是否有已添加或已修改脚本
- res, err := g.DB().Model(model.YounggeeScriptInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "YounggeeScriptInfo find failed"}
- }
- if res == 1 && (taskInfo.ScriptStatus == 2 || taskInfo.ScriptStatus == 4) {
- _, err = g.DB().Model(model.YounggeeScriptInfo{}).Data(g.Map{"is_submit": "1", "submit_at": gtime.Now()}).Where("task_id = ? and is_submit = 0", taskId).Update()
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: "YounggeeScriptInfo update failed"}
- }
- _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "8"}).Where("task_id = ?", taskId).Update()
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
- }
- // 记录任务日志-上传脚本
- taskLog := model.YounggeeTaskLog{
- TaskId: taskId,
- Content: "上传脚本",
- LogAt: gtime.Now(),
- }
- _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
- if err != nil {
- return &TalentHttpResult{Code: -7, Msg: "YounggeeTaskLog insert failed"}
- }
- projectInfo := model.ProjectInfo{}
- err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
- if err1 != nil {
- return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
- }
- messageInfo := model.YounggeeMessageInfo{
- MessageId: 10,
- MessageType: 2,
- CreatedAt: gtime.Now(),
- TalentId: taskInfo.TalentId,
- ProjectName: projectInfo.ProjectName,
- IsReaded: 0,
- IsDeleted: 0,
- }
- _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
- if err != nil {
- return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success"}
- }
- // 查询脚本提交审阅记录service
- func GetTaskScript(r *ghttp.Request) *TalentHttpResult {
- taskId := r.Get("task_id")
- res, err := g.DB().Model(dao.YounggeeScriptInfo.Table).Where("is_submit = 1 and task_id = ?", taskId).OrderAsc("submit_at").All()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
- }
- // 查询未提交脚本service
- func GetUnSubmitTaskScript(r *ghttp.Request) *TalentHttpResult {
- taskId := r.Get("task_id")
- res, err := g.DB().Model(dao.YounggeeScriptInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderAsc("submit_at").One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
- }
|