task_data.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. // 查询是否处于违约状态
  154. err = g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  155. //修改task表的属性
  156. err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", DataInfoReq.TaskId).Scan(&taskInfo)
  157. if err1 != nil {
  158. return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  159. }
  160. if taskInfo.CurDefaultType == 7 || taskInfo.CurDefaultType == 9 {
  161. // 若处于违约状态则解除并更新企业应支付金额
  162. _, 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()
  163. if err1 != nil {
  164. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  165. }
  166. // 更新违约记录表
  167. _, 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()
  168. if err1 != nil {
  169. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  170. }
  171. }
  172. //设置为数据待审
  173. _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"task_stage": "14"}).Where("task_id = ?", DataInfoReq.TaskId).Update()
  174. if err != nil {
  175. return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  176. }
  177. // 记录任务日志-上传数据
  178. taskLog := youngee_talent_model.YounggeeLocalTaskLog{
  179. TaskId: DataInfoReq.TaskId,
  180. Content: "上传数据",
  181. LogAt: gtime.Now(),
  182. }
  183. _, err = g.DB().Model("younggee_local_task_log").Data(&taskLog).Insert()
  184. if err != nil {
  185. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed", Data: err.Error()}
  186. }
  187. }
  188. return &TalentHttpResult{Code: 0, Msg: "success"}
  189. }
  190. // 提交数据service
  191. //func SubmitTaskData(r *ghttp.Request) *TalentHttpResult {
  192. // taskId, _ := r.Get("task_id").(string)
  193. // taskInfo := model.YoungeeTaskInfo{}
  194. // // 查询是否处于违约状态
  195. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  196. // if err1 != nil {
  197. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  198. // }
  199. // if taskInfo.CurDefaultType == 7 || taskInfo.CurDefaultType == 9 {
  200. // // 若处于违约状态则解除并更新企业应支付金额
  201. // _, 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()
  202. // if err1 != nil {
  203. // return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  204. // }
  205. //
  206. // // 更新违约记录表
  207. // _, 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()
  208. // if err1 != nil {
  209. // return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  210. // }
  211. // }
  212. //
  213. // // 查询该任务是否有已添加或已修改数据
  214. // res, err := g.DB().Model(model.YounggeeDataInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  215. // if err != nil {
  216. // return &TalentHttpResult{Code: -1, Msg: "YounggeeDataInfo find failed"}
  217. // }
  218. // if res == 1 && (taskInfo.DataStatus == 2 || taskInfo.DataStatus == 4) {
  219. // _, 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()
  220. // if err != nil {
  221. // return &TalentHttpResult{Code: -3, Msg: "YounggeeDataInfo update failed"}
  222. // }
  223. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "14"}).Where("task_id = ?", taskId).Update()
  224. // if err != nil {
  225. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  226. // }
  227. // // 记录任务日志-上传数据
  228. // taskLog := model.YounggeeTaskLog{
  229. // TaskId: taskId,
  230. // Content: "上传数据",
  231. // LogAt: gtime.Now(),
  232. // }
  233. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  234. // if err != nil {
  235. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  236. // }
  237. // projectInfo := model.ProjectInfo{}
  238. // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  239. // if err1 != nil {
  240. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  241. // }
  242. // messageInfo := model.YounggeeMessageInfo{
  243. // MessageId: 13,
  244. // MessageType: 2,
  245. // CreatedAt: gtime.Now(),
  246. // TalentId: taskInfo.TalentId,
  247. // ProjectName: projectInfo.ProjectName,
  248. // IsReaded: 0,
  249. // IsDeleted: 0,
  250. // }
  251. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  252. // if err != nil {
  253. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  254. // }
  255. // }
  256. //
  257. // return &TalentHttpResult{Code: 0, Msg: "success"}
  258. //}
  259. // 查询数据提交审阅记录service
  260. func GetTaskData(r *ghttp.Request) *TalentHttpResult {
  261. taskId := r.Get("task_id")
  262. res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderAsc("submit_at").All()
  263. if err != nil {
  264. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  265. }
  266. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  267. }
  268. // 查询未提交数据service
  269. func GetUnSubmitTaskData(r *ghttp.Request) *TalentHttpResult {
  270. taskId := r.Get("task_id")
  271. res, err := g.DB().Model(dao.YounggeeDataInfo.Table).Where("is_review = 0 and is_ok = 0 and task_id = ?", taskId).One()
  272. if err != nil {
  273. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  274. }
  275. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  276. }
  277. // 收藏种草项目
  278. func ProjectCollection(r *ghttp.Request) *TalentHttpResult {
  279. tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  280. pId := r.GetQueryString("project_id", "")
  281. if pId == "" {
  282. return &TalentHttpResult{Code: -1, Msg: "参数传递有误"}
  283. }
  284. record, err := g.DB().Model("younggee_project_collect_info").Where("talent_id = ? and project_id = ?", tId, pId).One()
  285. if err != nil {
  286. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  287. }
  288. if record == nil {
  289. collectionInfo := youngee_talent_model.ProjectCollection{
  290. TalentId: tId,
  291. ProjectId: pId,
  292. CreateTime: gtime.Now(),
  293. Deleted: 0,
  294. }
  295. _, err = g.DB().Model("younggee_project_collect_info").Data(collectionInfo).Insert()
  296. } else {
  297. // 如果记录存在,更新 Delete 字段的值 和 收藏时间
  298. fmt.Println("*******", record)
  299. currentDeleteValue := gconv.Int(record["deleted"])
  300. newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0
  301. _, err = g.DB().Model("younggee_project_collect_info").
  302. Where("talent_id = ? and project_id = ?", tId, pId).
  303. Data(g.Map{
  304. "deleted": newDeleteValue,
  305. "create_time": gtime.Now(),
  306. }).Update()
  307. if err != nil {
  308. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  309. }
  310. }
  311. return &TalentHttpResult{Code: 0, Msg: "collection success"}
  312. }
  313. // 收藏带货项目
  314. //func SelectionCollection(r *ghttp.Request) *TalentHttpResult {
  315. // tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  316. // selectionId := r.GetQueryString("selection_id")
  317. // productionId := r.GetQueryString("production_id")
  318. // record, err := g.DB().Model("younggee_selection_collect_info").Where("talent_id = ? and selection_id = ?", tId, selectionId).One()
  319. // if err != nil {
  320. // return &TalentHttpResult{Code: -1, Msg: err.Error()}
  321. // }
  322. // if record == nil {
  323. // collectionInfo := youngee_talent_model.SelectionCollection{
  324. // TalentId: tId,
  325. // SelectionId: selectionId,
  326. // ProductId: productionId,
  327. // CreateTime: gtime.Now(),
  328. // Deleted: 0,
  329. // }
  330. // _, err = g.DB().Model("younggee_selection_collect_info").Data(collectionInfo).Insert()
  331. //
  332. // } else {
  333. // // 如果记录存在,更新 Delete 字段的值 和 收藏时间
  334. // fmt.Println("*******", record)
  335. // currentDeleteValue := gconv.Int(record["deleted"])
  336. // newDeleteValue := 1 - currentDeleteValue // 0 改成 1,1 改成 0
  337. // _, err = g.DB().Model("younggee_selection_collect_info").
  338. // Where("talent_id = ? and selection_id = ?", tId, selectionId).
  339. // Data(g.Map{
  340. // "deleted": newDeleteValue,
  341. // "create_time": gtime.Now(),
  342. // }).Update()
  343. // if err != nil {
  344. // return &TalentHttpResult{Code: -1, Msg: err.Error()}
  345. // }
  346. // }
  347. // return &TalentHttpResult{Code: 0, Data: record["deleted"], Msg: "collection success"}
  348. //}
  349. func SelectionCollection(r *ghttp.Request) *TalentHttpResult {
  350. tId, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  351. selectionId := r.GetQueryString("selection_id")
  352. productionId := r.GetQueryString("production_id")
  353. collectionRes := []youngee_talent_model.SelectionCollection{}
  354. err := g.DB().Model("younggee_selection_collect_info").Where("talent_id = ? and selection_id = ?", tId, selectionId).Scan(&collectionRes)
  355. if err != nil {
  356. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  357. }
  358. // 1. 没有数据,插入新记录
  359. if len(collectionRes) == 0 {
  360. collectInfo := &youngee_talent_model.SelectionCollection{
  361. TalentId: tId,
  362. SelectionId: selectionId,
  363. ProductId: productionId,
  364. CreateTime: gtime.Now(),
  365. Deleted: 0, // 默认未删除状态
  366. }
  367. _, err := g.DB().Model("younggee_selection_collect_info").Data(collectInfo).Insert()
  368. if err != nil {
  369. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  370. }
  371. return &TalentHttpResult{Code: 0, Msg: "收藏成功", Data: 0} //收藏
  372. }
  373. // 2. 有数据,且 Deleted == 0,更新 Deleted 为 1(取消收藏)
  374. if len(collectionRes) != 0 && collectionRes[0].Deleted == 0 {
  375. _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{
  376. "Deleted": 1,
  377. "UpdateTime": gtime.Now(),
  378. }).Update()
  379. if err != nil {
  380. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  381. }
  382. return &TalentHttpResult{Code: 0, Msg: "取消收藏成功", Data: 1} //取消收藏
  383. }
  384. // 3. 有数据,且 Deleted == 1,更新 Deleted 为 0(重新收藏)
  385. if len(collectionRes) != 0 && collectionRes[0].Deleted == 1 {
  386. _, err := g.DB().Model("younggee_selection_collect_info").Where("collection_id = ?", collectionRes[0].CollectionId).Data(g.Map{
  387. "Deleted": 0,
  388. "UpdateTime": gtime.Now(),
  389. }).Update()
  390. if err != nil {
  391. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  392. }
  393. return &TalentHttpResult{Code: 0, Msg: "重新收藏成功"}
  394. }
  395. return &TalentHttpResult{Code: 0, Msg: "操作成功"}
  396. }