123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- package youngee_task_service
- import (
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/gtime"
- "strings"
- "time"
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- )
- // 添加初稿service done
- 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, ",")
- //获取task表,根据创建时间倒序的数据
- taskSketchInfo := []youngee_talent_model.TaskSketchInfo{}
- err = g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? ", sketchInfoReq.TaskId).OrderDesc("create_at").Scan(&taskSketchInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed", Data: err.Error()}
- }
- var autoAgreeAt *gtime.Time
- //获取种草和本地生活的task表
- taskInfo := youngee_talent_model.YoungeeTaskInfo{}
- localTaskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
- //查找auto_task_info表 AutoAgreeAt= task的创建时间 + auto_task_info的review_auto
- if sketchInfoReq.TaskType == 1 {
- err = g.DB().Model("youngee_task_info").WithAll().Where("task_id = ?", sketchInfoReq.TaskId).Scan(&taskInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo find failed", Data: err.Error()}
- }
- autoTaskInfo, err := g.DB().Model("info_auto_task").Where("auto_task_id = ?", taskInfo.ProjectDetail.AutoTaskId).One()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
- }
- if autoTaskInfo != nil {
- autoAgreeAt = taskInfo.CreateDate.Add(time.Duration(autoTaskInfo["review_auto"].Int64()) * time.Hour)
- } else {
- return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
- }
- } else if sketchInfoReq.TaskType == 2 {
- err = g.DB().Model("youngee_local_task_info").WithAll().Where("task_id = ?", sketchInfoReq.TaskId).Scan(localTaskInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeLocalTaskInfo find failed", Data: err.Error()}
- }
- autoTaskInfo, err := g.DB().Model("info_auto_task").WithAll().Where("auto_task_id = ?", localTaskInfo.LocalInfoDetail.AutoTaskId).One()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
- }
- if autoTaskInfo != nil {
- autoAgreeAt = localTaskInfo.CreateDate.Add(time.Duration(autoTaskInfo["review_auto"].Int64()) * time.Hour)
- } else {
- return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
- }
- }
- // 种草 or 本地生活都使用此数据
- sketchInfo := model.YounggeeSketchInfo{
- TaskId: sketchInfoReq.TaskId,
- Title: sketchInfoReq.Title,
- Type: sketchInfoReq.Type,
- Content: sketchInfoReq.Content,
- CreateAt: gtime.Now(),
- IsReview: 0,
- IsSubmit: 0, //忽略
- IsOk: 0,
- TaskType: sketchInfoReq.TaskType, // 1:种草 2:本地生活
- AutoAgreeAt: autoAgreeAt, // 自动审核时间
- }
- //上传过但是被拒了
- var condition1 bool = len(taskSketchInfo) != 0 && taskSketchInfo[0].IsReview == 1 && taskSketchInfo[0].IsOk == 0
- //没有上传过初稿
- var condition2 bool = len(taskSketchInfo) == 0
- // 初稿一旦提交,不能修改,除非被驳回
- if condition1 || condition2 { //上传过但是被拒了 或者 没有上传过
- //插入新数据
- 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"}
- }
- }
- } else {
- return &TalentHttpResult{Code: -4, Msg: "已提交初稿,不能修改"}
- }
- if sketchInfoReq.TaskType == 1 { //种草
- //修改task表中的字段待添加变成已添加,待修改变成已修改
- sketchStatus, err := g.DB().Model(youngee_talent_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"}
- }
- }
- taskInfo := youngee_talent_model.YoungeeTaskInfo{}
- //task设置为初稿待审核
- _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
- // 若处于违约状态则解除
- if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
- //将task设置为未违约
- _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
- }
- // 更新违约记录表,default_status设置为已重新上传
- _, err = g.DB().Model(model.YoungeeContractInfo{}).Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", sketchInfoReq.TaskId, g.Slice{1, 3, 4}).Update()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
- }
- }
- // 记录任务日志-上传初稿
- taskLog := model.YounggeeTaskLog{
- TaskId: sketchInfoReq.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"}
- }
- } else if sketchInfoReq.TaskType == 2 { //本地生活
- //修改task表中的字段待添加变成已添加,待修改变成已修改
- sketchStatus, err := g.DB().Model("youngee_local_task_info").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("youngee_local_task_info").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("youngee_local_task_info").Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4})
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
- }
- }
- taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
- //task设置为初稿待审核
- _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
- // 若处于违约状态则解除
- if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
- //将task设置为未违约
- _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
- }
- // 更新违约记录表,default_status设置为已重新上传
- _, err = g.DB().Model(model.YoungeeContractInfo{}).Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", sketchInfoReq.TaskId, g.Slice{1, 3, 4}).Update()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
- }
- }
- // 记录任务日志-上传初稿
- taskLog := youngee_talent_model.YounggeeLocalTaskLog{
- TaskId: sketchInfoReq.TaskId,
- Content: "上传初稿",
- LogAt: gtime.Now(),
- }
- //上传日志,用于详情页判断上一个状态是什么
- _, err = g.DB().Model("younggee_local_task_log").Data(&taskLog).Insert()
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed", Data: err.Error()}
- }
- } else {
- return &TalentHttpResult{Code: -7, Msg: "TaskType error"}
- }
- //todo 添加初稿报错 ProjectInfo find 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 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"}
- // }
- // //若当前是违约状态
- //
- // //如果有提交过,且被拒绝
- //
- // // 查询该任务是否有已添加或已修改初稿
- // //add之后is_submit就是0 && sketch_status变成已添加/已修改
- // //
- // 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"}
- // }
- // // add之后一定会满足此条件
- // if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) {
- // //将这条task改成已提交并修改提交时间
- // _, 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"}
- // }
- // //将这条task_stage改成10(初稿待审)
- // _, 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 done
- func GetTaskSketch(r *ghttp.Request) *TalentHttpResult {
- taskId := r.GetQueryString("task_id")
- var sketchInfoList []*youngee_talent_model.TaskSketchInfo
- err := g.DB().Model("younggee_sketch_info").Where("is_review = 1 and task_id = ?", taskId).OrderDesc("create_at").Scan(&sketchInfoList)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- //每条审阅记录都有对应的图片or视频
- for _, v := range sketchInfoList {
- var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
- err = g.DB().Model("younggee_sketch_photo").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}
- }
- // 还未被审核过的初稿,如果有的话,返回,没有
- 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 is_ok = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- if len(unSubmitSketch) == 0 {
- return &TalentHttpResult{Code: 0, Msg: "没有未审核的初稿", Data: nil}
- } else {
- var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
- err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: err.Error()}
- }
- unSubmitSketch[0].Photo = sketchPhotoList
- return &TalentHttpResult{Code: 0, Msg: "存在未处理的初稿", Data: unSubmitSketch[0]}
- }
- }
- // hasProceededSketch
- func hasProceededSketch(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).OrderDesc("create_at").Scan(&unSubmitSketch)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- if len(unSubmitSketch) == 0 {
- return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
- } else {
- var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
- err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: err.Error()}
- }
- unSubmitSketch[0].Photo = sketchPhotoList
- return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch[0]}
- }
- }
|