sectask_service.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package sectask
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/frame/g"
  6. "strconv"
  7. "youngmini_server/app/dao"
  8. "youngmini_server/app/model"
  9. "youngmini_server/app/model/youngee_talent_model"
  10. "youngmini_server/app/utils"
  11. //"youngmini_server/app/model/youngee_talent_model"
  12. _ "youngmini_server/app/model/youngee_talent_model"
  13. )
  14. var service = new(secTaskService)
  15. type secTaskService struct {
  16. }
  17. func (s *secTaskService) List(ctx context.Context, listSecTaskReq *ListSecTaskReq, tid string) (res ListSecTaskRes, err error) {
  18. var taskStageList = g.Slice{}
  19. switch listSecTaskReq.TaskStage {
  20. case 1:
  21. taskStageList = g.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  22. break
  23. case 2:
  24. taskStageList = g.Slice{2, 3}
  25. break
  26. case 3:
  27. taskStageList = g.Slice{6, 7, 8}
  28. break
  29. case 4:
  30. taskStageList = g.Slice{5, 9, 10}
  31. break
  32. }
  33. //根据达人id和任务阶段筛选,含任务信息。
  34. whereCondition := g.Map{
  35. dao.YounggeeSecTaskInfo.Columns.TaskStage: taskStageList,
  36. dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
  37. }
  38. err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Scan(&res.SecTask)
  39. if err != nil {
  40. return
  41. }
  42. res.Count = len(res.SecTask)
  43. //键为字符串类型,值为model.InfoThirdPlatform类型
  44. platformMap := make(map[string]model.InfoThirdPlatform)
  45. platformInfo := []*model.InfoThirdPlatform{}
  46. if res.Count != 0 {
  47. err = g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  48. if err != nil {
  49. fmt.Println(err)
  50. return
  51. }
  52. //以便后续根据平台ID快速检索和访问平台信息。
  53. //strconv.Itoa用于将int转为字符串
  54. //ListSecTaskSql中定义了平台表中的属性
  55. for i, _ := range platformInfo {
  56. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  57. }
  58. // 为每个任务根据项目id查询项目名称和主图
  59. for index, v := range res.SecTask {
  60. whereCondition1 := g.Map{
  61. dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId,
  62. }
  63. var selection *model.YounggeeSelectionInfo
  64. err = g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Scan(&selection)
  65. if err != nil || selection == nil {
  66. if err == nil {
  67. fmt.Println("没查到选品")
  68. } else {
  69. return
  70. }
  71. }
  72. whereCondition1 = g.Map{
  73. dao.YoungeePlatformAccountInfo.Columns.PlatformId: selection.Platform,
  74. dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  75. }
  76. var account *model.YoungeePlatformAccountInfo
  77. err = g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition1).Scan(&account)
  78. if err != nil {
  79. fmt.Println(err)
  80. return
  81. }
  82. // 查询RewardStrategy表数据
  83. // 或者使用指针类型并初始化
  84. var RewardStrategy []*youngee_talent_model.RewardStrategy
  85. err = g.DB().Model(youngee_talent_model.RewardStrategy{}).WithAll().Where("selection_id", v.SelectionId).Scan(&RewardStrategy)
  86. if err != nil {
  87. fmt.Println("ffff")
  88. }
  89. var sectaskTable *youngee_talent_model.SecTaskInfoDetail
  90. err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? AND selection_id = ? ", tid, v.SelectionId).Scan(&sectaskTable)
  91. if err != nil {
  92. fmt.Println(err)
  93. return
  94. }
  95. res.SecTask[index].PlatformIconUrl = platformMap[strconv.Itoa(selection.Platform)].PlatformIcon
  96. res.SecTask[index].PlatformName = platformMap[strconv.Itoa(selection.Platform)].PlatformName
  97. res.SecTask[index].PlatformNickName = account.PlatformNickname
  98. res.SecTask[index].SelectionName = selection.SelectionName
  99. res.SecTask[index].ProductPhotoSnap = selection.ProductPhotoSnap
  100. res.SecTask[index].TaskDdl = selection.TaskDdl
  101. res.SecTask[index].RewardStrategy = RewardStrategy //悬赏策略表
  102. res.SecTask[index].SecTaskTable = sectaskTable //sectask表中全部数据
  103. //res.SecTask[index].YounggeeProductPhoto = ProductPhoto
  104. //代替商品照片快照
  105. //fmt.Println("--------------res.SecTask[index]: ", res.SecTask[index])
  106. fmt.Println("--------------selection: ", selection)
  107. }
  108. }
  109. return
  110. }
  111. func UpdateStageAndStatus(ctx context.Context, updateStageReq *UpdateStageReq) (err error) {
  112. whereCondition := g.Map{
  113. dao.YounggeeSecTaskInfo.Columns.TaskId: updateStageReq.TaskId,
  114. }
  115. dataUpdate := g.Map{
  116. dao.YounggeeSecTaskInfo.Columns.TaskStage: updateStageReq.TaskStage,
  117. dao.YounggeeSecTaskInfo.Columns.AssignmentStatus: updateStageReq.AssignmentStatus,
  118. }
  119. fmt.Println("------>", dataUpdate)
  120. _, err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Data(dataUpdate).Update()
  121. if err != nil {
  122. return
  123. }
  124. return
  125. }
  126. func (s *secTaskService) ShowLogisticsDetail(ctx context.Context, tid, taskId string) (*LogisticsDetail, error) {
  127. var resp = LogisticsDetail{
  128. LogisticsCompany: "",
  129. LogisticsNumber: "",
  130. AddressSnap: "",
  131. LogisticsContext: nil,
  132. }
  133. // 校验达人id是否一致,并查询达人收货地址快照
  134. talentWhereCondition := g.Map{
  135. dao.YounggeeSecTaskInfo.Columns.TaskId: taskId,
  136. }
  137. var secTask *model.YounggeeSecTaskInfo
  138. err := dao.YounggeeSecTaskInfo.Ctx(ctx).Where(talentWhereCondition).Scan(&secTask)
  139. if err != nil || secTask == nil {
  140. g.Log().Error("任务表查询失败")
  141. return nil, err
  142. }
  143. if secTask.TalentId != tid {
  144. g.Log().Error("用户id不一致")
  145. return nil, err
  146. }
  147. resp.AddressSnap = secTask.TalentPostAddrSnap
  148. // 根据任务id查询物流快递公司和快递单号
  149. whereCondition := g.Map{
  150. dao.YoungeeTaskLogistics.Columns.TaskId: taskId,
  151. }
  152. var logisticsInfo *model.YoungeeTaskLogistics
  153. err = dao.YoungeeTaskLogistics.Ctx(ctx).Where(whereCondition).Scan(&logisticsInfo)
  154. if err != nil || logisticsInfo == nil {
  155. g.Log().Error("物流信息表查询失败")
  156. return nil, err
  157. }
  158. resp.LogisticsCompany = logisticsInfo.CompanyName
  159. resp.LogisticsNumber = logisticsInfo.LogisticsNumber
  160. // 查询物流详细信息
  161. var logisticsDetail = utils.GetKDDetails(logisticsInfo.CompanyName, logisticsInfo.LogisticsNumber)
  162. if err != nil || logisticsInfo == nil {
  163. g.Log().Error("调用快递100API查询失败")
  164. return nil, err
  165. }
  166. resp.LogisticsContext = logisticsDetail
  167. return &resp, nil
  168. }