task_sketch.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. package youngee_task_service
  2. import (
  3. "github.com/gogf/gf/frame/g"
  4. "github.com/gogf/gf/net/ghttp"
  5. "github.com/gogf/gf/os/gtime"
  6. "strings"
  7. "time"
  8. "youngmini_server/app/dao"
  9. "youngmini_server/app/model"
  10. "youngmini_server/app/model/youngee_talent_model"
  11. )
  12. // 添加初稿service done
  13. func AddTaskSketch(r *ghttp.Request) *TalentHttpResult {
  14. var sketchInfoReq *youngee_talent_model.AddTaskSketchRequest
  15. //解析添加初稿的图文
  16. err := r.ParseForm(&sketchInfoReq)
  17. if err != nil {
  18. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  19. }
  20. photoUrl := strings.Split(sketchInfoReq.PhotoUrl, ",")
  21. //获取task表,根据创建时间倒序的数据
  22. taskSketchInfo := []youngee_talent_model.TaskSketchInfo{}
  23. err = g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? ", sketchInfoReq.TaskId).OrderDesc("create_at").Scan(&taskSketchInfo)
  24. if err != nil {
  25. return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed", Data: err.Error()}
  26. }
  27. var autoAgreeAt *gtime.Time
  28. //获取种草和本地生活的task表
  29. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  30. localTaskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  31. //查找auto_task_info表 AutoAgreeAt= task的创建时间 + auto_task_info的review_auto
  32. if sketchInfoReq.TaskType == 1 {
  33. err = g.DB().Model("youngee_task_info").WithAll().Where("task_id = ?", sketchInfoReq.TaskId).Scan(&taskInfo)
  34. if err != nil {
  35. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo find failed", Data: err.Error()}
  36. }
  37. autoTaskInfo, err := g.DB().Model("info_auto_task").Where("auto_task_id = ?", taskInfo.ProjectDetail.AutoTaskId).One()
  38. if err != nil {
  39. return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
  40. }
  41. if autoTaskInfo != nil {
  42. autoAgreeAt = taskInfo.CreateDate.Add(time.Duration(autoTaskInfo["review_auto"].Int64()) * time.Hour)
  43. } else {
  44. return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
  45. }
  46. } else if sketchInfoReq.TaskType == 2 {
  47. err = g.DB().Model("youngee_local_task_info").WithAll().Where("task_id = ?", sketchInfoReq.TaskId).Scan(localTaskInfo)
  48. if err != nil {
  49. return &TalentHttpResult{Code: -2, Msg: "YoungeeLocalTaskInfo find failed", Data: err.Error()}
  50. }
  51. autoTaskInfo, err := g.DB().Model("info_auto_task").WithAll().Where("auto_task_id = ?", localTaskInfo.LocalInfoDetail.AutoTaskId).One()
  52. if err != nil {
  53. return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
  54. }
  55. if autoTaskInfo != nil {
  56. autoAgreeAt = localTaskInfo.CreateDate.Add(time.Duration(autoTaskInfo["review_auto"].Int64()) * time.Hour)
  57. } else {
  58. return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
  59. }
  60. }
  61. // 种草 or 本地生活都使用此数据
  62. sketchInfo := model.YounggeeSketchInfo{
  63. TaskId: sketchInfoReq.TaskId,
  64. Title: sketchInfoReq.Title,
  65. Type: sketchInfoReq.Type,
  66. Content: sketchInfoReq.Content,
  67. CreateAt: gtime.Now(),
  68. IsReview: 0,
  69. IsSubmit: 0, //忽略
  70. IsOk: 0,
  71. TaskType: sketchInfoReq.TaskType, // 1:种草 2:本地生活
  72. AutoAgreeAt: autoAgreeAt, // 自动审核时间
  73. }
  74. //上传过但是被拒了
  75. var condition1 bool = len(taskSketchInfo) != 0 && taskSketchInfo[0].IsReview == 1 && taskSketchInfo[0].IsOk == 0
  76. //没有上传过初稿
  77. var condition2 bool = len(taskSketchInfo) == 0
  78. // 初稿一旦提交,不能修改,除非被驳回
  79. if condition1 || condition2 { //上传过但是被拒了 或者 没有上传过
  80. //插入新数据
  81. sketchId, err := g.DB().Model(model.YounggeeSketchInfo{}).Data(sketchInfo).InsertAndGetId()
  82. if err != nil {
  83. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo insert failed"}
  84. }
  85. //插入新图片
  86. for _, v := range photoUrl {
  87. _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert()
  88. if err != nil {
  89. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"}
  90. }
  91. }
  92. } else {
  93. return &TalentHttpResult{Code: -4, Msg: "已提交初稿,不能修改"}
  94. }
  95. if sketchInfoReq.TaskType == 1 { //种草
  96. //修改task表中的字段待添加变成已添加,待修改变成已修改
  97. sketchStatus, err := g.DB().Model(youngee_talent_model.YoungeeTaskInfo{}).Fields("sketch_status").Where("task_id = ?", sketchInfoReq.TaskId).Value()
  98. if err != nil {
  99. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  100. }
  101. if sketchStatus.Int64() == 1 {
  102. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 2})
  103. if err != nil {
  104. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  105. }
  106. } else if sketchStatus.Int64() == 3 {
  107. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4})
  108. if err != nil {
  109. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  110. }
  111. }
  112. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  113. //task设置为初稿待审核
  114. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  115. // 若处于违约状态则解除
  116. if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
  117. //将task设置为未违约
  118. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  119. if err != nil {
  120. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  121. }
  122. // 更新违约记录表,default_status设置为已重新上传
  123. _, 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()
  124. if err != nil {
  125. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  126. }
  127. }
  128. // 记录任务日志-上传初稿
  129. taskLog := model.YounggeeTaskLog{
  130. TaskId: sketchInfoReq.TaskId,
  131. Content: "上传初稿",
  132. LogAt: gtime.Now(),
  133. }
  134. //上传日志,用于详情页判断上一个状态是什么
  135. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  136. if err != nil {
  137. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  138. }
  139. } else if sketchInfoReq.TaskType == 2 { //本地生活
  140. //修改task表中的字段待添加变成已添加,待修改变成已修改
  141. sketchStatus, err := g.DB().Model("youngee_local_task_info").Fields("sketch_status").Where("task_id = ?", sketchInfoReq.TaskId).Value()
  142. if err != nil {
  143. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  144. }
  145. if sketchStatus.Int64() == 1 {
  146. _, err = g.Model("youngee_local_task_info").Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 2})
  147. if err != nil {
  148. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  149. }
  150. } else if sketchStatus.Int64() == 3 {
  151. _, err = g.Model("youngee_local_task_info").Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4})
  152. if err != nil {
  153. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  154. }
  155. }
  156. taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  157. //task设置为初稿待审核
  158. _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  159. // 若处于违约状态则解除
  160. if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
  161. //将task设置为未违约
  162. _, 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()
  163. if err != nil {
  164. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  165. }
  166. // 更新违约记录表,default_status设置为已重新上传
  167. _, 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()
  168. if err != nil {
  169. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  170. }
  171. }
  172. // 记录任务日志-上传初稿
  173. taskLog := youngee_talent_model.YounggeeLocalTaskLog{
  174. TaskId: sketchInfoReq.TaskId,
  175. Content: "上传初稿",
  176. LogAt: gtime.Now(),
  177. }
  178. //上传日志,用于详情页判断上一个状态是什么
  179. _, err = g.DB().Model("younggee_local_task_log").Data(&taskLog).Insert()
  180. if err != nil {
  181. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed", Data: err.Error()}
  182. }
  183. } else {
  184. return &TalentHttpResult{Code: -7, Msg: "TaskType error"}
  185. }
  186. //todo 添加初稿报错 ProjectInfo find failed
  187. //插入一条消息
  188. //projectInfo := model.ProjectInfo{}
  189. //err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  190. //if err1 != nil {
  191. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  192. //}
  193. //messageInfo := model.YounggeeMessageInfo{
  194. // MessageId: 11,
  195. // MessageType: 2,
  196. // CreatedAt: gtime.Now(),
  197. // TalentId: taskInfo.TalentId,
  198. // ProjectName: projectInfo.ProjectName,
  199. // IsReaded: 0,
  200. // IsDeleted: 0,
  201. //}
  202. //_, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  203. //if err != nil {
  204. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  205. //}
  206. return &TalentHttpResult{Code: 0, Msg: "success"}
  207. }
  208. // 提交初稿service
  209. //func SubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  210. // taskId, _ := r.Get("task_id").(string) // 查询是否处于违约状态
  211. // taskInfo := model.YoungeeTaskInfo{}
  212. // // 查询是否处于违约状态
  213. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  214. // if err1 != nil {
  215. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  216. // }
  217. // //若当前是违约状态
  218. //
  219. // //如果有提交过,且被拒绝
  220. //
  221. // // 查询该任务是否有已添加或已修改初稿
  222. // //add之后is_submit就是0 && sketch_status变成已添加/已修改
  223. // //
  224. // res, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  225. // if err != nil {
  226. // return &TalentHttpResult{Code: -1, Msg: "YounggeeSketchInfo find failed"}
  227. // }
  228. // // add之后一定会满足此条件
  229. // if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) {
  230. // //将这条task改成已提交并修改提交时间
  231. // _, 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()
  232. // if err != nil {
  233. // return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo update failed"}
  234. // }
  235. // //将这条task_stage改成10(初稿待审)
  236. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", taskId).Update()
  237. // if err != nil {
  238. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  239. // }
  240. // // 记录任务日志-上传初稿
  241. // taskLog := model.YounggeeTaskLog{
  242. // TaskId: taskId,
  243. // Content: "上传初稿",
  244. // LogAt: gtime.Now(),
  245. // }
  246. // //上传日志,用于详情页判断上一个状态是什么
  247. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  248. // if err != nil {
  249. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  250. // }
  251. // //插入一条消息
  252. // projectInfo := model.ProjectInfo{}
  253. // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  254. // if err1 != nil {
  255. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  256. // }
  257. // messageInfo := model.YounggeeMessageInfo{
  258. // MessageId: 11,
  259. // MessageType: 2,
  260. // CreatedAt: gtime.Now(),
  261. // TalentId: taskInfo.TalentId,
  262. // ProjectName: projectInfo.ProjectName,
  263. // IsReaded: 0,
  264. // IsDeleted: 0,
  265. // }
  266. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  267. // if err != nil {
  268. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  269. // }
  270. // }
  271. //
  272. // return &TalentHttpResult{Code: 0, Msg: "success"}
  273. //}
  274. // 查询初稿提交审阅记录service done
  275. func GetTaskSketch(r *ghttp.Request) *TalentHttpResult {
  276. taskId := r.GetQueryString("task_id")
  277. var sketchInfoList []*youngee_talent_model.TaskSketchInfo
  278. err := g.DB().Model("younggee_sketch_info").Where("is_review = 1 and task_id = ?", taskId).OrderDesc("create_at").Scan(&sketchInfoList)
  279. if err != nil {
  280. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  281. }
  282. //每条审阅记录都有对应的图片or视频
  283. for _, v := range sketchInfoList {
  284. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  285. err = g.DB().Model("younggee_sketch_photo").Where("sketch_id = ?", v.SketchId).Scan(&sketchPhotoList)
  286. if err != nil {
  287. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  288. }
  289. v.Photo = sketchPhotoList
  290. }
  291. return &TalentHttpResult{Code: 0, Msg: "success", Data: sketchInfoList}
  292. }
  293. // 还未被审核过的初稿,如果有的话,返回,没有
  294. func GetUnSubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  295. taskId := r.Get("task_id")
  296. var unSubmitSketch []*youngee_talent_model.TaskSketchInfo
  297. // 获取当前任务的最新,未审核的初稿
  298. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and is_ok = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch)
  299. if err != nil {
  300. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  301. }
  302. if len(unSubmitSketch) == 0 {
  303. return &TalentHttpResult{Code: 0, Msg: "没有未审核的初稿", Data: nil}
  304. } else {
  305. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  306. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
  307. if err != nil {
  308. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  309. }
  310. unSubmitSketch[0].Photo = sketchPhotoList
  311. return &TalentHttpResult{Code: 0, Msg: "存在未处理的初稿", Data: unSubmitSketch[0]}
  312. }
  313. }
  314. // hasProceededSketch
  315. func hasProceededSketch(r *ghttp.Request) *TalentHttpResult {
  316. taskId := r.Get("task_id")
  317. var unSubmitSketch []*youngee_talent_model.TaskSketchInfo
  318. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch)
  319. if err != nil {
  320. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  321. }
  322. if len(unSubmitSketch) == 0 {
  323. return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
  324. } else {
  325. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  326. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
  327. if err != nil {
  328. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  329. }
  330. unSubmitSketch[0].Photo = sketchPhotoList
  331. return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch[0]}
  332. }
  333. }