task_info.go 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. package youngee_task_service
  2. import (
  3. "context"
  4. "fmt"
  5. "youngmini_server/app/dao"
  6. "youngmini_server/app/model"
  7. "youngmini_server/app/model/youngee_talent_model"
  8. "youngmini_server/app/service/youngee_talent_service"
  9. "youngmini_server/app/utils"
  10. "github.com/gogf/gf/database/gdb"
  11. "github.com/gogf/gf/encoding/gjson"
  12. "github.com/gogf/gf/frame/g"
  13. "github.com/gogf/gf/net/ghttp"
  14. "github.com/gogf/gf/os/gtime"
  15. )
  16. // 新建任务service
  17. //func SignUpTask(r *ghttp.Request) *TalentHttpResult {
  18. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  19. // if err != nil {
  20. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  21. // }
  22. //
  23. // var signTaskInfo *youngee_talent_model.SignTaskInfo
  24. // err = r.ParseForm(&signTaskInfo)
  25. // if err != nil {
  26. // return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  27. // }
  28. // var projectDetail *youngee_talent_model.ProjectDetail
  29. // err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  30. // if err != nil {
  31. // return &TalentHttpResult{Code: -3, Msg: err.Error()}
  32. // }
  33. //
  34. // var talentInfo *youngee_talent_model.TalentInfo
  35. // err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  36. // if err != nil {
  37. // return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  38. // }
  39. //
  40. // var accountInfo *youngee_talent_model.PlatformAccountInfo
  41. // err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
  42. // if err != nil {
  43. // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  44. // }
  45. //
  46. // address, err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).One("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId)
  47. // if err != nil {
  48. // return &TalentHttpResult{Code: -6, Msg: err.Error()}
  49. // }
  50. //
  51. // var newTaskId string
  52. // // 首先生成任务id
  53. // newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  54. //
  55. // //// 生成达人平台账号信息快照
  56. // accountSnap, err := gjson.Encode(accountInfo)
  57. // //if err != nil {
  58. // // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  59. // //}
  60. //
  61. // // 生成达人信息快照
  62. // talentSnap, err := gjson.Encode(talentInfo)
  63. // if err != nil {
  64. // return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  65. // }
  66. //
  67. // // 生成收货地址快照
  68. // addrSnap, err := gjson.Encode(address)
  69. // if err != nil {
  70. // return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  71. // }
  72. // taskInfo := model.YoungeeTaskInfo{}
  73. // if projectDetail.ProjectType == 1 {
  74. // // 全流程任务
  75. //
  76. // // 计算平台服务费
  77. // // 1. 先获取稿费形式
  78. // var strategy *youngee_talent_model.RecruitStrategy
  79. // err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  80. // if err != nil {
  81. // return &TalentHttpResult{Code: -10, Msg: err.Error()}
  82. // }
  83. //
  84. // // 2. 根据稿费形式、平台、粉丝数获取服务费最高的定价策略
  85. // // 2.1 查询所有对应定价策略
  86. // 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)
  87. // 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)
  88. // 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)
  89. // 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)
  90. // var pricings []*model.InfoPricingStrategy
  91. // err = g.DB().Model("recruit_strategy").WithAll().Where(whereStr1).Or(orStr1).Or(orStr2).Or(orStr3).Scan(&pricings)
  92. // if err != nil {
  93. // return &TalentHttpResult{Code: -11, Msg: err.Error()}
  94. // } else if pricings == nil {
  95. // return &TalentHttpResult{Code: -12, Msg: "无相关定价策略"}
  96. // }
  97. // var pricing *model.InfoPricingStrategy
  98. // // 2.2 从对应定价策略中选取服务费率最高
  99. // if strategy.FeeForm == 1 {
  100. // var maxCharge float64 = 0
  101. // for _, v := range pricings {
  102. // if v.ServiceCharge >= maxCharge {
  103. // maxCharge = v.ServiceCharge
  104. // pricing = v
  105. // }
  106. // }
  107. // } else {
  108. // var maxRate int = 0
  109. // for _, v := range pricings {
  110. // if v.ServiceRate >= maxRate {
  111. // maxRate = v.ServiceRate
  112. // pricing = v
  113. // }
  114. // }
  115. // }
  116. // var serviceCharge = 0.0
  117. // var serviceRate = 0
  118. // var allReward = 0.0
  119. // var allPayment = 0.0
  120. // switch strategy.FeeForm {
  121. // case 1: // 产品置换,服务费固定,在项目生成时确定
  122. // serviceCharge = float64(strategy.ServiceCharge)
  123. // allPayment = serviceCharge
  124. // break
  125. // case 2: // 固定稿费,m2 = y2 * r2
  126. // allPayment = float64(strategy.Offer)
  127. // serviceRate = pricing.ServiceRate
  128. // serviceCharge = allPayment * float64(serviceRate) / 1000
  129. // allReward = allPayment - serviceCharge
  130. // break
  131. // case 3: // 自报价,m3 = x3 * r3
  132. // allReward = float64(signTaskInfo.Offer)
  133. // serviceRate = pricing.ServiceRate
  134. // var tmpRate = float64(1000-serviceRate) / 1000
  135. // allPayment = allReward / tmpRate
  136. // serviceCharge = allPayment - allReward
  137. // break
  138. // default:
  139. // break
  140. // }
  141. // taskInfo = model.YoungeeTaskInfo{
  142. // TaskId: newTaskId,
  143. // ProjectId: signTaskInfo.ProjectId,
  144. // TalentId: tid,
  145. // AccountId: accountInfo.AccountId,
  146. // TalentPlatformInfoSnap: string(accountSnap),
  147. // TalentPersonalInfoSnap: string(talentSnap),
  148. // TalentPostAddrSnap: string(addrSnap),
  149. // StrategyId: signTaskInfo.StrategyId,
  150. // TaskReward: allReward,
  151. // SettleAmount: allReward,
  152. // AllPayment: allPayment,
  153. // TaskStage: 1,
  154. // RealPayment: allPayment,
  155. // FeeForm: strategy.FeeForm,
  156. // ServiceCharge: serviceCharge,
  157. // ServiceRate: serviceRate,
  158. // CreateDate: gtime.Now(),
  159. // TaskStatus: 1,
  160. // LogisticsStatus: 1,
  161. // LinkStatus: 1,
  162. // DataStatus: 1,
  163. // ScriptStatus: 1,
  164. // SketchStatus: 1,
  165. // CompleteStatus: 1,
  166. // CurDefaultType: 0,
  167. // WithdrawStatus: 1,
  168. // SettleStatus: 1,
  169. // }
  170. // } else {
  171. // // 专项任务
  172. // taskInfo = model.YoungeeTaskInfo{
  173. // TaskId: newTaskId,
  174. // ProjectId: signTaskInfo.ProjectId,
  175. // TalentId: tid,
  176. // AccountId: accountInfo.AccountId,
  177. // //TalentPlatformInfoSnap: string(accountSnap),
  178. // TalentPersonalInfoSnap: string(talentSnap),
  179. // TalentPostAddrSnap: string(addrSnap),
  180. // TaskStage: 1,
  181. // CreateDate: gtime.Now(),
  182. // TaskStatus: 1,
  183. // LogisticsStatus: 1,
  184. // LinkStatus: 1,
  185. // DataStatus: 1,
  186. // ScriptStatus: 1,
  187. // SketchStatus: 1,
  188. // CompleteStatus: 1,
  189. // CurDefaultType: 0,
  190. // WithdrawStatus: 1,
  191. // }
  192. // }
  193. // err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  194. // // 在task_info表中插入任务
  195. // _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
  196. // if err != nil {
  197. // return err
  198. // }
  199. //
  200. // // 对应项目的报名人数自增
  201. // _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
  202. // if err != nil {
  203. // return err
  204. // }
  205. // return nil
  206. // })
  207. // if err != nil {
  208. // return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  209. // }
  210. //
  211. // return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  212. //}
  213. // 判断是否已报名任务,快手平台账号选择时,已经判断过
  214. func IsSignUpTask(r *ghttp.Request) *TalentHttpResult {
  215. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  216. if err != nil {
  217. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  218. }
  219. projectId := r.GetQueryInt("project_id", -1)
  220. fmt.Printf("%+v\n", projectId)
  221. task := []model.YoungeeTaskInfo{}
  222. err = g.Model(dao.YoungeeTaskInfo.Table).Where("project_id = ? and talent_id = ?", projectId, tid).Scan(&task)
  223. if err != nil {
  224. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  225. }
  226. isSign := youngee_talent_model.IsSign{}
  227. if len(task) != 0 {
  228. isSign.TaskInfo = &task[0]
  229. isSign.IsSign = 1
  230. isSign.IsAgree = task[0].TaskStatus
  231. } else {
  232. isSign.IsSign = 0
  233. isSign.IsAgree = 0
  234. }
  235. return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
  236. }
  237. // 查询所有任务
  238. func GetTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  239. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  240. if err != nil {
  241. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  242. }
  243. taskType := r.GetInt("task_type", 0) //任务类型
  244. if taskType == 0 {
  245. return &TalentHttpResult{Code: -1, Msg: "task_type is nil"}
  246. }
  247. // 构造查询条件tid和taskType
  248. whereStr := fmt.Sprintf("talent_id = %s and project_type = %d", tid, taskType)
  249. // 获取任务列表
  250. var taskList []*youngee_talent_model.YoungeeTaskInfo
  251. //此达人下,所有账号的任务都展示
  252. err = g.Model("youngee_task_info").Where(whereStr).Order("create_date desc").Scan(&taskList)
  253. if err != nil {
  254. return &TalentHttpResult{Code: -1, Msg: "Get task list failed", Data: err.Error()}
  255. }
  256. //为每个任务根据项目id查询项目名称和主图
  257. //taskBriefList存了各个阶段的tasklist
  258. taskBriefList := youngee_talent_model.TaskInfoBriefList{}
  259. fmt.Println("taskList----的长度为:", len(taskList))
  260. for _, v := range taskList { //taskList含所有任务
  261. //获取具体的招募策略,taskInfo中
  262. var projectDetail *youngee_talent_model.ProjectDetail
  263. err := g.Model("project_info").WithAll().Where("project_id = ?", v.ProjectId).Scan(&projectDetail)
  264. //各阶段扣款比例
  265. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", projectDetail.AutoDefaultId).One()
  266. if err != nil {
  267. return &TalentHttpResult{Code: 0, Msg: err.Error()}
  268. } else {
  269. projectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
  270. projectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
  271. projectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
  272. }
  273. //各阶段扣款时间
  274. one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", projectDetail.AutoTaskId).One()
  275. if err2 != nil {
  276. return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
  277. } else {
  278. projectDetail.DraftBreakTime = one2["draft_default"].Int()
  279. projectDetail.LinkBreakTime = one2["link_breach"].Int()
  280. projectDetail.DataBreakTime = one2["case_close_default"].Int()
  281. }
  282. var account *youngee_talent_model.KuaishouUserInfo
  283. fmt.Println("openid---->", v.OpenId)
  284. err = g.DB().Model("platform_kuaishou_user_info").Where("platform_id = ? and talent_id = ? and open_id = ?", v.PlatformId, tid, v.OpenId).Scan(&account)
  285. //拿快手平台验证是否过期
  286. if v.PlatformId == 8 || v.PlatformId == 4 {
  287. expired := youngee_talent_service.CheckKuaishouTokenExp(account.OpenId)
  288. account.Expired = expired
  289. } else if v.PlatformId == 2 {
  290. expired := youngee_talent_service.CheckDouyinTokenExp(account.OpenId)
  291. account.Expired = expired
  292. }
  293. if err != nil {
  294. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  295. }
  296. //taskInfoBrief含需要展示在页面的内容,被加入各阶段List
  297. taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  298. TaskId: v.TaskId,
  299. //PlatformIconUrl: platformMap[strconv.Itoa(projectDetail.PlatformInfo.PlatformId)].PlatformIcon,
  300. //PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  301. //PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  302. ProjectName: projectDetail.ProjectName,
  303. ProductPhotoSnap: projectDetail.ProductPhotoSnap,
  304. TaskStatus: v.TaskStatus,
  305. TaskStage: v.TaskStage,
  306. LinkStatus: v.LinkStatus,
  307. DataStatus: v.DataStatus,
  308. ScriptStatus: v.ScriptStatus,
  309. SketchStatus: v.SketchStatus,
  310. TaskReward: v.TaskReward,
  311. BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  312. CurBreakAt: v.CurBreakAt,
  313. FeeForm: v.FeeForm,
  314. ProjectDetail: projectDetail,
  315. TaskInfo: v,
  316. AccountInfo: account, //含是否过期,粉丝数,作品数目
  317. }
  318. taskBriefList.AllTaskInfoList = append(taskBriefList.AllTaskInfoList, taskInfoBrief)
  319. if v.TaskStage <= 2 {
  320. taskBriefList.SignUpTaskInfoList = append(taskBriefList.SignUpTaskInfoList, taskInfoBrief)
  321. } else if v.TaskStage <= 14 && v.TaskStage >= 4 {
  322. taskBriefList.GoingOnTaskInfoList = append(taskBriefList.GoingOnTaskInfoList, taskInfoBrief)
  323. } else if v.TaskStage == 15 {
  324. taskBriefList.WaitToPayInfoList = append(taskBriefList.WaitToPayInfoList, taskInfoBrief)
  325. } else {
  326. taskBriefList.CompletedTaskInfoList = append(taskBriefList.CompletedTaskInfoList, taskInfoBrief)
  327. }
  328. }
  329. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  330. }
  331. // 查询执行中所有任务
  332. //func GetExeTaskBriefList(r *ghttp.Request) *TalentHttpResult {
  333. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  334. // if err != nil {
  335. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  336. // }
  337. // var taskStageList = [5]int{0, 7, 9, 11, 13}
  338. // taskStageKey := r.GetQueryInt("taskStage", 0)
  339. // if taskStageKey == 0 {
  340. // return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  341. // }
  342. // taskStage := taskStageList[taskStageKey+1]
  343. //
  344. // // 获取任务列表
  345. // //这是一个切片,其中的每个元素都是指向 model.YoungeeTaskInfo 结构体的指针。通常用于存储多个任务信息的列表。
  346. // var taskList []*model.YoungeeTaskInfo
  347. // whereCondition := g.Map{
  348. // dao.YoungeeTaskInfo.Columns.TalentId: tid,
  349. // dao.YoungeeTaskInfo.Columns.TaskStage: taskStage,
  350. // }
  351. // err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereCondition).Scan(&taskList)
  352. // if err != nil {
  353. // return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  354. // }
  355. //
  356. // platformMap := make(map[string]model.InfoThirdPlatform)
  357. // var platformInfo []*model.InfoThirdPlatform
  358. // if len(taskList) != 0 {
  359. // err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  360. // if err != nil {
  361. // return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  362. // }
  363. //
  364. // for i, _ := range platformInfo {
  365. // platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  366. // }
  367. // }
  368. //
  369. // // 为每个任务根据项目id查询项目名称和主图
  370. // var taskBriefList []*youngee_talent_model.TaskInfoBrief
  371. // for _, v := range taskList {
  372. // whereCondition = g.Map{
  373. // dao.ProjectInfo.Columns.ProjectId: v.ProjectId,
  374. // }
  375. // projectInfo, err := g.Model(dao.ProjectInfo.Table).Where(whereCondition).One()
  376. // if err != nil {
  377. // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  378. // }
  379. // whereCondition = g.Map{
  380. // dao.YoungeePlatformAccountInfo.Columns.PlatformId: projectInfo[dao.ProjectInfo.Columns.ProjectPlatform],
  381. // dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  382. // }
  383. // account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One()
  384. // if err != nil {
  385. // return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  386. // }
  387. // taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
  388. // TaskId: v.TaskId,
  389. // PlatformIconUrl: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformIcon,
  390. // PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
  391. // PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  392. // ProjectName: projectInfo[dao.ProjectInfo.Columns.ProjectName].String(),
  393. // ProductPhotoSnap: projectInfo[dao.ProjectInfo.Columns.ProductPhotoSnap].String(),
  394. // TaskStatus: v.TaskStatus,
  395. // TaskStage: v.TaskStage,
  396. // LinkStatus: v.LinkStatus,
  397. // DataStatus: v.DataStatus,
  398. // ScriptStatus: v.ScriptStatus,
  399. // SketchStatus: v.SketchStatus,
  400. // TaskReward: v.TaskReward,
  401. // BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
  402. // CurBreakAt: v.CurBreakAt,
  403. // FeeForm: v.FeeForm,
  404. // }
  405. // taskBriefList = append(taskBriefList, taskInfoBrief)
  406. // }
  407. //
  408. // return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  409. //}
  410. // 查询执行中所有任务
  411. func GetExeTaskNum(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. nums, err := g.Model("youngee_task_info").Where("talent_id = ?", tid).Fields("COUNT(*) ,task_stage").Group("task_stage").All()
  417. if err != nil {
  418. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  419. }
  420. return &TalentHttpResult{Code: 0, Msg: "success", Data: nums}
  421. }
  422. func GetTaskNum(r *ghttp.Request) *TalentHttpResult {
  423. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  424. if err != nil {
  425. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  426. }
  427. // 构造查询条件
  428. whereStr1 := fmt.Sprintf("talent_id = '%s'", tid)
  429. whereStr2 := fmt.Sprintf("talent_id = '%s' and task_stage <= 2", tid)
  430. whereStr3 := fmt.Sprintf("talent_id = '%s' and task_stage <= 14 and task_stage >= 4", tid)
  431. whereStr4 := fmt.Sprintf("talent_id = '%s' and (task_stage = 3 or task_stage >= 15)", tid)
  432. num1, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr1).Count()
  433. if err != nil {
  434. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  435. }
  436. num2, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr2).Count()
  437. if err != nil {
  438. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  439. }
  440. num3, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr3).Count()
  441. if err != nil {
  442. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  443. }
  444. num4, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr4).Count()
  445. if err != nil {
  446. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  447. }
  448. TaskNum := &youngee_talent_model.TaskNum{
  449. AllNum: num1,
  450. SignUpNum: num2,
  451. GoingOnNum: num3,
  452. CompletedNum: num4,
  453. }
  454. return &TalentHttpResult{Code: 0, Msg: "success", Data: TaskNum}
  455. }
  456. // 获取任务详情
  457. func GetTaskDetail(r *ghttp.Request) *TalentHttpResult {
  458. taskId := r.GetQueryString("task_id", -1)
  459. var task *youngee_talent_model.YoungeeTaskInfo
  460. err := g.Model("youngee_task_info").Where("task_id = ?", taskId).Scan(&task)
  461. if err != nil {
  462. return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
  463. }
  464. var projectDetail *youngee_talent_model.ProjectDetail
  465. err = g.Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", task.ProjectId).Scan(&projectDetail)
  466. if err != nil {
  467. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  468. }
  469. //各阶段扣款比例
  470. one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", projectDetail.AutoDefaultId).One()
  471. if err != nil {
  472. return &TalentHttpResult{Code: 0, Msg: err.Error()}
  473. } else {
  474. projectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
  475. projectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
  476. projectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
  477. }
  478. //各阶段扣款时间
  479. one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", projectDetail.AutoTaskId).One()
  480. if err2 != nil {
  481. return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
  482. } else {
  483. projectDetail.DraftBreakTime = one2["draft_default"].Int()
  484. projectDetail.LinkBreakTime = one2["link_breach"].Int()
  485. projectDetail.DataBreakTime = one2["case_close_default"].Int()
  486. }
  487. var productPhoto *youngee_talent_model.YounggeeProductPhoto
  488. err = g.Model(dao.YounggeeProductPhoto.Table).Where("product_id = ? and symbol = 1", projectDetail.ProductId).Scan(&productPhoto)
  489. if err != nil {
  490. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  491. }
  492. var withdrawStatus = 1
  493. var taskIncome *model.YounggeeTalentIncome
  494. err = g.Model(dao.YounggeeTalentIncome.Table).Where("task_id = ? and income_type = 1", taskId).Scan(&taskIncome)
  495. if err != nil {
  496. return &TalentHttpResult{Code: -3, Msg: "Get task income detail failed."}
  497. }
  498. if taskIncome != nil {
  499. withdrawStatus = taskIncome.WithdrawStatus + 1
  500. }
  501. taskDetail := &youngee_talent_model.TaskDetail{}
  502. if projectDetail.ProjectType == 1 {
  503. var strategy *youngee_talent_model.RecruitStrategy
  504. err = g.Model("recruit_strategy").Where("project_id = ? and strategy_id = ?", task.ProjectId, task.StrategyId).Scan(&strategy)
  505. if err != nil {
  506. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  507. }
  508. taskDetail = &youngee_talent_model.TaskDetail{
  509. TaskInfo: task,
  510. ProjectDetail: projectDetail,
  511. ProductPhoto: productPhoto,
  512. Strategy: strategy,
  513. WithdrawStatus: withdrawStatus,
  514. }
  515. } else {
  516. taskDetail = &youngee_talent_model.TaskDetail{
  517. TaskInfo: task,
  518. ProjectDetail: projectDetail,
  519. ProductPhoto: productPhoto,
  520. WithdrawStatus: withdrawStatus,
  521. }
  522. }
  523. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  524. }
  525. // 匹配种草策略,含是否可选属性
  526. func GetProjRecruitList(r *ghttp.Request) *TalentHttpResult {
  527. fanNum := r.GetQueryInt("fan_num", -1)
  528. projectId := r.GetQueryString("project_id", -1)
  529. SProjectId := r.GetQueryInt("s_project_id", 0)
  530. var recruitStrategies []*youngee_talent_model.RecruitStrategy
  531. //不经过服务商
  532. if SProjectId == 0 {
  533. err := g.DB().Model("recruit_strategy").Where("project_id = ? and strategy_type=?", projectId, 1).Scan(&recruitStrategies)
  534. if err != nil {
  535. fmt.Println(err.Error())
  536. }
  537. } else { //经过服务商
  538. _ = g.DB().Model("recruit_strategy").Where("s_project_id = ?", SProjectId).Scan(&recruitStrategies)
  539. }
  540. for _, strategy := range recruitStrategies {
  541. // 判断粉丝数是否满足当前策略的要求
  542. if fanNum >= strategy.FollowersLow {
  543. // 如果粉丝数满足策略的范围,设置 is_fit 为 1
  544. strategy.IsFit = 1
  545. } else {
  546. // 否则设置 is_fit 为 0
  547. strategy.IsFit = 0
  548. }
  549. }
  550. //根据projectId获取招募策略表多条策略,
  551. return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
  552. }
  553. // 匹配种草策略,含是否可选属性
  554. //func GetLocalRecruitList(r *ghttp.Request) *TalentHttpResult {
  555. // fanNum := r.GetQueryInt("fan_num", -1)
  556. // projectId := r.GetQueryString("project_id", -1)
  557. // SProjectId := r.GetQueryInt("s_project_id", 0)
  558. // var recruitStrategies []*youngee_talent_model.RecruitStrategy
  559. // //不经过服务商
  560. // if SProjectId == 0 {
  561. // err := g.DB().Model("recruit_strategy").Where("project_id = ? and strategy_type=?", projectId, 1).Scan(&recruitStrategies)
  562. // if err != nil {
  563. // fmt.Println(err.Error())
  564. // }
  565. // } else { //经过服务商
  566. // _ = g.DB().Model("recruit_strategy").Where("s_project_id = ?", SProjectId).Scan(&recruitStrategies)
  567. // }
  568. // for _, strategy := range recruitStrategies {
  569. // // 判断粉丝数是否满足当前策略的要求
  570. // if fanNum >= strategy.FollowersLow {
  571. // // 如果粉丝数满足策略的范围,设置 is_fit 为 1
  572. // strategy.IsFit = 1
  573. // } else {
  574. // // 否则设置 is_fit 为 0
  575. // strategy.IsFit = 0
  576. // }
  577. // }
  578. //
  579. // //根据projectId获取招募策略表多条策略,
  580. // return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
  581. //}
  582. // 报名种草任务
  583. func SignUpTaskWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  584. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  585. if err != nil {
  586. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  587. }
  588. //POST请求体信息
  589. var signTaskInfo *youngee_talent_model.SignTaskInfo
  590. err = r.ParseForm(&signTaskInfo)
  591. if err != nil {
  592. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  593. }
  594. //种草详情信息
  595. var projectDetail *youngee_talent_model.ProjectDetail
  596. err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  597. if err != nil {
  598. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  599. }
  600. //达人用户信息
  601. var talentInfo *youngee_talent_model.TalentInfo
  602. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  603. if err != nil {
  604. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  605. }
  606. //达人快手信息
  607. var accountInfo *youngee_talent_model.KuaishouUserInfo
  608. err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, 8).Scan(&accountInfo)
  609. if err != nil {
  610. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  611. }
  612. //var accountInfo *youngee_talent_model.PlatformAccountInfo
  613. //err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
  614. //if err != nil {
  615. // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  616. //}
  617. //project_form=1寄拍需要填写地址
  618. var address *model.YoungeeTalentDeliveryAddress
  619. if projectDetail.ProjectForm == 1 {
  620. err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
  621. if err != nil {
  622. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  623. }
  624. } else {
  625. address = new(model.YoungeeTalentDeliveryAddress) //赋空值
  626. }
  627. var newTaskId string
  628. // 首先生成任务id
  629. newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  630. //// 生成达人平台账号信息快照
  631. accountSnap, err := gjson.Encode(accountInfo)
  632. //if err != nil {
  633. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  634. //}
  635. // 生成达人信息快照
  636. talentSnap, err := gjson.Encode(talentInfo)
  637. if err != nil {
  638. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  639. }
  640. // 生成收货地址快照
  641. addrSnap, err := gjson.Encode(address)
  642. if err != nil {
  643. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  644. }
  645. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  646. // 公开任务
  647. if projectDetail.ProjectType == 1 {
  648. //经过服务商
  649. if signTaskInfo.SProjectId != 0 {
  650. var strategy *youngee_talent_model.RecruitStrategy
  651. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  652. var ServiceChargePrice = 0.0 //服务费
  653. var SupporPricer = 0.0 //提报价
  654. if signTaskInfo.StrategyId == 3 { //自报价
  655. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  656. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  657. } else if signTaskInfo.StrategyId == 2 { //一口价
  658. ServiceChargePrice = strategy.ServiceCharge
  659. SupporPricer = signTaskInfo.Offer
  660. } else { //无费置换
  661. ServiceChargePrice = 0.0
  662. SupporPricer = 0.0
  663. }
  664. if err != nil {
  665. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  666. }
  667. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  668. TaskId: newTaskId,
  669. ProjectId: signTaskInfo.ProjectId,
  670. SProjectId: signTaskInfo.SProjectId,
  671. TalentId: tid,
  672. OpenId: signTaskInfo.OpenID,
  673. TalentPlatformInfoSnap: string(accountSnap),
  674. TalentPersonalInfoSnap: string(talentSnap),
  675. TalentPostAddrSnap: string(addrSnap),
  676. StrategyId: signTaskInfo.StrategyId,
  677. TaskStage: 1,
  678. FeeForm: strategy.FeeForm,
  679. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  680. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  681. SupportFee: SupporPricer,
  682. CreateDate: gtime.Now(),
  683. TaskStatus: 1,
  684. LogisticsStatus: 1,
  685. LinkStatus: 1,
  686. DataStatus: 1,
  687. ScriptStatus: 1,
  688. SketchStatus: 1,
  689. CompleteStatus: 1,
  690. CurDefaultType: 0,
  691. WithdrawStatus: 1,
  692. SettleStatus: 1,
  693. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  694. SettleAmount: signTaskInfo.Offer,
  695. SupplierStatus: 1,
  696. WxNum: signTaskInfo.WxNum,
  697. }
  698. } else {
  699. //不经过服务商
  700. var strategy *youngee_talent_model.RecruitStrategy
  701. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
  702. if err != nil {
  703. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  704. }
  705. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  706. TaskId: newTaskId,
  707. ProjectId: signTaskInfo.ProjectId,
  708. TalentId: tid,
  709. OpenId: signTaskInfo.OpenID,
  710. TalentPlatformInfoSnap: string(accountSnap),
  711. TalentPersonalInfoSnap: string(talentSnap),
  712. TalentPostAddrSnap: string(addrSnap),
  713. StrategyId: signTaskInfo.StrategyId,
  714. TaskStage: 1,
  715. FeeForm: strategy.FeeForm,
  716. ServiceCharge: 0, //不经过服务商则为0
  717. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
  718. SupportFee: signTaskInfo.Offer,
  719. CreateDate: gtime.Now(),
  720. TaskStatus: 1,
  721. LogisticsStatus: 1,
  722. LinkStatus: 1,
  723. DataStatus: 1,
  724. ScriptStatus: 1,
  725. SketchStatus: 1,
  726. CompleteStatus: 1,
  727. CurDefaultType: 0,
  728. WithdrawStatus: 1,
  729. SettleStatus: 1,
  730. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  731. SettleAmount: signTaskInfo.Offer,
  732. WxNum: signTaskInfo.WxNum,
  733. }
  734. }
  735. } else if projectDetail.ProjectType == 2 { //定向任务
  736. //经过服务商
  737. if signTaskInfo.SProjectId != 0 {
  738. //查找服务商定义的策略
  739. var strategy *youngee_talent_model.RecruitStrategy
  740. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
  741. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  742. TaskId: newTaskId,
  743. ProjectId: signTaskInfo.ProjectId,
  744. TalentId: tid,
  745. OpenId: signTaskInfo.OpenID,
  746. TalentPlatformInfoSnap: string(accountSnap),
  747. TalentPersonalInfoSnap: string(talentSnap),
  748. TalentPostAddrSnap: string(addrSnap),
  749. TaskStage: 1,
  750. CreateDate: gtime.Now(),
  751. TaskStatus: 1,
  752. LogisticsStatus: 1,
  753. LinkStatus: 1,
  754. DataStatus: 1,
  755. ScriptStatus: 1,
  756. SketchStatus: 1,
  757. CompleteStatus: 1,
  758. CurDefaultType: 0,
  759. WithdrawStatus: 1,
  760. ServiceCharge: 0, //不经过服务商,无服务费
  761. ServiceRate: 0, //服务费率
  762. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  763. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  764. WxNum: signTaskInfo.WxNum,
  765. }
  766. } else {
  767. //不经过服务商
  768. }
  769. //定向任务,服务费在哪设置
  770. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  771. TaskId: newTaskId,
  772. ProjectId: signTaskInfo.ProjectId,
  773. TalentId: tid,
  774. OpenId: signTaskInfo.OpenID,
  775. TalentPlatformInfoSnap: string(accountSnap),
  776. TalentPersonalInfoSnap: string(talentSnap),
  777. TalentPostAddrSnap: string(addrSnap),
  778. TaskStage: 1,
  779. CreateDate: gtime.Now(),
  780. TaskStatus: 1,
  781. LogisticsStatus: 1,
  782. LinkStatus: 1,
  783. DataStatus: 1,
  784. ScriptStatus: 1,
  785. SketchStatus: 1,
  786. CompleteStatus: 1,
  787. CurDefaultType: 0,
  788. WithdrawStatus: 1,
  789. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  790. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  791. WxNum: signTaskInfo.WxNum,
  792. }
  793. }
  794. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  795. // 在task_info表中插入任务
  796. _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
  797. if err != nil {
  798. return err
  799. }
  800. // 对应项目的报名人数自增
  801. _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
  802. if err != nil {
  803. return err
  804. }
  805. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  806. if signTaskInfo.SProjectId != 0 {
  807. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
  808. if err != nil {
  809. return err
  810. }
  811. }
  812. // 记录任务日志-上传初稿
  813. taskLog := model.YounggeeTaskLog{
  814. TaskId: newTaskId,
  815. Content: "报名成功",
  816. LogAt: gtime.Now(),
  817. }
  818. //上传日志,用于详情页判断上一个状态是什么
  819. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  820. if err != nil {
  821. return err
  822. }
  823. return nil
  824. })
  825. if err != nil {
  826. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  827. }
  828. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  829. }
  830. func SignUpTaskWithAccount(r *ghttp.Request) *TalentHttpResult {
  831. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  832. if err != nil {
  833. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  834. }
  835. //POST请求体信息
  836. var signTaskInfo *youngee_talent_model.SignTaskInfo
  837. err = r.ParseForm(&signTaskInfo)
  838. if err != nil {
  839. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  840. }
  841. //种草详情信息
  842. var projectDetail *youngee_talent_model.ProjectDetail
  843. err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
  844. if err != nil {
  845. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  846. }
  847. //达人用户信息
  848. var talentInfo *youngee_talent_model.TalentInfo
  849. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  850. if err != nil {
  851. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  852. }
  853. //达人社媒信息
  854. var platform_id = projectDetail.ProjectPlatform
  855. var accountInfo *youngee_talent_model.KuaishouUserInfo
  856. err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, platform_id).Scan(&accountInfo)
  857. if err != nil {
  858. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  859. }
  860. //project_form=1寄拍需要填写地址
  861. var address *model.YoungeeTalentDeliveryAddress
  862. if projectDetail.ProjectForm == 1 {
  863. err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
  864. if err != nil {
  865. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  866. }
  867. } else {
  868. address = new(model.YoungeeTalentDeliveryAddress) //赋空值
  869. }
  870. var newTaskId string
  871. // 首先生成任务id
  872. newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
  873. //// 生成达人平台账号信息快照
  874. accountSnap, err := gjson.Encode(accountInfo)
  875. // 生成达人信息快照
  876. talentSnap, err := gjson.Encode(talentInfo)
  877. if err != nil {
  878. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  879. }
  880. // 生成收货地址快照
  881. addrSnap, err := gjson.Encode(address)
  882. if err != nil {
  883. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  884. }
  885. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  886. // 公开任务
  887. if projectDetail.ProjectType == 1 {
  888. //经过服务商
  889. if signTaskInfo.SProjectId != 0 {
  890. var strategy *youngee_talent_model.RecruitStrategy
  891. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  892. var ServiceChargePrice = 0.0 //服务费
  893. var SupporPricer = 0.0 //提报价
  894. if signTaskInfo.StrategyId == 3 { //自报价
  895. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  896. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  897. } else if signTaskInfo.StrategyId == 2 { //一口价
  898. ServiceChargePrice = strategy.ServiceCharge
  899. SupporPricer = signTaskInfo.Offer
  900. } else { //无费置换
  901. ServiceChargePrice = 0.0
  902. SupporPricer = 0.0
  903. }
  904. if err != nil {
  905. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  906. }
  907. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  908. TaskId: newTaskId,
  909. ProjectId: signTaskInfo.ProjectId,
  910. SProjectId: signTaskInfo.SProjectId,
  911. TalentId: tid,
  912. OpenId: signTaskInfo.OpenID,
  913. TalentPlatformInfoSnap: string(accountSnap),
  914. TalentPersonalInfoSnap: string(talentSnap),
  915. TalentPostAddrSnap: string(addrSnap),
  916. StrategyId: signTaskInfo.StrategyId,
  917. TaskStage: 1,
  918. FeeForm: strategy.FeeForm,
  919. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  920. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  921. SupportFee: SupporPricer,
  922. CreateDate: gtime.Now(),
  923. TaskStatus: 1,
  924. LogisticsStatus: 1,
  925. LinkStatus: 1,
  926. DataStatus: 1,
  927. ScriptStatus: 1,
  928. SketchStatus: 1,
  929. CompleteStatus: 1,
  930. CurDefaultType: 0,
  931. WithdrawStatus: 1,
  932. SettleStatus: 1,
  933. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  934. SettleAmount: signTaskInfo.Offer,
  935. SupplierStatus: 1,
  936. WxNum: signTaskInfo.WxNum,
  937. TalentName: talentInfo.TalentNickname,
  938. PlatformId: platform_id,
  939. ProjectType: projectDetail.ProjectType,
  940. }
  941. } else {
  942. //不经过服务商
  943. var strategy *youngee_talent_model.RecruitStrategy
  944. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  945. var ServiceChargePrice = 0.0 //服务费
  946. var SupporPricer = 0.0 //提报价
  947. if strategy.FeeForm == 3 { //自报价
  948. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  949. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  950. } else if strategy.FeeForm == 2 { //一口价
  951. ServiceChargePrice = strategy.ServiceCharge
  952. SupporPricer = signTaskInfo.Offer
  953. } else if strategy.FeeForm == 1 { //无费置换
  954. ServiceChargePrice = 0.0
  955. SupporPricer = 0.0
  956. } else {
  957. return &TalentHttpResult{Code: -10, Msg: "策略设置错误"}
  958. }
  959. if err != nil {
  960. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  961. }
  962. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  963. TaskId: newTaskId,
  964. ProjectId: signTaskInfo.ProjectId,
  965. TalentId: tid,
  966. OpenId: signTaskInfo.OpenID,
  967. TalentPlatformInfoSnap: string(accountSnap),
  968. TalentPersonalInfoSnap: string(talentSnap),
  969. TalentPostAddrSnap: string(addrSnap),
  970. StrategyId: signTaskInfo.StrategyId,
  971. TaskStage: 1,
  972. FeeForm: strategy.FeeForm,
  973. ServiceCharge: ServiceChargePrice,
  974. ServiceRate: projectDetail.ServiceChargeRate,
  975. SupportFee: SupporPricer,
  976. CreateDate: gtime.Now(),
  977. TaskStatus: 1,
  978. LogisticsStatus: 1,
  979. LinkStatus: 1,
  980. DataStatus: 1,
  981. ScriptStatus: 1,
  982. SketchStatus: 1,
  983. CompleteStatus: 1,
  984. CurDefaultType: 0,
  985. WithdrawStatus: 1,
  986. SettleStatus: 1,
  987. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  988. SettleAmount: signTaskInfo.Offer,
  989. WxNum: signTaskInfo.WxNum,
  990. TalentName: talentInfo.TalentNickname,
  991. PlatformId: platform_id,
  992. ProjectType: projectDetail.ProjectType,
  993. }
  994. }
  995. } else if projectDetail.ProjectType == 2 { //定向任务
  996. if signTaskInfo.SProjectId != 0 { //经过服务商
  997. var strategy *youngee_talent_model.RecruitStrategy
  998. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
  999. var ServiceChargePrice = 0.0 //服务费
  1000. var SupporPricer = 0.0 //提报价
  1001. if signTaskInfo.StrategyId == 3 { //自报价
  1002. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  1003. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  1004. } else if signTaskInfo.StrategyId == 2 { //一口价
  1005. ServiceChargePrice = strategy.ServiceCharge
  1006. SupporPricer = signTaskInfo.Offer
  1007. } else { //无费置换
  1008. ServiceChargePrice = 0.0
  1009. SupporPricer = 0.0
  1010. }
  1011. if err != nil {
  1012. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1013. }
  1014. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  1015. TaskId: newTaskId,
  1016. ProjectId: signTaskInfo.ProjectId,
  1017. TalentId: tid,
  1018. OpenId: signTaskInfo.OpenID,
  1019. TalentPlatformInfoSnap: string(accountSnap),
  1020. TalentPersonalInfoSnap: string(talentSnap),
  1021. TalentPostAddrSnap: string(addrSnap),
  1022. TaskStage: 1,
  1023. CreateDate: gtime.Now(),
  1024. TaskStatus: 1,
  1025. LogisticsStatus: 1,
  1026. LinkStatus: 1,
  1027. DataStatus: 1,
  1028. ScriptStatus: 1,
  1029. SketchStatus: 1,
  1030. CompleteStatus: 1,
  1031. CurDefaultType: 0,
  1032. WithdrawStatus: 1,
  1033. ServiceCharge: ServiceChargePrice, //经过服务商,有服务费
  1034. ServiceRate: strategy.ServiceRate, //服务费率
  1035. SupportFee: SupporPricer, //经过服务商, 提报价格=一口价*(1+服务费率)
  1036. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1037. WxNum: signTaskInfo.WxNum,
  1038. PlatformId: platform_id,
  1039. }
  1040. } else {
  1041. //不经过服务商
  1042. var strategy *youngee_talent_model.RecruitStrategy
  1043. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
  1044. var SupporPricer = 0.0 //提报价
  1045. if signTaskInfo.StrategyId == 3 { //自报价
  1046. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  1047. } else if signTaskInfo.StrategyId == 2 { //一口价
  1048. SupporPricer = signTaskInfo.Offer
  1049. } else { //无费置换
  1050. SupporPricer = 0.0
  1051. }
  1052. if err != nil {
  1053. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1054. }
  1055. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  1056. TaskId: newTaskId,
  1057. ProjectId: signTaskInfo.ProjectId,
  1058. TalentId: tid,
  1059. OpenId: signTaskInfo.OpenID,
  1060. TalentPlatformInfoSnap: string(accountSnap),
  1061. TalentPersonalInfoSnap: string(talentSnap),
  1062. TalentPostAddrSnap: string(addrSnap),
  1063. TaskStage: 1,
  1064. CreateDate: gtime.Now(),
  1065. TaskStatus: 1,
  1066. LogisticsStatus: 1,
  1067. LinkStatus: 1,
  1068. DataStatus: 1,
  1069. ScriptStatus: 1,
  1070. SketchStatus: 1,
  1071. CompleteStatus: 1,
  1072. CurDefaultType: 0,
  1073. WithdrawStatus: 1,
  1074. ServiceCharge: 0, //不经过服务商,无服务费
  1075. ServiceRate: strategy.ServiceRate, //服务费率
  1076. SupportFee: SupporPricer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1077. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1078. WxNum: signTaskInfo.WxNum,
  1079. PlatformId: platform_id,
  1080. ProjectType: projectDetail.ProjectType,
  1081. }
  1082. }
  1083. //定向任务,服务费设置
  1084. taskInfo = youngee_talent_model.YoungeeTaskInfo{
  1085. TaskId: newTaskId,
  1086. ProjectId: signTaskInfo.ProjectId,
  1087. TalentId: tid,
  1088. OpenId: signTaskInfo.OpenID,
  1089. TalentPlatformInfoSnap: string(accountSnap),
  1090. TalentPersonalInfoSnap: string(talentSnap),
  1091. TalentPostAddrSnap: string(addrSnap),
  1092. TaskStage: 1,
  1093. CreateDate: gtime.Now(),
  1094. TaskStatus: 1,
  1095. LogisticsStatus: 1,
  1096. LinkStatus: 1,
  1097. DataStatus: 1,
  1098. ScriptStatus: 1,
  1099. SketchStatus: 1,
  1100. CompleteStatus: 1,
  1101. CurDefaultType: 0,
  1102. WithdrawStatus: 1,
  1103. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1104. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1105. WxNum: signTaskInfo.WxNum,
  1106. ProjectType: projectDetail.ProjectType,
  1107. }
  1108. }
  1109. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  1110. // 对应项目的报名人数自增
  1111. _, err = tx.Ctx(ctx).Model("project_info").Where("project_id = ?", projectDetail.ProjectId).Increment("apply_num", 1)
  1112. if err != nil {
  1113. return err
  1114. }
  1115. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  1116. if signTaskInfo.SProjectId != 0 {
  1117. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
  1118. if err != nil {
  1119. return err
  1120. }
  1121. var InfoSupplier *youngee_talent_model.ProjectInfoSupplier
  1122. err := g.DB().Model("younggee_s_project_info").Where("s_project_id=?", signTaskInfo.SProjectId).Scan(&InfoSupplier)
  1123. if err != nil {
  1124. fmt.Println("projectInfoSupplier err:", err.Error())
  1125. }
  1126. taskInfo.SupplierId = InfoSupplier.SupplierID //设置服务商ID
  1127. taskInfo.SProjectId = signTaskInfo.SProjectId //设置服务商项目ID
  1128. }
  1129. // 在task_info表中插入任务
  1130. _, err = tx.Ctx(ctx).Model("youngee_task_info").Data(&taskInfo).Insert()
  1131. if err != nil {
  1132. return err
  1133. }
  1134. return nil
  1135. })
  1136. if err != nil {
  1137. return &TalentHttpResult{Code: -18, Msg: "报名失败,您可能重复报名", Data: err.Error()}
  1138. }
  1139. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  1140. }
  1141. // 本地生活报名
  1142. func SignUpLocalWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  1143. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  1144. if err != nil {
  1145. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  1146. }
  1147. //POST请求体信息
  1148. var signTaskInfo *youngee_talent_model.SignLocalTaskInfo
  1149. err = r.ParseForm(&signTaskInfo)
  1150. if err != nil {
  1151. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  1152. }
  1153. var projectDetail *youngee_talent_model.LocalInfoDetail
  1154. err = g.DB().Model(youngee_talent_model.LocalInfoDetail{}).WithAll().Where("local_id", signTaskInfo.LocalId).Scan(&projectDetail)
  1155. if err != nil {
  1156. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  1157. }
  1158. //达人用户信息
  1159. var talentInfo *youngee_talent_model.TalentInfo
  1160. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  1161. if err != nil {
  1162. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  1163. }
  1164. //达人快手信息
  1165. var accountInfo *youngee_talent_model.KuaishouUserInfo
  1166. 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)
  1167. if err != nil {
  1168. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  1169. }
  1170. var newTaskId string
  1171. // 首先生成任务id
  1172. newTaskId = utils.GetUuid.GetTaskId(projectDetail.LocalId, projectDetail.EnterpriseId, tid)
  1173. //// 生成达人平台账号信息快照
  1174. accountSnap, err := gjson.Encode(accountInfo)
  1175. //if err != nil {
  1176. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  1177. //}
  1178. // 生成达人信息快照
  1179. talentSnap, err := gjson.Encode(talentInfo)
  1180. if err != nil {
  1181. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  1182. }
  1183. taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  1184. // 公开任务
  1185. if projectDetail.LocalType == 1 {
  1186. //经过服务商
  1187. if signTaskInfo.SLocalId != 0 {
  1188. var strategy *youngee_talent_model.RecruitStrategy
  1189. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1190. var ServiceChargePrice = 0.0 //服务费
  1191. var SupporPricer = 0.0 //提报价
  1192. if strategy.FeeForm == 3 { //自报价
  1193. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  1194. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  1195. } else if strategy.FeeForm == 2 { //一口价
  1196. ServiceChargePrice = strategy.ServiceCharge
  1197. SupporPricer = signTaskInfo.Offer
  1198. } else if strategy.FeeForm == 1 { //无费置换
  1199. ServiceChargePrice = 0.0
  1200. SupporPricer = 0.0
  1201. }
  1202. if err != nil {
  1203. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1204. }
  1205. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1206. TaskId: newTaskId,
  1207. PlatformId: projectDetail.LocalPlatform,
  1208. LocalId: signTaskInfo.LocalId,
  1209. SLocalId: signTaskInfo.SLocalId,
  1210. TalentId: tid,
  1211. OpenId: signTaskInfo.OpenID,
  1212. TalentPlatformInfoSnap: string(accountSnap),
  1213. TalentPersonalInfoSnap: string(talentSnap),
  1214. StrategyId: signTaskInfo.StrategyId,
  1215. TaskStage: 1,
  1216. FeeForm: strategy.FeeForm,
  1217. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  1218. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  1219. SupportFee: SupporPricer,
  1220. CreateDate: gtime.Now(),
  1221. TaskStatus: 1,
  1222. LogisticsStatus: 1,
  1223. LinkStatus: 1,
  1224. DataStatus: 1,
  1225. //ScriptStatus: 1,
  1226. SketchStatus: 1,
  1227. CompleteStatus: 1,
  1228. CurDefaultType: 0,
  1229. WithdrawStatus: 1,
  1230. SettleStatus: 1,
  1231. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  1232. SettleAmount: signTaskInfo.Offer,
  1233. SupplierStatus: 1,
  1234. WxNum: signTaskInfo.WxNum,
  1235. LocalType: projectDetail.LocalType,
  1236. }
  1237. } else {
  1238. //不经过服务商
  1239. var strategy *youngee_talent_model.RecruitStrategy
  1240. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.LocalId).Scan(&strategy)
  1241. if err != nil {
  1242. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1243. }
  1244. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1245. TaskId: newTaskId,
  1246. LocalId: signTaskInfo.LocalId,
  1247. TalentId: tid,
  1248. OpenId: signTaskInfo.OpenID,
  1249. TalentPlatformInfoSnap: string(accountSnap),
  1250. TalentPersonalInfoSnap: string(talentSnap),
  1251. StrategyId: signTaskInfo.StrategyId,
  1252. TaskStage: 1,
  1253. FeeForm: strategy.FeeForm,
  1254. ServiceCharge: 0, //不经过服务商则为0
  1255. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
  1256. SupportFee: signTaskInfo.Offer,
  1257. CreateDate: gtime.Now(),
  1258. TaskStatus: 1,
  1259. LogisticsStatus: 1,
  1260. LinkStatus: 1,
  1261. DataStatus: 1,
  1262. //ScriptStatus: 1,
  1263. SketchStatus: 1,
  1264. CompleteStatus: 1,
  1265. CurDefaultType: 0,
  1266. WithdrawStatus: 1,
  1267. SettleStatus: 1,
  1268. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  1269. SettleAmount: signTaskInfo.Offer,
  1270. WxNum: signTaskInfo.WxNum,
  1271. LocalType: projectDetail.LocalType,
  1272. }
  1273. }
  1274. } else if projectDetail.LocalType == 2 { //定向任务
  1275. //经过服务商
  1276. if signTaskInfo.SLocalId != 0 {
  1277. //查找服务商定义的策略
  1278. var strategy *youngee_talent_model.RecruitStrategy
  1279. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1280. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1281. TaskId: newTaskId,
  1282. LocalId: signTaskInfo.LocalId,
  1283. SLocalId: signTaskInfo.SLocalId,
  1284. TalentId: tid,
  1285. OpenId: signTaskInfo.OpenID,
  1286. TalentPlatformInfoSnap: string(accountSnap),
  1287. TalentPersonalInfoSnap: string(talentSnap),
  1288. TaskStage: 1,
  1289. CreateDate: gtime.Now(),
  1290. TaskStatus: 1,
  1291. LogisticsStatus: 1,
  1292. LinkStatus: 1,
  1293. DataStatus: 1,
  1294. //ScriptStatus: 1,
  1295. SketchStatus: 1,
  1296. CompleteStatus: 1,
  1297. CurDefaultType: 0,
  1298. WithdrawStatus: 1,
  1299. ServiceCharge: 0, //不经过服务商,无服务费
  1300. ServiceRate: 0, //服务费率
  1301. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1302. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1303. WxNum: signTaskInfo.WxNum,
  1304. LocalType: projectDetail.LocalType,
  1305. }
  1306. } else {
  1307. //不经过服务商
  1308. //查找服务商定义的策略
  1309. var strategy *youngee_talent_model.RecruitStrategy
  1310. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1311. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1312. TaskId: newTaskId,
  1313. LocalId: signTaskInfo.LocalId,
  1314. PlatformId: projectDetail.LocalPlatform,
  1315. TalentId: tid,
  1316. OpenId: signTaskInfo.OpenID,
  1317. TalentPlatformInfoSnap: string(accountSnap),
  1318. TalentPersonalInfoSnap: string(talentSnap),
  1319. TaskStage: 1,
  1320. CreateDate: gtime.Now(),
  1321. TaskStatus: 1,
  1322. LogisticsStatus: 1,
  1323. LinkStatus: 1,
  1324. DataStatus: 1,
  1325. //ScriptStatus: 1,
  1326. SketchStatus: 1,
  1327. CompleteStatus: 1,
  1328. CurDefaultType: 0,
  1329. WithdrawStatus: 1,
  1330. ServiceCharge: 0, //不经过服务商,无服务费
  1331. ServiceRate: 0, //服务费率
  1332. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1333. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1334. WxNum: signTaskInfo.WxNum,
  1335. LocalType: projectDetail.LocalType,
  1336. }
  1337. }
  1338. }
  1339. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  1340. // 对应项目的报名人数自增
  1341. _, err = tx.Ctx(ctx).Model("younggee_local_life_info").Where("local_id=?", projectDetail.LocalId).Increment("apply_num", 1)
  1342. if err != nil {
  1343. return err
  1344. }
  1345. //如果经过服务商,younggee_s_local_life_info中报名人数加一
  1346. if signTaskInfo.SLocalId != 0 {
  1347. var InfoSupplier *youngee_talent_model.LocalInfoSupplier
  1348. err := g.DB().Model("younggee_s_local_life_info").Where("s_local_id=?", signTaskInfo.SLocalId).Scan(&InfoSupplier)
  1349. if err != nil {
  1350. fmt.Println("projectInfoSupplier err:", err.Error())
  1351. }
  1352. taskInfo.SupplierId = InfoSupplier.SupplierID //设置服务商ID
  1353. taskInfo.SLocalId = signTaskInfo.SLocalId //设置服务商项目ID
  1354. _, err = tx.Ctx(ctx).Model("younggee_s_local_life_info").Where("s_local_id = ? ", signTaskInfo.SLocalId).Increment("apply_num", 1)
  1355. if err != nil {
  1356. return err
  1357. }
  1358. }
  1359. // 在task_info表中插入任务
  1360. _, err = tx.Ctx(ctx).Model("youngee_local_task_info").Data(&taskInfo).Insert()
  1361. if err != nil {
  1362. return err
  1363. }
  1364. return nil
  1365. })
  1366. if err != nil {
  1367. return &TalentHttpResult{Code: -18, Msg: "报名失败,您可能进行了重复报名", Data: err.Error()}
  1368. }
  1369. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  1370. }