task_info.go 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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. // 在task_info表中插入任务
  1111. _, err = tx.Ctx(ctx).Model("youngee_task_info").Data(&taskInfo).Insert()
  1112. if err != nil {
  1113. return err
  1114. }
  1115. // 对应项目的报名人数自增
  1116. _, err = tx.Ctx(ctx).Model("project_info").Where("project_id = ?", projectDetail.ProjectId).Increment("apply_num", 1)
  1117. if err != nil {
  1118. return err
  1119. }
  1120. //如果经过服务商,服务younggee_s_project_info中报名人数加一
  1121. if signTaskInfo.SProjectId != 0 {
  1122. _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
  1123. if err != nil {
  1124. return err
  1125. }
  1126. }
  1127. return nil
  1128. })
  1129. if err != nil {
  1130. return &TalentHttpResult{Code: -18, Msg: "报名失败,您可能重复报名", Data: err.Error()}
  1131. }
  1132. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  1133. }
  1134. // 本地生活报名
  1135. func SignUpLocalWithKsAccount(r *ghttp.Request) *TalentHttpResult {
  1136. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  1137. if err != nil {
  1138. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  1139. }
  1140. //POST请求体信息
  1141. var signTaskInfo *youngee_talent_model.SignLocalTaskInfo
  1142. err = r.ParseForm(&signTaskInfo)
  1143. if err != nil {
  1144. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  1145. }
  1146. var projectDetail *youngee_talent_model.LocalInfoDetail
  1147. err = g.DB().Model(youngee_talent_model.LocalInfoDetail{}).WithAll().Where("local_id", signTaskInfo.LocalId).Scan(&projectDetail)
  1148. if err != nil {
  1149. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  1150. }
  1151. //达人用户信息
  1152. var talentInfo *youngee_talent_model.TalentInfo
  1153. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  1154. if err != nil {
  1155. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  1156. }
  1157. //达人快手信息
  1158. var accountInfo *youngee_talent_model.KuaishouUserInfo
  1159. 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)
  1160. if err != nil {
  1161. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  1162. }
  1163. var newTaskId string
  1164. // 首先生成任务id
  1165. newTaskId = utils.GetUuid.GetTaskId(projectDetail.LocalId, projectDetail.EnterpriseId, tid)
  1166. //// 生成达人平台账号信息快照
  1167. accountSnap, err := gjson.Encode(accountInfo)
  1168. //if err != nil {
  1169. // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  1170. //}
  1171. // 生成达人信息快照
  1172. talentSnap, err := gjson.Encode(talentInfo)
  1173. if err != nil {
  1174. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  1175. }
  1176. taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
  1177. // 公开任务
  1178. if projectDetail.LocalType == 1 {
  1179. //经过服务商
  1180. if signTaskInfo.SLocalId != 0 {
  1181. var strategy *youngee_talent_model.RecruitStrategy
  1182. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1183. var ServiceChargePrice = 0.0 //服务费
  1184. var SupporPricer = 0.0 //提报价
  1185. if strategy.FeeForm == 3 { //自报价
  1186. ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
  1187. SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
  1188. } else if strategy.FeeForm == 2 { //一口价
  1189. ServiceChargePrice = strategy.ServiceCharge
  1190. SupporPricer = signTaskInfo.Offer
  1191. } else if strategy.FeeForm == 1 { //无费置换
  1192. ServiceChargePrice = 0.0
  1193. SupporPricer = 0.0
  1194. }
  1195. if err != nil {
  1196. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1197. }
  1198. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1199. TaskId: newTaskId,
  1200. PlatformId: projectDetail.LocalPlatform,
  1201. LocalId: signTaskInfo.LocalId,
  1202. SLocalId: signTaskInfo.SLocalId,
  1203. TalentId: tid,
  1204. OpenId: signTaskInfo.OpenID,
  1205. TalentPlatformInfoSnap: string(accountSnap),
  1206. TalentPersonalInfoSnap: string(talentSnap),
  1207. StrategyId: signTaskInfo.StrategyId,
  1208. TaskStage: 1,
  1209. FeeForm: strategy.FeeForm,
  1210. ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
  1211. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
  1212. SupportFee: SupporPricer,
  1213. CreateDate: gtime.Now(),
  1214. TaskStatus: 1,
  1215. LogisticsStatus: 1,
  1216. LinkStatus: 1,
  1217. DataStatus: 1,
  1218. //ScriptStatus: 1,
  1219. SketchStatus: 1,
  1220. CompleteStatus: 1,
  1221. CurDefaultType: 0,
  1222. WithdrawStatus: 1,
  1223. SettleStatus: 1,
  1224. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  1225. SettleAmount: signTaskInfo.Offer,
  1226. SupplierStatus: 1,
  1227. WxNum: signTaskInfo.WxNum,
  1228. LocalType: projectDetail.LocalType,
  1229. }
  1230. } else {
  1231. //不经过服务商
  1232. var strategy *youngee_talent_model.RecruitStrategy
  1233. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.LocalId).Scan(&strategy)
  1234. if err != nil {
  1235. return &TalentHttpResult{Code: -10, Msg: err.Error()}
  1236. }
  1237. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1238. TaskId: newTaskId,
  1239. LocalId: signTaskInfo.LocalId,
  1240. TalentId: tid,
  1241. OpenId: signTaskInfo.OpenID,
  1242. TalentPlatformInfoSnap: string(accountSnap),
  1243. TalentPersonalInfoSnap: string(talentSnap),
  1244. StrategyId: signTaskInfo.StrategyId,
  1245. TaskStage: 1,
  1246. FeeForm: strategy.FeeForm,
  1247. ServiceCharge: 0, //不经过服务商则为0
  1248. ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
  1249. SupportFee: signTaskInfo.Offer,
  1250. CreateDate: gtime.Now(),
  1251. TaskStatus: 1,
  1252. LogisticsStatus: 1,
  1253. LinkStatus: 1,
  1254. DataStatus: 1,
  1255. //ScriptStatus: 1,
  1256. SketchStatus: 1,
  1257. CompleteStatus: 1,
  1258. CurDefaultType: 0,
  1259. WithdrawStatus: 1,
  1260. SettleStatus: 1,
  1261. DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
  1262. SettleAmount: signTaskInfo.Offer,
  1263. WxNum: signTaskInfo.WxNum,
  1264. LocalType: projectDetail.LocalType,
  1265. }
  1266. }
  1267. } else if projectDetail.LocalType == 2 { //定向任务
  1268. //经过服务商
  1269. if signTaskInfo.SLocalId != 0 {
  1270. //查找服务商定义的策略
  1271. var strategy *youngee_talent_model.RecruitStrategy
  1272. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1273. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1274. TaskId: newTaskId,
  1275. LocalId: signTaskInfo.LocalId,
  1276. SLocalId: signTaskInfo.SLocalId,
  1277. TalentId: tid,
  1278. OpenId: signTaskInfo.OpenID,
  1279. TalentPlatformInfoSnap: string(accountSnap),
  1280. TalentPersonalInfoSnap: string(talentSnap),
  1281. TaskStage: 1,
  1282. CreateDate: gtime.Now(),
  1283. TaskStatus: 1,
  1284. LogisticsStatus: 1,
  1285. LinkStatus: 1,
  1286. DataStatus: 1,
  1287. //ScriptStatus: 1,
  1288. SketchStatus: 1,
  1289. CompleteStatus: 1,
  1290. CurDefaultType: 0,
  1291. WithdrawStatus: 1,
  1292. ServiceCharge: 0, //不经过服务商,无服务费
  1293. ServiceRate: 0, //服务费率
  1294. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1295. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1296. WxNum: signTaskInfo.WxNum,
  1297. LocalType: projectDetail.LocalType,
  1298. }
  1299. } else {
  1300. //不经过服务商
  1301. //查找服务商定义的策略
  1302. var strategy *youngee_talent_model.RecruitStrategy
  1303. err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
  1304. taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
  1305. TaskId: newTaskId,
  1306. LocalId: signTaskInfo.LocalId,
  1307. PlatformId: projectDetail.LocalPlatform,
  1308. TalentId: tid,
  1309. OpenId: signTaskInfo.OpenID,
  1310. TalentPlatformInfoSnap: string(accountSnap),
  1311. TalentPersonalInfoSnap: string(talentSnap),
  1312. TaskStage: 1,
  1313. CreateDate: gtime.Now(),
  1314. TaskStatus: 1,
  1315. LogisticsStatus: 1,
  1316. LinkStatus: 1,
  1317. DataStatus: 1,
  1318. //ScriptStatus: 1,
  1319. SketchStatus: 1,
  1320. CompleteStatus: 1,
  1321. CurDefaultType: 0,
  1322. WithdrawStatus: 1,
  1323. ServiceCharge: 0, //不经过服务商,无服务费
  1324. ServiceRate: 0, //服务费率
  1325. SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
  1326. DraftFee: signTaskInfo.Offer, //稿费价格,一口价
  1327. WxNum: signTaskInfo.WxNum,
  1328. LocalType: projectDetail.LocalType,
  1329. }
  1330. }
  1331. }
  1332. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  1333. // 在task_info表中插入任务
  1334. _, err = tx.Ctx(ctx).Model("youngee_local_task_info").Data(&taskInfo).Insert()
  1335. if err != nil {
  1336. return err
  1337. }
  1338. // 对应项目的报名人数自增
  1339. _, err = tx.Ctx(ctx).Model("younggee_local_life_info").Where("local_id=?", projectDetail.LocalId).Increment("apply_num", 1)
  1340. if err != nil {
  1341. return err
  1342. }
  1343. //如果经过服务商,younggee_s_local_life_info中报名人数加一
  1344. if signTaskInfo.SLocalId != 0 {
  1345. _, err = tx.Ctx(ctx).Model("younggee_s_local_life_info").Where("s_local_id = ? ", signTaskInfo.SLocalId).Increment("apply_num", 1)
  1346. if err != nil {
  1347. return err
  1348. }
  1349. }
  1350. return nil
  1351. })
  1352. if err != nil {
  1353. return &TalentHttpResult{Code: -18, Msg: "报名失败,您可能进行了重复报名", Data: err.Error()}
  1354. }
  1355. return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
  1356. }