task_info.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. package youngee_task_service
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "youngmini_server/app/dao"
  7. "youngmini_server/app/model"
  8. "youngmini_server/app/model/youngee_talent_model"
  9. "youngmini_server/app/service/youngee_talent_service"
  10. "youngmini_server/app/utils"
  11. "github.com/gogf/gf/database/gdb"
  12. "github.com/gogf/gf/encoding/gjson"
  13. "github.com/gogf/gf/frame/g"
  14. "github.com/gogf/gf/net/ghttp"
  15. "github.com/gogf/gf/os/gtime"
  16. )
  17. // 新建任务service
  18. //func SignUpTask(r *ghttp.Request) *TalentHttpResult {
  19. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  20. // if err != nil {
  21. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  22. // }
  23. //
  24. // var signTaskInfo *youngee_talent_model.SignTaskInfo
  25. // err = r.ParseForm(&signTaskInfo)
  26. // if err != nil {
  27. // return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  28. // }
  29. // var projectDetail *youngee_talent_model.ProjectDetail
  30. // err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  31. // if err != nil {
  32. // return &TalentHttpResult{Code: -3, Msg: err.Error()}
  33. // }
  34. //
  35. // var talentInfo *youngee_talent_model.TalentInfo
  36. // err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  37. // if err != nil {
  38. // return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  39. // }
  40. //
  41. // var accountInfo *youngee_talent_model.PlatformAccountInfo
  42. // err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
  43. // if err != nil {
  44. // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  45. // }
  46. //
  47. // address, err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).One("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId)
  48. // if err != nil {
  49. // return &TalentHttpResult{Code: -6, Msg: err.Error()}
  50. // }
  51. //
  52. // var newTaskId string
  53. // // 首先生成任务id
  54. // newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  55. //
  56. // //// 生成达人平台账号信息快照
  57. // accountSnap, err := gjson.Encode(accountInfo)
  58. // //if err != nil {
  59. // // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  60. // //}
  61. //
  62. // // 生成达人信息快照
  63. // talentSnap, err := gjson.Encode(talentInfo)
  64. // if err != nil {
  65. // return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  66. // }
  67. //
  68. // // 生成收货地址快照
  69. // addrSnap, err := gjson.Encode(address)
  70. // if err != nil {
  71. // return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  72. // }
  73. // taskInfo := model.YoungeeTaskInfo{}
  74. // if projectDetail.ProjectType == 1 {
  75. // // 全流程任务
  76. //
  77. // // 计算平台服务费
  78. // // 1. 先获取稿费形式
  79. // var strategy *youngee_talent_model.RecruitStrategy
  80. // err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  81. // if err != nil {
  82. // return &TalentHttpResult{Code: -10, Msg: err.Error()}
  83. // }
  84. //
  85. // // 2. 根据稿费形式、平台、粉丝数获取服务费最高的定价策略
  86. // // 2.1 查询所有对应定价策略
  87. // whereStr1 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up > %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersLow)
  88. // orStr1 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low < %d and fans_up >= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersUp, strategy.FollowersUp)
  89. // orStr2 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low >= %d and fans_up <= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersUp)
  90. // orStr3 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up >= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersUp)
  91. // var pricings []*model.InfoPricingStrategy
  92. // err = g.DB().Model("recruit_strategy").WithAll().Where(whereStr1).Or(orStr1).Or(orStr2).Or(orStr3).Scan(&pricings)
  93. // if err != nil {
  94. // return &TalentHttpResult{Code: -11, Msg: err.Error()}
  95. // } else if pricings == nil {
  96. // return &TalentHttpResult{Code: -12, Msg: "无相关定价策略"}
  97. // }
  98. // var pricing *model.InfoPricingStrategy
  99. // // 2.2 从对应定价策略中选取服务费率最高
  100. // if strategy.FeeForm == 1 {
  101. // var maxCharge float64 = 0
  102. // for _, v := range pricings {
  103. // if v.ServiceCharge >= maxCharge {
  104. // maxCharge = v.ServiceCharge
  105. // pricing = v
  106. // }
  107. // }
  108. // } else {
  109. // var maxRate int = 0
  110. // for _, v := range pricings {
  111. // if v.ServiceRate >= maxRate {
  112. // maxRate = v.ServiceRate
  113. // pricing = v
  114. // }
  115. // }
  116. // }
  117. // var serviceCharge = 0.0
  118. // var serviceRate = 0
  119. // var allReward = 0.0
  120. // var allPayment = 0.0
  121. // switch strategy.FeeForm {
  122. // case 1: // 产品置换,服务费固定,在项目生成时确定
  123. // serviceCharge = float64(strategy.ServiceCharge)
  124. // allPayment = serviceCharge
  125. // break
  126. // case 2: // 固定稿费,m2 = y2 * r2
  127. // allPayment = float64(strategy.Offer)
  128. // serviceRate = pricing.ServiceRate
  129. // serviceCharge = allPayment * float64(serviceRate) / 1000
  130. // allReward = allPayment - serviceCharge
  131. // break
  132. // case 3: // 自报价,m3 = x3 * r3
  133. // allReward = float64(signTaskInfo.Offer)
  134. // serviceRate = pricing.ServiceRate
  135. // var tmpRate = float64(1000-serviceRate) / 1000
  136. // allPayment = allReward / tmpRate
  137. // serviceCharge = allPayment - allReward
  138. // break
  139. // default:
  140. // break
  141. // }
  142. // taskInfo = model.YoungeeTaskInfo{
  143. // TaskId: newTaskId,
  144. // ProjectId: signTaskInfo.ProjectId,
  145. // TalentId: tid,
  146. // AccountId: accountInfo.AccountId,
  147. // TalentPlatformInfoSnap: string(accountSnap),
  148. // TalentPersonalInfoSnap: string(talentSnap),
  149. // TalentPostAddrSnap: string(addrSnap),
  150. // StrategyId: signTaskInfo.StrategyId,
  151. // TaskReward: allReward,
  152. // SettleAmount: allReward,
  153. // AllPayment: allPayment,
  154. // TaskStage: 1,
  155. // RealPayment: allPayment,
  156. // FeeForm: strategy.FeeForm,
  157. // ServiceCharge: serviceCharge,
  158. // ServiceRate: serviceRate,
  159. // CreateDate: gtime.Now(),
  160. // TaskStatus: 1,
  161. // LogisticsStatus: 1,
  162. // LinkStatus: 1,
  163. // DataStatus: 1,
  164. // ScriptStatus: 1,
  165. // SketchStatus: 1,
  166. // CompleteStatus: 1,
  167. // CurDefaultType: 0,
  168. // WithdrawStatus: 1,
  169. // SettleStatus: 1,
  170. // }
  171. // } else {
  172. // // 专项任务
  173. // taskInfo = model.YoungeeTaskInfo{
  174. // TaskId: newTaskId,
  175. // ProjectId: signTaskInfo.ProjectId,
  176. // TalentId: tid,
  177. // AccountId: accountInfo.AccountId,
  178. // //TalentPlatformInfoSnap: string(accountSnap),
  179. // TalentPersonalInfoSnap: string(talentSnap),
  180. // TalentPostAddrSnap: string(addrSnap),
  181. // TaskStage: 1,
  182. // CreateDate: gtime.Now(),
  183. // TaskStatus: 1,
  184. // LogisticsStatus: 1,
  185. // LinkStatus: 1,
  186. // DataStatus: 1,
  187. // ScriptStatus: 1,
  188. // SketchStatus: 1,
  189. // CompleteStatus: 1,
  190. // CurDefaultType: 0,
  191. // WithdrawStatus: 1,
  192. // }
  193. // }
  194. // err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  195. // // 在task_info表中插入任务
  196. // _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
  197. // if err != nil {
  198. // return err
  199. // }
  200. //
  201. // // 对应项目的报名人数自增
  202. // _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
  203. // if err != nil {
  204. // return err
  205. // }
  206. // return nil
  207. // })
  208. // if err != nil {
  209. // return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  210. // }
  211. //
  212. // return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  213. //}
  214. // 判断是否已报名任务,快手平台账号选择时,已经判断过
  215. func IsSignUpTask(r *ghttp.Request) *TalentHttpResult {
  216. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  217. if err != nil {
  218. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  219. }
  220. projectId := r.GetQueryInt("project_id", -1)
  221. fmt.Printf("%+v\n", projectId)
  222. task := []model.YoungeeTaskInfo{}
  223. err = g.Model(dao.YoungeeTaskInfo.Table).Where("project_id = ? and talent_id = ?", projectId, tid).Scan(&task)
  224. if err != nil {
  225. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  226. }
  227. isSign := youngee_talent_model.IsSign{}
  228. if len(task) != 0 {
  229. isSign.TaskInfo = &task[0]
  230. isSign.IsSign = 1
  231. isSign.IsAgree = task[0].TaskStatus
  232. } else {
  233. isSign.IsSign = 0
  234. isSign.IsAgree = 0
  235. }
  236. return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
  237. }
  238. // 查询所有任务
  239. func GetTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  240. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  241. if err != nil {
  242. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  243. }
  244. // 构造查询条件
  245. whereStr := fmt.Sprintf("talent_id = '%s'", tid)
  246. fmt.Print(whereStr)
  247. // 获取任务列表
  248. var taskList []*youngee_talent_model.YoungeeTaskInfo
  249. //此达人下,所有快手账号的任务都展示
  250. err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr).Scan(&taskList)
  251. if err != nil {
  252. return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  253. }
  254. //便后续根据 PlatformId 快速查找平台信息。platformMap的key是PlatformId,value是平台具体描述
  255. platformMap := make(map[string]model.InfoThirdPlatform)
  256. platformInfo := []*model.InfoThirdPlatform{}
  257. if len(taskList) != 0 {
  258. err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  259. if err != nil {
  260. return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  261. }
  262. for i, _ := range platformInfo {
  263. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  264. }
  265. }
  266. // 为每个任务根据项目id查询项目名称和主图
  267. //taskBriefList存了各个阶段的tasklist
  268. taskBriefList := youngee_talent_model.TaskInfoBriefList{}
  269. for _, v := range taskList { //taskList含所有任务
  270. //获取具体的招募策略,taskInfo中
  271. var projectDetail *youngee_talent_model.ProjectDetail
  272. err := g.Model("project_info").WithAll().Where("project_id = ?", v.ProjectId).Scan(&projectDetail)
  273. fmt.Println("projectDetail-----", projectDetail)
  274. if err != nil {
  275. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  276. }
  277. var account *youngee_talent_model.KuaishouUserInfo
  278. err = g.Model("platform_kuaishou_user_info").Where("platform_id = ? and talent_id = ? and open_id = ?", 8, tid, v.OpenId).Scan(&account)
  279. //拿快手平台验证是否过期
  280. expired := youngee_talent_service.CheckKuaishouTokenExp(account.OpenId)
  281. account.Expired = expired
  282. if err != nil {
  283. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  284. }
  285. //taskInfoBrief含需要展示在页面的内容,被加入各阶段List
  286. taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  287. TaskId: v.TaskId,
  288. PlatformIconUrl: platformMap[strconv.Itoa(projectDetail.PlatformInfo.PlatformId)].PlatformIcon,
  289. //PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  290. //PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  291. ProjectName: projectDetail.ProjectName,
  292. ProductPhotoSnap: projectDetail.ProductPhotoSnap,
  293. TaskStatus: v.TaskStatus,
  294. TaskStage: v.TaskStage,
  295. LinkStatus: v.LinkStatus,
  296. DataStatus: v.DataStatus,
  297. ScriptStatus: v.ScriptStatus,
  298. SketchStatus: v.SketchStatus,
  299. TaskReward: v.TaskReward,
  300. BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  301. CurBreakAt: v.CurBreakAt,
  302. FeeForm: v.FeeForm,
  303. ProjectDetail: projectDetail,
  304. TaskInfo: v,
  305. AccountInfo: account, //含是否过期,粉丝数,作品数目
  306. }
  307. taskBriefList.AllTaskInfoList = append(taskBriefList.AllTaskInfoList, taskInfoBrief)
  308. if v.TaskStage <= 2 {
  309. taskBriefList.SignUpTaskInfoList = append(taskBriefList.SignUpTaskInfoList, taskInfoBrief)
  310. } else if v.TaskStage <= 14 && v.TaskStage >= 4 {
  311. taskBriefList.GoingOnTaskInfoList = append(taskBriefList.GoingOnTaskInfoList, taskInfoBrief)
  312. } else {
  313. taskBriefList.CompletedTaskInfoList = append(taskBriefList.CompletedTaskInfoList, taskInfoBrief)
  314. }
  315. }
  316. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  317. }
  318. // 查询执行中所有任务
  319. //func GetExeTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  320. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  321. // if err != nil {
  322. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  323. // }
  324. // var taskStageList = [5]int{0, 7, 9, 11, 13}
  325. // taskStageKey := r.GetQueryInt("taskStage", 0)
  326. // if taskStageKey == 0 {
  327. // return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  328. // }
  329. // taskStage := taskStageList[taskStageKey+1]
  330. //
  331. // // 获取任务列表
  332. // //这是一个切片,其中的每个元素都是指向 model.YoungeeTaskInfo 结构体的指针。通常用于存储多个任务信息的列表。
  333. // var taskList []*model.YoungeeTaskInfo
  334. // whereCondition := g.Map{
  335. // dao.YoungeeTaskInfo.Columns.TalentId: tid,
  336. // dao.YoungeeTaskInfo.Columns.TaskStage: taskStage,
  337. // }
  338. // err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereCondition).Scan(&taskList)
  339. // if err != nil {
  340. // return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  341. // }
  342. //
  343. // platformMap := make(map[string]model.InfoThirdPlatform)
  344. // var platformInfo []*model.InfoThirdPlatform
  345. // if len(taskList) != 0 {
  346. // err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  347. // if err != nil {
  348. // return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  349. // }
  350. //
  351. // for i, _ := range platformInfo {
  352. // platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  353. // }
  354. // }
  355. //
  356. // // 为每个任务根据项目id查询项目名称和主图
  357. // var taskBriefList []*youngee_talent_model.TaskInfoBrief
  358. // for _, v := range taskList {
  359. // whereCondition = g.Map{
  360. // dao.ProjectInfo.Columns.ProjectId: v.ProjectId,
  361. // }
  362. // projectInfo, err := g.Model(dao.ProjectInfo.Table).Where(whereCondition).One()
  363. // if err != nil {
  364. // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  365. // }
  366. // whereCondition = g.Map{
  367. // dao.YoungeePlatformAccountInfo.Columns.PlatformId: projectInfo[dao.ProjectInfo.Columns.ProjectPlatform],
  368. // dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  369. // }
  370. // account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One()
  371. // if err != nil {
  372. // return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  373. // }
  374. // taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  375. // TaskId: v.TaskId,
  376. // PlatformIconUrl: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformIcon,
  377. // PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  378. // PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  379. // ProjectName: projectInfo[dao.ProjectInfo.Columns.ProjectName].String(),
  380. // ProductPhotoSnap: projectInfo[dao.ProjectInfo.Columns.ProductPhotoSnap].String(),
  381. // TaskStatus: v.TaskStatus,
  382. // TaskStage: v.TaskStage,
  383. // LinkStatus: v.LinkStatus,
  384. // DataStatus: v.DataStatus,
  385. // ScriptStatus: v.ScriptStatus,
  386. // SketchStatus: v.SketchStatus,
  387. // TaskReward: v.TaskReward,
  388. // BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  389. // CurBreakAt: v.CurBreakAt,
  390. // FeeForm: v.FeeForm,
  391. // }
  392. // taskBriefList = append(taskBriefList, taskInfoBrief)
  393. // }
  394. //
  395. // return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  396. //}
  397. // 查询执行中所有任务
  398. func GetExeTaskNum(r *ghttp.Request) *TalentHttpResult {
  399. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  400. if err != nil {
  401. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  402. }
  403. nums, err := g.Model("youngee_task_info").Where("talent_id = ?", tid).Fields("COUNT(*) ,task_stage").Group("task_stage").All()
  404. if err != nil {
  405. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  406. }
  407. return &TalentHttpResult{Code: 0, Msg: "success", Data: nums}
  408. }
  409. func GetTaskNum(r *ghttp.Request) *TalentHttpResult {
  410. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  411. if err != nil {
  412. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  413. }
  414. // 构造查询条件
  415. whereStr1 := fmt.Sprintf("talent_id = '%s'", tid)
  416. whereStr2 := fmt.Sprintf("talent_id = '%s' and task_stage <= 2", tid)
  417. whereStr3 := fmt.Sprintf("talent_id = '%s' and task_stage <= 14 and task_stage >= 4", tid)
  418. whereStr4 := fmt.Sprintf("talent_id = '%s' and (task_stage = 3 or task_stage >= 15)", tid)
  419. num1, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr1).Count()
  420. if err != nil {
  421. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  422. }
  423. num2, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr2).Count()
  424. if err != nil {
  425. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  426. }
  427. num3, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr3).Count()
  428. if err != nil {
  429. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  430. }
  431. num4, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr4).Count()
  432. if err != nil {
  433. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  434. }
  435. TaskNum := &youngee_talent_model.TaskNum{
  436. AllNum: num1,
  437. SignUpNum: num2,
  438. GoingOnNum: num3,
  439. CompletedNum: num4,
  440. }
  441. return &TalentHttpResult{Code: 0, Msg: "success", Data: TaskNum}
  442. }
  443. // 获取任务详情
  444. func GetTaskDetail(r *ghttp.Request) *TalentHttpResult {
  445. taskId := r.GetQueryInt("task_id", -1)
  446. var task *model.YoungeeTaskInfo
  447. err := g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", taskId).Scan(&task)
  448. if err != nil {
  449. return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
  450. }
  451. var projectDetail *youngee_talent_model.ProjectDetail
  452. err = g.Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", task.ProjectId).Scan(&projectDetail)
  453. if err != nil {
  454. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  455. }
  456. var productPhoto *model.YounggeeProductPhoto
  457. err = g.Model(dao.YounggeeProductPhoto.Table).Where("product_id = ? and symbol = 1", projectDetail.ProductId).Scan(&productPhoto)
  458. if err != nil {
  459. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  460. }
  461. var withdrawStatus = 1
  462. var taskIncome *model.YounggeeTalentIncome
  463. err = g.Model(dao.YounggeeTalentIncome.Table).Where("task_id = ? and income_type = 1", taskId).Scan(&taskIncome)
  464. if err != nil {
  465. return &TalentHttpResult{Code: -3, Msg: "Get task income detail failed."}
  466. }
  467. if taskIncome != nil {
  468. withdrawStatus = taskIncome.WithdrawStatus + 1
  469. }
  470. taskDetail := &youngee_talent_model.TaskDetail{}
  471. if projectDetail.ProjectType == 1 {
  472. var strategy *model.RecruitStrategy
  473. err = g.Model(dao.RecruitStrategy.Table).Where("project_id = ? and strategy_id = ?", task.ProjectId, task.StrategyId).Scan(&strategy)
  474. if err != nil {
  475. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  476. }
  477. taskDetail = &youngee_talent_model.TaskDetail{
  478. TaskInfo: task,
  479. ProjectDetail: projectDetail,
  480. ProductPhoto: productPhoto,
  481. Strategy: strategy,
  482. WithdrawStatus: withdrawStatus,
  483. }
  484. } else {
  485. taskDetail = &youngee_talent_model.TaskDetail{
  486. TaskInfo: task,
  487. ProjectDetail: projectDetail,
  488. ProductPhoto: productPhoto,
  489. WithdrawStatus: withdrawStatus,
  490. }
  491. }
  492. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  493. }
  494. // 匹配种草策略,含是否可选属性
  495. func GetProjRecruitList(r *ghttp.Request) *TalentHttpResult {
  496. fanNum := r.GetQueryInt("fan_num", -1)
  497. projectId := r.GetQueryString("project_id", -1)
  498. var recruitStrategies []*youngee_talent_model.RecruitStrategy
  499. err := g.DB().Model("recruit_strategy").Where("project_id = ?", projectId).Scan(&recruitStrategies)
  500. if err != nil {
  501. fmt.Println(err.Error())
  502. }
  503. for _, strategy := range recruitStrategies {
  504. // 判断粉丝数是否满足当前策略的要求
  505. if fanNum >= strategy.FollowersLow {
  506. // 如果粉丝数满足策略的范围,设置 is_fit 为 1
  507. strategy.IsFit = 1
  508. } else {
  509. // 否则设置 is_fit 为 0
  510. strategy.IsFit = 0
  511. }
  512. }
  513. //根据projectId获取招募策略表多条策略,
  514. return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
  515. }
  516. // 报名种草任务
  517. func SignUpTaskWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  518. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  519. if err != nil {
  520. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  521. }
  522. //POST请求体信息
  523. var signTaskInfo *youngee_talent_model.SignTaskInfo
  524. err = r.ParseForm(&signTaskInfo)
  525. if err != nil {
  526. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  527. }
  528. //种草详情信息
  529. var projectDetail *youngee_talent_model.ProjectDetail
  530. err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  531. if err != nil {
  532. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  533. }
  534. //达人用户信息
  535. var talentInfo *youngee_talent_model.TalentInfo
  536. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  537. if err != nil {
  538. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  539. }
  540. //达人快手信息
  541. var accountInfo *youngee_talent_model.KuaishouUserInfo
  542. err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, 8).Scan(&accountInfo)
  543. if err != nil {
  544. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  545. }
  546. //var accountInfo *youngee_talent_model.PlatformAccountInfo
  547. //err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
  548. //if err != nil {
  549. // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  550. //}
  551. //project_form=1寄拍需要填写地址
  552. var address *model.YoungeeTalentDeliveryAddress
  553. if projectDetail.ProjectForm == 1 {
  554. err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
  555. if err != nil {
  556. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  557. }
  558. } else {
  559. address = new(model.YoungeeTalentDeliveryAddress) //赋空值
  560. }
  561. var newTaskId string
  562. // 首先生成任务id
  563. newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  564. //// 生成达人平台账号信息快照
  565. accountSnap, err := gjson.Encode(accountInfo)
  566. //if err != nil {
  567. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  568. //}
  569. // 生成达人信息快照
  570. talentSnap, err := gjson.Encode(talentInfo)
  571. if err != nil {
  572. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  573. }
  574. // 生成收货地址快照
  575. addrSnap, err := gjson.Encode(address)
  576. if err != nil {
  577. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  578. }
  579. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  580. if projectDetail.ProjectType == 1 {
  581. // 全流程任务/公开任务
  582. var strategy *youngee_talent_model.RecruitStrategy
  583. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  584. if err != nil {
  585. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  586. }
  587. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  588. TaskId: newTaskId,
  589. ProjectId: signTaskInfo.ProjectId,
  590. TalentId: tid,
  591. OpenId: accountInfo.OpenId,
  592. TalentPlatformInfoSnap: string(accountSnap),
  593. TalentPersonalInfoSnap: string(talentSnap),
  594. TalentPostAddrSnap: string(addrSnap),
  595. StrategyId: signTaskInfo.StrategyId,
  596. TaskStage: 1,
  597. FeeForm: strategy.FeeForm,
  598. //ServiceCharge: serviceCharge,
  599. //ServiceRate: serviceRate,
  600. CreateDate: gtime.Now(),
  601. TaskStatus: 1,
  602. LogisticsStatus: 1,
  603. LinkStatus: 1,
  604. DataStatus: 1,
  605. ScriptStatus: 1,
  606. SketchStatus: 1,
  607. CompleteStatus: 1,
  608. CurDefaultType: 0,
  609. WithdrawStatus: 1,
  610. SettleStatus: 1,
  611. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的,
  612. SettleAmount: signTaskInfo.Offer,
  613. }
  614. }
  615. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  616. // 在task_info表中插入任务
  617. _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
  618. if err != nil {
  619. return err
  620. }
  621. // 对应项目的报名人数自增
  622. _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
  623. if err != nil {
  624. return err
  625. }
  626. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  627. if projectDetail.ProjectInfoSupplier != nil {
  628. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("project_id = ? ", projectDetail.ProjectId).Increment("apply_num", 1)
  629. if err != nil {
  630. return err
  631. }
  632. }
  633. return nil
  634. })
  635. if err != nil {
  636. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  637. }
  638. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  639. }