selection_info_service.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/sirupsen/logrus"
  6. "reflect"
  7. "strings"
  8. "time"
  9. "youngee_b_api/app/dao"
  10. "youngee_b_api/app/entity"
  11. "youngee_b_api/app/service/review_service"
  12. "youngee_b_api/app/util"
  13. "youngee_b_api/app/vo"
  14. )
  15. type SelectionInfoService struct{}
  16. //func (s *SelectionInfoService) GetSelectionInfo(ctx *gin.Context, selectionId string) (*http_model.SelectionDetail, error) {
  17. // selectionDetail := http_model.SelectionDetail{}
  18. // selectionInfo, err := db.GetSelectionById(ctx, selectionId)
  19. //
  20. // if err != nil {
  21. // logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionInfo error,err:%+v", err)
  22. // return nil, err
  23. // }
  24. // selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
  25. // if err != nil {
  26. // logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionBriefInfo error,err:%+v", err)
  27. // return nil, err
  28. // }
  29. // selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
  30. // if err != nil {
  31. // logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionExampleInfo error,err:%+v", err)
  32. // return nil, err
  33. // }
  34. // productInfo, err := db.GetProductInfoBySelectionId(ctx, selectionId)
  35. // if err != nil {
  36. // logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductInfo error,err:%+v", err)
  37. // return nil, err
  38. // }
  39. // productPhotoInfo, err := db.GetProductPhotoInfoBySelectionId(ctx, selectionId)
  40. // if err != nil {
  41. // logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductPhotoInfo error,err:%+v", err)
  42. // return nil, err
  43. // }
  44. // selectionDetail.SelectionBrief = selectionBriefInfo
  45. // selectionDetail.SelectionInfo = selectionInfo
  46. // selectionDetail.SelectionExample = selectionExampleInfo
  47. // selectionDetail.ProductInfo = productInfo
  48. // selectionDetail.ProductPhotoInfo = productPhotoInfo
  49. // return &selectionDetail, nil
  50. //}
  51. // 创建带货任务
  52. func (s SelectionInfoService) CreateSelectionInfo(param *vo.SelectionInfoCreateParam) (*string, error) {
  53. // a) 生成选品id
  54. selectionId := util.GetSelectionID()
  55. // b) 查找关联商品信息
  56. product, err := dao.ProductDAO{}.GetProductByID(param.ProductId)
  57. if err != nil {
  58. return nil, err
  59. }
  60. if product == nil {
  61. return nil, errors.New("未找到关联商品")
  62. }
  63. productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(param.ProductId)
  64. productInfoToJson, _ := json.Marshal(product)
  65. productPhotosToJson, _ := json.Marshal(productPhotos)
  66. // c) 选品名称
  67. //selectionName := product.ProductName
  68. // d)创建选品
  69. // 获取定时任务配置
  70. infoAutoTask := entity.InfoAutoTask{}
  71. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
  72. t := time.Now()
  73. newSelection := entity.SelectionInfo{
  74. SelectionStatus: 1,
  75. SelectionID: selectionId,
  76. ProductID: param.ProductId,
  77. ProductCategory: product.ProductCategory,
  78. EnterpriseID: param.EnterpriseId,
  79. SubAccountId: param.SubAccountId,
  80. Platform: param.Platform,
  81. ProductSnap: string(productInfoToJson),
  82. ProductPhotoSnap: string(productPhotosToJson),
  83. CreatedAt: t,
  84. UpdatedAt: t,
  85. AutoTaskID: infoAutoTask.AutoTaskID,
  86. }
  87. err = dao.SelectionInfoDAO{}.CreateSelectionInfo(newSelection)
  88. if err != nil {
  89. return nil, err
  90. }
  91. return &selectionId, nil
  92. }
  93. // 更新带货任务(样品奖励、补充信息)
  94. func (s SelectionInfoService) UpdateSelectionInfo(selectionUpdateParam *vo.SelectionInfoUpdateParam) (*string, error) {
  95. // 1. 检查该企业id和商品id有无选品
  96. selectionID := selectionUpdateParam.SelectionID
  97. selectionInfo, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionID)
  98. if err != nil {
  99. return nil, err
  100. }
  101. if selectionInfo == nil {
  102. return nil, errors.New("选品不存在")
  103. }
  104. // 2. 数据准备
  105. // a) 查找关联商品信息
  106. product, err := dao.ProductDAO{}.GetProductByID(selectionInfo.ProductID)
  107. if err != nil {
  108. return nil, err
  109. }
  110. productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(selectionInfo.ProductID)
  111. productInfoToJson, _ := json.Marshal(product)
  112. productPhotosToJson, _ := json.Marshal(productPhotos)
  113. // d) 任务截止时间
  114. taskDdl := time.Time{} //赋零值
  115. taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", selectionUpdateParam.TaskDdl, time.Local)
  116. // f) 更新选品状态
  117. if selectionUpdateParam.SelectionStatus != 2 && selectionUpdateParam.SelectionStatus != 7 {
  118. selectionUpdateParam.SelectionStatus = 1
  119. }
  120. t := time.Now()
  121. var sampleMode, taskMode int64
  122. if len(selectionUpdateParam.FreeStrategys) > 0 {
  123. sampleMode = 1
  124. } else {
  125. sampleMode = 3
  126. }
  127. if len(selectionUpdateParam.RewardStrategys) > 0 {
  128. taskMode = 1
  129. } else {
  130. taskMode = 2
  131. }
  132. updateSelection := entity.SelectionInfo{
  133. SelectionID: selectionUpdateParam.SelectionID,
  134. SelectionStatus: selectionUpdateParam.SelectionStatus,
  135. SelectionName: selectionUpdateParam.SelectionName,
  136. EnterpriseID: selectionUpdateParam.EnterpriseId,
  137. SubAccountId: selectionUpdateParam.SubAccountId,
  138. ProductID: selectionUpdateParam.ProductId,
  139. ProductUrl: selectionUpdateParam.ProductUrl,
  140. TaskMode: taskMode,
  141. SampleMode: sampleMode,
  142. SampleNum: selectionUpdateParam.SampleNum,
  143. RemainNum: selectionUpdateParam.SampleNum,
  144. CommissionRate: selectionUpdateParam.CommissionRate,
  145. TaskReward: selectionUpdateParam.TaskReward,
  146. SettlementAmount: selectionUpdateParam.SettlementAmount,
  147. EstimatedCost: selectionInfo.EstimatedCost,
  148. SampleCondition: selectionUpdateParam.SampleCondition,
  149. RewardCondition: selectionUpdateParam.RewardCondition,
  150. TaskDdl: taskDdl,
  151. Detail: selectionUpdateParam.Detail,
  152. ProductSnap: string(productInfoToJson),
  153. ProductPhotoSnap: string(productPhotosToJson),
  154. CreatedAt: selectionInfo.CreatedAt,
  155. UpdatedAt: t,
  156. }
  157. if selectionUpdateParam.SelectionStatus == 2 {
  158. updateSelection.SubmitAt = t
  159. }
  160. if selectionUpdateParam.Status == 1 {
  161. updateSelection.Status = 1
  162. }
  163. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  164. result := util.MergeStructValue(&updateSelection, selectionInfo)
  165. // 利用反射机制将interface类型转换为结构体类型
  166. v := reflect.ValueOf(&result).Elem()
  167. if v.Kind() == reflect.Struct {
  168. updateSelection = v.Interface().(entity.SelectionInfo)
  169. //fmt.Println(p)
  170. }
  171. // c) 计算预估成本(如果有)
  172. /*
  173. var estimatedCost float64
  174. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  175. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  176. }
  177. estimatedCostToString, _ := conv.String(estimatedCost)
  178. updateSelection.EstimatedCost = estimatedCostToString
  179. */
  180. // 3. 更新选品
  181. err = dao.SelectionInfoDAO{}.UpdateSelectionInfo(updateSelection)
  182. if err != nil {
  183. return nil, err
  184. }
  185. // 4. 更新选品brief和示例(带货任务补充信息)
  186. if selectionUpdateParam.SecBrief != nil {
  187. // 删除已有brief
  188. err = dao.SecBriefDao{}.DeleteSecBriefBySelectionId(selectionInfo.SelectionID)
  189. if err != nil {
  190. return nil, err
  191. }
  192. // 插入新的brief
  193. for _, v := range selectionUpdateParam.SecBrief {
  194. brief := entity.SecBrief{
  195. SelectionID: selectionInfo.SelectionID,
  196. FileUid: v.FileUid,
  197. FileName: v.Name,
  198. FileUrl: v.FileUrl,
  199. CreatedAt: time.Now(),
  200. Type: v.Type,
  201. }
  202. err = dao.SecBriefDao{}.CreateSecBrief(brief)
  203. if err != nil {
  204. return nil, err
  205. }
  206. }
  207. }
  208. if selectionUpdateParam.SecMaterial != nil {
  209. // 删除已有示例
  210. err = dao.SecMaterialDao{}.DeleteSecMaterialBySelectionId(selectionInfo.SelectionID)
  211. if err != nil {
  212. return nil, err
  213. }
  214. // 插入新的示例
  215. for _, v := range selectionUpdateParam.SecMaterial {
  216. secMaterial := entity.SecMaterial{
  217. SelectionID: selectionInfo.SelectionID,
  218. FileUid: v.FileUid,
  219. FileName: v.Name,
  220. FileUrl: v.FileUrl,
  221. CreatedAt: time.Now(),
  222. Type: v.Type,
  223. }
  224. err = dao.SecMaterialDao{}.CreateSecMaterial(secMaterial)
  225. if err != nil {
  226. return nil, err
  227. }
  228. }
  229. }
  230. println("更新带货任务的免费领样策略")
  231. // 更新带货任务的免费领样策略
  232. if selectionUpdateParam.FreeStrategys != nil {
  233. // 1. 删除已有的免费领样策略
  234. err = dao.FreeStrategyDao{}.DeleteFreeStrategyBySelectionId(selectionUpdateParam.SelectionID)
  235. if err != nil {
  236. return nil, err
  237. }
  238. // 2. 接收并创建新的免费领样策略
  239. if sampleMode == 1 {
  240. var frees []entity.FreeStrategy
  241. for _, v := range selectionUpdateParam.FreeStrategys {
  242. free := entity.FreeStrategy{
  243. SelectionId: selectionInfo.SelectionID,
  244. StrategyId: v.StrategyId,
  245. FansNum: v.FansNum,
  246. SaleNum: v.SaleNum,
  247. StrategyStatus: 1,
  248. EnrollNum: 0,
  249. ChooseNum: 0,
  250. }
  251. frees = append(frees, free)
  252. }
  253. err = dao.FreeStrategyDao{}.CreateFreeStrategy(frees)
  254. if err != nil {
  255. return nil, err
  256. }
  257. }
  258. }
  259. println("更新带货任务的悬赏策略")
  260. // 更新带货任务的悬赏策略
  261. if selectionUpdateParam.RewardStrategys != nil {
  262. // 1. 删除已有的悬赏策略
  263. err = dao.RewardStrategyDao{}.DeleteRewardStrategyBySelectionId(selectionUpdateParam.SelectionID)
  264. if err != nil {
  265. return nil, err
  266. }
  267. if taskMode == 1 {
  268. var rewards []entity.RewardStrategy
  269. for _, v := range selectionUpdateParam.RewardStrategys {
  270. reward := entity.RewardStrategy{
  271. SelectionId: selectionInfo.SelectionID,
  272. Reward: v.Reward,
  273. SaleActual: v.SaleActual,
  274. PerReward: v.PerReward,
  275. StrategyStatus: 1,
  276. }
  277. rewards = append(rewards, reward)
  278. }
  279. err = dao.RewardStrategyDao{}.CreateRewardStrategy(rewards)
  280. if err != nil {
  281. return nil, err
  282. }
  283. }
  284. }
  285. return &updateSelection.SelectionID, nil
  286. }
  287. // 电商带货任务预览
  288. func (s SelectionInfoService) GetSelectionDetail(selectionId string) (*vo.ReSelectionDetail, error) {
  289. reSelectionDetail := vo.ReSelectionDetail{}
  290. selection, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  291. if err != nil {
  292. logrus.Errorf("[selectionInfoDB service] call GetSelection error,err:%+v", err)
  293. return nil, err
  294. }
  295. reSelectionDetail.SelectionName = selection.SelectionName
  296. // 系统信息
  297. reSelectionDetail.SelectionId = selectionId
  298. reSelectionDetail.SelectionStatus = selection.SelectionStatus
  299. reSelectionDetail.SelectionPlatform = selection.Platform
  300. reSelectionDetail.CreatedAt = selection.CreatedAt.Format("2006-01-02 15:04:05")
  301. reSelectionDetail.SubmitAt = selection.SubmitAt.Format("2006-01-02 15:04:05")
  302. var creatorName, phone string
  303. var rewardSum float64
  304. if selection.SubAccountId == 0 {
  305. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(selection.EnterpriseID)
  306. if err == nil && enterprise != nil {
  307. creatorName = enterprise.BusinessName
  308. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  309. }
  310. } else {
  311. subAccount, err := dao.SubAccountDao{}.GetSubAccount(selection.SubAccountId)
  312. if err == nil && subAccount != nil {
  313. creatorName = subAccount.SubAccountName
  314. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  315. }
  316. }
  317. reSelectionDetail.CreatorName = creatorName
  318. reSelectionDetail.Phone = phone
  319. // 关联商品
  320. var reProduct vo.ReProductPreview
  321. product, err := dao.ProductDAO{}.GetProductByID(selection.ProductID)
  322. if err == nil {
  323. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(product.ProductID)
  324. if e != nil {
  325. photoUrl = ""
  326. }
  327. reProduct = vo.ReProductPreview{
  328. ProductID: product.ProductID,
  329. ProductName: product.ProductName,
  330. ProductType: product.ProductType,
  331. ProductCategory: product.ProductCategory,
  332. ProductPrice: product.ProductPrice,
  333. ProductDetail: product.ProductDetail,
  334. CreatedAt: product.CreatedAt.Format("2006-01-02 15:04:05"),
  335. PhotoUrl: photoUrl,
  336. }
  337. }
  338. reSelectionDetail.ProductInfo = &reProduct
  339. // 样品奖励
  340. reSelectionDetail.TaskDdl = selection.TaskDdl.Format("2006-01-02 15:04:05")
  341. reSelectionDetail.SampleNum = selection.SampleNum
  342. var freeStrategyPreviews []*vo.FreeStrategyPreview // 领样策略
  343. freeStrategys, err := dao.FreeStrategyDao{}.GetFreeStrategyBySelectionId(selectionId)
  344. if err != nil {
  345. logrus.Errorf("[selectionInfoDB service] call GetFreeStrategy error,err:%+v", err)
  346. return nil, err
  347. }
  348. for _, freeStrategy := range freeStrategys {
  349. freeStrategyPreview := &vo.FreeStrategyPreview{
  350. StrategyId: freeStrategy.StrategyId,
  351. FansNum: freeStrategy.FansNum,
  352. SaleNum: freeStrategy.SaleNum,
  353. StrategyStatus: freeStrategy.StrategyStatus,
  354. }
  355. freeStrategyPreviews = append(freeStrategyPreviews, freeStrategyPreview)
  356. }
  357. reSelectionDetail.FreeStrategys = freeStrategyPreviews
  358. var rewardStrategyPreviews []*vo.RewardStrategyPreview // 悬赏策略
  359. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(selectionId)
  360. if err != nil {
  361. logrus.Errorf("[selectionInfoDB service] call GetRewardStrategy error,err:%+v", err)
  362. return nil, err
  363. }
  364. for _, rewardStrategy := range rewardStrategys {
  365. rewardStrategyPreview := &vo.RewardStrategyPreview{
  366. Reward: rewardStrategy.Reward,
  367. SaleActual: rewardStrategy.SaleActual,
  368. PerReward: rewardStrategy.PerReward,
  369. StrategyStatus: rewardStrategy.StrategyStatus,
  370. }
  371. rewardStrategyPreviews = append(rewardStrategyPreviews, rewardStrategyPreview)
  372. }
  373. reSelectionDetail.FreeStrategys = freeStrategyPreviews
  374. reSelectionDetail.RewardStrategys = rewardStrategyPreviews
  375. for _, rewardStrategy := range rewardStrategys {
  376. rewardSum += rewardStrategy.Reward
  377. }
  378. reSelectionDetail.RewardSum = rewardSum
  379. // 补充信息
  380. selectionBriefInfos, err := dao.SecBriefDao{}.GetSelectionBriefInfo(selectionId)
  381. if err != nil {
  382. logrus.Errorf("[selectionInfoDB service] call GetSelectionBriefInfo error,err:%+v", err)
  383. return nil, err
  384. }
  385. selectionMaterials, err := dao.SecMaterialDao{}.GetSelectionMaterialInfo(selectionId)
  386. if err != nil {
  387. logrus.Errorf("[selectionInfoDB service] call GetSelectionMaterialInfo error,err:%+v", err)
  388. return nil, err
  389. }
  390. reSelectionDetail.SelectionBriefs = selectionBriefInfos
  391. reSelectionDetail.SelectionMaterials = selectionMaterials
  392. return &reSelectionDetail, nil
  393. }
  394. // 电商带货提交审核
  395. func (s SelectionInfoService) SelectionToReview(param *vo.SelectionInfoUpdateParam) (*string, error) {
  396. selectionId := param.SelectionID
  397. selection, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  398. if err != nil {
  399. logrus.Errorf("[selectionInfoDB service] call GetSelection error,err:%+v", err)
  400. return nil, err
  401. }
  402. selectionName := selection.SelectionName // 任务标题
  403. product, err := dao.ProductDAO{}.GetProductByID(selection.ProductID)
  404. if err != nil {
  405. return nil, err
  406. }
  407. productName := product.ProductName // 商品标题
  408. productDetail := product.ProductDetail // 卖点总结
  409. mainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(selection.ProductID)
  410. if err1 != nil {
  411. return nil, err1
  412. }
  413. var images []string
  414. var videos []string
  415. var videoJobIds []string
  416. var documents []string
  417. var documentJobIds []string
  418. reviewService := review_service.GetConfig()
  419. productPhotos, err2 := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(selection.ProductID)
  420. if err2 != nil {
  421. return nil, err2
  422. }
  423. for _, productPhoto := range productPhotos {
  424. if productPhoto.Symbol == 2 || productPhoto.Symbol == 4 {
  425. images = append(images, productPhoto.PhotoUrl)
  426. } else if productPhoto.Symbol == 3 || productPhoto.Symbol == 5 {
  427. var videoJobId *string
  428. var reviewErr error
  429. i := 10
  430. for {
  431. videoJobId, reviewErr = reviewService.CheckVideo(productPhoto.PhotoUrl)
  432. if reviewErr == nil || i == 0 {
  433. break
  434. }
  435. i -= 1
  436. }
  437. if reviewErr != nil {
  438. return nil, reviewErr
  439. }
  440. videos = append(videos, productPhoto.PhotoUrl)
  441. videoJobIds = append(videoJobIds, *videoJobId)
  442. }
  443. }
  444. selectionBriefInfos, err := dao.SecBriefDao{}.GetSelectionBriefInfo(selectionId)
  445. if err != nil {
  446. return nil, err
  447. }
  448. for _, selectionBriefInfo := range selectionBriefInfos {
  449. if selectionBriefInfo.Type == 1 {
  450. images = append(images, selectionBriefInfo.FileUrl)
  451. } else if selectionBriefInfo.Type == 2 {
  452. var documentJobId *string
  453. var reviewErr error
  454. i := 10
  455. fileType := "pdf"
  456. parts := strings.Split(selectionBriefInfo.FileName, ".")
  457. if len(parts) > 1 {
  458. fileType = parts[len(parts)-1]
  459. }
  460. for {
  461. documentJobId, reviewErr = reviewService.CheckDocument(selectionBriefInfo.FileUrl, fileType)
  462. if reviewErr == nil || i == 0 {
  463. break
  464. }
  465. i -= 1
  466. }
  467. if reviewErr != nil {
  468. return nil, reviewErr
  469. }
  470. documents = append(documents, selectionBriefInfo.FileUrl)
  471. documentJobIds = append(documentJobIds, *documentJobId)
  472. }
  473. }
  474. selectionMaterials, err := dao.SecMaterialDao{}.GetSelectionMaterialInfo(selectionId)
  475. if err != nil {
  476. return nil, err
  477. }
  478. for _, selectionMaterial := range selectionMaterials {
  479. if selectionMaterial.Type == 1 {
  480. images = append(images, selectionMaterial.FileUrl)
  481. } else if selectionMaterial.Type == 2 {
  482. var videoJobId *string
  483. var reviewErr error
  484. i := 10
  485. for {
  486. videoJobId, reviewErr = reviewService.CheckVideo(selectionMaterial.FileUrl)
  487. if reviewErr == nil || i == 0 {
  488. break
  489. }
  490. i -= 1
  491. }
  492. if reviewErr != nil {
  493. return nil, reviewErr
  494. }
  495. videos = append(videos, selectionMaterial.FileUrl)
  496. videoJobIds = append(videoJobIds, *videoJobId)
  497. }
  498. }
  499. newReviewSelection := &entity.ReviewSelection{
  500. SelectionID: selectionId,
  501. TaskName: selectionName,
  502. ProductName: productName,
  503. ProductDetail: productDetail,
  504. MainPhoto: mainPhoto,
  505. Images: strings.Join(images, ","),
  506. Videos: strings.Join(videos, ","),
  507. Documents: strings.Join(documents, ","),
  508. VideoJobIds: strings.Join(videoJobIds, ","),
  509. DocumentJobIds: strings.Join(documentJobIds, ","),
  510. Status: 1,
  511. }
  512. err5 := dao.SelectionReviewDao{}.Create(newReviewSelection)
  513. if err5 != nil {
  514. return nil, err5
  515. }
  516. t := time.Now()
  517. updateSelection := entity.SelectionInfo{
  518. SelectionID: selectionId,
  519. SelectionStatus: 2,
  520. UpdatedAt: t,
  521. }
  522. err6 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(updateSelection)
  523. if err6 != nil {
  524. return nil, err
  525. }
  526. return &selectionId, nil
  527. }
  528. // 电商带货任务列表
  529. func (s SelectionInfoService) GetSelectionTaskList(param *vo.SelectionSearchParam) (vo.ResultVO, error) {
  530. if param.Page == 0 {
  531. param.Page = 1
  532. }
  533. if param.PageSize == 0 {
  534. param.PageSize = 10
  535. }
  536. var result vo.ResultVO
  537. reSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetSelectionPreviews(param)
  538. if err != nil {
  539. return result, err
  540. }
  541. for i := range reSelectionTaskPreviews {
  542. var creatorName string
  543. var productName string
  544. var productPrice float64
  545. var mainImage string
  546. var reward float64
  547. if reSelectionTaskPreviews[i].SubAccountId == 0 {
  548. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reSelectionTaskPreviews[i].EnterpriseId)
  549. if err == nil && enterprise != nil {
  550. creatorName = enterprise.BusinessName
  551. }
  552. } else {
  553. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reSelectionTaskPreviews[i].SubAccountId)
  554. if err == nil && subAccount != nil {
  555. creatorName = subAccount.SubAccountName
  556. }
  557. }
  558. product, err := dao.ProductDAO{}.GetProductByID(reSelectionTaskPreviews[i].ProductId)
  559. if err == nil && product != nil {
  560. productName = product.ProductName
  561. productPrice = product.ProductPrice
  562. }
  563. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reSelectionTaskPreviews[i].ProductId)
  564. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(reSelectionTaskPreviews[i].SelectionId)
  565. for _, rewardStrategy := range rewardStrategys {
  566. reward += rewardStrategy.Reward
  567. }
  568. reSelectionTaskPreviews[i].CreatorName = creatorName
  569. reSelectionTaskPreviews[i].ProductName = productName
  570. reSelectionTaskPreviews[i].ProductPrice = productPrice
  571. reSelectionTaskPreviews[i].MainImage = mainImage
  572. reSelectionTaskPreviews[i].Reward = reward
  573. }
  574. result = vo.ResultVO{
  575. Page: param.Page,
  576. PageSize: param.PageSize,
  577. Total: total,
  578. Data: reSelectionTaskPreviews,
  579. }
  580. return result, nil
  581. }
  582. // 删除带货任务
  583. func (s SelectionInfoService) DeleteSelection(selectionId string) (*string, error) {
  584. res, err := dao.SelectionInfoDAO{}.DeleteSelection(selectionId)
  585. if err != nil {
  586. logrus.Errorf("[projectDB service] call DeleteSelection error,err:%+v", err)
  587. return res, err
  588. }
  589. return res, nil
  590. }
  591. // 草稿箱——电商带货
  592. func (s SelectionInfoService) GetSelectionDraftList(param *vo.SelectionDraftParam) (vo.ResultVO, error) {
  593. if param.Page == 0 {
  594. param.Page = 1
  595. }
  596. if param.PageSize == 0 {
  597. param.PageSize = 10
  598. }
  599. var result vo.ResultVO
  600. reSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetSelectionDraftList(param)
  601. if err != nil {
  602. return result, err
  603. }
  604. for i := range reSelectionTaskPreviews {
  605. var creatorName string
  606. var productName string
  607. var productPrice float64
  608. var mainImage string
  609. if reSelectionTaskPreviews[i].SubAccountId == 0 {
  610. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reSelectionTaskPreviews[i].EnterpriseId)
  611. if err == nil && enterprise != nil {
  612. creatorName = enterprise.BusinessName
  613. }
  614. } else {
  615. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reSelectionTaskPreviews[i].SubAccountId)
  616. if err == nil && subAccount != nil {
  617. creatorName = subAccount.SubAccountName
  618. }
  619. }
  620. product, err := dao.ProductDAO{}.GetProductByID(reSelectionTaskPreviews[i].ProductId)
  621. if err == nil && product != nil {
  622. productName = product.ProductName
  623. productPrice = product.ProductPrice
  624. }
  625. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reSelectionTaskPreviews[i].ProductId)
  626. reSelectionTaskPreviews[i].CreatorName = creatorName
  627. reSelectionTaskPreviews[i].ProductName = productName
  628. reSelectionTaskPreviews[i].ProductPrice = productPrice
  629. reSelectionTaskPreviews[i].MainImage = mainImage
  630. }
  631. result = vo.ResultVO{
  632. Page: param.Page,
  633. PageSize: param.PageSize,
  634. Total: total,
  635. Data: reSelectionTaskPreviews,
  636. }
  637. return result, nil
  638. }