seletion_square.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package youngee_sectask_service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/gogf/gf/database/gdb"
  7. "reflect"
  8. "youngmini_server/app/dao"
  9. "youngmini_server/app/model"
  10. "youngmini_server/app/model/youngee_talent_model"
  11. "youngmini_server/app/utils"
  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. const (
  18. selectionStatusCreating = iota + 1
  19. selectionStatusReviewing
  20. selectionStatusReviewed
  21. selectionStatusPaying
  22. selectionStatusPaid
  23. selectionStatusInProgress
  24. selectionStatusInvalid
  25. selectionStatusClosed
  26. )
  27. // 获取项目信息列表service
  28. func GetSelectionList(r *ghttp.Request) *TalentHttpResult {
  29. pageIndex := r.GetQueryInt("idx", -1)
  30. cntPerPage := r.GetQueryInt("cnt", -1)
  31. //platform := r.Get("platform")
  32. secForm := r.Get("secform")
  33. taskForm := r.Get("taskform")
  34. categoryForm := r.Get("categoryform")
  35. searchValue := r.Get("searchvalue")
  36. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  37. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  38. }
  39. // 如果有领样形式的过滤条件,则将过滤条件保存于secFormList
  40. var secFormList []interface{}
  41. if secForm != nil {
  42. if reflect.TypeOf(secForm).Kind() != reflect.Slice {
  43. return &TalentHttpResult{Code: -2, Msg: "搜索条件领样形式错误"}
  44. }
  45. secFormList = make([]interface{}, 0)
  46. secFormList = secForm.([]interface{})
  47. }
  48. // 如果有任务形式的过滤条件,则将过滤条件保存于taskFormList
  49. var taskFormList []interface{}
  50. if taskForm != nil {
  51. if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
  52. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  53. }
  54. taskFormList = make([]interface{}, 0)
  55. taskFormList = taskForm.([]interface{})
  56. }
  57. // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
  58. var categoryFormList []interface{}
  59. if categoryForm != nil {
  60. if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
  61. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  62. }
  63. categoryFormList = make([]interface{}, 0)
  64. categoryFormList = categoryForm.([]interface{})
  65. }
  66. // 如果有平台的过滤条件,则将平台列表保存于platformList 弃用
  67. /* var platformList []interface{}
  68. if platform != nil {
  69. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  70. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  71. }
  72. platformList = make([]interface{}, 0)
  73. platformList = platform.([]interface{})
  74. }*/
  75. // 构造查询的条件
  76. startId := pageIndex * cntPerPage
  77. whereStr := fmt.Sprintf("(selection_status >= %d)", selectionStatusInProgress)
  78. /* if platformList != nil {
  79. whereStr = whereStr + " and platform in ("
  80. for _, v := range platformList {
  81. whereStr += v.(string) + ", "
  82. }
  83. whereStr = whereStr[0 : len(whereStr)-2]
  84. whereStr += ")"
  85. }*/
  86. if taskFormList != nil {
  87. whereStr += " and task_mode in ("
  88. for _, v := range taskFormList {
  89. whereStr += v.(string) + ", "
  90. }
  91. whereStr = whereStr[0 : len(whereStr)-2]
  92. whereStr += ")"
  93. }
  94. if secFormList != nil {
  95. whereStr += " and sample_mode in ("
  96. for _, v := range secFormList {
  97. whereStr += v.(string) + ", "
  98. }
  99. whereStr = whereStr[0 : len(whereStr)-2]
  100. whereStr += ")"
  101. }
  102. if categoryFormList != nil {
  103. whereStr += " and product_category in ("
  104. for _, v := range categoryFormList {
  105. whereStr += v.(string) + ", "
  106. }
  107. whereStr = whereStr[0 : len(whereStr)-2]
  108. whereStr += ")"
  109. }
  110. //搜索栏
  111. if searchValue != nil {
  112. whereStr += " and selection_name like '%" + searchValue.(string) + "%'"
  113. }
  114. // 查询所有selection
  115. //YounggeeSelectionInfo含有表中的所有属性
  116. var selectionList = []model.YounggeeSelectionInfo{}
  117. //err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Scan(&selectionList)
  118. //展示带货商品的排序规则 预估赚、ddl未处理
  119. err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Order("commission_rate DESC , task_reward DESC ").Scan(&selectionList)
  120. if err != nil {
  121. return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
  122. }
  123. fmt.Println("****searchValue:", searchValue)
  124. fmt.Println("****secFormList:", secFormList)
  125. fmt.Println("****taskFormList:", taskFormList)
  126. fmt.Println("****whereStr: ", whereStr)
  127. // 判断请求页面是否超过最大页面
  128. c, err := g.DB().Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Count()
  129. if err != nil {
  130. return &TalentHttpResult{Code: -4, Msg: err.Error(), Data: nil}
  131. }
  132. maxPage := c / cntPerPage
  133. if c%cntPerPage > 0 {
  134. maxPage += 1
  135. }
  136. if pageIndex+1 > maxPage {
  137. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  138. }
  139. var selectionInfoList = youngee_talent_model.SelectionInfoList{
  140. Count: c,
  141. }
  142. err = g.DB().Model(dao.YounggeeSelectionInfo.Table).WithAll().Where(whereStr).
  143. Order("selection_status ASC , task_ddl DESC , commission_rate DESC , task_reward DESC, selection_id").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
  144. if err != nil {
  145. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  146. }
  147. selectionInfoList.MaxPage = maxPage
  148. return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionInfoList}
  149. }
  150. // 获取单个选品详情service
  151. func GetSelectionDetail(r *ghttp.Request) *TalentHttpResult {
  152. sid := r.GetQueryString("selectionid", 0)
  153. pid := r.GetQueryString("productid", 0)
  154. if sid == "" {
  155. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  156. }
  157. var selectionDetail *youngee_talent_model.SelectionDetail
  158. err := g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", sid).Scan(&selectionDetail)
  159. if err != nil {
  160. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  161. }
  162. // 查询younggee_product表数据
  163. var younggeeProduct []*youngee_talent_model.YounggeeProduct
  164. err = g.DB().Model(youngee_talent_model.YounggeeProduct{}).WithAll().Where("product_id", pid).Scan(&younggeeProduct)
  165. if err != nil {
  166. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  167. }
  168. //查询younggee_product_photo表数据
  169. var younggeeProductPhoto []*youngee_talent_model.YounggeeProductPhoto
  170. err = g.DB().Model(youngee_talent_model.YounggeeProductPhoto{}).WithAll().Where("product_id", pid).Scan(&younggeeProductPhoto)
  171. if err != nil {
  172. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  173. }
  174. //selectionDetail.FreeStrategy = freeStrategy
  175. //selectionDetail.RewardStrategy = rewardStrategy
  176. selectionDetail.YounggeeProduct = younggeeProduct
  177. selectionDetail.YounggeeProductPhoto = younggeeProductPhoto
  178. //selectionDetail.SelectionBrief = selectionBrief
  179. //selectionDetail.SelectionExample = selectionExample
  180. return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionDetail}
  181. }
  182. func GetProductDetail(r *ghttp.Request) *TalentHttpResult {
  183. pid := r.GetQueryString("productid", 0)
  184. if pid == "" {
  185. return &TalentHttpResult{Code: -2, Msg: "data query failed"}
  186. }
  187. var productDetail *youngee_talent_model.YounggeeProduct
  188. err := g.DB().Model(youngee_talent_model.YounggeeProduct{}).WithAll().Where("product_id", pid).Scan(&productDetail)
  189. if err != nil {
  190. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  191. }
  192. return &TalentHttpResult{Code: 0, Msg: "success", Data: productDetail}
  193. }
  194. func GetProductPhoto(r *ghttp.Request) *TalentHttpResult {
  195. //访问表,获取图片
  196. return nil
  197. }
  198. // 判断是否已报名任务,如果是提供免费领样(按钮既然有肯定是免费领样),sectask中的sample_mode==3,或者没有数据。表示还没报名,只是添加橱窗了
  199. func IsSignUpSecTask(r *ghttp.Request) *TalentHttpResult {
  200. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  201. if err != nil {
  202. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  203. }
  204. selectionId := r.GetQueryInt("selection_id", -1)
  205. //定义接口存该达人所有的报名任务
  206. task := []model.YounggeeSecTaskInfo{}
  207. err = g.Model(dao.YounggeeSecTaskInfo.Table).Where("selection_id = ? and talent_id = ?", selectionId, tid).Scan(&task)
  208. if err != nil {
  209. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  210. }
  211. isSign := youngee_talent_model.IsSignSecTask{}
  212. //如果有数据且sample_mode==3说明没有报名,否则报名了
  213. //有数据且sample_mode==1说明报名了,否则没报名 &&左边为false就不执行了
  214. if len(task) != 0 && task[0].SampleMode == 1 {
  215. isSign.SecTaskInfo = &task[0]
  216. isSign.IsSign = 1
  217. } else {
  218. isSign.IsSign = 0
  219. }
  220. return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
  221. }
  222. // 选品任务报名service
  223. func SignUpSecTask(r *ghttp.Request) *TalentHttpResult {
  224. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  225. if err != nil {
  226. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  227. }
  228. // 解析前端传来的参数
  229. var signSecTaskReq *youngee_talent_model.SignSecTaskReq
  230. err = r.ParseForm(&signSecTaskReq)
  231. if err != nil {
  232. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  233. }
  234. // 查得的selectionDetail包含product、photo、策略表等综合数据
  235. var selectionDetail *youngee_talent_model.SelectionDetail
  236. err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionDetail)
  237. if err != nil {
  238. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  239. }
  240. //获取选品表中的ddl
  241. var selectionInfo *model.YounggeeSelectionInfo
  242. err = g.DB().Model("younggee_selection_info").Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionInfo)
  243. var product model.YounggeeProduct
  244. err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
  245. if err != nil {
  246. return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
  247. }
  248. // 查询达人详情
  249. var talentInfo *youngee_talent_model.TalentInfo
  250. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  251. if err != nil {
  252. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  253. }
  254. // 社媒账号详情
  255. var accountInfo *youngee_talent_model.PlatformAccountInfo
  256. err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, selectionDetail.Platform).Scan(&accountInfo)
  257. if err != nil {
  258. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  259. }
  260. // 收货地址详情
  261. address, err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).One("talent_id = ? and address_id = ?", tid, signSecTaskReq.AddressId)
  262. if err != nil {
  263. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  264. }
  265. var newTaskId string
  266. // 首先生成任务id
  267. newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.EnterpriseId, tid)
  268. // 生成达人平台账号信息快照
  269. accountSnap, err := gjson.Encode(accountInfo)
  270. if err != nil {
  271. return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  272. }
  273. // 生成达人信息快照
  274. talentSnap, err := gjson.Encode(talentInfo)
  275. if err != nil {
  276. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  277. }
  278. // 生成收货地址快照
  279. addrSnap, err := gjson.Encode(address)
  280. if err != nil {
  281. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  282. }
  283. secTaskInfo := youngee_talent_model.SecTaskInfoDetail{
  284. TaskId: newTaskId,
  285. SelectionId: signSecTaskReq.SelectionId,
  286. ProductId: signSecTaskReq.ProductId,
  287. SaleNum: signSecTaskReq.SaleNum,
  288. FansNum: signSecTaskReq.FansNum,
  289. TalentId: tid,
  290. AccountId: accountInfo.AccountId,
  291. TalentPlatformInfoSnap: string(accountSnap),
  292. TalentPersonalInfoSnap: string(talentSnap),
  293. TalentPostAddrSnap: string(addrSnap),
  294. TaskReward: selectionDetail.TaskReward,
  295. TalentPayment: product.ProductPrice,
  296. IsPayPayment: 0,
  297. IsPayReward: 0,
  298. TaskMode: selectionDetail.TaskMode,
  299. SampleMode: selectionDetail.SampleMode,
  300. FreeStage: 1, //领样状态:已申请 悬赏状态默认为0
  301. PlatformId: 4, //快手平台
  302. TaskStage: 3,
  303. TaskStatus: 1,
  304. CreateDate: gtime.Now(),
  305. CompleteStatus: 1,
  306. LogisticsStatus: 1,
  307. AssignmentStatus: 1,
  308. UpdateAt: gtime.Now(),
  309. WithdrawStatus: 1,
  310. LeadTeamId: signSecTaskReq.LeadTeamId,
  311. TeamId: signSecTaskReq.TeamId,
  312. TeamIncome: 0,
  313. TeamPoint: 0,
  314. TaskDdl: selectionInfo.TaskDdl,
  315. }
  316. //删除添加橱窗时创建的不完整的数据
  317. _, err = g.DB().Model("younggee_sec_task_info").
  318. Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
  319. Delete()
  320. if err != nil {
  321. return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
  322. }
  323. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  324. // young之团收益计算
  325. var rewardConfig *model.YounggeeTeamRewardConfig
  326. whereCondition := g.Map{
  327. dao.YounggeeTeamRewardConfig.Columns.ProjectType: 2,
  328. dao.YounggeeTeamRewardConfig.Columns.TaskForm: selectionDetail.TaskMode + 3,
  329. dao.YounggeeTeamRewardConfig.Columns.ContentForm: selectionDetail.ContentType,
  330. dao.YounggeeTeamRewardConfig.Columns.RewardReason: talentInfo.UserType,
  331. }
  332. err = tx.Model(dao.YounggeeTeamRewardConfig.Table).Where(whereCondition).Scan(&rewardConfig)
  333. if err != nil {
  334. fmt.Println(err)
  335. return err
  336. }
  337. if rewardConfig != nil {
  338. secTaskInfo.TeamPoint = rewardConfig.Point
  339. secTaskInfo.TeamIncome = rewardConfig.Money
  340. whereCondition = g.Map{
  341. dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.LeadTeamId,
  342. }
  343. whereCondition1 := g.Map{
  344. dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.TeamId,
  345. }
  346. updateData := g.Map{
  347. dao.YounggeeTalentTeam.Columns.PointIncome: gdb.Raw(fmt.Sprintf("%s + %d", dao.YounggeeTalentTeam.Columns.PointIncome, rewardConfig.Point)),
  348. dao.YounggeeTalentTeam.Columns.MoneyIncome: gdb.Raw(fmt.Sprintf("%s + %f", dao.YounggeeTalentTeam.Columns.MoneyIncome, float64(rewardConfig.Money)*secTaskInfo.TaskReward/100)),
  349. }
  350. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition).Update()
  351. if err != nil {
  352. return err
  353. }
  354. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition1).Update()
  355. if err != nil {
  356. return err
  357. }
  358. // young之团状态变更
  359. if signSecTaskReq.LeadTeamId != "" {
  360. // 更新young之团状态
  361. whereCondition2 := g.Map{
  362. dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
  363. }
  364. updateData = g.Map{
  365. dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
  366. }
  367. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Where(whereCondition2).Data(updateData).Update()
  368. if err != nil {
  369. return err
  370. }
  371. }
  372. if signSecTaskReq.TeamId != "" {
  373. // 更新young之团状态
  374. whereCondition2 := g.Map{
  375. dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
  376. }
  377. updateData = g.Map{
  378. dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
  379. }
  380. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition1).Where(whereCondition2).Data(updateData).Update()
  381. if err != nil {
  382. return err
  383. }
  384. }
  385. }
  386. if selectionDetail.SampleMode == 2 {
  387. // 减少选品库存
  388. whereCondition1 := g.Map{
  389. dao.YounggeeSelectionInfo.Columns.SelectionId: selectionDetail.SelectionId,
  390. }
  391. updateData := g.Map{
  392. dao.YounggeeSelectionInfo.Columns.RemainNum: gdb.Raw(fmt.Sprintf("%s - 1", dao.YounggeeSelectionInfo.Columns.RemainNum)),
  393. }
  394. _, err = tx.Ctx(ctx).Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Data(updateData).Update()
  395. if err != nil {
  396. return err
  397. }
  398. // 新建任务,初始化状态为待发货
  399. secTaskInfo.TaskStage = 6
  400. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  401. if err != nil {
  402. return err
  403. }
  404. } else {
  405. // 新建任务,初始化状态为待确认
  406. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  407. if err != nil {
  408. return err
  409. }
  410. }
  411. return nil
  412. })
  413. if err != nil {
  414. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  415. }
  416. signSecTaskResp := youngee_talent_model.SignSecTaskResp{
  417. TaskId: newTaskId,
  418. }
  419. return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
  420. //return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionDetail}
  421. }
  422. func SignUpSecTaskFromWindow(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. // 解析body/json参数
  428. var signSecTaskReq *youngee_talent_model.SignSecTaskReq
  429. err = r.ParseForm(&signSecTaskReq)
  430. if err != nil {
  431. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  432. }
  433. // 查询选品详情
  434. var selectionDetail *youngee_talent_model.SelectionDetail
  435. err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionDetail)
  436. if err != nil {
  437. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  438. }
  439. //获取选品表中的ddl
  440. var selectionInfo *model.YounggeeSelectionInfo
  441. err = g.DB().Model("younggee_selection_info").Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionInfo)
  442. var product model.YounggeeProduct
  443. err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
  444. if err != nil {
  445. return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
  446. }
  447. // 查询达人详情
  448. var talentInfo *youngee_talent_model.TalentInfo
  449. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  450. if err != nil {
  451. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  452. }
  453. // 社媒账号详情
  454. var accountInfo *youngee_talent_model.PlatformAccountInfo
  455. err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, selectionDetail.Platform).Scan(&accountInfo)
  456. if err != nil {
  457. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  458. }
  459. var newTaskId string
  460. // 首先生成任务id
  461. newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.EnterpriseId, tid)
  462. // 生成达人平台账号信息快照
  463. accountSnap, err := gjson.Encode(accountInfo)
  464. if err != nil {
  465. return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  466. }
  467. // 生成达人信息快照
  468. talentSnap, err := gjson.Encode(talentInfo)
  469. if err != nil {
  470. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  471. }
  472. secTaskInfo := youngee_talent_model.SecTaskInfoWindowDetail{
  473. TaskId: newTaskId,
  474. SelectionId: signSecTaskReq.SelectionId,
  475. ProductId: signSecTaskReq.ProductId,
  476. SaleNum: signSecTaskReq.SaleNum,
  477. FansNum: signSecTaskReq.FansNum,
  478. TalentId: tid,
  479. AccountId: accountInfo.AccountId,
  480. TalentPlatformInfoSnap: string(accountSnap),
  481. TalentPersonalInfoSnap: string(talentSnap),
  482. //TalentPostAddrSnap: string(addrSnap),
  483. TaskReward: selectionInfo.TaskReward,
  484. TalentPayment: product.ProductPrice,
  485. IsPayPayment: 0,
  486. IsPayReward: 0,
  487. TaskMode: selectionInfo.TaskMode,
  488. SampleMode: 3, //添加橱窗,当作不提供领样处理
  489. PlatformId: 4, //快手平台
  490. TaskStage: 3,
  491. TaskStatus: 1,
  492. CreateDate: gtime.Now(),
  493. CompleteStatus: 1,
  494. LogisticsStatus: 1,
  495. AssignmentStatus: 1,
  496. UpdateAt: gtime.Now(),
  497. WithdrawStatus: 1,
  498. LeadTeamId: signSecTaskReq.LeadTeamId,
  499. TeamId: signSecTaskReq.TeamId,
  500. TeamIncome: 0,
  501. TeamPoint: 0,
  502. TaskDdl: selectionInfo.TaskDdl,
  503. }
  504. //如果已经有数据了,删除。模拟在快手侧里把橱窗商品删了,想再加回来
  505. //删除添加橱窗时创建的不完整的数据
  506. _, err = g.DB().Model("younggee_sec_task_info").
  507. Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
  508. Delete()
  509. if err != nil {
  510. return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
  511. }
  512. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  513. // 新建任务,初始化状态为待确认
  514. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  515. if err != nil {
  516. return err
  517. }
  518. return nil
  519. })
  520. if err != nil {
  521. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  522. }
  523. signSecTaskResp := youngee_talent_model.SignSecTaskResp{
  524. TaskId: newTaskId,
  525. }
  526. return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
  527. }