task_link.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "youngmini_server/app/dao"
  5. "youngmini_server/app/model"
  6. "youngmini_server/app/model/youngee_talent_model"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/net/ghttp"
  9. "github.com/gogf/gf/os/gtime"
  10. )
  11. // 添加链接service
  12. func AddTaskLink(r *ghttp.Request) *TalentHttpResult {
  13. var LinkInfoReq *youngee_talent_model.AddTaskLinkRequest
  14. err := r.ParseForm(&LinkInfoReq)
  15. if err != nil {
  16. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  17. }
  18. taskLinkInfo := []model.YounggeeLinkInfo{}
  19. err = g.DB().Model(model.YounggeeLinkInfo{}).Where("task_id = ? ", LinkInfoReq.TaskId).OrderDesc("create_at").Scan(&taskLinkInfo)
  20. //上传过但是被拒了
  21. var condition1 bool = len(taskLinkInfo) != 0 && taskLinkInfo[0].IsReview == 1 && taskLinkInfo[0].IsOk == 0
  22. //没有上传过初稿
  23. var condition2 bool = len(taskLinkInfo) == 0
  24. //最新sketch数据
  25. linkInfo := model.YounggeeLinkInfo{
  26. TaskId: LinkInfoReq.TaskId,
  27. LinkUrl: LinkInfoReq.LinkUrl,
  28. //PhotoUrl: LinkInfoReq.PhotoUrl,
  29. CreateAt: gtime.Now(),
  30. IsReview: 0,
  31. IsSubmit: 0, //忽略
  32. IsOk: 0,
  33. }
  34. if condition1 || condition2 {
  35. //插入新数据
  36. LinkId, err := g.DB().Model(model.YounggeeLinkInfo{}).Data(linkInfo).InsertAndGetId()
  37. if err != nil {
  38. return &TalentHttpResult{Code: -3, Msg: "YounggeeLinkInfo insert failed"}
  39. }
  40. //上传过,把旧的删掉
  41. if condition1 {
  42. _, err := g.DB().Model(model.YounggeeLinkInfo{}).Where("link_id=?", LinkId).Delete()
  43. if err != nil {
  44. fmt.Println("err:", err.Error())
  45. }
  46. }
  47. } else { //有数据,但是,还没有被审核,更新
  48. linkId := taskLinkInfo[0].LinkId
  49. // 使用主键 ID 更新记录
  50. _, err := g.DB().Model(model.YounggeeLinkInfo{}).Where("link_id = ?", linkId).Data(linkInfo).Update()
  51. if err != nil {
  52. return &TalentHttpResult{Code: -4, Msg: "YounggeeSketchInfo update failed"}
  53. }
  54. }
  55. LinkStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("link_status").Where("task_id = ?", LinkInfoReq.TaskId).Value()
  56. if err != nil {
  57. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  58. }
  59. if LinkStatus.Int64() == 1 {
  60. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", LinkInfoReq.TaskId).Update(g.Map{"link_status": 2})
  61. if err != nil {
  62. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  63. }
  64. } else if LinkStatus.Int64() == 3 {
  65. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", LinkInfoReq.TaskId).Update(g.Map{"link_status": 4})
  66. if err != nil {
  67. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  68. }
  69. }
  70. //修改task表,插入log和message
  71. taskInfo := model.YoungeeTaskInfo{}
  72. // 查询是否处于违约状态
  73. err = g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", LinkInfoReq.TaskId).Scan(&taskInfo)
  74. if taskInfo.CurDefaultType == 5 || taskInfo.CurDefaultType == 9 {
  75. // 若处于违约状态则解除并更新企业应支付金额
  76. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", LinkInfoReq.TaskId).Update()
  77. if err != nil {
  78. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  79. }
  80. // 更新违约记录表
  81. _, err = g.DB().Model(model.YoungeeContractInfo{}).Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", LinkInfoReq.TaskId, g.Slice{1, 3, 4}).Update()
  82. if err != nil {
  83. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  84. }
  85. }
  86. //task设置为链接待审
  87. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "12"}).Where("task_id = ?", LinkInfoReq.TaskId).Update()
  88. if err != nil {
  89. return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  90. }
  91. // 记录任务日志-上传链接
  92. taskLog := model.YounggeeTaskLog{
  93. TaskId: LinkInfoReq.TaskId,
  94. Content: "上传链接",
  95. LogAt: gtime.Now(),
  96. }
  97. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  98. if err != nil {
  99. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  100. }
  101. projectInfo := model.ProjectInfo{}
  102. err = g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  103. if err != nil {
  104. return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  105. }
  106. messageInfo := model.YounggeeMessageInfo{
  107. MessageId: 12,
  108. MessageType: 2,
  109. CreatedAt: gtime.Now(),
  110. TalentId: taskInfo.TalentId,
  111. ProjectName: projectInfo.ProjectName,
  112. IsReaded: 0,
  113. IsDeleted: 0,
  114. }
  115. _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  116. if err != nil {
  117. return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  118. }
  119. return &TalentHttpResult{Code: 0, Msg: "success"}
  120. }
  121. // 提交链接service
  122. //func SubmitTaskLink(r *ghttp.Request) *TalentHttpResult {
  123. // taskId, _ := r.Get("task_id").(string)
  124. // taskInfo := model.YoungeeTaskInfo{}
  125. // // 查询是否处于违约状态
  126. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  127. // if err1 != nil {
  128. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  129. // }
  130. // if taskInfo.CurDefaultType == 5 || taskInfo.CurDefaultType == 9 {
  131. // // 若处于违约状态则解除并更新企业应支付金额
  132. // _, 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()
  133. // if err1 != nil {
  134. // return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  135. // }
  136. //
  137. // // 更新违约记录表
  138. // _, 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()
  139. // if err1 != nil {
  140. // return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  141. // }
  142. // }
  143. //
  144. // // 查询该任务是否有已添加或已修改链接
  145. // res, err := g.DB().Model(model.YounggeeLinkInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  146. // if err != nil {
  147. // return &TalentHttpResult{Code: -1, Msg: "YounggeeLinkInfo find failed"}
  148. // }
  149. // if res == 1 && (taskInfo.LinkStatus == 2 || taskInfo.LinkStatus == 4) {
  150. // _, err = g.DB().Model(model.YounggeeLinkInfo{}).Data(g.Map{"is_submit": "1", "submit_at": gtime.Now()}).Where("task_id = ? and is_submit = 0", taskId).Update()
  151. // if err != nil {
  152. // return &TalentHttpResult{Code: -3, Msg: "YounggeeLinkInfo update failed"}
  153. // }
  154. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "12"}).Where("task_id = ?", taskId).Update()
  155. // if err != nil {
  156. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  157. // }
  158. // // 记录任务日志-上传链接
  159. // taskLog := model.YounggeeTaskLog{
  160. // TaskId: taskId,
  161. // Content: "上传链接",
  162. // LogAt: gtime.Now(),
  163. // }
  164. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  165. // if err != nil {
  166. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  167. // }
  168. // projectInfo := model.ProjectInfo{}
  169. // err1 = g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  170. // if err1 != nil {
  171. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  172. // }
  173. // messageInfo := model.YounggeeMessageInfo{
  174. // MessageId: 12,
  175. // MessageType: 2,
  176. // CreatedAt: gtime.Now(),
  177. // TalentId: taskInfo.TalentId,
  178. // ProjectName: projectInfo.ProjectName,
  179. // IsReaded: 0,
  180. // IsDeleted: 0,
  181. // }
  182. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  183. // if err != nil {
  184. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  185. // }
  186. // }
  187. //
  188. // return &TalentHttpResult{Code: 0, Msg: "success"}
  189. //}
  190. // 查询链接提交审阅记录service
  191. func GetTaskLink(r *ghttp.Request) *TalentHttpResult {
  192. taskId := r.Get("task_id")
  193. res, err := g.DB().Model(dao.YounggeeLinkInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderDesc("create_at").All()
  194. if err != nil {
  195. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  196. }
  197. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  198. }
  199. // 查询未提交链接service
  200. func GetUnSubmitTaskLink(r *ghttp.Request) *TalentHttpResult {
  201. taskId := r.Get("task_id")
  202. res, err := g.DB().Model(dao.YounggeeLinkInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderDesc("create_at").One()
  203. if err != nil {
  204. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  205. }
  206. if res == nil {
  207. return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
  208. }
  209. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  210. }