project_info.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/os/glog"
  5. "github.com/gogf/gf/os/gtime"
  6. "github.com/gogf/gf/util/gconv"
  7. "math"
  8. "sort"
  9. "strings"
  10. "youngmini_server/app/dao"
  11. "youngmini_server/app/model/youngee_talent_model"
  12. "youngmini_server/app/service/youngee_talent_service"
  13. "youngmini_server/app/utils"
  14. "github.com/gogf/gf/frame/g"
  15. "github.com/gogf/gf/net/ghttp"
  16. )
  17. type projectStatus int
  18. const (
  19. projectStatusCreating = iota + 1
  20. projectStatusReviewing
  21. projectStatusReviewed
  22. projectStatusRecruiting
  23. projectStatusRecruited
  24. projectStatusPaying
  25. projectStatusPaid
  26. projectStatusInvalid
  27. projectStatusInProgress
  28. projectStatusClosed
  29. )
  30. // 获取项目信息列表service
  31. func GetProjectInfoList(r *ghttp.Request) *TalentHttpResult {
  32. pageIndex := r.GetQueryInt("idx", -1)
  33. cntPerPage := r.GetQueryInt("cnt", -1)
  34. //组合筛选
  35. platform := r.Get("platform", nil) //抖音、快手、红Book、B站、微博
  36. projectForm := r.Get("projectform", nil) //1.商品寄拍、3.虚拟产品评测、2.素材分发
  37. contentType := r.Get("contenttype", nil) //图文形式、视频形式
  38. createTime := r.Get("createTime", nil) //任务上线时间
  39. categoryForm := r.Get("productCategory", nil) //商品类目 智能家居、食品饮料等20种
  40. //排根据浏览量排序
  41. viewOrder := r.GetQueryInt("pageViewOrder", -1) //根据哪个字段排序
  42. //仅稿费”+“稿费+赠品"。这个在recruit表中,得到列表之后进行排序
  43. feeForm := r.GetInt("feeform", 0)
  44. searchValue := r.Get("searchvalue", nil)
  45. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  46. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  47. }
  48. // 构造查询的条件
  49. startId := pageIndex * cntPerPage
  50. // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
  51. whereStr := fmt.Sprintf("project_status >= %d and fail_reason <> 2 and project_type = 1", projectStatusRecruiting)
  52. // 处理 平台类型 project_platform
  53. if platform != nil {
  54. whereStr += " and project_platform = " + platform.(string)
  55. }
  56. //处理 内容类型
  57. if contentType != nil {
  58. whereStr += " and content_type = " + contentType.(string)
  59. }
  60. // 处理 创建时间
  61. if createTime != nil {
  62. switch createTime.(string) {
  63. case "1": // 近7天
  64. whereStr += " AND created_at >= (NOW() - INTERVAL 7 DAY)"
  65. case "2": // 近30天
  66. whereStr += " AND created_at >= (NOW() - INTERVAL 30 DAY)"
  67. case "3": // 近90天
  68. whereStr += " AND created_at >= (NOW() - INTERVAL 90 DAY)"
  69. default:
  70. // 无效的过滤条件,跳过
  71. return &TalentHttpResult{
  72. Code: -2,
  73. Msg: "无效的创建时间过滤条件",
  74. }
  75. }
  76. }
  77. // 处理 项目形式
  78. if projectForm != nil {
  79. whereStr += " and project_form = " + projectForm.(string)
  80. }
  81. // 处理 商品类型
  82. if categoryForm != nil {
  83. whereStr += " and product_category = '" + categoryForm.(string) + "'"
  84. }
  85. // 处理搜索条件
  86. if searchValue != nil {
  87. whereStr += " and project_name like '%" + searchValue.(string) + "%'"
  88. }
  89. fmt.Println("query afterAll--->:", whereStr)
  90. // 判断请求页面是否超过最大页面
  91. c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
  92. fmt.Println("c---->", c)
  93. if err != nil {
  94. return &TalentHttpResult{Code: -4, Msg: "查询数据库失败", Data: err.Error()}
  95. }
  96. maxPage := c / cntPerPage
  97. if c%cntPerPage > 0 {
  98. maxPage += 1
  99. }
  100. var projectInfoList = youngee_talent_model.ProjectInfoList{}
  101. // 查询数据库
  102. err = g.DB().Model("project_info").WithAll().Where(whereStr).
  103. Order("project_status ASC,recruit_ddl DESC").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
  104. if err != nil {
  105. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  106. }
  107. for _, project := range projectInfoList.ProjectInfos {
  108. fmt.Println("ids---->", project.ProjectId)
  109. }
  110. // 遍历projectList
  111. for i, project := range projectInfoList.ProjectInfos {
  112. fmt.Println("project.EnterpriseId---", project.EnterpriseId)
  113. //处理浏览量
  114. projectViewKey := "project:view:" + gconv.String(project.ProjectId)
  115. //redis中取浏览量 返回的是gvar.Var类型。 不存咋则为nil。经过viewCount.Int变成0
  116. viewCount, err := g.Redis().DoVar("GET", projectViewKey)
  117. if err != nil {
  118. glog.Error(err)
  119. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  120. }
  121. projectInfoList.ProjectInfos[i].WatchedNum = viewCount.Int()
  122. // 统计 RecruitStrategys 数组中的最低粉丝量和最高粉丝量
  123. var minFollowers, maxFollowers int
  124. // 初始值可以设为极大/极小值
  125. minFollowers = math.MaxInt32
  126. maxFollowers = math.MinInt32
  127. var totalRecruitNum int
  128. // 遍历 RecruitStrategys,找出最低粉丝量和最高粉丝量,以及总招募任务
  129. for _, strategy := range project.RecruitStrategys {
  130. totalRecruitNum += strategy.RecruitNumber
  131. if strategy.FollowersLow < minFollowers {
  132. minFollowers = strategy.FollowersLow
  133. }
  134. if strategy.FollowersUp > maxFollowers {
  135. maxFollowers = strategy.FollowersUp
  136. }
  137. }
  138. // 打印最低粉丝量和最高粉丝量
  139. fmt.Printf("ProjectId: %d, MinFollowers: %d, MaxFollowers: %d\n", project.ProjectId, minFollowers, maxFollowers)
  140. // 如果需要,可以将这些值保存到 ProjectInfo 中,供后续使用
  141. projectInfoList.ProjectInfos[i].MinFollowers = minFollowers
  142. projectInfoList.ProjectInfos[i].MaxFollowers = maxFollowers
  143. projectInfoList.ProjectInfos[i].AllRecruitNum = totalRecruitNum
  144. //稿费的展示情况
  145. allFeeFormNoFee := true // 假设都是无费置换
  146. var hasSelfPrice bool
  147. var minOffer, maxOffer int
  148. for _, strategy := range project.RecruitStrategys {
  149. if strategy.FeeForm != 1 { // 如果存在非无费置换的策略
  150. allFeeFormNoFee = false
  151. }
  152. if strategy.FeeForm == 3 { // 存在自报价
  153. hasSelfPrice = true
  154. }
  155. if strategy.FeeForm == 2 { // 一口价策略
  156. if strategy.TOffer < minOffer || minOffer == 0 {
  157. minOffer = strategy.TOffer
  158. }
  159. if strategy.TOffer > maxOffer {
  160. maxOffer = strategy.TOffer
  161. }
  162. }
  163. }
  164. // 根据判断结果设置 IsShowOffer 和 HaveSelfPrice
  165. if allFeeFormNoFee {
  166. project.IsShowOffer = 2 // 不展示稿费
  167. } else {
  168. project.IsShowOffer = 1 // 展示稿费
  169. if hasSelfPrice {
  170. project.HaveSelfOffer = 1 //存在自报价
  171. } else {
  172. project.HaveSelfOffer = 2 //存在自报价
  173. }
  174. projectInfoList.ProjectInfos[i].MaxOffer = maxOffer
  175. projectInfoList.ProjectInfos[i].MinOffer = minOffer
  176. }
  177. }
  178. // 根据 WatchedNum 从高到低排序
  179. if viewOrder != -1 {
  180. sort.Slice(projectInfoList.ProjectInfos, func(i, j int) bool {
  181. return projectInfoList.ProjectInfos[i].WatchedNum > projectInfoList.ProjectInfos[j].WatchedNum
  182. })
  183. }
  184. projectInfoList.MaxPage = maxPage
  185. var filteredProjects []*youngee_talent_model.ProjectInfo
  186. //筛选出“仅稿费”+“稿费+赠品”任务,
  187. //只要策略中有 无费置换 之外的fee_form就是有稿费,projectform是 商品寄拍 和 虚拟产品测评 ,就是有赠品
  188. if feeForm != 0 {
  189. for _, project := range projectInfoList.ProjectInfos {
  190. // 条件1:筛选出所有 project_form 为 1 或 3 的项目
  191. if project.ProjectForm == 1 || project.ProjectForm == 3 {
  192. filteredProjects = append(filteredProjects, project)
  193. continue // 如果满足条件1,直接跳过后续条件判断
  194. }
  195. // 条件2:RecruitStrategy 中存在 fee_form 不等于 1 的数据
  196. for _, strategy := range project.RecruitStrategys {
  197. if strategy.FeeForm != 1 {
  198. filteredProjects = append(filteredProjects, project)
  199. break // 找到符合条件的策略,跳出当前循环,避免重复添加
  200. }
  201. }
  202. }
  203. projectInfoList.ProjectInfos = filteredProjects
  204. }
  205. return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
  206. }
  207. // 获取单个项目详情service
  208. func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
  209. g.Log().Info("This is an GetProjectDetail message")
  210. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  211. //列表页面进入
  212. pid := r.GetQueryString("project_id", "")
  213. //扫码进入:1. 商家端的码 2. 服务商的码
  214. s_project_id := r.GetQueryInt("s_project_id", 0)
  215. // Redis key
  216. projectViewKey := "project:view:" + pid
  217. userViewedKey := "user:viewed:" + tid + ":" + pid
  218. //在redis中增加浏览量
  219. // Check if the user has already viewed the product
  220. //DoVar方便进行类型转化
  221. viewed, err := g.Redis().DoVar("GET", userViewedKey)
  222. if err != nil {
  223. glog.Error(err)
  224. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  225. }
  226. var ProjectDetail *youngee_talent_model.ProjectDetail
  227. //TalentType转成String
  228. var talentCategory []*youngee_talent_model.YounggeeTalentCategory
  229. err = g.DB().Model("younggee_talent_category").Scan(&talentCategory)
  230. if err != nil {
  231. // 处理查询错误
  232. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  233. }
  234. // 创建一个数字到汉字的映射
  235. categoryMap := make(map[string]string)
  236. for _, category := range talentCategory {
  237. categoryMap[fmt.Sprint(category.Id)] = category.Category
  238. }
  239. err = g.DB().Model("project_info").WithAll().Where("project_id", pid).Scan(&ProjectDetail)
  240. if err != nil {
  241. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  242. }
  243. // 将 TalentType 转换为逗号隔开的汉字字符串
  244. talentTypes := strings.Split(ProjectDetail.TalentType, ",")
  245. var result []string
  246. for _, t := range talentTypes {
  247. if name, ok := categoryMap[t]; ok {
  248. result = append(result, name)
  249. }
  250. }
  251. // 将结果拼接成逗号隔开的字符串
  252. resultStr := strings.Join(result, ",")
  253. ProjectDetail.TalentType = resultStr
  254. if ProjectDetail.ProjectType == 1 { //公开任务才有违约信息
  255. //各阶段扣款比例
  256. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", ProjectDetail.AutoDefaultId).One()
  257. if err != nil {
  258. return &TalentHttpResult{Code: 0, Msg: err.Error()}
  259. } else {
  260. ProjectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
  261. ProjectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
  262. ProjectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
  263. }
  264. //各阶段扣款时间
  265. one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", ProjectDetail.AutoTaskId).One()
  266. if err2 != nil {
  267. return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
  268. } else {
  269. ProjectDetail.DraftBreakTime = one2["draft_default"].Int()
  270. ProjectDetail.LinkBreakTime = one2["link_breach"].Int()
  271. ProjectDetail.DataBreakTime = one2["case_close_default"].Int()
  272. }
  273. }
  274. if viewed.IsNil() {
  275. // User hasn't viewed this product yet, increase the view count
  276. _, err = g.Redis().Do("INCR", projectViewKey)
  277. if err != nil {
  278. glog.Error(err)
  279. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  280. }
  281. // Mark the product as viewed by this user
  282. _, err = g.Redis().Do("SET", userViewedKey, true)
  283. if err != nil {
  284. glog.Error(err)
  285. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  286. }
  287. }
  288. viewNum, err := g.Redis().DoVar("GET", projectViewKey)
  289. if err != nil {
  290. fmt.Println("获取浏览量失败")
  291. }
  292. ProjectDetail.ViewNum = viewNum.Int()
  293. //浏览历史
  294. currentDate := gtime.Now().Format("Ymd")
  295. // 设计 Redis Key
  296. redisBrowseKey := fmt.Sprintf("browseProject:%s:%s", currentDate, tid)
  297. fmt.Println("redis浏览记录的key为——————————", redisBrowseKey)
  298. // 将 project_id:s_project_id 添加到 Redis 中的 SET 中,因为project_id可以对应多个s_project_id(被多个服务商接手)
  299. // 组合 pid 和 s_project_id
  300. browseItem := fmt.Sprintf("%s:%s", pid, s_project_id)
  301. _, err = g.Redis().Do("SADD", redisBrowseKey, browseItem)
  302. if err != nil {
  303. return &TalentHttpResult{Code: 0, Msg: "Redis 存浏览历史数据失败"}
  304. }
  305. // 设置 Key 的过期时间为 7 天
  306. _, err = g.Redis().Do("EXPIRE", redisBrowseKey, 7*24*60*60) // 7 天的秒数
  307. if err != nil {
  308. return &TalentHttpResult{Code: 0, Msg: "Redis 设置过期时间失败"}
  309. }
  310. //填充收藏信息
  311. collectionInfo := []youngee_talent_model.ProjectCollection{}
  312. err = g.DB().Model("younggee_project_collect_info").Where("project_id=? and talent_id = ?", pid, tid).Scan(&collectionInfo)
  313. if err != nil {
  314. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  315. }
  316. //已被收藏
  317. if len(collectionInfo) != 0 && collectionInfo[0].Deleted == 0 { //有数据 且 没取消收藏
  318. ProjectDetail.IsCollected = 1
  319. } else {
  320. ProjectDetail.IsCollected = 0 //没数据 或 有数据但取消了收藏
  321. }
  322. //返回的data作为收藏接口的is_collect字段传入
  323. if err != nil {
  324. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  325. }
  326. // 来自服务商
  327. if s_project_id != 0 {
  328. projectInfoSupplier := youngee_talent_model.ProjectInfoSupplier{}
  329. err := g.DB().Model("younggee_s_project_info").Where("s_project_id=?", s_project_id).Scan(&projectInfoSupplier)
  330. if err != nil {
  331. fmt.Println("projectInfoSupplier err:", err.Error())
  332. }
  333. var younggeeSupplier *youngee_talent_model.YounggeeSupplier
  334. err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", projectInfoSupplier.SupplierID).Scan(&younggeeSupplier)
  335. if err != nil {
  336. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  337. }
  338. ProjectDetail.YounggeeSupplier = younggeeSupplier
  339. ProjectDetail.ProjectInfoSupplier = &projectInfoSupplier
  340. } else {
  341. //商家发布的
  342. var enterprise *youngee_talent_model.Enterprise
  343. err = g.DB().Model("enterprise").Where("enterprise_id", ProjectDetail.EnterpriseId).Scan(&enterprise)
  344. if err != nil {
  345. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  346. }
  347. ProjectDetail.Enterprise = enterprise
  348. }
  349. return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
  350. }
  351. func GetProjectDetailFromBrowse(r *ghttp.Request) *TalentHttpResult {
  352. //从redis的 key--》browseProject:currentDate:tid中获取对应的 project_id:s_project_id
  353. pid := r.GetQueryInt("project_id", 0)
  354. enterprise_id := r.GetQueryString("enterprise_id", "") //来自商家
  355. s_project_id := r.GetQueryString("s_project_id", "")
  356. projectInfoSupplier := youngee_talent_model.ProjectInfoSupplier{}
  357. if s_project_id != "" {
  358. // 来自服务商
  359. err := g.DB().Model("younggee_s_project_info").Where("s_project_id=?", s_project_id).Scan(&projectInfoSupplier)
  360. if err != nil {
  361. fmt.Println("projectInfoSupplier err:", err.Error())
  362. }
  363. }
  364. if pid == 0 {
  365. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  366. }
  367. var ProjectDetail *youngee_talent_model.ProjectDetail
  368. err := g.DB().Model("project_info").WithAll().Where("project_id", pid).Scan(&ProjectDetail)
  369. if err != nil {
  370. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  371. }
  372. //违约
  373. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", ProjectDetail.AutoDefaultId).One()
  374. one2, err := g.DB().Model("info_auto_task").Where("auto_task_id=?", ProjectDetail.AutoTaskId).One()
  375. ProjectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
  376. ProjectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
  377. ProjectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
  378. ProjectDetail.DraftBreakTime = one2["draft_default"].Int()
  379. ProjectDetail.DraftBreakTime = one2["link_breach"].Int()
  380. ProjectDetail.DraftBreakTime = one2["case_close_default"].Int()
  381. if s_project_id != "" { // 来自服务商
  382. var younggeeSupplier *youngee_talent_model.YounggeeSupplier
  383. err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", projectInfoSupplier.SupplierID).Scan(&younggeeSupplier)
  384. if err != nil {
  385. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  386. }
  387. ProjectDetail.YounggeeSupplier = younggeeSupplier
  388. ProjectDetail.ProjectInfoSupplier = &projectInfoSupplier
  389. } else { //project来自商家
  390. var enterprise *youngee_talent_model.Enterprise
  391. err = g.DB().Model("enterprise").WithAll().Where("enterprise_id", enterprise_id).Scan(&enterprise)
  392. if err != nil {
  393. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  394. }
  395. ProjectDetail.Enterprise = enterprise
  396. }
  397. return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
  398. }
  399. func SignUpProjKuaishouList(r *ghttp.Request) *TalentHttpResult {
  400. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  401. pid := r.GetQueryString("project_id", 0)
  402. // 定义用于存储查询结果的结构体切片
  403. var results []*youngee_talent_model.KuaishouUserInfo
  404. // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
  405. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  406. Where("talent_id = ?", tid).
  407. Where("platform_id IN (?, ?)", 4, 8).
  408. Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
  409. Scan(&results)
  410. if err != nil {
  411. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  412. }
  413. // 创建一个 map,用于记录每个 open_id 对应的记录
  414. //key是openid,value是数组,从而实现一对多
  415. openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
  416. // 将查询结果按 open_id 分组
  417. for _, record := range results {
  418. openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
  419. }
  420. // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
  421. var resInfo []*youngee_talent_model.KuaishouUserInfo
  422. for _, records := range openIdMap {
  423. if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
  424. for _, record := range records {
  425. if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
  426. resInfo = append(resInfo, record)
  427. break
  428. }
  429. }
  430. }
  431. }
  432. // 遍历 resInfo 检查过期和是否报名
  433. for _, record := range resInfo {
  434. // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
  435. expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
  436. // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
  437. record.Expired = expired
  438. //是否报名
  439. isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? talent_id=?", pid, record.OpenId, tid).One()
  440. // 根据查询结果设置 IsSign 属性
  441. if err != nil || isSignResult.IsEmpty() {
  442. record.IsSign = 0 // 没有查到数据,设置为 0
  443. } else {
  444. record.IsSign = 1 // 查到数据,设置为 1
  445. }
  446. }
  447. return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
  448. }
  449. // 根据project的平台出现对应的社媒账号列表
  450. func SignUpProjAccountList(r *ghttp.Request) *TalentHttpResult {
  451. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  452. pid := r.GetQueryString("project_id", "")
  453. platformId := r.GetInt("platform_id", 0)
  454. if pid == "" || platformId == 0 {
  455. return &TalentHttpResult{Code: -1, Msg: "参数有误", Data: nil}
  456. }
  457. //快手平台
  458. if platformId == 4 {
  459. // 定义用于存储查询结果的结构体切片
  460. var results []*youngee_talent_model.KuaishouUserInfo
  461. // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
  462. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  463. Where("talent_id = ?", tid).
  464. Where("platform_id IN (?, ?)", 4, 8).
  465. Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
  466. Scan(&results)
  467. if err != nil {
  468. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  469. }
  470. // 创建一个 map,用于记录每个 open_id 对应的记录
  471. //key是openid,value是数组,从而实现一对多
  472. openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
  473. // 将查询结果按 open_id 分组
  474. for _, record := range results {
  475. openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
  476. }
  477. // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
  478. var resInfo []*youngee_talent_model.KuaishouUserInfo
  479. for _, records := range openIdMap {
  480. if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
  481. for _, record := range records {
  482. if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
  483. resInfo = append(resInfo, record)
  484. break
  485. }
  486. }
  487. }
  488. }
  489. // 遍历 resInfo 检查过期和是否报名
  490. for _, record := range resInfo {
  491. // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
  492. expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
  493. // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
  494. record.Expired = expired
  495. //是否报名
  496. isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
  497. if err != nil {
  498. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  499. }
  500. // 根据查询结果设置 IsSign 属性
  501. if isSignResult.IsEmpty() {
  502. record.IsSign = 0 // 没有查到数据,设置为 0
  503. } else {
  504. record.IsSign = 1 // 查到数据,设置为 1
  505. }
  506. }
  507. return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
  508. } else if platformId == 2 { //抖音
  509. //获取列表
  510. var results2 []*youngee_talent_model.KuaishouUserInfo
  511. //获取达人在此平台的全部账号
  512. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  513. Where("talent_id = ?", tid).
  514. Where("platform_id = ? ", 2).
  515. Scan(&results2)
  516. if err != nil {
  517. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  518. }
  519. // 遍历 resInfo 检查过期和是否报名
  520. for _, record := range results2 {
  521. // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
  522. expired := youngee_talent_service.CheckDouyinTokenExp(record.OpenId)
  523. // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
  524. record.Expired = expired
  525. //是否报名
  526. isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
  527. if err != nil {
  528. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  529. }
  530. // 根据查询结果设置 IsSign 属性
  531. if isSignResult.IsEmpty() {
  532. record.IsSign = 0 // 没有查到数据,设置为 0
  533. } else {
  534. record.IsSign = 1 // 查到数据,设置为 1
  535. }
  536. }
  537. return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
  538. } else { //小红书 、 b站 、 微博
  539. //获取列表
  540. var results2 []*youngee_talent_model.KuaishouUserInfo
  541. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  542. Where("talent_id = ?", tid).
  543. Where("platform_id = ? ", platformId).
  544. Scan(&results2)
  545. if err != nil {
  546. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  547. }
  548. // 遍历 resInfo 是否报名
  549. for _, record := range results2 {
  550. //是否报名
  551. isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
  552. if err != nil {
  553. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  554. }
  555. // 根据查询结果设置 IsSign 属性
  556. if isSignResult.IsEmpty() {
  557. record.IsSign = 0 // 没有查到数据,设置为 0
  558. } else {
  559. record.IsSign = 1 // 查到数据,设置为 1
  560. }
  561. }
  562. return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
  563. }
  564. }
  565. func SignUpLocalAccountList(r *ghttp.Request) *TalentHttpResult {
  566. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  567. localId := r.GetQueryString("local_id", "")
  568. platformId := r.GetInt("platform_id", 0)
  569. if localId == "" || platformId == 0 {
  570. return &TalentHttpResult{Code: -1, Msg: "参数有误", Data: nil}
  571. }
  572. //快手平台
  573. if platformId == 4 {
  574. // 定义用于存储查询结果的结构体切片
  575. var results []*youngee_talent_model.KuaishouUserInfo
  576. // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
  577. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  578. Where("talent_id = ?", tid).
  579. Where("platform_id IN (?, ?)", 4, 8).
  580. Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
  581. Scan(&results)
  582. if err != nil {
  583. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  584. }
  585. // 创建一个 map,用于记录每个 open_id 对应的记录
  586. //key是openid,value是数组,从而实现一对多
  587. openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
  588. // 将查询结果按 open_id 分组
  589. for _, record := range results {
  590. openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
  591. }
  592. // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
  593. var resInfo []*youngee_talent_model.KuaishouUserInfo
  594. for _, records := range openIdMap {
  595. if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
  596. for _, record := range records {
  597. if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
  598. resInfo = append(resInfo, record)
  599. break
  600. }
  601. }
  602. }
  603. }
  604. // 遍历 resInfo 检查过期和是否报名
  605. for _, record := range resInfo {
  606. // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
  607. expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
  608. // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
  609. record.Expired = expired
  610. //是否报名
  611. isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
  612. if err != nil {
  613. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  614. }
  615. // 根据查询结果设置 IsSign 属性
  616. if isSignResult.IsEmpty() {
  617. record.IsSign = 0 // 没有查到数据,设置为 0
  618. } else {
  619. record.IsSign = 1 // 查到数据,设置为 1
  620. }
  621. }
  622. return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
  623. } else if platformId == 2 { //抖音
  624. //获取列表
  625. var results2 []*youngee_talent_model.KuaishouUserInfo
  626. //获取达人在此平台的全部账号
  627. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  628. Where("talent_id = ?", tid).
  629. Where("platform_id = ? ", 2).
  630. Scan(&results2)
  631. if err != nil {
  632. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  633. }
  634. // 遍历 resInfo 检查过期和是否报名
  635. for _, record := range results2 {
  636. // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
  637. expired := youngee_talent_service.CheckDouyinTokenExp(record.OpenId)
  638. // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
  639. record.Expired = expired
  640. //是否报名
  641. isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
  642. if err != nil {
  643. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  644. }
  645. // 根据查询结果设置 IsSign 属性
  646. if isSignResult.IsEmpty() {
  647. record.IsSign = 0 // 没有查到数据,设置为 0
  648. } else {
  649. record.IsSign = 1 // 查到数据,设置为 1
  650. }
  651. }
  652. return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
  653. } else { //小红书 、 b站 、 微博
  654. //获取列表
  655. var results2 []*youngee_talent_model.KuaishouUserInfo
  656. err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
  657. Where("talent_id = ?", tid).
  658. Where("platform_id = ? ", platformId).
  659. Scan(&results2)
  660. if err != nil {
  661. return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
  662. }
  663. // 遍历 resInfo 是否报名
  664. for _, record := range results2 {
  665. //是否报名
  666. isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
  667. if err != nil {
  668. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  669. }
  670. // 根据查询结果设置 IsSign 属性
  671. if isSignResult.IsEmpty() {
  672. record.IsSign = 0 // 没有查到数据,设置为 0
  673. } else {
  674. record.IsSign = 1 // 查到数据,设置为 1
  675. }
  676. }
  677. return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
  678. }
  679. }