sectask_service.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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).WithAll().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 (s *secTaskService) ListTab(listSecTaskTabReq *ListSecTaskTabReq, tid string) (res *ListSecTaskTabRes) {
  112. //获得tab_stage
  113. var whereStr string
  114. //前端点击了那个tab TabStage
  115. switch listSecTaskTabReq.TabStage {
  116. case 1:
  117. // 返回指定talentId的所有数据
  118. whereStr = fmt.Sprintf("talent_id='%s'", tid)
  119. case 2:
  120. // 返回指定talentId且free_stage为3, 4, 5的数据
  121. whereStr = fmt.Sprintf("talent_id='%s' AND free_stage IN (3, 4, 5)", tid)
  122. case 3:
  123. // 返回指定talentId且sale_num_all大于0的数据
  124. whereStr = fmt.Sprintf("talent_id='%s' AND sale_num_all > 0", tid)
  125. case 4:
  126. // 返回指定talentId且已过DDL的数据
  127. whereStr = fmt.Sprintf("talent_id='%s' AND task_ddl < NOW()", tid)
  128. }
  129. //查task表全部数据
  130. var secTaskInfoList []youngee_talent_model.SecTaskInfoDetail
  131. err := g.DB().Model(youngee_talent_model.SecTaskInfoDetail{}).WithAll().
  132. Where(whereStr).
  133. Order("task_ddl DESC").
  134. Scan(&secTaskInfoList)
  135. if err != nil {
  136. return &ListSecTaskTabRes{Count: -1, Msg: err.Error(), SecTaskTable: nil}
  137. }
  138. c := len(secTaskInfoList)
  139. return &ListSecTaskTabRes{Count: c, Msg: "success", SecTaskTable: secTaskInfoList}
  140. }
  141. func UpdateStageAndStatus(ctx context.Context, updateStageReq *UpdateStageReq) (err error) {
  142. whereCondition := g.Map{
  143. dao.YounggeeSecTaskInfo.Columns.TaskId: updateStageReq.TaskId,
  144. }
  145. dataUpdate := g.Map{
  146. dao.YounggeeSecTaskInfo.Columns.TaskStage: updateStageReq.TaskStage,
  147. dao.YounggeeSecTaskInfo.Columns.AssignmentStatus: updateStageReq.AssignmentStatus,
  148. strconv.Itoa(dao.YounggeeSecTaskInfo.Columns.RewardStage): updateStageReq.RewardStage,
  149. }
  150. fmt.Println("----UpdateStageAndStatus-->", dataUpdate)
  151. _, err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Data(dataUpdate).Update()
  152. if err != nil {
  153. return
  154. }
  155. return
  156. }
  157. func (s *secTaskService) ShowLogisticsDetail(ctx context.Context, tid, taskId string) (*LogisticsDetail, error) {
  158. var resp = LogisticsDetail{
  159. LogisticsCompany: "",
  160. LogisticsNumber: "",
  161. AddressSnap: "",
  162. LogisticsContext: nil,
  163. }
  164. // 校验达人id是否一致,并查询达人收货地址快照
  165. talentWhereCondition := g.Map{
  166. dao.YounggeeSecTaskInfo.Columns.TaskId: taskId,
  167. }
  168. var secTask *model.YounggeeSecTaskInfo
  169. err := dao.YounggeeSecTaskInfo.Ctx(ctx).Where(talentWhereCondition).Scan(&secTask)
  170. if err != nil || secTask == nil {
  171. g.Log().Error("任务表查询失败")
  172. return nil, err
  173. }
  174. if secTask.TalentId != tid {
  175. g.Log().Error("用户id不一致")
  176. return nil, err
  177. }
  178. //报名成功时已有地址快照
  179. resp.AddressSnap = secTask.TalentPostAddrSnap
  180. // 根据任务id查询物流快递公司和快递单号
  181. whereCondition := g.Map{
  182. dao.YoungeeTaskLogistics.Columns.TaskId: taskId,
  183. }
  184. var logisticsInfo *model.YoungeeTaskLogistics
  185. err = dao.YoungeeTaskLogistics.Ctx(ctx).Where(whereCondition).Scan(&logisticsInfo)
  186. if err != nil || logisticsInfo == nil {
  187. g.Log().Error("物流信息表查询失败")
  188. return nil, err
  189. }
  190. resp.LogisticsCompany = logisticsInfo.CompanyName
  191. resp.LogisticsNumber = logisticsInfo.LogisticsNumber
  192. // 查询物流详细信息,返回规定的快递状态
  193. var logisticsDetail = utils.GetKDDetails(logisticsInfo.CompanyName, logisticsInfo.LogisticsNumber)
  194. if err != nil || logisticsInfo == nil {
  195. g.Log().Error("调用快递100API查询失败")
  196. return nil, err
  197. }
  198. resp.LogisticsContext = logisticsDetail
  199. return &resp, nil
  200. }