task_data.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/frame/g"
  5. "github.com/gogf/gf/net/ghttp"
  6. "github.com/gogf/gf/os/gtime"
  7. "github.com/gogf/gf/util/gconv"
  8. "time"
  9. "youngmini_server/app/dao"
  10. "youngmini_server/app/model"
  11. "youngmini_server/app/model/youngee_talent_model"
  12. "youngmini_server/app/utils"
  13. )
  14. // 添加数据service
  15. func AddTaskData(r *ghttp.Request) *TalentHttpResult {
  16. var DataInfoReq *youngee_talent_model.AddTaskDataRequest
  17. err := r.ParseForm(&DataInfoReq)
  18. if err != nil {
  19. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  20. }
  21. taskDataInfo := []model.YounggeeDataInfo{}
  22. err = g.DB().Model(model.YounggeeDataInfo{}).Where("task_id = ? ", DataInfoReq.TaskId).OrderDesc("create_at").Scan(&taskDataInfo)
  23. var autoAgreeAt *gtime.Time
  24. //获取种草和本地生活的task表
  25. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  26. localTaskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  27. //查找auto_task_info表 AutoAgreeAt= task的创建时间 + auto_task_info的task_finish_auto
  28. if DataInfoReq.TaskType == 1 {
  29. err = g.DB().Model("youngee_task_info").WithAll().Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  30. if err != nil {
  31. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo find failed", Data: err.Error()}
  32. }
  33. autoTaskInfo, err := g.DB().Model("info_auto_task").Where("auto_task_id = ?", taskInfo.ProjectDetail.AutoTaskId).One()
  34. if err != nil {
  35. return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
  36. }
  37. if autoTaskInfo != nil {
  38. autoAgreeAt = taskInfo.CreateDate.Add(time.Duration(autoTaskInfo["task_finish_auto"].Int64()) * time.Hour)
  39. } else {
  40. return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
  41. }
  42. } else if DataInfoReq.TaskType == 2 {
  43. err = g.DB().Model("youngee_local_task_info").WithAll().Where("task_id = ?", DataInfoReq.TaskId).Scan(&localTaskInfo)
  44. if err != nil {
  45. return &TalentHttpResult{Code: -2, Msg: "YoungeeLocalTaskInfo find failed", Data: err.Error()}
  46. }
  47. autoTaskInfo, err := g.DB().Model("info_auto_task").WithAll().Where("auto_task_id = ?", localTaskInfo.LocalInfoDetail.AutoTaskId).One()
  48. if err != nil {
  49. return &TalentHttpResult{Code: -2, Msg: "InfoAutoTask find failed", Data: err.Error()}
  50. }
  51. if autoTaskInfo != nil {
  52. autoAgreeAt = localTaskInfo.CreateDate.Add(time.Duration(autoTaskInfo["task_finish_auto"].Int64()) * time.Hour)
  53. } else {
  54. return &TalentHttpResult{Code: -2, Msg: "auto_task_id not found"}
  55. }
  56. }
  57. //最新data数据
  58. DataInfo := model.YounggeeDataInfo{
  59. TaskId: DataInfoReq.TaskId,
  60. LikeNumber: DataInfoReq.LikeNumber,
  61. PlayNumber: DataInfoReq.PlayNumber,
  62. CommentNumber: DataInfoReq.CommentNumber,
  63. CollectNumber: DataInfoReq.CollectNumber,
  64. PhotoUrl: DataInfoReq.PhotoUrl,
  65. ForwardNumber: DataInfoReq.ForwardNumber,
  66. CreateAt: gtime.Now(),
  67. IsReview: 0,
  68. IsSubmit: 0,
  69. IsOk: 0,
  70. AutoAgreeAt: autoAgreeAt,
  71. }
  72. //上传过但是被拒了
  73. var condition1 bool = len(taskDataInfo) != 0 && taskDataInfo[0].IsReview == 1 && taskDataInfo[0].IsOk == 0
  74. //没有上传过初稿
  75. var condition2 bool = len(taskDataInfo) == 0
  76. if condition1 || condition2 {
  77. //插入新数据
  78. _, err := g.DB().Model(model.YounggeeDataInfo{}).Data(DataInfo).InsertAndGetId()
  79. if err != nil {
  80. return &TalentHttpResult{Code: -3, Msg: "YounggeeLinkInfo insert failed"}
  81. }
  82. } else {
  83. return &TalentHttpResult{Code: -1, Msg: "数据已提交,请勿重复提交"}
  84. }
  85. if DataInfoReq.TaskType == 1 { //种草
  86. DataStatus, err := g.DB().Model("youngee_task_info").Fields("data_status").Where("task_id = ?", DataInfoReq.TaskId).Value()
  87. if err != nil {
  88. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  89. }
  90. if DataStatus.Int64() == 1 {
  91. _, err = g.Model("youngee_task_info").Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 2})
  92. if err != nil {
  93. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  94. }
  95. } else if DataStatus.Int64() == 3 {
  96. _, err = g.Model("youngee_task_info").Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 4})
  97. if err != nil {
  98. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  99. }
  100. }
  101. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  102. // 查询是否处于违约状态
  103. err = g.DB().Model("youngee_task_info").Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  104. //修改task表的属性
  105. err1 := g.DB().Model("youngee_task_info").Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  106. if err1 != nil {
  107. return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  108. }
  109. if taskInfo.CurDefaultType == 7 || taskInfo.CurDefaultType == 9 {
  110. // 若处于违约状态则解除并更新企业应支付金额
  111. _, err1 = g.DB().Model("youngee_task_info").Data(g.Map{"cur_default_type": "0", "real_payment": taskInfo.AllPayment, "err_break_rate": 0}).Where("task_id = ?", DataInfoReq.TaskId).Update()
  112. if err1 != nil {
  113. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  114. }
  115. // 更新违约记录表
  116. _, err1 = g.DB().Model("youngee_task_info").Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", DataInfoReq.TaskId, g.Slice{1, 3, 4}).Update()
  117. if err1 != nil {
  118. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  119. }
  120. }
  121. //设置为数据待审
  122. _, err = g.DB().Model("youngee_task_info").Data(g.Map{"task_stage": "14"}).Where("task_id = ?", DataInfoReq.TaskId).Update()
  123. if err != nil {
  124. return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  125. }
  126. // 记录任务日志-上传数据
  127. taskLog := model.YounggeeTaskLog{
  128. TaskId: DataInfoReq.TaskId,
  129. Content: "上传数据",
  130. LogAt: gtime.Now(),
  131. }
  132. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  133. if err != nil {
  134. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  135. }
  136. } else if DataInfoReq.TaskType == 2 { //本地生活
  137. DataStatus, err := g.DB().Model("youngee_local_task_info").Fields("data_status").Where("task_id = ?", DataInfoReq.TaskId).Value()
  138. if err != nil {
  139. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  140. }
  141. if DataStatus.Int64() == 1 {
  142. _, err = g.Model("youngee_local_task_info").Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 2})
  143. if err != nil {
  144. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  145. }
  146. } else if DataStatus.Int64() == 3 {
  147. _, err = g.Model("youngee_local_task_info").Where("task_id = ?", DataInfoReq.TaskId).Update(g.Map{"data_status": 4})
  148. if err != nil {
  149. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  150. }
  151. }
  152. taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  153. //修改task表的属性
  154. err1 := g.DB().Model("youngee_local_task_info").Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  155. if err1 != nil {
  156. return &TalentHttpResult{Code: -1, Msg: "youngee_local_task_info find failed"}
  157. }
  158. if taskInfo.CurDefaultType == 7 || taskInfo.CurDefaultType == 9 {
  159. // 若处于违约状态则解除并更新企业应支付金额
  160. _, err1 = g.DB().Model("youngee_local_task_info").Data(g.Map{"cur_default_type": "0", "real_payment": taskInfo.AllPayment, "err_break_rate": 0}).Where("task_id = ?", DataInfoReq.TaskId).Update()
  161. if err1 != nil {
  162. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  163. }
  164. // 更新违约记录表
  165. _, 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()
  166. if err1 != nil {
  167. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  168. }
  169. }
  170. //设置为数据待审
  171. _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"task_stage": "14"}).Where("task_id = ?", DataInfoReq.TaskId).Update()
  172. if err != nil {
  173. return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  174. }
  175. // 记录任务日志-上传数据
  176. taskLog := youngee_talent_model.YounggeeLocalTaskLog{
  177. TaskId: DataInfoReq.TaskId,
  178. Content: "上传数据",
  179. LogAt: gtime.Now(),
  180. }
  181. _, err = g.DB().Model("younggee_local_task_log").Data(&taskLog).Insert()
  182. if err != nil {
  183. return &TalentHttpResult{Code: -5, Msg: "youngee_local_task_info insert failed", Data: err.Error()}
  184. }
  185. }
  186. return &TalentHttpResult{Code: 0, Msg: "success"}
  187. }
  188. // 提交数据service
  189. //func SubmitTaskData(r *ghttp.Request) *TalentHttpResult {
  190. // taskId, _ := r.Get("task_id").(string)
  191. // taskInfo := model.YoungeeTaskInfo{}
  192. // // 查询是否处于违约状态
  193. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  194. // if err1 != nil {
  195. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  196. // }
  197. // if taskInfo.CurDefaultType == 7 || taskInfo.CurDefaultType == 9 {
  198. // // 若处于违约状态则解除并更新企业应支付金额
  199. // _, 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()
  200. // if err1 != nil {
  201. // return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  202. // }
  203. //
  204. // // 更新违约记录表
  205. // _, 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()
  206. // if err1 != nil {
  207. // return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  208. // }
  209. // }
  210. //
  211. // // 查询该任务是否有已添加或已修改数据
  212. // res, err := g.DB().Model(model.YounggeeDataInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  213. // if err != nil {
  214. // return &TalentHttpResult{Code: -1, Msg: "YounggeeDataInfo find failed"}
  215. // }
  216. // if res == 1 && (taskInfo.DataStatus == 2 || taskInfo.DataStatus == 4) {
  217. // _, 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()
  218. // if err != nil {
  219. // return &TalentHttpResult{Code: -3, Msg: "YounggeeDataInfo update failed"}
  220. // }
  221. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "14"}).Where("task_id = ?", taskId).Update()
  222. // if err != nil {
  223. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  224. // }
  225. // // 记录任务日志-上传数据
  226. // taskLog := model.YounggeeTaskLog{
  227. // TaskId: taskId,
  228. // Content: "上传数据",
  229. // LogAt: gtime.Now(),
  230. // }
  231. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  232. // if err != nil {
  233. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  234. // }
  235. // projectInfo := model.ProjectInfo{}
  236. // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  237. // if err1 != nil {
  238. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  239. // }
  240. // messageInfo := model.YounggeeMessageInfo{
  241. // MessageId: 13,
  242. // MessageType: 2,
  243. // CreatedAt: gtime.Now(),
  244. // TalentId: taskInfo.TalentId,
  245. // ProjectName: projectInfo.ProjectName,
  246. // IsReaded: 0,
  247. // IsDeleted: 0,
  248. // }
  249. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  250. // if err != nil {
  251. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  252. // }
  253. // }
  254. //
  255. // return &TalentHttpResult{Code: 0, Msg: "success"}
  256. //}
  257. // 查询数据提交审阅记录service
  258. func GetTaskData(r *ghttp.Request) *TalentHttpResult {
  259. taskId := r.Get("task_id")
  260. res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderAsc("submit_at").All()
  261. if err != nil {
  262. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  263. }
  264. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  265. }
  266. // 查询未提交数据service
  267. func GetUnSubmitTaskData(r *ghttp.Request) *TalentHttpResult {
  268. taskId := r.Get("task_id")
  269. res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_review = 0 and is_ok = 0 and task_id = ?", taskId).One()
  270. if err != nil {
  271. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  272. }
  273. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  274. }
  275. // 收藏种草项目
  276. func LocalCollection(r *ghttp.Request) *TalentHttpResult {
  277. tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  278. localId := r.GetQueryString("local_id", "")
  279. if localId == "" {
  280. return &TalentHttpResult{Code: -1, Msg: "参数传递有误"}
  281. }
  282. record, err := g.DB().Model("younggee_local_collect_info").Where("talent_id = ? and local_id = ?", tId, localId).One()
  283. if err != nil {
  284. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  285. }
  286. if record == nil {
  287. collectionInfo := youngee_talent_model.LocalCollection{
  288. TalentId: tId,
  289. LocalId: localId,
  290. CreateTime: gtime.Now(),
  291. Deleted: 0,
  292. }
  293. _, err = g.DB().Model("younggee_local_collect_info").Data(collectionInfo).Insert()
  294. } else {
  295. // 如果记录存在,更新 Delete 字段的值 和 收藏时间
  296. currentDeleteValue := gconv.Int(record["deleted"])
  297. newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0
  298. _, err = g.DB().Model("younggee_local_collect_info").
  299. Where("talent_id = ? and local_id = ?", tId, localId).
  300. Data(g.Map{
  301. "deleted": newDeleteValue,
  302. "create_time": gtime.Now(),
  303. }).Update()
  304. if err != nil {
  305. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  306. }
  307. }
  308. return &TalentHttpResult{Code: 0, Msg: "collection success"}
  309. }
  310. // 收藏种草项目
  311. func ProjectCollection(r *ghttp.Request) *TalentHttpResult {
  312. tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  313. pId := r.GetQueryString("project_id", "")
  314. if pId == "" {
  315. return &TalentHttpResult{Code: -1, Msg: "参数传递有误"}
  316. }
  317. record, err := g.DB().Model("younggee_project_collect_info").Where("talent_id = ? and project_id = ?", tId, pId).One()
  318. if err != nil {
  319. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  320. }
  321. if record == nil {
  322. collectionInfo := youngee_talent_model.ProjectCollection{
  323. TalentId: tId,
  324. ProjectId: pId,
  325. CreateTime: gtime.Now(),
  326. Deleted: 0,
  327. }
  328. _, err = g.DB().Model("younggee_project_collect_info").Data(collectionInfo).Insert()
  329. } else {
  330. // 如果记录存在,更新 Delete 字段的值 和 收藏时间
  331. fmt.Println("*******", record)
  332. currentDeleteValue := gconv.Int(record["deleted"])
  333. newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0
  334. _, err = g.DB().Model("younggee_project_collect_info").
  335. Where("talent_id = ? and project_id = ?", tId, pId).
  336. Data(g.Map{
  337. "deleted": newDeleteValue,
  338. "create_time": gtime.Now(),
  339. }).Update()
  340. if err != nil {
  341. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  342. }
  343. }
  344. return &TalentHttpResult{Code: 0, Msg: "collection success"}
  345. }
  346. func SelectionCollection(r *ghttp.Request) *TalentHttpResult {
  347. tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  348. selectionId := r.GetQueryString("selection_id")
  349. productionId := r.GetQueryString("production_id")
  350. collectionRes := []youngee_talent_model.SelectionCollection{}
  351. err := g.DB().Model("younggee_selection_collect_info").Where("talent_id = ? and selection_id = ?", tId, selectionId).Scan(&collectionRes)
  352. if err != nil {
  353. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  354. }
  355. // 1. 没有数据,插入新记录
  356. if len(collectionRes) == 0 {
  357. collectInfo := &youngee_talent_model.SelectionCollection{
  358. TalentId: tId,
  359. SelectionId: selectionId,
  360. ProductId: productionId,
  361. CreateTime: gtime.Now(),
  362. Deleted: 0, // 默认未删除状态
  363. }
  364. _, err := g.DB().Model("younggee_selection_collect_info").Data(collectInfo).Insert()
  365. if err != nil {
  366. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  367. }
  368. return &TalentHttpResult{Code: 0, Msg: "收藏成功", Data: 0} //收藏
  369. }
  370. // 2. 有数据,且 Deleted == 0,更新 Deleted 为 1(取消收藏)
  371. if len(collectionRes) != 0 && collectionRes[0].Deleted == 0 {
  372. _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{
  373. "Deleted": 1,
  374. "UpdateTime": gtime.Now(),
  375. }).Update()
  376. if err != nil {
  377. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  378. }
  379. return &TalentHttpResult{Code: 0, Msg: "取消收藏成功", Data: 1} //取消收藏
  380. }
  381. // 3. 有数据,且 Deleted == 1,更新 Deleted 为 0(重新收藏)
  382. if len(collectionRes) != 0 && collectionRes[0].Deleted == 1 {
  383. _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{
  384. "Deleted": 0,
  385. "UpdateTime": gtime.Now(),
  386. }).Update()
  387. if err != nil {
  388. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  389. }
  390. return &TalentHttpResult{Code: 0, Msg: "重新收藏成功"}
  391. }
  392. return &TalentHttpResult{Code: 0, Msg: "操作成功"}
  393. }