123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- package youngee_task_service
- import (
- "fmt"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/glog"
- "github.com/gogf/gf/os/gtime"
- "github.com/gogf/gf/util/gconv"
- "reflect"
- "sort"
- "strconv"
- "youngmini_server/app/dao"
- "youngmini_server/app/model/youngee_talent_model"
- "youngmini_server/app/utils"
- )
- func GetLocalLifeList(r *ghttp.Request) *TalentHttpResult {
- pageIndex := r.GetQueryInt("idx", -1)
- cntPerPage := r.GetQueryInt("cnt", -1)
- //组合筛选
- platform := r.Get("platform", "") //抖音、快手、红Book、B站、微博
- taskForm := r.Get("task_form", "") //任务形式,1-2分别代表线下探店,素材分发
- contentType := r.Get("contenttype", "") //图文形式、视频形式
- createTime := r.Get("createTime", "") //任务上线时间
- //categoryForm := r.Get("categoryform", "") ////商品类目 智能家居、食品饮料等20种
- //todo 城市参数?
- //Location := r.GetQueryString("city", "") //门店store所属城市,
- //排根据浏览量排序
- viewOrder := r.GetQueryInt("pageViewOrder", -1) //根据哪个字段排序
- //仅稿费”+“稿费+赠品"。这个在recruit表中,得到列表之后进行排序
- feeForm := r.GetInt("feeform", 0)
- searchValue := r.Get("searchvalue")
- if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数错误"}
- }
- // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
- var taskFormList []interface{}
- if taskForm != nil {
- if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- taskFormList = make([]interface{}, 0)
- taskFormList = taskForm.([]interface{})
- } else {
- taskFormList = make([]interface{}, 0)
- }
- // 如果有平台的过滤条件,则将平台列表保存于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{})
- }
- // 如果有内容形式的过滤条件,则将过滤条件保存于taskModeList
- var contentTypeList []interface{}
- if contentType != nil {
- if reflect.TypeOf(contentType).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{})
- //}
- //if len(categoryFormList) > 0 {
- // // 使用 categoryFormList 进行某些操作
- // fmt.Println("Filtered categoryFormList:", categoryFormList)
- //}
- // 构造查询的条件
- startId := pageIndex * cntPerPage
- // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
- whereStr := fmt.Sprintf("(task_status >= %d and local_type = 1)", projectStatusRecruiting)
- if platformList != nil {
- whereStr = whereStr + " and local_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 += ")"
- }
- // 处理 selectionFormList (创建时间的过滤条件)
- 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 += ")"
- }
- if taskFormList != nil {
- whereStr += " and task_form in ("
- for _, v := range taskFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- if searchValue != nil {
- whereStr += " and local_name like '%" + searchValue.(string) + "%'"
- }
- fmt.Println("whereStr:-----》 ", whereStr)
- // 查询所有project
- var localList = []youngee_talent_model.YounggeeLocalLifeInfo{}
- err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&localList)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
- }
- // 判断请求页面是否超过最大页面
- c, err := g.DB().Model("younggee_local_life_info").Fields("local_id").Where(whereStr).Count()
- if c <= 0 {
- return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
- }
- maxPage := c / cntPerPage
- if c%cntPerPage > 0 {
- maxPage += 1
- }
- if pageIndex+1 > maxPage {
- return &TalentHttpResult{Code: -5, Msg: "over max page"}
- }
- var localInfoList = youngee_talent_model.LocalInfoList{}
- err = g.DB().Model("younggee_local_life_info").WithAll().Where(whereStr).
- Order("task_status ASC,recruit_ddl DESC").Limit(startId, cntPerPage).Scan(&localInfoList.LocalInfos)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
- }
- // 遍历projectList
- for i, local := range localInfoList.LocalInfos {
- //处理浏览量
- localViewKey := "local:view:" + gconv.String(local.LocalId)
- //redis中取浏览量 返回的是gvar.Var类型。 不存咋则为nil。经过viewCount.Int变成0
- viewCount, err := g.Redis().DoVar("GET", localViewKey)
- if err != nil {
- glog.Error(err)
- return &TalentHttpResult{Code: 0, Msg: "Redis error"}
- }
- localInfoList.LocalInfos[i].WatchNum = viewCount.Int()
- // 根据 WatchedNum 从高到低排序
- if viewOrder != -1 {
- sort.Slice(localInfoList.LocalInfos, func(i, j int) bool {
- return localInfoList.LocalInfos[i].WatchNum > localInfoList.LocalInfos[j].WatchNum
- })
- }
- }
- localInfoList.MaxPage = maxPage
- var filteredLocalInfo []*youngee_talent_model.YounggeeLocalLifeInfo
- //筛选出“仅稿费”+“稿费+赠品”任务,
- //只要策略中有 无费置换 之外的fee_form就是有稿费,donate=1就是有赠品
- if feeForm != 0 {
- for _, local := range localInfoList.LocalInfos {
- if local.Donate == 1 {
- filteredLocalInfo = append(filteredLocalInfo, local)
- continue // 如果满足条件1,直接跳过后续条件判断
- }
- // 条件2:RecruitStrategy 中存在 fee_form 不等于 1 的数据
- for _, strategy := range local.RecruitStrategys {
- if strategy.FeeForm != 1 {
- filteredLocalInfo = append(filteredLocalInfo, local)
- break // 找到符合条件的策略,跳出当前循环,避免重复添加
- }
- }
- }
- localInfoList.LocalInfos = filteredLocalInfo
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: localInfoList}
- }
- func GetLocalLifeDetail(r *ghttp.Request) *TalentHttpResult {
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- local_id := r.GetQueryInt("id", 0)
- //通过首页进入的详情页,获取服务商id,younggee_supplier表
- enterprise_id := r.GetQueryString("enterprise_id", "")
- //通过扫服务商码进入的详情页,获取服务商id,younggee_supplier表
- //supplier_id := r.GetQueryString("supplier_id", "")
- s_local_id := r.GetQueryString("s_local_id", "")
- localInfoSupplier := youngee_talent_model.LocalInfoSupplier{}
- if s_local_id != "" {
- // 来自服务商
- err := g.DB().Model("younggee_s_local__info").Where("s_local_id=?", s_local_id).Scan(&localInfoSupplier)
- if err != nil {
- fmt.Println("projectInfoSupplier err:", err.Error())
- }
- }
- // Redis key
- loalViewKey := "local:view:" + strconv.Itoa(local_id)
- userViewedKey := "user:viewed:" + tid + ":" + strconv.Itoa(local_id)
- if local_id == 0 {
- 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 LocalDetail *youngee_talent_model.LocalInfoDetail
- err = g.DB().Model("younggee_local_life_info").WithAll().Where("id", local_id).Scan(&LocalDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //违约
- one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", LocalDetail.AutoDefaultId).One()
- one2, err := g.DB().Model("info_auto_task").Where("auto_task_id=?", LocalDetail.AutoTaskId).One()
- LocalDetail.DraftDefault.BreakPecent = one["sketch_replace_not_upload"].Int()
- LocalDetail.LinkDefault.BreakPecent = one["link_replace_not_upload"].Int()
- LocalDetail.DataDefault.BreakPecent = one["data_replace_not_upload"].Int()
- LocalDetail.DraftDefault.BreakTime = one2["draft_default"].Int()
- LocalDetail.DraftDefault.BreakTime = one2["link_breach"].Int()
- LocalDetail.DraftDefault.BreakTime = one2["case_close_default"].Int()
- if viewed.IsNil() {
- // User hasn't viewed this product yet, increase the view count
- _, err = g.Redis().Do("INCR", loalViewKey)
- 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", loalViewKey)
- if err != nil {
- fmt.Println("获取浏览量失败")
- }
- LocalDetail.WatchedNum = viewNum.Int()
- //浏览历史
- currentDate := gtime.Now().Format("Ymd")
- // 设计 Redis Key
- redisBrowseKey := fmt.Sprintf("browseLocal:%s:%s", currentDate, tid)
- fmt.Println("redis浏览记录的key为——————————", redisBrowseKey)
- // 将 project_id 添加到 Redis 中的 SET
- _, err = g.Redis().Do("SADD", redisBrowseKey, local_id)
- 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 设置过期时间失败"}
- }
- if enterprise_id != "" { //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()}
- }
- LocalDetail.Enterprise = enterprise
- }
- if s_local_id != "" {
- // 来自服务商
- var younggeeSupplier *youngee_talent_model.YounggeeSupplier
- err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", localInfoSupplier.SupplierID).Scan(&younggeeSupplier)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- LocalDetail.YounggeeSupplier = younggeeSupplier
- LocalDetail.LocalInfoSupplier = &localInfoSupplier
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: LocalDetail}
- }
|