seletion_square.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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. var product model.YounggeeProduct
  241. err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
  242. if err != nil {
  243. return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
  244. }
  245. // 查询达人详情
  246. var talentInfo *youngee_talent_model.TalentInfo
  247. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  248. if err != nil {
  249. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  250. }
  251. // 社媒账号详情
  252. var accountInfo *youngee_talent_model.PlatformAccountInfo
  253. err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, selectionDetail.Platform).Scan(&accountInfo)
  254. if err != nil {
  255. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  256. }
  257. // 收货地址详情
  258. address, err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).One("talent_id = ? and address_id = ?", tid, signSecTaskReq.AddressId)
  259. if err != nil {
  260. return &TalentHttpResult{Code: -6, Msg: err.Error()}
  261. }
  262. var newTaskId string
  263. // 首先生成任务id
  264. newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.EnterpriseId, tid)
  265. // 生成达人平台账号信息快照
  266. accountSnap, err := gjson.Encode(accountInfo)
  267. if err != nil {
  268. return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  269. }
  270. // 生成达人信息快照
  271. talentSnap, err := gjson.Encode(talentInfo)
  272. if err != nil {
  273. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  274. }
  275. // 生成收货地址快照
  276. addrSnap, err := gjson.Encode(address)
  277. if err != nil {
  278. return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
  279. }
  280. secTaskInfo := youngee_talent_model.SecTaskInfoDetail{
  281. TaskId: newTaskId,
  282. SelectionId: signSecTaskReq.SelectionId,
  283. ProductId: signSecTaskReq.ProductId,
  284. SaleNum: signSecTaskReq.SaleNum,
  285. FansNum: signSecTaskReq.FansNum,
  286. TalentId: tid,
  287. AccountId: accountInfo.AccountId,
  288. TalentPlatformInfoSnap: string(accountSnap),
  289. TalentPersonalInfoSnap: string(talentSnap),
  290. TalentPostAddrSnap: string(addrSnap),
  291. TaskReward: selectionDetail.TaskReward,
  292. TalentPayment: product.ProductPrice,
  293. IsPayPayment: 0,
  294. IsPayReward: 0,
  295. TaskMode: selectionDetail.TaskMode,
  296. SampleMode: selectionDetail.SampleMode,
  297. FreeStage: 1, //领样状态:已申请 悬赏状态默认为0
  298. TaskStage: 3,
  299. TaskStatus: 1,
  300. CreateDate: gtime.Now(),
  301. CompleteStatus: 1,
  302. LogisticsStatus: 1,
  303. AssignmentStatus: 1,
  304. UpdateAt: gtime.Now(),
  305. WithdrawStatus: 1,
  306. LeadTeamId: signSecTaskReq.LeadTeamId,
  307. TeamId: signSecTaskReq.TeamId,
  308. TeamIncome: 0,
  309. TeamPoint: 0,
  310. SelectionDetail: selectionDetail,
  311. }
  312. //删除添加橱窗时创建的不完整的数据
  313. _, err = g.DB().Model("younggee_sec_task_info").
  314. Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
  315. Delete()
  316. if err != nil {
  317. return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
  318. }
  319. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  320. // young之团收益计算
  321. var rewardConfig *model.YounggeeTeamRewardConfig
  322. whereCondition := g.Map{
  323. dao.YounggeeTeamRewardConfig.Columns.ProjectType: 2,
  324. dao.YounggeeTeamRewardConfig.Columns.TaskForm: selectionDetail.TaskMode + 3,
  325. dao.YounggeeTeamRewardConfig.Columns.ContentForm: selectionDetail.ContentType,
  326. dao.YounggeeTeamRewardConfig.Columns.RewardReason: talentInfo.UserType,
  327. }
  328. err = tx.Model(dao.YounggeeTeamRewardConfig.Table).Where(whereCondition).Scan(&rewardConfig)
  329. if err != nil {
  330. fmt.Println(err)
  331. return err
  332. }
  333. if rewardConfig != nil {
  334. secTaskInfo.TeamPoint = rewardConfig.Point
  335. secTaskInfo.TeamIncome = rewardConfig.Money
  336. whereCondition = g.Map{
  337. dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.LeadTeamId,
  338. }
  339. whereCondition1 := g.Map{
  340. dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.TeamId,
  341. }
  342. updateData := g.Map{
  343. dao.YounggeeTalentTeam.Columns.PointIncome: gdb.Raw(fmt.Sprintf("%s + %d", dao.YounggeeTalentTeam.Columns.PointIncome, rewardConfig.Point)),
  344. dao.YounggeeTalentTeam.Columns.MoneyIncome: gdb.Raw(fmt.Sprintf("%s + %f", dao.YounggeeTalentTeam.Columns.MoneyIncome, float64(rewardConfig.Money)*secTaskInfo.TaskReward/100)),
  345. }
  346. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition).Update()
  347. if err != nil {
  348. return err
  349. }
  350. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition1).Update()
  351. if err != nil {
  352. return err
  353. }
  354. // young之团状态变更
  355. if signSecTaskReq.LeadTeamId != "" {
  356. // 更新young之团状态
  357. whereCondition2 := g.Map{
  358. dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
  359. }
  360. updateData = g.Map{
  361. dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
  362. }
  363. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Where(whereCondition2).Data(updateData).Update()
  364. if err != nil {
  365. return err
  366. }
  367. }
  368. if signSecTaskReq.TeamId != "" {
  369. // 更新young之团状态
  370. whereCondition2 := g.Map{
  371. dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
  372. }
  373. updateData = g.Map{
  374. dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
  375. }
  376. _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition1).Where(whereCondition2).Data(updateData).Update()
  377. if err != nil {
  378. return err
  379. }
  380. }
  381. }
  382. if selectionDetail.SampleMode == 2 {
  383. // 减少选品库存
  384. whereCondition1 := g.Map{
  385. dao.YounggeeSelectionInfo.Columns.SelectionId: selectionDetail.SelectionId,
  386. }
  387. updateData := g.Map{
  388. dao.YounggeeSelectionInfo.Columns.RemainNum: gdb.Raw(fmt.Sprintf("%s - 1", dao.YounggeeSelectionInfo.Columns.RemainNum)),
  389. }
  390. _, err = tx.Ctx(ctx).Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Data(updateData).Update()
  391. if err != nil {
  392. return err
  393. }
  394. // 新建任务,初始化状态为待发货
  395. secTaskInfo.TaskStage = 6
  396. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  397. if err != nil {
  398. return err
  399. }
  400. } else {
  401. // 新建任务,初始化状态为待确认
  402. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  403. if err != nil {
  404. return err
  405. }
  406. }
  407. return nil
  408. })
  409. if err != nil {
  410. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  411. }
  412. signSecTaskResp := youngee_talent_model.SignSecTaskResp{
  413. TaskId: newTaskId,
  414. }
  415. return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
  416. //return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionDetail}
  417. }
  418. func SignUpSecTaskFromWindow(r *ghttp.Request) *TalentHttpResult {
  419. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  420. if err != nil {
  421. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  422. }
  423. // 解析body/json参数
  424. var signSecTaskReq *youngee_talent_model.SignSecTaskReq
  425. err = r.ParseForm(&signSecTaskReq)
  426. if err != nil {
  427. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  428. }
  429. // 查询选品详情
  430. var selectionDetail *youngee_talent_model.SelectionDetail
  431. err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionDetail)
  432. if err != nil {
  433. return &TalentHttpResult{Code: -3, Msg: err.Error()}
  434. }
  435. var product model.YounggeeProduct
  436. err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
  437. if err != nil {
  438. return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
  439. }
  440. // 查询达人详情
  441. var talentInfo *youngee_talent_model.TalentInfo
  442. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  443. if err != nil {
  444. return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
  445. }
  446. // 社媒账号详情
  447. var accountInfo *youngee_talent_model.PlatformAccountInfo
  448. err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, selectionDetail.Platform).Scan(&accountInfo)
  449. if err != nil {
  450. return &TalentHttpResult{Code: -5, Msg: err.Error()}
  451. }
  452. var newTaskId string
  453. // 首先生成任务id
  454. newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.EnterpriseId, tid)
  455. // 生成达人平台账号信息快照
  456. accountSnap, err := gjson.Encode(accountInfo)
  457. if err != nil {
  458. return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
  459. }
  460. // 生成达人信息快照
  461. talentSnap, err := gjson.Encode(talentInfo)
  462. if err != nil {
  463. return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
  464. }
  465. secTaskInfo := youngee_talent_model.SecTaskInfoWindowDetail{
  466. TaskId: newTaskId,
  467. SelectionId: signSecTaskReq.SelectionId,
  468. ProductId: signSecTaskReq.ProductId,
  469. SaleNum: signSecTaskReq.SaleNum,
  470. FansNum: signSecTaskReq.FansNum,
  471. TalentId: tid,
  472. AccountId: accountInfo.AccountId,
  473. TalentPlatformInfoSnap: string(accountSnap),
  474. TalentPersonalInfoSnap: string(talentSnap),
  475. //TalentPostAddrSnap: string(addrSnap),
  476. TaskReward: selectionDetail.TaskReward,
  477. TalentPayment: product.ProductPrice,
  478. IsPayPayment: 0,
  479. IsPayReward: 0,
  480. TaskMode: selectionDetail.TaskMode,
  481. //SampleMode: selectionDetail.SampleMode,
  482. SampleMode: 3, //添加橱窗,当作不提供领样处理
  483. TaskStage: 3,
  484. TaskStatus: 1,
  485. CreateDate: gtime.Now(),
  486. CompleteStatus: 1,
  487. LogisticsStatus: 1,
  488. AssignmentStatus: 1,
  489. UpdateAt: gtime.Now(),
  490. WithdrawStatus: 1,
  491. LeadTeamId: signSecTaskReq.LeadTeamId,
  492. TeamId: signSecTaskReq.TeamId,
  493. TeamIncome: 0,
  494. TeamPoint: 0,
  495. SelectionDetail: selectionDetail,
  496. }
  497. //如果已经有数据了,删除。模拟在快手侧里把橱窗商品删了,想再加回来
  498. //删除添加橱窗时创建的不完整的数据
  499. _, err = g.DB().Model("younggee_sec_task_info").
  500. Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
  501. Delete()
  502. if err != nil {
  503. return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
  504. }
  505. err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  506. // 新建任务,初始化状态为待确认
  507. _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
  508. if err != nil {
  509. return err
  510. }
  511. return nil
  512. })
  513. if err != nil {
  514. return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
  515. }
  516. signSecTaskResp := youngee_talent_model.SignSecTaskResp{
  517. TaskId: newTaskId,
  518. }
  519. return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
  520. }