package youngee_talent_service import ( "strings" "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 AddTaskSketch(r *ghttp.Request) *TalentHttpResult { var sketchInfoReq *youngee_talent_model.AddTaskSketchRequest err := r.ParseForm(&sketchInfoReq) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } photoUrl := strings.Split(sketchInfoReq.PhotoUrl, ",") // 查询该任务id是否有未提交初稿 // 查询该任务是否有未提交脚本,无则插入,有则更新 unSubmitSketch, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", sketchInfoReq.TaskId).One() if err != nil { return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed"} } if unSubmitSketch != nil { // 如果有未提交初稿,则删除并重新添加 _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Where("sketch_id = ?", unSubmitSketch[dao.YounggeeSketchInfo.Columns.SketchId]).Delete() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto delete failed"} } _, err = g.DB().Model(model.YounggeeSketchInfo{}).Where("sketch_id = ?", unSubmitSketch[dao.YounggeeSketchInfo.Columns.SketchId]).Delete() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo delete failed"} } } // 如果无未提交初稿,则直接插入 sketchInfo := model.YounggeeSketchInfo{ TaskId: sketchInfoReq.TaskId, Title: sketchInfoReq.Title, Type: sketchInfoReq.Type, Content: sketchInfoReq.Content, CreateAt: gtime.Now(), IsReview: 0, IsSubmit: 0, IsOk: 0, } sketchId, err := g.DB().Model(model.YounggeeSketchInfo{}).Data(sketchInfo).InsertAndGetId() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo insert failed"} } for _, v := range photoUrl { _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"} } } sketchStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("sketch_status").Where("task_id = ?", sketchInfoReq.TaskId).Value() if err != nil { return &TalentHttpResult{Code: -5, Msg: "Get task info failed"} } if sketchStatus.Int64() == 1 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 2}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } else if sketchStatus.Int64() == 3 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } return &TalentHttpResult{Code: 0, Msg: "success"} } // 提交初稿service func SubmitTaskSketch(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 == 3 || 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.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count() if err != nil { return &TalentHttpResult{Code: -1, Msg: "YounggeeSketchInfo find failed"} } if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) { _, err = g.DB().Model(model.YounggeeSketchInfo{}).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: -3, Msg: "YounggeeSketchInfo update failed"} } _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", taskId).Update() if err != nil { return &TalentHttpResult{Code: -4, 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: -5, 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: 11, 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 GetTaskSketch(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") var sketchInfoList []*youngee_talent_model.TaskSketchInfo err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_submit = 1 and is_review = 1 and task_id = ?", taskId).OrderAsc("submit_at").Scan(&sketchInfoList) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } for _, v := range sketchInfoList { var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", v.SketchId).Scan(&sketchPhotoList) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } v.Photo = sketchPhotoList } return &TalentHttpResult{Code: 0, Msg: "success", Data: sketchInfoList} } // 查询未提交初稿service func GetUnSubmitTaskSketch(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") var unSubmitSketch *youngee_talent_model.TaskSketchInfo err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderAsc("submit_at").Scan(&unSubmitSketch) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch.SketchId).Scan(&sketchPhotoList) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } unSubmitSketch.Photo = sketchPhotoList return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch} }