task_data.go 14 KB

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