project_info.go 29 KB

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