package youngee_task_service import ( "fmt" "github.com/gogf/gf/util/gconv" "youngmini_server/app/dao" "youngmini_server/app/model" "youngmini_server/app/model/youngee_talent_model" "youngmini_server/app/utils" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/os/gtime" ) // 添加数据service 14 func AddTaskData(r *ghttp.Request) *TalentHttpResult { var DataInfoReq *youngee_talent_model.AddTaskDataRequest err := r.ParseForm(&DataInfoReq) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } taskDataInfo := []model.YounggeeDataInfo{} err = g.DB().Model(model.YounggeeLinkInfo{}).Where("task_id = ? ", DataInfoReq.TaskId).OrderDesc("create_at").Scan(&taskDataInfo) //上传过但是被拒了 var condition1 bool = len(taskDataInfo) != 0 && taskDataInfo[0].IsReview == 1 && taskDataInfo[0].IsOk == 0 //没有上传过初稿 var condition2 bool = len(taskDataInfo) == 0 //最新sketch数据 DataInfo := model.YounggeeDataInfo{ TaskId: DataInfoReq.TaskId, LikeNumber: DataInfoReq.LikeNumber, PlayNumber: DataInfoReq.PlayNumber, CommentNumber: DataInfoReq.CommentNumber, CollectNumber: DataInfoReq.CollectNumber, PhotoUrl: DataInfoReq.PhotoUrl, CreateAt: gtime.Now(), IsReview: 0, IsSubmit: 0, IsOk: 0, } if condition1 || condition2 { //插入新数据 DataId, err := g.DB().Model(model.YounggeeDataInfo{}).Data(DataInfo).InsertAndGetId() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeLinkInfo insert failed"} } //上传过,把旧的删掉 if condition1 { _, err := g.DB().Model(model.YounggeeDataInfo{}).Where("data_id=?", DataId).Delete() if err != nil { fmt.Println("err:", err.Error()) } } } else { //有数据,但是,还没有被审核,更新 dataId := taskDataInfo[0].DataId // 使用主键 ID 更新记录 _, err := g.DB().Model(model.YounggeeDataInfo{}).Where("data_id = ?", dataId).Data(DataInfo).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "YounggeeSketchInfo update failed"} } } DataStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("data_status").Where("task_id = ?", DataInfoReq.TaskId).Value() if err != nil { return &TalentHttpResult{Code: -5, Msg: "Get task info failed"} } if DataStatus.Int64() == 1 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 2}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } else if DataStatus.Int64() == 3 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 4}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } taskInfo := model.YoungeeTaskInfo{} // 查询是否处于违约状态 err = g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo) //修改task表的属性 err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo) if err1 != nil { return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"} } if taskInfo.CurDefaultType == 7 || 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 = ?", DataInfoReq.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 (?)", DataInfoReq.TaskId, g.Slice{1, 3, 4}).Update() if err1 != nil { return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"} } } //设置为数据待审 _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "14"}).Where("task_id = ?", DataInfoReq.TaskId).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"} } // 记录任务日志-上传数据 taskLog := model.YounggeeTaskLog{ TaskId: DataInfoReq.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{} err = g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo) if err != nil { return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"} } messageInfo := model.YounggeeMessageInfo{ MessageId: 13, 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 SubmitTaskData(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 == 7 || 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.YounggeeDataInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count() // if err != nil { // return &TalentHttpResult{Code: -1, Msg: "YounggeeDataInfo find failed"} // } // if res == 1 && (taskInfo.DataStatus == 2 || taskInfo.DataStatus == 4) { // _, err = g.DB().Model(model.YounggeeDataInfo{}).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: "YounggeeDataInfo update failed"} // } // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "14"}).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: 13, // 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 GetTaskData(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_submit = 1 and is_review = 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 GetUnSubmitTaskData(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_review = 0 and task_id = ?", taskId).One() if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } return &TalentHttpResult{Code: 0, Msg: "success", Data: res} } // 收藏种草项目 func ProjectCollection(r *ghttp.Request) *TalentHttpResult { tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r) pId := r.GetQueryString("project_id") record, err := g.DB().Model("younggee_project_collect_info").Where("talent_id = ? and project_id = ?", tId, pId).One() if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } if record == nil { collectionInfo := youngee_talent_model.ProjectCollection{ TalentId: tId, ProjectId: pId, CreateTime: gtime.Now(), Deleted: 0, } _, err = g.DB().Model("younggee_project_collect_info").Data(collectionInfo).Insert() } else { // 如果记录存在,更新 Delete 字段的值 和 收藏时间 fmt.Println("*******", record) currentDeleteValue := gconv.Int(record["deleted"]) newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0 _, err = g.DB().Model("younggee_project_collect_info"). Where("talent_id = ? and project_id = ?", tId, pId). Data(g.Map{ "deleted": newDeleteValue, "create_time": gtime.Now(), }).Update() if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } } return &TalentHttpResult{Code: 0, Msg: "collection success"} } // 收藏带货项目 //func SelectionCollection(r *ghttp.Request) *TalentHttpResult { // tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r) // selectionId := r.GetQueryString("selection_id") // productionId := r.GetQueryString("production_id") // record, err := g.DB().Model("younggee_selection_collect_info").Where("talent_id = ? and selection_id = ?", tId, selectionId).One() // if err != nil { // return &TalentHttpResult{Code: -1, Msg: err.Error()} // } // if record == nil { // collectionInfo := youngee_talent_model.SelectionCollection{ // TalentId: tId, // SelectionId: selectionId, // ProductId: productionId, // CreateTime: gtime.Now(), // Deleted: 0, // } // _, err = g.DB().Model("younggee_selection_collect_info").Data(collectionInfo).Insert() // // } else { // // 如果记录存在,更新 Delete 字段的值 和 收藏时间 // fmt.Println("*******", record) // currentDeleteValue := gconv.Int(record["deleted"]) // newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0 // _, err = g.DB().Model("younggee_selection_collect_info"). // Where("talent_id = ? and selection_id = ?", tId, selectionId). // Data(g.Map{ // "deleted": newDeleteValue, // "create_time": gtime.Now(), // }).Update() // if err != nil { // return &TalentHttpResult{Code: -1, Msg: err.Error()} // } // } // return &TalentHttpResult{Code: 0, Data: record["deleted"], Msg: "collection success"} //} func SelectionCollection(r *ghttp.Request) *TalentHttpResult { tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r) selectionId := r.GetQueryString("selection_id") productionId := r.GetQueryString("production_id") collectionRes := []youngee_talent_model.SelectionCollection{} err := g.DB().Model("younggee_selection_collect_info").Where("talent_id = ? and selection_id = ?", tId, selectionId).Scan(&collectionRes) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } // 1. 没有数据,插入新记录 if len(collectionRes) == 0 { collectInfo := &youngee_talent_model.SelectionCollection{ TalentId: tId, SelectionId: selectionId, ProductId: productionId, CreateTime: gtime.Now(), Deleted: 0, // 默认未删除状态 } _, err := g.DB().Model("younggee_selection_collect_info").Data(collectInfo).Insert() if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } return &TalentHttpResult{Code: 0, Msg: "收藏成功", Data: 0} //收藏 } // 2. 有数据,且 Deleted == 0,更新 Deleted 为 1(取消收藏) if len(collectionRes) != 0 && collectionRes[0].Deleted == 0 { _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{ "Deleted": 1, "UpdateTime": gtime.Now(), }).Update() if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } return &TalentHttpResult{Code: 0, Msg: "取消收藏成功", Data: 1} //取消收藏 } // 3. 有数据,且 Deleted == 1,更新 Deleted 为 0(重新收藏) if len(collectionRes) != 0 && collectionRes[0].Deleted == 1 { _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{ "Deleted": 0, "UpdateTime": gtime.Now(), }).Update() if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } return &TalentHttpResult{Code: 0, Msg: "重新收藏成功"} } return &TalentHttpResult{Code: 0, Msg: "操作成功"} }