task_info.go 57 KB

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