local_life_info.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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"
  14. "youngmini_server/app/model/youngee_talent_model"
  15. "youngmini_server/app/service/youngee_talent_service"
  16. "youngmini_server/app/utils"
  17. )
  18. func GetLocalLifeList(r *ghttp.Request) *TalentHttpResult {
  19. pageIndex := r.GetQueryInt("idx", -1)
  20. cntPerPage := r.GetQueryInt("cnt", -1)
  21. //组合筛选
  22. platform := r.Get("platform", "") //抖音、快手、红Book、B站、微博
  23. taskForm := r.Get("task_form", "") //任务形式,1-2分别代表线下探店,素材分发
  24. contentType := r.Get("contenttype", "") //图文形式、视频形式
  25. createTime := r.Get("createTime", "") //任务上线时间
  26. //categoryForm := r.Get("categoryform", "") ////商品类目 智能家居、食品饮料等20种
  27. //todo 城市参数?
  28. //Location := r.GetQueryString("city", "") //门店store所属城市,
  29. //排根据浏览量排序
  30. viewOrder := r.GetQueryInt("pageViewOrder", -1) //根据哪个字段排序
  31. //仅稿费”+“稿费+赠品"。这个在recruit表中,得到列表之后进行排序
  32. feeForm := r.GetInt("feeform", 0)
  33. searchValue := r.Get("searchvalue")
  34. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  35. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  36. }
  37. // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
  38. var taskFormList []interface{}
  39. if taskForm != nil {
  40. if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
  41. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  42. }
  43. taskFormList = make([]interface{}, 0)
  44. taskFormList = taskForm.([]interface{})
  45. } else {
  46. taskFormList = make([]interface{}, 0)
  47. }
  48. // 如果有平台的过滤条件,则将平台列表保存于platformList
  49. var platformList []interface{}
  50. if platform != nil {
  51. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  52. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  53. }
  54. platformList = make([]interface{}, 0)
  55. platformList = platform.([]interface{})
  56. }
  57. // 如果有内容形式的过滤条件,则将过滤条件保存于taskModeList
  58. var contentTypeList []interface{}
  59. if contentType != nil {
  60. if reflect.TypeOf(contentType).Kind() != reflect.Slice {
  61. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  62. }
  63. contentTypeList = make([]interface{}, 0)
  64. contentTypeList = contentType.([]interface{})
  65. }
  66. // 上线时间
  67. var createTimeList []interface{}
  68. if createTime != nil {
  69. if reflect.TypeOf(createTime).Kind() != reflect.Slice {
  70. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  71. }
  72. createTimeList = make([]interface{}, 0)
  73. createTimeList = createTime.([]interface{})
  74. }
  75. // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
  76. //var categoryFormList []interface{}
  77. //if categoryForm != nil {
  78. // if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
  79. // return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  80. // }
  81. //
  82. // categoryFormList = make([]interface{}, 0)
  83. // categoryFormList = categoryForm.([]interface{})
  84. //}
  85. //if len(categoryFormList) > 0 {
  86. // // 使用 categoryFormList 进行某些操作
  87. // fmt.Println("Filtered categoryFormList:", categoryFormList)
  88. //}
  89. // 构造查询的条件
  90. startId := pageIndex * cntPerPage
  91. // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
  92. whereStr := fmt.Sprintf("(task_status >= %d and local_type = 1)", projectStatusRecruiting)
  93. if platformList != nil {
  94. whereStr = whereStr + " and local_platform in ("
  95. for _, v := range platformList {
  96. whereStr += v.(string) + ", "
  97. }
  98. whereStr = whereStr[0 : len(whereStr)-2]
  99. whereStr += ")"
  100. }
  101. if contentTypeList != nil {
  102. whereStr = whereStr + " and content_type in ("
  103. for _, v := range contentTypeList {
  104. whereStr += v.(string) + ", "
  105. }
  106. whereStr = whereStr[0 : len(whereStr)-2]
  107. whereStr += ")"
  108. }
  109. // 处理 selectionFormList (创建时间的过滤条件)
  110. if createTimeList != nil {
  111. whereStr += " AND created_at >= (NOW() - INTERVAL "
  112. for _, v := range createTimeList {
  113. switch v.(string) {
  114. case "1": // 近7天
  115. whereStr += "7 DAY"
  116. case "2": // 近30天
  117. whereStr += "30 DAY"
  118. case "3": // 近90天
  119. whereStr += "90 DAY"
  120. default:
  121. continue // 无效的过滤条件,跳过
  122. }
  123. }
  124. whereStr += ")"
  125. }
  126. if taskFormList != nil {
  127. whereStr += " and task_form in ("
  128. for _, v := range taskFormList {
  129. whereStr += v.(string) + ", "
  130. }
  131. whereStr = whereStr[0 : len(whereStr)-2]
  132. whereStr += ")"
  133. }
  134. if searchValue != nil {
  135. whereStr += " and local_name like '%" + searchValue.(string) + "%'"
  136. }
  137. fmt.Println("whereStr:-----》 ", whereStr)
  138. // 查询所有project
  139. var localList = []youngee_talent_model.YounggeeLocalLifeInfo{}
  140. err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&localList)
  141. if err != nil {
  142. return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
  143. }
  144. // 判断请求页面是否超过最大页面
  145. c, err := g.DB().Model("younggee_local_life_info").Fields("local_id").Where(whereStr).Count()
  146. if c <= 0 {
  147. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  148. }
  149. maxPage := c / cntPerPage
  150. if c%cntPerPage > 0 {
  151. maxPage += 1
  152. }
  153. if pageIndex+1 > maxPage {
  154. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  155. }
  156. var localInfoList = youngee_talent_model.LocalInfoList{}
  157. err = g.DB().Model("younggee_local_life_info").WithAll().Where(whereStr).
  158. Order("task_status ASC,recruit_ddl DESC").Limit(startId, cntPerPage).Scan(&localInfoList.LocalInfos)
  159. if err != nil {
  160. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  161. }
  162. // 遍历projectList
  163. for i, local := range localInfoList.LocalInfos {
  164. //处理浏览量
  165. localViewKey := "local:view:" + gconv.String(local.LocalId)
  166. //redis中取浏览量 返回的是gvar.Var类型。 不存咋则为nil。经过viewCount.Int变成0
  167. viewCount, err := g.Redis().DoVar("GET", localViewKey)
  168. if err != nil {
  169. glog.Error(err)
  170. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  171. }
  172. localInfoList.LocalInfos[i].WatchNum = viewCount.Int()
  173. // 根据 WatchedNum 从高到低排序
  174. if viewOrder != -1 {
  175. sort.Slice(localInfoList.LocalInfos, func(i, j int) bool {
  176. return localInfoList.LocalInfos[i].WatchNum > localInfoList.LocalInfos[j].WatchNum
  177. })
  178. }
  179. }
  180. localInfoList.MaxPage = maxPage
  181. var filteredLocalInfo []*youngee_talent_model.YounggeeLocalLifeInfo
  182. //筛选出“仅稿费”+“稿费+赠品”任务,
  183. //只要策略中有 无费置换 之外的fee_form就是有稿费,donate=1就是有赠品
  184. if feeForm != 0 {
  185. for _, local := range localInfoList.LocalInfos {
  186. if local.Donate == 1 {
  187. filteredLocalInfo = append(filteredLocalInfo, local)
  188. continue // 如果满足条件1,直接跳过后续条件判断
  189. }
  190. // 条件2:RecruitStrategy 中存在 fee_form 不等于 1 的数据
  191. for _, strategy := range local.RecruitStrategys {
  192. if strategy.FeeForm != 1 {
  193. filteredLocalInfo = append(filteredLocalInfo, local)
  194. break // 找到符合条件的策略,跳出当前循环,避免重复添加
  195. }
  196. }
  197. }
  198. localInfoList.LocalInfos = filteredLocalInfo
  199. }
  200. return &TalentHttpResult{Code: 0, Msg: "success", Data: localInfoList}
  201. }
  202. func GetLocalLifeDetail(r *ghttp.Request) *TalentHttpResult {
  203. tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  204. local_id := r.GetQueryInt("id", 0)
  205. //通过首页进入的详情页,获取服务商id,younggee_supplier表
  206. enterprise_id := r.GetQueryString("enterprise_id", "")
  207. //通过扫服务商码进入的详情页,获取服务商id,younggee_supplier表
  208. //supplier_id := r.GetQueryString("supplier_id", "")
  209. s_local_id := r.GetQueryString("s_local_id", "")
  210. localInfoSupplier := youngee_talent_model.LocalInfoSupplier{}
  211. if s_local_id != "" {
  212. // 来自服务商
  213. err := g.DB().Model("younggee_s_local__info").Where("s_local_id=?", s_local_id).Scan(&localInfoSupplier)
  214. if err != nil {
  215. fmt.Println("projectInfoSupplier err:", err.Error())
  216. }
  217. }
  218. // Redis key
  219. loalViewKey := "local:view:" + strconv.Itoa(local_id)
  220. userViewedKey := "user:viewed:" + tid + ":" + strconv.Itoa(local_id)
  221. if local_id == 0 {
  222. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  223. }
  224. //在redis中增加浏览量
  225. // Check if the user has already viewed the product
  226. //DoVar方便进行类型转化
  227. viewed, err := g.Redis().DoVar("GET", userViewedKey)
  228. if err != nil {
  229. glog.Error(err)
  230. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  231. }
  232. var LocalDetail *youngee_talent_model.LocalInfoDetail
  233. err = g.DB().Model("younggee_local_life_info").WithAll().Where("id", local_id).Scan(&LocalDetail)
  234. if err != nil {
  235. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  236. }
  237. //违约
  238. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", LocalDetail.AutoDefaultId).One()
  239. one2, err := g.DB().Model("info_auto_task").Where("auto_task_id=?", LocalDetail.AutoTaskId).One()
  240. LocalDetail.DraftDefault.BreakPecent = one["sketch_replace_not_upload"].Int()
  241. LocalDetail.LinkDefault.BreakPecent = one["link_replace_not_upload"].Int()
  242. LocalDetail.DataDefault.BreakPecent = one["data_replace_not_upload"].Int()
  243. LocalDetail.DraftDefault.BreakTime = one2["draft_default"].Int()
  244. LocalDetail.DraftDefault.BreakTime = one2["link_breach"].Int()
  245. LocalDetail.DraftDefault.BreakTime = one2["case_close_default"].Int()
  246. if viewed.IsNil() {
  247. // User hasn't viewed this product yet, increase the view count
  248. _, err = g.Redis().Do("INCR", loalViewKey)
  249. if err != nil {
  250. glog.Error(err)
  251. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  252. }
  253. // Mark the product as viewed by this user
  254. _, err = g.Redis().Do("SET", userViewedKey, true)
  255. if err != nil {
  256. glog.Error(err)
  257. return &TalentHttpResult{Code: 0, Msg: "Redis error"}
  258. }
  259. }
  260. viewNum, err := g.Redis().DoVar("GET", loalViewKey)
  261. if err != nil {
  262. fmt.Println("获取浏览量失败")
  263. }
  264. LocalDetail.WatchedNum = viewNum.Int()
  265. //浏览历史
  266. currentDate := gtime.Now().Format("Ymd")
  267. // 设计 Redis Key
  268. redisBrowseKey := fmt.Sprintf("browseLocal:%s:%s", currentDate, tid)
  269. fmt.Println("redis浏览记录的key为——————————", redisBrowseKey)
  270. _, err = g.Redis().Do("SADD", redisBrowseKey, local_id)
  271. if err != nil {
  272. return &TalentHttpResult{Code: 0, Msg: "Redis 存浏览历史数据失败"}
  273. }
  274. // 设置 Key 的过期时间为 7 天
  275. _, err = g.Redis().Do("EXPIRE", redisBrowseKey, 7*24*60*60) // 7 天的秒数
  276. if err != nil {
  277. return &TalentHttpResult{Code: 0, Msg: "Redis 设置过期时间失败"}
  278. }
  279. if enterprise_id != "" { //project来自商家
  280. var enterprise *youngee_talent_model.Enterprise
  281. err = g.DB().Model("enterprise").WithAll().Where("enterprise_id", enterprise_id).Scan(&enterprise)
  282. if err != nil {
  283. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  284. }
  285. LocalDetail.Enterprise = enterprise
  286. }
  287. if s_local_id != "" {
  288. // 来自服务商
  289. var younggeeSupplier *youngee_talent_model.YounggeeSupplier
  290. err = g.DB().Model("younggee_supplier").WithAll().Where("supplier_id", localInfoSupplier.SupplierID).Scan(&younggeeSupplier)
  291. if err != nil {
  292. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  293. }
  294. LocalDetail.YounggeeSupplier = younggeeSupplier
  295. LocalDetail.LocalInfoSupplier = &localInfoSupplier
  296. }
  297. return &TalentHttpResult{Code: 0, Msg: "success", Data: LocalDetail}
  298. }
  299. // 查询所有任务
  300. func GetLocalTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  301. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  302. if err != nil {
  303. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  304. }
  305. // 构造查询条件
  306. whereStr := fmt.Sprintf("talent_id = '%s'", tid)
  307. // 获取任务列表
  308. var taskList []*youngee_talent_model.YoungeeLocalTaskInfo
  309. //此达人下,所有快手账号的任务都展示
  310. err = g.Model("youngee_local_task_info").Where(whereStr).Scan(&taskList)
  311. if err != nil {
  312. return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  313. }
  314. //后续根据 PlatformId 快速查找平台信息。platformMap的key是PlatformId,value是平台具体描述
  315. platformMap := make(map[string]model.InfoThirdPlatform)
  316. platformInfo := []*model.InfoThirdPlatform{}
  317. if len(taskList) != 0 {
  318. err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  319. if err != nil {
  320. return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  321. }
  322. for i, _ := range platformInfo {
  323. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  324. }
  325. }
  326. //为每个任务根据项目id查询项目名称和主图
  327. //taskBriefList存了各个阶段的tasklist
  328. taskBriefList := youngee_talent_model.LocalTaskInfoBriefList{}
  329. for _, v := range taskList { //taskList含所有任务
  330. //获取具体的招募策略,taskInfo中
  331. var localDetail *youngee_talent_model.LocalInfoDetail
  332. err := g.Model("younggee_local_life_info").WithAll().Where("local_id = ?", v.LocalId).Scan(&localDetail)
  333. if err != nil {
  334. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  335. }
  336. var account *youngee_talent_model.KuaishouUserInfo
  337. fmt.Println("openid---->", v.OpenId)
  338. err = g.Model("platform_kuaishou_user_info").Where("platform_id = ? and talent_id = ? and open_id = ?", localDetail.LocalPlatform, tid, v.OpenId).Scan(&account)
  339. //拿快手平台验证是否过期
  340. expired := youngee_talent_service.CheckKuaishouTokenExp(account.OpenId)
  341. account.Expired = expired
  342. if err != nil {
  343. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  344. }
  345. //taskInfoBrief含需要展示在页面的内容,被加入各阶段List
  346. taskInfoBrief := &youngee_talent_model.LocalTaskInfoBrief{
  347. TaskId: v.TaskId,
  348. PlatformIconUrl: platformMap[strconv.Itoa(localDetail.PlatformInfo.PlatformId)].PlatformIcon,
  349. //PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  350. //PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  351. ProjectName: localDetail.LocalName,
  352. //ProductPhotoSnap: localDetail.ProductPhotoSnap,
  353. TaskStatus: v.TaskStatus,
  354. TaskStage: v.TaskStage,
  355. LinkStatus: v.LinkStatus,
  356. DataStatus: v.DataStatus,
  357. //ScriptStatus: v.ScriptStatus,
  358. SketchStatus: v.SketchStatus,
  359. TaskReward: v.TaskReward,
  360. BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  361. CurBreakAt: v.CurBreakAt,
  362. FeeForm: v.FeeForm,
  363. LocalDetail: localDetail,
  364. TaskInfo: v,
  365. AccountInfo: account, //含是否过期,粉丝数,作品数目
  366. }
  367. taskBriefList.AllTaskInfoList = append(taskBriefList.AllTaskInfoList, taskInfoBrief)
  368. if v.TaskStage <= 2 {
  369. taskBriefList.SignUpTaskInfoList = append(taskBriefList.SignUpTaskInfoList, taskInfoBrief)
  370. } else if v.TaskStage == 4 { //如果是线下探店
  371. taskBriefList.WaitBookList = append(taskBriefList.WaitBookList, taskInfoBrief)
  372. } else if v.TaskStage <= 14 && v.TaskStage >= 5 {
  373. taskBriefList.GoingOnTaskInfoList = append(taskBriefList.GoingOnTaskInfoList, taskInfoBrief)
  374. } else {
  375. taskBriefList.CompletedTaskInfoList = append(taskBriefList.CompletedTaskInfoList, taskInfoBrief)
  376. }
  377. }
  378. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  379. }
  380. func GetLocalTaskDetail(r *ghttp.Request) *TalentHttpResult {
  381. taskId := r.GetQueryInt("task_id", -1)
  382. var task *youngee_talent_model.YoungeeLocalTaskInfo
  383. err := g.Model("youngee_local_task_info").Where("task_id = ?", taskId).Scan(&task)
  384. if err != nil {
  385. return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
  386. }
  387. var localDetail *youngee_talent_model.LocalInfoDetail
  388. err = g.Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("local_id", task.LocalId).Scan(&localDetail)
  389. if err != nil {
  390. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  391. }
  392. var productPhoto *youngee_talent_model.YounggeeProductPhoto
  393. err = g.Model("younggee_product_photo").Where("store_id = ? and symbol = 1", localDetail.StoreId).Scan(&productPhoto)
  394. if err != nil {
  395. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  396. }
  397. var withdrawStatus = 1
  398. var taskIncome *model.YounggeeTalentIncome
  399. err = g.Model(dao.YounggeeTalentIncome.Table).Where("task_id = ? and income_type = 1", taskId).Scan(&taskIncome)
  400. if err != nil {
  401. return &TalentHttpResult{Code: -3, Msg: "Get task income detail failed."}
  402. }
  403. if taskIncome != nil {
  404. withdrawStatus = taskIncome.WithdrawStatus + 1
  405. }
  406. taskDetail := &youngee_talent_model.LocalTaskDetail{}
  407. if localDetail.LocalType == 1 {
  408. var strategy *youngee_talent_model.RecruitStrategy
  409. err = g.Model(dao.RecruitStrategy.Table).Where("local_id = ? and strategy_id = ?", task.LocalId, task.StrategyId).Scan(&strategy)
  410. if err != nil {
  411. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  412. }
  413. taskDetail = &youngee_talent_model.LocalTaskDetail{
  414. TaskInfo: task,
  415. LocalDetail: localDetail,
  416. ProductPhoto: productPhoto,
  417. Strategy: strategy,
  418. WithdrawStatus: withdrawStatus,
  419. }
  420. } else {
  421. taskDetail = &youngee_talent_model.LocalTaskDetail{
  422. TaskInfo: task,
  423. LocalDetail: localDetail,
  424. ProductPhoto: productPhoto,
  425. WithdrawStatus: withdrawStatus,
  426. }
  427. }
  428. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  429. }
  430. func GetLocalTaskBook(r *ghttp.Request) *TalentHttpResult {
  431. taskId := r.Get("task_id")
  432. res, err := g.DB().Model("younggee_book_info").Where("is_review = 1 and task_id = ?", taskId).OrderDesc("create_at").All()
  433. if err != nil {
  434. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  435. }
  436. return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
  437. }
  438. // 添加初稿service done
  439. func AddLocalTaskBook(r *ghttp.Request) *TalentHttpResult {
  440. var bookInfoReq *youngee_talent_model.AddLocalTaskBookRequest
  441. //解析添加初稿的图文
  442. err := r.ParseForm(&bookInfoReq)
  443. if err != nil {
  444. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  445. }
  446. taskbookInfo := []youngee_talent_model.LocalTaskBookInfo{}
  447. err = g.DB().Model("younggee_book_info").Where("task_id = ? ", bookInfoReq.TaskId).OrderDesc("create_at").Scan(&taskbookInfo)
  448. if err != nil {
  449. return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed"}
  450. }
  451. //上传过但是被拒了
  452. var condition1 bool = len(taskbookInfo) != 0 && taskbookInfo[0].IsReview == 1 && taskbookInfo[0].IsOk == 0
  453. //没有上传过初稿
  454. var condition2 bool = len(taskbookInfo) == 0
  455. bookInfo := youngee_talent_model.LocalTaskBookInfo{
  456. TaskId: bookInfoReq.TaskId,
  457. Day: bookInfoReq.Day,
  458. Time: bookInfoReq.Time,
  459. CreateAt: gtime.Now(),
  460. IsReview: 0,
  461. IsSubmit: 0, //忽略
  462. IsOk: 0,
  463. }
  464. //只有这两种情况才能上传探店时间
  465. if condition1 || condition2 {
  466. //插入新数据
  467. _, err := g.DB().Model("younggee_book_info").Data(bookInfo).InsertAndGetId()
  468. if err != nil {
  469. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo insert failed"}
  470. }
  471. }
  472. //修改task表中的字段待添加变成已添加,待修改变成已修改
  473. bookStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("book_status").Where("task_id = ?", bookInfoReq.TaskId).Value()
  474. if err != nil {
  475. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  476. }
  477. if bookStatus.Int64() == 1 {
  478. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", bookInfoReq.TaskId).Update(g.Map{"bookStatus": 2})
  479. if err != nil {
  480. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  481. }
  482. } else if bookStatus.Int64() == 3 {
  483. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", bookInfoReq.TaskId).Update(g.Map{"bookStatus": 4})
  484. if err != nil {
  485. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  486. }
  487. }
  488. //task设置为预约确认中
  489. _, err = g.DB().Model("youngee_local_task_info").Data(g.Map{"task_stage": "5"}).Where("task_id = ?", bookInfoReq.TaskId).Update()
  490. return &TalentHttpResult{Code: 0, Msg: "success"}
  491. }
  492. func AddLocalTaskPhoto(r *ghttp.Request) *TalentHttpResult {
  493. var bookInfoReq *youngee_talent_model.AddLocalTaskPhotoRequest
  494. //解析添加初稿的图文
  495. err := r.ParseForm(&bookInfoReq)
  496. if err != nil {
  497. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  498. }
  499. bookPhotoInfo := youngee_talent_model.YounggeeBookPhoto{
  500. TaskId: bookInfoReq.TaskId,
  501. PhotoUrl: bookInfoReq.PhotoUrl,
  502. CreateAt: gtime.Now(),
  503. }
  504. //修改task表中的字段待添加变成已添加,待修改变成已修改
  505. _, err = g.DB().Model("younggee_book_photo").Data(&bookPhotoInfo).Insert()
  506. if err != nil {
  507. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  508. }
  509. _, err = g.DB().Model("youngee_local_task_info").Where("task_id = ?", bookInfoReq.TaskId).Data(g.Map{"task_stage": 9}).Update()
  510. _, err = g.DB().Model("youngee_local_task_info").Where("task_id = ?", bookInfoReq.TaskId).Data(g.Map{"book_status": 5}).Update()
  511. if err != nil {
  512. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  513. }
  514. return &TalentHttpResult{Code: 0, Msg: "success"}
  515. }