task_info.go 57 KB

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