local_life_info.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/frame/g"
  5. "github.com/gogf/gf/net/ghttp"
  6. "github.com/gogf/gf/os/glog"
  7. "github.com/gogf/gf/os/gtime"
  8. "github.com/gogf/gf/util/gconv"
  9. "reflect"
  10. "sort"
  11. "strconv"
  12. "youngmini_server/app/dao"
  13. "youngmini_server/app/model/youngee_talent_model"
  14. "youngmini_server/app/utils"
  15. )
  16. func GetLocalLifeList(r *ghttp.Request) *TalentHttpResult {
  17. pageIndex := r.GetQueryInt("idx", -1)
  18. cntPerPage := r.GetQueryInt("cnt", -1)
  19. //组合筛选
  20. platform := r.Get("platform", "") //抖音、快手、红Book、B站、微博
  21. taskForm := r.Get("task_form", "") //任务形式,1-2分别代表线下探店,素材分发
  22. contentType := r.Get("contenttype", "") //图文形式、视频形式
  23. createTime := r.Get("createTime", "") //任务上线时间
  24. //categoryForm := r.Get("categoryform", "") ////商品类目 智能家居、食品饮料等20种
  25. //todo 城市参数?
  26. //Location := r.GetQueryString("city", "") //门店store所属城市,
  27. //排根据浏览量排序
  28. viewOrder := r.GetQueryInt("pageViewOrder", -1) //根据哪个字段排序
  29. //仅稿费”+“稿费+赠品"。这个在recruit表中,得到列表之后进行排序
  30. feeForm := r.GetInt("feeform", 0)
  31. searchValue := r.Get("searchvalue")
  32. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  33. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  34. }
  35. // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
  36. var taskFormList []interface{}
  37. if taskForm != nil {
  38. if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
  39. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  40. }
  41. taskFormList = make([]interface{}, 0)
  42. taskFormList = taskForm.([]interface{})
  43. } else {
  44. taskFormList = make([]interface{}, 0)
  45. }
  46. // 如果有平台的过滤条件,则将平台列表保存于platformList
  47. var platformList []interface{}
  48. if platform != nil {
  49. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  50. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  51. }
  52. platformList = make([]interface{}, 0)
  53. platformList = platform.([]interface{})
  54. }
  55. // 如果有内容形式的过滤条件,则将过滤条件保存于taskModeList
  56. var contentTypeList []interface{}
  57. if contentType != nil {
  58. if reflect.TypeOf(contentType).Kind() != reflect.Slice {
  59. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  60. }
  61. contentTypeList = make([]interface{}, 0)
  62. contentTypeList = contentType.([]interface{})
  63. }
  64. // 上线时间
  65. var createTimeList []interface{}
  66. if createTime != nil {
  67. if reflect.TypeOf(createTime).Kind() != reflect.Slice {
  68. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  69. }
  70. createTimeList = make([]interface{}, 0)
  71. createTimeList = createTime.([]interface{})
  72. }
  73. // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
  74. //var categoryFormList []interface{}
  75. //if categoryForm != nil {
  76. // if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
  77. // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  78. // }
  79. //
  80. // categoryFormList = make([]interface{}, 0)
  81. // categoryFormList = categoryForm.([]interface{})
  82. //}
  83. //if len(categoryFormList) > 0 {
  84. // // 使用 categoryFormList 进行某些操作
  85. // fmt.Println("Filtered categoryFormList:", categoryFormList)
  86. //}
  87. // 构造查询的条件
  88. startId := pageIndex * cntPerPage
  89. // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
  90. whereStr := fmt.Sprintf("(task_status >= %d and local_type = 1)", projectStatusRecruiting)
  91. if platformList != nil {
  92. whereStr = whereStr + " and local_platform in ("
  93. for _, v := range platformList {
  94. whereStr += v.(string) + ", "
  95. }
  96. whereStr = whereStr[0 : len(whereStr)-2]
  97. whereStr += ")"
  98. }
  99. if contentTypeList != nil {
  100. whereStr = whereStr + " and content_type in ("
  101. for _, v := range contentTypeList {
  102. whereStr += v.(string) + ", "
  103. }
  104. whereStr = whereStr[0 : len(whereStr)-2]
  105. whereStr += ")"
  106. }
  107. // 处理 selectionFormList (创建时间的过滤条件)
  108. if createTimeList != nil {
  109. whereStr += " AND created_at >= (NOW() - INTERVAL "
  110. for _, v := range createTimeList {
  111. switch v.(string) {
  112. case "1": // 近7天
  113. whereStr += "7 DAY"
  114. case "2": // 近30天
  115. whereStr += "30 DAY"
  116. case "3": // 近90天
  117. whereStr += "90 DAY"
  118. default:
  119. continue // 无效的过滤条件,跳过
  120. }
  121. }
  122. whereStr += ")"
  123. }
  124. if taskFormList != nil {
  125. whereStr += " and task_form in ("
  126. for _, v := range taskFormList {
  127. whereStr += v.(string) + ", "
  128. }
  129. whereStr = whereStr[0 : len(whereStr)-2]
  130. whereStr += ")"
  131. }
  132. if searchValue != nil {
  133. whereStr += " and local_name like '%" + searchValue.(string) + "%'"
  134. }
  135. fmt.Println("whereStr:-----》 ", whereStr)
  136. // 查询所有project
  137. var localList = []youngee_talent_model.YounggeeLocalLifeInfo{}
  138. err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&localList)
  139. if err != nil {
  140. return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
  141. }
  142. // 判断请求页面是否超过最大页面
  143. c, err := g.DB().Model("younggee_local_life_info").Fields("local_id").Where(whereStr).Count()
  144. if c <= 0 {
  145. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  146. }
  147. maxPage := c / cntPerPage
  148. if c%cntPerPage > 0 {
  149. maxPage += 1
  150. }
  151. if pageIndex+1 > maxPage {
  152. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  153. }
  154. var localInfoList = youngee_talent_model.LocalInfoList{}
  155. err = g.DB().Model("younggee_local_life_info").WithAll().Where(whereStr).
  156. Order("task_status ASC,recruit_ddl DESC").Limit(startId, cntPerPage).Scan(&localInfoList.LocalInfos)
  157. if err != nil {
  158. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  159. }
  160. // 遍历projectList
  161. for i, local := range localInfoList.LocalInfos {
  162. //处理浏览量
  163. localViewKey := "local:view:" + gconv.String(local.LocalId)
  164. //redis中取浏览量 返回的是gvar.Var类型。 不存咋则为nil。经过viewCount.Int变成0
  165. viewCount, err := g.Redis().DoVar("GET", localViewKey)
  166. if err != nil {
  167. glog.Error(err)
  168. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  169. }
  170. localInfoList.LocalInfos[i].WatchNum = viewCount.Int()
  171. // 根据 WatchedNum 从高到低排序
  172. if viewOrder != -1 {
  173. sort.Slice(localInfoList.LocalInfos, func(i, j int) bool {
  174. return localInfoList.LocalInfos[i].WatchNum > localInfoList.LocalInfos[j].WatchNum
  175. })
  176. }
  177. }
  178. localInfoList.MaxPage = maxPage
  179. var filteredLocalInfo []*youngee_talent_model.YounggeeLocalLifeInfo
  180. //筛选出“仅稿费”+“稿费+赠品”任务,
  181. //只要策略中有 无费置换 之外的fee_form就是有稿费,donate=1就是有赠品
  182. if feeForm != 0 {
  183. for _, local := range localInfoList.LocalInfos {
  184. if local.Donate == 1 {
  185. filteredLocalInfo = append(filteredLocalInfo, local)
  186. continue // 如果满足条件1,直接跳过后续条件判断
  187. }
  188. // 条件2:RecruitStrategy 中存在 fee_form 不等于 1 的数据
  189. for _, strategy := range local.RecruitStrategys {
  190. if strategy.FeeForm != 1 {
  191. filteredLocalInfo = append(filteredLocalInfo, local)
  192. break // 找到符合条件的策略,跳出当前循环,避免重复添加
  193. }
  194. }
  195. }
  196. localInfoList.LocalInfos = filteredLocalInfo
  197. }
  198. return &TalentHttpResult{Code: 0, Msg: "success", Data: localInfoList}
  199. }
  200. func GetLocalLifeDetail(r *ghttp.Request) *TalentHttpResult {
  201. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  202. local_id := r.GetQueryInt("id", 0)
  203. //通过首页进入的详情页,获取服务商id,younggee_supplier表
  204. enterprise_id := r.GetQueryString("enterprise_id", "")
  205. //通过扫服务商码进入的详情页,获取服务商id,younggee_supplier表
  206. //supplier_id := r.GetQueryString("supplier_id", "")
  207. s_local_id := r.GetQueryString("s_local_id", "")
  208. localInfoSupplier := youngee_talent_model.LocalInfoSupplier{}
  209. if s_local_id != "" {
  210. // 来自服务商
  211. err := g.DB().Model("younggee_s_local__info").Where("s_local_id=?", s_local_id).Scan(&localInfoSupplier)
  212. if err != nil {
  213. fmt.Println("projectInfoSupplier err:", err.Error())
  214. }
  215. }
  216. // Redis key
  217. loalViewKey := "local:view:" + strconv.Itoa(local_id)
  218. userViewedKey := "user:viewed:" + tid + ":" + strconv.Itoa(local_id)
  219. if local_id == 0 {
  220. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  221. }
  222. //在redis中增加浏览量
  223. // Check if the user has already viewed the product
  224. //DoVar方便进行类型转化
  225. viewed, err := g.Redis().DoVar("GET", userViewedKey)
  226. if err != nil {
  227. glog.Error(err)
  228. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  229. }
  230. var LocalDetail *youngee_talent_model.LocalInfoDetail
  231. err = g.DB().Model("younggee_local_life_info").WithAll().Where("id", local_id).Scan(&LocalDetail)
  232. if err != nil {
  233. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  234. }
  235. //违约
  236. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", LocalDetail.AutoDefaultId).One()
  237. one2, err := g.DB().Model("info_auto_task").Where("auto_task_id=?", LocalDetail.AutoTaskId).One()
  238. LocalDetail.DraftDefault.BreakPecent = one["sketch_replace_not_upload"].Int()
  239. LocalDetail.LinkDefault.BreakPecent = one["link_replace_not_upload"].Int()
  240. LocalDetail.DataDefault.BreakPecent = one["data_replace_not_upload"].Int()
  241. LocalDetail.DraftDefault.BreakTime = one2["draft_default"].Int()
  242. LocalDetail.DraftDefault.BreakTime = one2["link_breach"].Int()
  243. LocalDetail.DraftDefault.BreakTime = one2["case_close_default"].Int()
  244. if viewed.IsNil() {
  245. // User hasn't viewed this product yet, increase the view count
  246. _, err = g.Redis().Do("INCR", loalViewKey)
  247. if err != nil {
  248. glog.Error(err)
  249. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  250. }
  251. // Mark the product as viewed by this user
  252. _, err = g.Redis().Do("SET", userViewedKey, true)
  253. if err != nil {
  254. glog.Error(err)
  255. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  256. }
  257. }
  258. viewNum, err := g.Redis().DoVar("GET", loalViewKey)
  259. if err != nil {
  260. fmt.Println("获取浏览量失败")
  261. }
  262. LocalDetail.WatchedNum = viewNum.Int()
  263. //浏览历史
  264. currentDate := gtime.Now().Format("Ymd")
  265. // 设计 Redis Key
  266. redisBrowseKey := fmt.Sprintf("browseLocal:%s:%s", currentDate, tid)
  267. fmt.Println("redis浏览记录的key为——————————", redisBrowseKey)
  268. // 将 project_id 添加到 Redis 中的 SET
  269. _, err = g.Redis().Do("SADD", redisBrowseKey, local_id)
  270. if err != nil {
  271. return &TalentHttpResult{Code: 0, Msg: "Redis 存浏览历史数据失败"}
  272. }
  273. // 设置 Key 的过期时间为 7 天
  274. _, err = g.Redis().Do("EXPIRE", redisBrowseKey, 7*24*60*60) // 7 天的秒数
  275. if err != nil {
  276. return &TalentHttpResult{Code: 0, Msg: "Redis 设置过期时间失败"}
  277. }
  278. if enterprise_id != "" { //project来自商家
  279. var enterprise *youngee_talent_model.Enterprise
  280. err = g.DB().Model("enterprise").WithAll().Where("enterprise_id", enterprise_id).Scan(&enterprise)
  281. if err != nil {
  282. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  283. }
  284. LocalDetail.Enterprise = enterprise
  285. }
  286. if s_local_id != "" {
  287. // 来自服务商
  288. var younggeeSupplier *youngee_talent_model.YounggeeSupplier
  289. err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", localInfoSupplier.SupplierID).Scan(&younggeeSupplier)
  290. if err != nil {
  291. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  292. }
  293. LocalDetail.YounggeeSupplier = younggeeSupplier
  294. LocalDetail.LocalInfoSupplier = &localInfoSupplier
  295. }
  296. return &TalentHttpResult{Code: 0, Msg: "success", Data: LocalDetail}
  297. }