123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- package youngee_task_service
- import (
- "fmt"
- "github.com/gogf/gf/os/glog"
- "github.com/gogf/gf/os/gtime"
- "github.com/gogf/gf/util/gconv"
- "math"
- "reflect"
- "sort"
- "youngmini_server/app/dao"
- "youngmini_server/app/model/youngee_talent_model"
- "youngmini_server/app/service/youngee_talent_service"
- "youngmini_server/app/utils"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- )
- type projectStatus int
- const (
- projectStatusCreating = iota + 1
- projectStatusReviewing
- projectStatusReviewed
- projectStatusRecruiting
- projectStatusRecruited
- projectStatusPaying
- projectStatusPaid
- projectStatusInvalid
- projectStatusInProgress
- projectStatusClosed
- )
- // 获取项目信息列表service
- func GetProjectInfoList(r *ghttp.Request) *TalentHttpResult {
- pageIndex := r.GetQueryInt("idx", -1)
- cntPerPage := r.GetQueryInt("cnt", -1)
- //组合筛选
- platform := r.Get("platform", nil) //抖音、快手、红Book、B站、微博
- projectForm := r.Get("projectform", nil) //1.商品寄拍、3.虚拟产品评测、2.素材分发
- contentType := r.Get("contenttype", nil) //图文形式、视频形式
- createTime := r.Get("createTime", nil) //任务上线时间
- categoryForm := r.Get("productCategory", nil) //商品类目 智能家居、食品饮料等20种
- //排根据浏览量排序
- viewOrder := r.GetQueryInt("pageViewOrder", -1) //根据哪个字段排序
- //仅稿费”+“稿费+赠品"。这个在recruit表中,得到列表之后进行排序
- feeForm := r.GetInt("feeform", 0)
- searchValue := r.Get("searchvalue", nil)
- if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数错误"}
- }
- // 如果有稿费形式的过滤条件,则将过滤条件保存于taskModeList
- //var feeFormList []interface{}
- //if feeForm != nil {
- // if reflect.TypeOf(feeForm).Kind() != reflect.Slice {
- // return &TalentHttpResult{Code: -2, Msg: "搜索条件稿费形式错误"}
- // }
- //
- // feeFormList = make([]interface{}, 0)
- // feeFormList = feeForm.([]interface{})
- //}
- // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
- var projectFormList []interface{}
- if projectForm != nil {
- if reflect.TypeOf(projectForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- projectFormList = make([]interface{}, 0)
- projectFormList = projectForm.([]interface{})
- }
- // 如果有平台的过滤条件,则将平台列表保存于platformList
- var platformList []interface{}
- if platform != nil {
- if reflect.TypeOf(platform).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
- }
- platformList = make([]interface{}, 0) //初始化一个空的切片
- platformList = platform.([]interface{}) //类型断言将 platform 的值赋给 platformList。
- }
- var contentTypeList []interface{}
- if contentType != nil {
- if reflect.TypeOf(projectForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- contentTypeList = make([]interface{}, 0)
- contentTypeList = contentType.([]interface{})
- }
- var createTimeList []interface{}
- if createTime != nil {
- if reflect.TypeOf(createTime).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- createTimeList = make([]interface{}, 0)
- createTimeList = createTime.([]interface{})
- }
- // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
- var categoryFormList []interface{}
- if categoryForm != nil {
- if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- categoryFormList = make([]interface{}, 0)
- categoryFormList = categoryForm.([]interface{})
- }
- // 构造查询的条件
- startId := pageIndex * cntPerPage
- // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
- whereStr := fmt.Sprintf("project_status >= %d and fail_reason <> 2 and project_type = 1", projectStatusRecruiting)
- // 处理 平台类型
- if platformList != nil {
- whereStr = whereStr + " and project_platform in ("
- for _, v := range platformList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- //处理 内容类型
- if contentTypeList != nil {
- whereStr = whereStr + " and content_type in ("
- for _, v := range contentTypeList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- // 处理 创建时间
- if createTimeList != nil {
- whereStr += " AND created_at >= (NOW() - INTERVAL "
- for _, v := range createTimeList {
- switch v.(string) {
- case "1": // 近7天
- whereStr += "7 DAY"
- case "2": // 近30天
- whereStr += "30 DAY"
- case "3": // 近90天
- whereStr += "90 DAY"
- default:
- continue // 无效的过滤条件,跳过
- }
- }
- whereStr += ")"
- }
- fmt.Println("query after createTimeList:", whereStr)
- // 处理 项目形式
- if projectFormList != nil {
- whereStr += " and project_form in ("
- for _, v := range projectFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- // 处理 商品类型
- if categoryFormList != nil {
- whereStr += " and product_category in ("
- for _, v := range categoryFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- // 处理搜索条件
- if searchValue != nil {
- whereStr += " and project_name like '%" + searchValue.(string) + "%'"
- }
- fmt.Println("query afterAll--->:", whereStr)
- // 判断请求页面是否超过最大页面
- c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
- fmt.Println("c---->", c)
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: "查询数据库失败", Data: err.Error()}
- }
- maxPage := c / cntPerPage
- if c%cntPerPage > 0 {
- maxPage += 1
- }
- var projectInfoList = youngee_talent_model.ProjectInfoList{}
- // 查询数据库
- err = g.DB().Model("project_info").WithAll().Where(whereStr).
- Order("project_status ASC,recruit_ddl DESC").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
- }
- for _, project := range projectInfoList.ProjectInfos {
- fmt.Println("ids---->", project.ProjectId)
- }
- // 遍历projectList
- for i, project := range projectInfoList.ProjectInfos {
- fmt.Println("project.EnterpriseId---", project.EnterpriseId)
- //处理浏览量
- projectViewKey := "project:view:" + gconv.String(project.ProjectId)
- //redis中取浏览量 返回的是gvar.Var类型。 不存咋则为nil。经过viewCount.Int变成0
- viewCount, err := g.Redis().DoVar("GET", projectViewKey)
- if err != nil {
- glog.Error(err)
- return &TalentHttpResult{Code: 0, Msg: "Redis error"}
- }
- projectInfoList.ProjectInfos[i].WatchedNum = viewCount.Int()
- // 根据 WatchedNum 从高到低排序
- if viewOrder != -1 {
- sort.Slice(projectInfoList.ProjectInfos, func(i, j int) bool {
- return projectInfoList.ProjectInfos[i].WatchedNum > projectInfoList.ProjectInfos[j].WatchedNum
- })
- }
- // 统计 RecruitStrategys 数组中的最低粉丝量和最高粉丝量
- var minFollowers, maxFollowers int
- // 初始值可以设为极大/极小值
- minFollowers = math.MaxInt32
- maxFollowers = math.MinInt32
- // 遍历 RecruitStrategys,找出最低粉丝量和最高粉丝量
- for _, strategy := range project.RecruitStrategys {
- if strategy.FollowersLow < minFollowers {
- minFollowers = strategy.FollowersLow
- }
- if strategy.FollowersUp > maxFollowers {
- maxFollowers = strategy.FollowersUp
- }
- }
- // 打印最低粉丝量和最高粉丝量
- fmt.Printf("ProjectId: %d, MinFollowers: %d, MaxFollowers: %d\n", project.ProjectId, minFollowers, maxFollowers)
- // 如果需要,可以将这些值保存到 ProjectInfo 中,供后续使用
- projectInfoList.ProjectInfos[i].MinFollowers = minFollowers
- projectInfoList.ProjectInfos[i].MaxFollowers = maxFollowers
- //稿费的展示情况
- allFeeFormNoFee := true // 假设都是无费置换
- var hasSelfPrice bool
- var minOffer, maxOffer int
- for _, strategy := range project.RecruitStrategys {
- if strategy.FeeForm != 1 { // 如果存在非无费置换的策略
- allFeeFormNoFee = false
- }
- if strategy.FeeForm == 3 { // 存在自报价
- hasSelfPrice = true
- }
- if strategy.FeeForm == 2 { // 一口价策略
- if strategy.TOffer < minOffer || minOffer == 0 {
- minOffer = strategy.TOffer
- }
- if strategy.TOffer > maxOffer {
- maxOffer = strategy.TOffer
- }
- }
- }
- // 根据判断结果设置 IsShowOffer 和 HaveSelfPrice
- if allFeeFormNoFee {
- project.IsShowOffer = 2 // 不展示稿费
- } else {
- project.IsShowOffer = 1 // 展示稿费
- if hasSelfPrice {
- project.HaveSelfOffer = 1 //存在自报价
- } else {
- project.HaveSelfOffer = 2 //存在自报价
- }
- projectInfoList.ProjectInfos[i].MaxOffer = maxOffer
- projectInfoList.ProjectInfos[i].MinOffer = minOffer
- }
- }
- projectInfoList.MaxPage = maxPage
- var filteredProjects []*youngee_talent_model.ProjectInfo
- //筛选出“仅稿费”+“稿费+赠品”任务,
- //只要策略中有 无费置换 之外的fee_form就是有稿费,projectform是 商品寄拍 和 虚拟产品测评 ,就是有赠品
- if feeForm != 0 {
- for _, project := range projectInfoList.ProjectInfos {
- // 条件1:筛选出所有 project_form 为 1 或 3 的项目
- if project.ProjectForm == 1 || project.ProjectForm == 3 {
- filteredProjects = append(filteredProjects, project)
- continue // 如果满足条件1,直接跳过后续条件判断
- }
- // 条件2:RecruitStrategy 中存在 fee_form 不等于 1 的数据
- for _, strategy := range project.RecruitStrategys {
- if strategy.FeeForm != 1 {
- filteredProjects = append(filteredProjects, project)
- break // 找到符合条件的策略,跳出当前循环,避免重复添加
- }
- }
- }
- projectInfoList.ProjectInfos = filteredProjects
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
- }
- // 获取单个项目详情service
- func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- //列表页面进入
- pid := r.GetQueryString("project_id", "") //?value?value?
- enterprise_id := r.GetQueryString("enterprise_id", "")
- //扫码进入:1. 商家端的码 2. 服务商的码
- s_project_id := r.GetQueryInt("s_project_id", 0)
- // Redis key
- projectViewKey := "project:view:" + pid
- userViewedKey := "user:viewed:" + tid + ":" + pid
- if pid == "" {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- //在redis中增加浏览量
- // Check if the user has already viewed the product
- //DoVar方便进行类型转化
- viewed, err := g.Redis().DoVar("GET", userViewedKey)
- if err != nil {
- glog.Error(err)
- return &TalentHttpResult{Code: 0, Msg: "Redis error"}
- }
- var ProjectDetail *youngee_talent_model.ProjectDetail
- err = g.DB().Model("project_info").WithAll().Where("project_id", pid).Scan(&ProjectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //各阶段扣款比例
- one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", ProjectDetail.AutoDefaultId).One()
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error()}
- } else {
- ProjectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
- ProjectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
- ProjectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
- }
- //各阶段扣款时间
- one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", ProjectDetail.AutoTaskId).One()
- if err2 != nil {
- return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
- } else {
- ProjectDetail.DraftBreakTime = one2["draft_default"].Int()
- ProjectDetail.LinkBreakTime = one2["link_breach"].Int()
- ProjectDetail.DataBreakTime = one2["case_close_default"].Int()
- }
- if viewed.IsNil() {
- // User hasn't viewed this product yet, increase the view count
- _, err = g.Redis().Do("INCR", projectViewKey)
- if err != nil {
- glog.Error(err)
- return &TalentHttpResult{Code: 0, Msg: "Redis error"}
- }
- // Mark the product as viewed by this user
- _, err = g.Redis().Do("SET", userViewedKey, true)
- if err != nil {
- glog.Error(err)
- return &TalentHttpResult{Code: 0, Msg: "Redis error"}
- }
- }
- viewNum, err := g.Redis().DoVar("GET", projectViewKey)
- if err != nil {
- fmt.Println("获取浏览量失败")
- }
- ProjectDetail.ViewNum = viewNum.Int()
- //浏览历史
- currentDate := gtime.Now().Format("Ymd")
- // 设计 Redis Key
- redisBrowseKey := fmt.Sprintf("browseProject:%s:%s", currentDate, tid)
- fmt.Println("redis浏览记录的key为——————————", redisBrowseKey)
- // 将 project_id:s_project_id 添加到 Redis 中的 SET 中,因为project_id可以对应多个s_project_id(被多个服务商接手)
- // 组合 pid 和 s_project_id
- browseItem := fmt.Sprintf("%s:%s", pid, s_project_id)
- _, err = g.Redis().Do("SADD", redisBrowseKey, browseItem)
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: "Redis 存浏览历史数据失败"}
- }
- // 设置 Key 的过期时间为 7 天
- _, err = g.Redis().Do("EXPIRE", redisBrowseKey, 7*24*60*60) // 7 天的秒数
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: "Redis 设置过期时间失败"}
- }
- //填充收藏信息
- collectionInfo := []youngee_talent_model.ProjectCollection{}
- err = g.DB().Model("younggee_project_collect_info").Where("project_id=? and talent_id = ?", pid, tid).Scan(&collectionInfo)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- //已被收藏
- if len(collectionInfo) != 0 && collectionInfo[0].Deleted == 0 { //有数据 且 没取消收藏
- ProjectDetail.IsCollected = 1
- } else {
- ProjectDetail.IsCollected = 0 //没数据 或 有数据但取消了收藏
- }
- //返回的data作为收藏接口的is_collect字段传入
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- // 来自服务商
- if s_project_id != 0 {
- projectInfoSupplier := youngee_talent_model.ProjectInfoSupplier{}
- err := g.DB().Model("younggee_s_project_info").Where("s_project_id=?", s_project_id).Scan(&projectInfoSupplier)
- if err != nil {
- fmt.Println("projectInfoSupplier err:", err.Error())
- }
- var younggeeSupplier *youngee_talent_model.YounggeeSupplier
- err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", projectInfoSupplier.SupplierID).Scan(&younggeeSupplier)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- ProjectDetail.YounggeeSupplier = younggeeSupplier
- ProjectDetail.ProjectInfoSupplier = &projectInfoSupplier
- } else {
- //商家发布的
- var enterprise *youngee_talent_model.Enterprise
- err = g.DB().Model("enterprise").Where("enterprise_id", enterprise_id).Scan(&enterprise)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- ProjectDetail.Enterprise = enterprise
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
- }
- func GetProjectDetailFromBrowse(r *ghttp.Request) *TalentHttpResult {
- //从redis的 key--》browseProject:currentDate:tid中获取对应的 project_id:s_project_id
- pid := r.GetQueryInt("project_id", 0)
- enterprise_id := r.GetQueryString("enterprise_id", "") //来自商家
- s_project_id := r.GetQueryString("s_project_id", "")
- projectInfoSupplier := youngee_talent_model.ProjectInfoSupplier{}
- if s_project_id != "" {
- // 来自服务商
- err := g.DB().Model("younggee_s_project_info").Where("s_project_id=?", s_project_id).Scan(&projectInfoSupplier)
- if err != nil {
- fmt.Println("projectInfoSupplier err:", err.Error())
- }
- }
- if pid == 0 {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- var ProjectDetail *youngee_talent_model.ProjectDetail
- err := g.DB().Model("project_info").WithAll().Where("project_id", pid).Scan(&ProjectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //违约
- one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", ProjectDetail.AutoDefaultId).One()
- one2, err := g.DB().Model("info_auto_task").Where("auto_task_id=?", ProjectDetail.AutoTaskId).One()
- ProjectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
- ProjectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
- ProjectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
- ProjectDetail.DraftBreakTime = one2["draft_default"].Int()
- ProjectDetail.DraftBreakTime = one2["link_breach"].Int()
- ProjectDetail.DraftBreakTime = one2["case_close_default"].Int()
- if s_project_id != "" { // 来自服务商
- var younggeeSupplier *youngee_talent_model.YounggeeSupplier
- err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", projectInfoSupplier.SupplierID).Scan(&younggeeSupplier)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- ProjectDetail.YounggeeSupplier = younggeeSupplier
- ProjectDetail.ProjectInfoSupplier = &projectInfoSupplier
- } else { //project来自商家
- var enterprise *youngee_talent_model.Enterprise
- err = g.DB().Model("enterprise").WithAll().Where("enterprise_id", enterprise_id).Scan(&enterprise)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- ProjectDetail.Enterprise = enterprise
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
- }
- func SignUpProjKuaishouList(r *ghttp.Request) *TalentHttpResult {
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- pid := r.GetQueryString("project_id", 0)
- // 定义用于存储查询结果的结构体切片
- var results []*youngee_talent_model.KuaishouUserInfo
- // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id IN (?, ?)", 4, 8).
- Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
- Scan(&results)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 创建一个 map,用于记录每个 open_id 对应的记录
- //key是openid,value是数组,从而实现一对多
- openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
- // 将查询结果按 open_id 分组
- for _, record := range results {
- openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
- }
- // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
- var resInfo []*youngee_talent_model.KuaishouUserInfo
- for _, records := range openIdMap {
- if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
- for _, record := range records {
- if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
- resInfo = append(resInfo, record)
- break
- }
- }
- }
- }
- // 遍历 resInfo 检查过期和是否报名
- for _, record := range resInfo {
- // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
- expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
- // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
- record.Expired = expired
- //是否报名
- isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? talent_id=?", pid, record.OpenId, tid).One()
- // 根据查询结果设置 IsSign 属性
- if err != nil || isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
- }
- // 根据project的平台出现对应的社媒账号列表
- func SignUpProjAccountList(r *ghttp.Request) *TalentHttpResult {
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- pid := r.GetQueryString("project_id", "")
- platformId := r.GetInt("platform_id", 0)
- if pid == "" || platformId == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数有误", Data: nil}
- }
- //快手平台
- if platformId == 4 {
- // 定义用于存储查询结果的结构体切片
- var results []*youngee_talent_model.KuaishouUserInfo
- // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id IN (?, ?)", 4, 8).
- Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
- Scan(&results)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 创建一个 map,用于记录每个 open_id 对应的记录
- //key是openid,value是数组,从而实现一对多
- openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
- // 将查询结果按 open_id 分组
- for _, record := range results {
- openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
- }
- // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
- var resInfo []*youngee_talent_model.KuaishouUserInfo
- for _, records := range openIdMap {
- if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
- for _, record := range records {
- if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
- resInfo = append(resInfo, record)
- break
- }
- }
- }
- }
- // 遍历 resInfo 检查过期和是否报名
- for _, record := range resInfo {
- // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
- expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
- // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
- record.Expired = expired
- //是否报名
- isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
- } else if platformId == 2 { //抖音
- //获取列表
- var results2 []*youngee_talent_model.KuaishouUserInfo
- //获取达人在此平台的全部账号
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id = ? ", 2).
- Scan(&results2)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 遍历 resInfo 检查过期和是否报名
- for _, record := range results2 {
- // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
- expired := youngee_talent_service.CheckDouyinTokenExp(record.OpenId)
- // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
- record.Expired = expired
- //是否报名
- isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
- } else { //小红书 、 b站 、 微博
- //获取列表
- var results2 []*youngee_talent_model.KuaishouUserInfo
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id = ? ", platformId).
- Scan(&results2)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 遍历 resInfo 是否报名
- for _, record := range results2 {
- //是否报名
- isSignResult, err := g.DB().Model("youngee_task_info").Where("project_id=? AND open_id=? AND talent_id=?", pid, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
- }
- }
- func SignUpLocalAccountList(r *ghttp.Request) *TalentHttpResult {
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- localId := r.GetQueryString("local_id", "")
- platformId := r.GetInt("platform_id", 0)
- if localId == "" || platformId == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数有误", Data: nil}
- }
- //快手平台
- if platformId == 4 {
- // 定义用于存储查询结果的结构体切片
- var results []*youngee_talent_model.KuaishouUserInfo
- // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id IN (?, ?)", 4, 8).
- Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
- Scan(&results)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 创建一个 map,用于记录每个 open_id 对应的记录
- //key是openid,value是数组,从而实现一对多
- openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
- // 将查询结果按 open_id 分组
- for _, record := range results {
- openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
- }
- // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
- var resInfo []*youngee_talent_model.KuaishouUserInfo
- for _, records := range openIdMap {
- if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
- for _, record := range records {
- if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
- resInfo = append(resInfo, record)
- break
- }
- }
- }
- }
- // 遍历 resInfo 检查过期和是否报名
- for _, record := range resInfo {
- // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
- expired := youngee_talent_service.CheckKuaishouTokenExp(record.OpenId)
- // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
- record.Expired = expired
- //是否报名
- isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: resInfo}
- } else if platformId == 2 { //抖音
- //获取列表
- var results2 []*youngee_talent_model.KuaishouUserInfo
- //获取达人在此平台的全部账号
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id = ? ", 2).
- Scan(&results2)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 遍历 resInfo 检查过期和是否报名
- for _, record := range results2 {
- // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
- expired := youngee_talent_service.CheckDouyinTokenExp(record.OpenId)
- // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
- record.Expired = expired
- //是否报名
- isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
- } else { //小红书 、 b站 、 微博
- //获取列表
- var results2 []*youngee_talent_model.KuaishouUserInfo
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
- Where("talent_id = ?", tid).
- Where("platform_id = ? ", platformId).
- Scan(&results2)
- if err != nil {
- return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
- }
- // 遍历 resInfo 是否报名
- for _, record := range results2 {
- //是否报名
- isSignResult, err := g.DB().Model("youngee_local_task_info").Where("local_id=? AND open_id=? AND talent_id=?", localId, record.OpenId, tid).One()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- // 根据查询结果设置 IsSign 属性
- if isSignResult.IsEmpty() {
- record.IsSign = 0 // 没有查到数据,设置为 0
- } else {
- record.IsSign = 1 // 查到数据,设置为 1
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: results2}
- }
- }
|