task_info.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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. fmt.Println("getTaskBriefList-----")
  241. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  242. if err != nil {
  243. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  244. }
  245. // 构造查询条件
  246. whereStr := fmt.Sprintf("talent_id = '%s'", tid)
  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. fmt.Println("taskList----的长度为:", len(taskList))
  270. for _, v := range taskList { //taskList含所有任务
  271. //获取具体的招募策略,taskInfo中
  272. var projectDetail *youngee_talent_model.ProjectDetail
  273. err := g.Model("project_info").WithAll().Where("project_id = ?", v.ProjectId).Scan(&projectDetail)
  274. fmt.Println("projectDetail-----", projectDetail)
  275. if err != nil {
  276. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  277. }
  278. var account *youngee_talent_model.KuaishouUserInfo
  279. fmt.Println("openid---->", v.OpenId)
  280. err = g.Model("platform_kuaishou_user_info").Where("platform_id = ? and talent_id = ? and open_id = ?", 8, tid, v.OpenId).Scan(&account)
  281. //拿快手平台验证是否过期
  282. expired := youngee_talent_service.CheckKuaishouTokenExp(account.OpenId)
  283. account.Expired = expired
  284. if err != nil {
  285. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  286. }
  287. //taskInfoBrief含需要展示在页面的内容,被加入各阶段List
  288. taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  289. TaskId: v.TaskId,
  290. PlatformIconUrl: platformMap[strconv.Itoa(projectDetail.PlatformInfo.PlatformId)].PlatformIcon,
  291. //PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  292. //PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  293. ProjectName: projectDetail.ProjectName,
  294. ProductPhotoSnap: projectDetail.ProductPhotoSnap,
  295. TaskStatus: v.TaskStatus,
  296. TaskStage: v.TaskStage,
  297. LinkStatus: v.LinkStatus,
  298. DataStatus: v.DataStatus,
  299. ScriptStatus: v.ScriptStatus,
  300. SketchStatus: v.SketchStatus,
  301. TaskReward: v.TaskReward,
  302. BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  303. CurBreakAt: v.CurBreakAt,
  304. FeeForm: v.FeeForm,
  305. ProjectDetail: projectDetail,
  306. TaskInfo: v,
  307. AccountInfo: account, //含是否过期,粉丝数,作品数目
  308. }
  309. taskBriefList.AllTaskInfoList = append(taskBriefList.AllTaskInfoList, taskInfoBrief)
  310. if v.TaskStage <= 2 {
  311. taskBriefList.SignUpTaskInfoList = append(taskBriefList.SignUpTaskInfoList, taskInfoBrief)
  312. } else if v.TaskStage <= 14 && v.TaskStage >= 4 {
  313. taskBriefList.GoingOnTaskInfoList = append(taskBriefList.GoingOnTaskInfoList, taskInfoBrief)
  314. } else {
  315. taskBriefList.CompletedTaskInfoList = append(taskBriefList.CompletedTaskInfoList, taskInfoBrief)
  316. }
  317. }
  318. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  319. }
  320. // 查询执行中所有任务
  321. //func GetExeTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  322. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  323. // if err != nil {
  324. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  325. // }
  326. // var taskStageList = [5]int{0, 7, 9, 11, 13}
  327. // taskStageKey := r.GetQueryInt("taskStage", 0)
  328. // if taskStageKey == 0 {
  329. // return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  330. // }
  331. // taskStage := taskStageList[taskStageKey+1]
  332. //
  333. // // 获取任务列表
  334. // //这是一个切片,其中的每个元素都是指向 model.YoungeeTaskInfo 结构体的指针。通常用于存储多个任务信息的列表。
  335. // var taskList []*model.YoungeeTaskInfo
  336. // whereCondition := g.Map{
  337. // dao.YoungeeTaskInfo.Columns.TalentId: tid,
  338. // dao.YoungeeTaskInfo.Columns.TaskStage: taskStage,
  339. // }
  340. // err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereCondition).Scan(&taskList)
  341. // if err != nil {
  342. // return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  343. // }
  344. //
  345. // platformMap := make(map[string]model.InfoThirdPlatform)
  346. // var platformInfo []*model.InfoThirdPlatform
  347. // if len(taskList) != 0 {
  348. // err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  349. // if err != nil {
  350. // return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  351. // }
  352. //
  353. // for i, _ := range platformInfo {
  354. // platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  355. // }
  356. // }
  357. //
  358. // // 为每个任务根据项目id查询项目名称和主图
  359. // var taskBriefList []*youngee_talent_model.TaskInfoBrief
  360. // for _, v := range taskList {
  361. // whereCondition = g.Map{
  362. // dao.ProjectInfo.Columns.ProjectId: v.ProjectId,
  363. // }
  364. // projectInfo, err := g.Model(dao.ProjectInfo.Table).Where(whereCondition).One()
  365. // if err != nil {
  366. // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  367. // }
  368. // whereCondition = g.Map{
  369. // dao.YoungeePlatformAccountInfo.Columns.PlatformId: projectInfo[dao.ProjectInfo.Columns.ProjectPlatform],
  370. // dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  371. // }
  372. // account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One()
  373. // if err != nil {
  374. // return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  375. // }
  376. // taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  377. // TaskId: v.TaskId,
  378. // PlatformIconUrl: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformIcon,
  379. // PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  380. // PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  381. // ProjectName: projectInfo[dao.ProjectInfo.Columns.ProjectName].String(),
  382. // ProductPhotoSnap: projectInfo[dao.ProjectInfo.Columns.ProductPhotoSnap].String(),
  383. // TaskStatus: v.TaskStatus,
  384. // TaskStage: v.TaskStage,
  385. // LinkStatus: v.LinkStatus,
  386. // DataStatus: v.DataStatus,
  387. // ScriptStatus: v.ScriptStatus,
  388. // SketchStatus: v.SketchStatus,
  389. // TaskReward: v.TaskReward,
  390. // BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  391. // CurBreakAt: v.CurBreakAt,
  392. // FeeForm: v.FeeForm,
  393. // }
  394. // taskBriefList = append(taskBriefList, taskInfoBrief)
  395. // }
  396. //
  397. // return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  398. //}
  399. // 查询执行中所有任务
  400. func GetExeTaskNum(r *ghttp.Request) *TalentHttpResult {
  401. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  402. if err != nil {
  403. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  404. }
  405. nums, err := g.Model("youngee_task_info").Where("talent_id = ?", tid).Fields("COUNT(*) ,task_stage").Group("task_stage").All()
  406. if err != nil {
  407. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  408. }
  409. return &TalentHttpResult{Code: 0, Msg: "success", Data: nums}
  410. }
  411. func GetTaskNum(r *ghttp.Request) *TalentHttpResult {
  412. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  413. if err != nil {
  414. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  415. }
  416. // 构造查询条件
  417. whereStr1 := fmt.Sprintf("talent_id = '%s'", tid)
  418. whereStr2 := fmt.Sprintf("talent_id = '%s' and task_stage <= 2", tid)
  419. whereStr3 := fmt.Sprintf("talent_id = '%s' and task_stage <= 14 and task_stage >= 4", tid)
  420. whereStr4 := fmt.Sprintf("talent_id = '%s' and (task_stage = 3 or task_stage >= 15)", tid)
  421. num1, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr1).Count()
  422. if err != nil {
  423. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  424. }
  425. num2, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr2).Count()
  426. if err != nil {
  427. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  428. }
  429. num3, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr3).Count()
  430. if err != nil {
  431. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  432. }
  433. num4, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr4).Count()
  434. if err != nil {
  435. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  436. }
  437. TaskNum := &youngee_talent_model.TaskNum{
  438. AllNum: num1,
  439. SignUpNum: num2,
  440. GoingOnNum: num3,
  441. CompletedNum: num4,
  442. }
  443. return &TalentHttpResult{Code: 0, Msg: "success", Data: TaskNum}
  444. }
  445. // 获取任务详情
  446. func GetTaskDetail(r *ghttp.Request) *TalentHttpResult {
  447. taskId := r.GetQueryInt("task_id", -1)
  448. var task *model.YoungeeTaskInfo
  449. err := g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", taskId).Scan(&task)
  450. if err != nil {
  451. return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
  452. }
  453. var projectDetail *youngee_talent_model.ProjectDetail
  454. err = g.Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", task.ProjectId).Scan(&projectDetail)
  455. if err != nil {
  456. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  457. }
  458. var productPhoto *model.YounggeeProductPhoto
  459. err = g.Model(dao.YounggeeProductPhoto.Table).Where("product_id = ? and symbol = 1", projectDetail.ProductId).Scan(&productPhoto)
  460. if err != nil {
  461. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  462. }
  463. var withdrawStatus = 1
  464. var taskIncome *model.YounggeeTalentIncome
  465. err = g.Model(dao.YounggeeTalentIncome.Table).Where("task_id = ? and income_type = 1", taskId).Scan(&taskIncome)
  466. if err != nil {
  467. return &TalentHttpResult{Code: -3, Msg: "Get task income detail failed."}
  468. }
  469. if taskIncome != nil {
  470. withdrawStatus = taskIncome.WithdrawStatus + 1
  471. }
  472. taskDetail := &youngee_talent_model.TaskDetail{}
  473. if projectDetail.ProjectType == 1 {
  474. var strategy *model.RecruitStrategy
  475. err = g.Model(dao.RecruitStrategy.Table).Where("project_id = ? and strategy_id = ?", task.ProjectId, task.StrategyId).Scan(&strategy)
  476. if err != nil {
  477. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  478. }
  479. taskDetail = &youngee_talent_model.TaskDetail{
  480. TaskInfo: task,
  481. ProjectDetail: projectDetail,
  482. ProductPhoto: productPhoto,
  483. Strategy: strategy,
  484. WithdrawStatus: withdrawStatus,
  485. }
  486. } else {
  487. taskDetail = &youngee_talent_model.TaskDetail{
  488. TaskInfo: task,
  489. ProjectDetail: projectDetail,
  490. ProductPhoto: productPhoto,
  491. WithdrawStatus: withdrawStatus,
  492. }
  493. }
  494. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  495. }
  496. // 匹配种草策略,含是否可选属性
  497. func GetProjRecruitList(r *ghttp.Request) *TalentHttpResult {
  498. fanNum := r.GetQueryInt("fan_num", -1)
  499. projectId := r.GetQueryString("project_id", -1)
  500. SProjectId := r.GetQueryInt("project_id", 0)
  501. var recruitStrategies []*youngee_talent_model.RecruitStrategy
  502. //不经过服务商
  503. if SProjectId == 0 {
  504. err := g.DB().Model("recruit_strategy").Where("project_id = ? and strategy_type=?", projectId, 1).Scan(&recruitStrategies)
  505. if err != nil {
  506. fmt.Println(err.Error())
  507. }
  508. } else { //经过服务商
  509. _ = g.DB().Model("recruit_strategy").Where("s_project_id = ?", SProjectId).Scan(&recruitStrategies)
  510. }
  511. for _, strategy := range recruitStrategies {
  512. // 判断粉丝数是否满足当前策略的要求
  513. if fanNum >= strategy.FollowersLow {
  514. // 如果粉丝数满足策略的范围,设置 is_fit 为 1
  515. strategy.IsFit = 1
  516. } else {
  517. // 否则设置 is_fit 为 0
  518. strategy.IsFit = 0
  519. }
  520. }
  521. //根据projectId获取招募策略表多条策略,
  522. return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
  523. }
  524. // 报名种草任务
  525. func SignUpTaskWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  526. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  527. if err != nil {
  528. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  529. }
  530. //POST请求体信息
  531. var signTaskInfo *youngee_talent_model.SignTaskInfo
  532. err = r.ParseForm(&signTaskInfo)
  533. if err != nil {
  534. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  535. }
  536. //种草详情信息
  537. var projectDetail *youngee_talent_model.ProjectDetail
  538. err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  539. if err != nil {
  540. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  541. }
  542. //达人用户信息
  543. var talentInfo *youngee_talent_model.TalentInfo
  544. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  545. if err != nil {
  546. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  547. }
  548. //达人快手信息
  549. var accountInfo *youngee_talent_model.KuaishouUserInfo
  550. err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, 8).Scan(&accountInfo)
  551. if err != nil {
  552. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  553. }
  554. //var accountInfo *youngee_talent_model.PlatformAccountInfo
  555. //err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
  556. //if err != nil {
  557. // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  558. //}
  559. //project_form=1寄拍需要填写地址
  560. var address *model.YoungeeTalentDeliveryAddress
  561. if projectDetail.ProjectForm == 1 {
  562. err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
  563. if err != nil {
  564. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  565. }
  566. } else {
  567. address = new(model.YoungeeTalentDeliveryAddress) //赋空值
  568. }
  569. var newTaskId string
  570. // 首先生成任务id
  571. newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  572. //// 生成达人平台账号信息快照
  573. accountSnap, err := gjson.Encode(accountInfo)
  574. //if err != nil {
  575. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  576. //}
  577. // 生成达人信息快照
  578. talentSnap, err := gjson.Encode(talentInfo)
  579. if err != nil {
  580. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  581. }
  582. // 生成收货地址快照
  583. addrSnap, err := gjson.Encode(address)
  584. if err != nil {
  585. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  586. }
  587. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  588. // 公开任务
  589. if projectDetail.ProjectType == 1 {
  590. //经过服务商
  591. if signTaskInfo.SProjectId != 0 {
  592. var strategy *youngee_talent_model.RecruitStrategy
  593. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  594. var ServiceChargePrice = 0.0 //服务费
  595. var SupporPricer = 0.0 //提报价
  596. if signTaskInfo.StrategyId == 3 { //自报价
  597. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  598. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  599. } else if signTaskInfo.StrategyId == 2 { //一口价
  600. ServiceChargePrice = strategy.ServiceCharge
  601. SupporPricer = signTaskInfo.Offer
  602. } else { //无费置换
  603. ServiceChargePrice = 0.0
  604. SupporPricer = 0.0
  605. }
  606. if err != nil {
  607. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  608. }
  609. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  610. TaskId: newTaskId,
  611. ProjectId: signTaskInfo.ProjectId,
  612. SProjectId: signTaskInfo.SProjectId,
  613. TalentId: tid,
  614. OpenId: signTaskInfo.OpenID,
  615. TalentPlatformInfoSnap: string(accountSnap),
  616. TalentPersonalInfoSnap: string(talentSnap),
  617. TalentPostAddrSnap: string(addrSnap),
  618. StrategyId: signTaskInfo.StrategyId,
  619. TaskStage: 1,
  620. FeeForm: strategy.FeeForm,
  621. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  622. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  623. SupportFee: SupporPricer,
  624. CreateDate: gtime.Now(),
  625. TaskStatus: 1,
  626. LogisticsStatus: 1,
  627. LinkStatus: 1,
  628. DataStatus: 1,
  629. ScriptStatus: 1,
  630. SketchStatus: 1,
  631. CompleteStatus: 1,
  632. CurDefaultType: 0,
  633. WithdrawStatus: 1,
  634. SettleStatus: 1,
  635. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  636. SettleAmount: signTaskInfo.Offer,
  637. SupplierStatus: 1,
  638. WxNum: signTaskInfo.WxNum,
  639. }
  640. } else {
  641. //不经过服务商
  642. var strategy *youngee_talent_model.RecruitStrategy
  643. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
  644. if err != nil {
  645. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  646. }
  647. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  648. TaskId: newTaskId,
  649. ProjectId: signTaskInfo.ProjectId,
  650. TalentId: tid,
  651. OpenId: signTaskInfo.OpenID,
  652. TalentPlatformInfoSnap: string(accountSnap),
  653. TalentPersonalInfoSnap: string(talentSnap),
  654. TalentPostAddrSnap: string(addrSnap),
  655. StrategyId: signTaskInfo.StrategyId,
  656. TaskStage: 1,
  657. FeeForm: strategy.FeeForm,
  658. ServiceCharge: 0, //不经过服务商则为0
  659. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
  660. SupportFee: signTaskInfo.Offer,
  661. CreateDate: gtime.Now(),
  662. TaskStatus: 1,
  663. LogisticsStatus: 1,
  664. LinkStatus: 1,
  665. DataStatus: 1,
  666. ScriptStatus: 1,
  667. SketchStatus: 1,
  668. CompleteStatus: 1,
  669. CurDefaultType: 0,
  670. WithdrawStatus: 1,
  671. SettleStatus: 1,
  672. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  673. SettleAmount: signTaskInfo.Offer,
  674. WxNum: signTaskInfo.WxNum,
  675. }
  676. }
  677. } else if projectDetail.ProjectType == 2 { //定向任务
  678. //经过服务商
  679. if signTaskInfo.SProjectId != 0 {
  680. //查找服务商定义的策略
  681. var strategy *youngee_talent_model.RecruitStrategy
  682. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
  683. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  684. TaskId: newTaskId,
  685. ProjectId: signTaskInfo.ProjectId,
  686. TalentId: tid,
  687. OpenId: signTaskInfo.OpenID,
  688. TalentPlatformInfoSnap: string(accountSnap),
  689. TalentPersonalInfoSnap: string(talentSnap),
  690. TalentPostAddrSnap: string(addrSnap),
  691. TaskStage: 1,
  692. CreateDate: gtime.Now(),
  693. TaskStatus: 1,
  694. LogisticsStatus: 1,
  695. LinkStatus: 1,
  696. DataStatus: 1,
  697. ScriptStatus: 1,
  698. SketchStatus: 1,
  699. CompleteStatus: 1,
  700. CurDefaultType: 0,
  701. WithdrawStatus: 1,
  702. ServiceCharge: 0, //不经过服务商,无服务费
  703. ServiceRate: 0, //服务费率
  704. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  705. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  706. WxNum: signTaskInfo.WxNum,
  707. }
  708. } else {
  709. //不经过服务商
  710. }
  711. //定向任务,服务费在哪设置
  712. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  713. TaskId: newTaskId,
  714. ProjectId: signTaskInfo.ProjectId,
  715. TalentId: tid,
  716. OpenId: signTaskInfo.OpenID,
  717. TalentPlatformInfoSnap: string(accountSnap),
  718. TalentPersonalInfoSnap: string(talentSnap),
  719. TalentPostAddrSnap: string(addrSnap),
  720. TaskStage: 1,
  721. CreateDate: gtime.Now(),
  722. TaskStatus: 1,
  723. LogisticsStatus: 1,
  724. LinkStatus: 1,
  725. DataStatus: 1,
  726. ScriptStatus: 1,
  727. SketchStatus: 1,
  728. CompleteStatus: 1,
  729. CurDefaultType: 0,
  730. WithdrawStatus: 1,
  731. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  732. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  733. WxNum: signTaskInfo.WxNum,
  734. }
  735. }
  736. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  737. // 在task_info表中插入任务
  738. _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
  739. if err != nil {
  740. return err
  741. }
  742. // 对应项目的报名人数自增
  743. _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
  744. if err != nil {
  745. return err
  746. }
  747. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  748. if signTaskInfo.SProjectId != 0 {
  749. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
  750. if err != nil {
  751. return err
  752. }
  753. }
  754. return nil
  755. })
  756. if err != nil {
  757. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  758. }
  759. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  760. }
  761. // 本地生活报名
  762. func SignUpLocalWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  763. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  764. if err != nil {
  765. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  766. }
  767. //POST请求体信息
  768. var signTaskInfo *youngee_talent_model.SignLocalTaskInfo
  769. err = r.ParseForm(&signTaskInfo)
  770. if err != nil {
  771. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  772. }
  773. var projectDetail *youngee_talent_model.LocalInfoDetail
  774. err = g.DB().Model(youngee_talent_model.LocalInfoDetail{}).WithAll().Where("local_id", signTaskInfo.LocalId).Scan(&projectDetail)
  775. if err != nil {
  776. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  777. }
  778. //达人用户信息
  779. var talentInfo *youngee_talent_model.TalentInfo
  780. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  781. if err != nil {
  782. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  783. }
  784. //达人快手信息
  785. var accountInfo *youngee_talent_model.KuaishouUserInfo
  786. err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, projectDetail.LocalPlatform).Scan(&accountInfo)
  787. if err != nil {
  788. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  789. }
  790. var newTaskId string
  791. // 首先生成任务id
  792. newTaskId = utils.GetUuid.GetTaskId(projectDetail.LocalId, projectDetail.EnterpriseId, tid)
  793. //// 生成达人平台账号信息快照
  794. accountSnap, err := gjson.Encode(accountInfo)
  795. //if err != nil {
  796. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  797. //}
  798. // 生成达人信息快照
  799. talentSnap, err := gjson.Encode(talentInfo)
  800. if err != nil {
  801. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  802. }
  803. if err != nil {
  804. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  805. }
  806. taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  807. // 公开任务
  808. if projectDetail.LocalType == 1 {
  809. //经过服务商
  810. if signTaskInfo.SLocalId != 0 {
  811. var strategy *youngee_talent_model.RecruitStrategy
  812. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  813. var ServiceChargePrice = 0.0 //服务费
  814. var SupporPricer = 0.0 //提报价
  815. if signTaskInfo.StrategyId == 3 { //自报价
  816. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  817. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  818. } else if signTaskInfo.StrategyId == 2 { //一口价
  819. ServiceChargePrice = strategy.ServiceCharge
  820. SupporPricer = signTaskInfo.Offer
  821. } else { //无费置换
  822. ServiceChargePrice = 0.0
  823. SupporPricer = 0.0
  824. }
  825. if err != nil {
  826. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  827. }
  828. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  829. TaskId: newTaskId,
  830. PlatformId: projectDetail.LocalPlatform,
  831. SProjectId: signTaskInfo.SLocalId,
  832. TalentId: tid,
  833. OpenId: signTaskInfo.OpenID,
  834. TalentPlatformInfoSnap: string(accountSnap),
  835. TalentPersonalInfoSnap: string(talentSnap),
  836. StrategyId: signTaskInfo.StrategyId,
  837. TaskStage: 1,
  838. FeeForm: strategy.FeeForm,
  839. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  840. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  841. SupportFee: SupporPricer,
  842. CreateDate: gtime.Now(),
  843. TaskStatus: 1,
  844. LogisticsStatus: 1,
  845. LinkStatus: 1,
  846. DataStatus: 1,
  847. //ScriptStatus: 1,
  848. SketchStatus: 1,
  849. CompleteStatus: 1,
  850. CurDefaultType: 0,
  851. WithdrawStatus: 1,
  852. SettleStatus: 1,
  853. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  854. SettleAmount: signTaskInfo.Offer,
  855. SupplierStatus: 1,
  856. WxNum: signTaskInfo.WxNum,
  857. }
  858. } else {
  859. //不经过服务商
  860. var strategy *youngee_talent_model.RecruitStrategy
  861. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.LocalId).Scan(&strategy)
  862. if err != nil {
  863. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  864. }
  865. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  866. TaskId: newTaskId,
  867. LocalId: signTaskInfo.LocalId,
  868. TalentId: tid,
  869. OpenId: signTaskInfo.OpenID,
  870. TalentPlatformInfoSnap: string(accountSnap),
  871. TalentPersonalInfoSnap: string(talentSnap),
  872. StrategyId: signTaskInfo.StrategyId,
  873. TaskStage: 1,
  874. FeeForm: strategy.FeeForm,
  875. ServiceCharge: 0, //不经过服务商则为0
  876. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
  877. SupportFee: signTaskInfo.Offer,
  878. CreateDate: gtime.Now(),
  879. TaskStatus: 1,
  880. LogisticsStatus: 1,
  881. LinkStatus: 1,
  882. DataStatus: 1,
  883. //ScriptStatus: 1,
  884. SketchStatus: 1,
  885. CompleteStatus: 1,
  886. CurDefaultType: 0,
  887. WithdrawStatus: 1,
  888. SettleStatus: 1,
  889. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  890. SettleAmount: signTaskInfo.Offer,
  891. WxNum: signTaskInfo.WxNum,
  892. }
  893. }
  894. } else if projectDetail.LocalType == 2 { //定向任务
  895. //经过服务商
  896. if signTaskInfo.SLocalId != 0 {
  897. //查找服务商定义的策略
  898. var strategy *youngee_talent_model.RecruitStrategy
  899. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  900. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  901. TaskId: newTaskId,
  902. LocalId: signTaskInfo.LocalId,
  903. TalentId: tid,
  904. OpenId: signTaskInfo.OpenID,
  905. TalentPlatformInfoSnap: string(accountSnap),
  906. TalentPersonalInfoSnap: string(talentSnap),
  907. TaskStage: 1,
  908. CreateDate: gtime.Now(),
  909. TaskStatus: 1,
  910. LogisticsStatus: 1,
  911. LinkStatus: 1,
  912. DataStatus: 1,
  913. //ScriptStatus: 1,
  914. SketchStatus: 1,
  915. CompleteStatus: 1,
  916. CurDefaultType: 0,
  917. WithdrawStatus: 1,
  918. ServiceCharge: 0, //不经过服务商,无服务费
  919. ServiceRate: 0, //服务费率
  920. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  921. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  922. WxNum: signTaskInfo.WxNum,
  923. }
  924. } else {
  925. //不经过服务商
  926. //查找服务商定义的策略
  927. var strategy *youngee_talent_model.RecruitStrategy
  928. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  929. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  930. TaskId: newTaskId,
  931. LocalId: signTaskInfo.LocalId,
  932. PlatformId: projectDetail.LocalPlatform,
  933. TalentId: tid,
  934. OpenId: signTaskInfo.OpenID,
  935. TalentPlatformInfoSnap: string(accountSnap),
  936. TalentPersonalInfoSnap: string(talentSnap),
  937. TaskStage: 1,
  938. CreateDate: gtime.Now(),
  939. TaskStatus: 1,
  940. LogisticsStatus: 1,
  941. LinkStatus: 1,
  942. DataStatus: 1,
  943. //ScriptStatus: 1,
  944. SketchStatus: 1,
  945. CompleteStatus: 1,
  946. CurDefaultType: 0,
  947. WithdrawStatus: 1,
  948. ServiceCharge: 0, //不经过服务商,无服务费
  949. ServiceRate: 0, //服务费率
  950. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  951. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  952. WxNum: signTaskInfo.WxNum,
  953. }
  954. }
  955. }
  956. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  957. // 在task_info表中插入任务
  958. _, err = tx.Ctx(ctx).Model("youngee_local_task_info").Data(&taskInfo).Insert()
  959. if err != nil {
  960. return err
  961. }
  962. // 对应项目的报名人数自增
  963. _, err = tx.Ctx(ctx).Model("younggee_local_life_info").Where("local_id=?", projectDetail.LocalId).Increment("apply_num", 1)
  964. if err != nil {
  965. return err
  966. }
  967. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  968. if signTaskInfo.SLocalId != 0 {
  969. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SLocalId).Increment("apply_num", 1)
  970. if err != nil {
  971. return err
  972. }
  973. }
  974. return nil
  975. })
  976. if err != nil {
  977. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  978. }
  979. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  980. }