selection_info_service.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. FollowersLow: v.FollowersLow,
  246. FollowersUp: v.FollowersUp,
  247. SaleNum: v.SaleNum,
  248. StrategyStatus: 1,
  249. EnrollNum: 0,
  250. ChooseNum: 0,
  251. }
  252. frees = append(frees, free)
  253. }
  254. err = dao.FreeStrategyDao{}.CreateFreeStrategy(frees)
  255. if err != nil {
  256. return nil, err
  257. }
  258. }
  259. }
  260. println("更新带货任务的悬赏策略")
  261. // 更新带货任务的悬赏策略
  262. if selectionUpdateParam.RewardStrategys != nil {
  263. // 1. 删除已有的悬赏策略
  264. err = dao.RewardStrategyDao{}.DeleteRewardStrategyBySelectionId(selectionUpdateParam.SelectionID)
  265. if err != nil {
  266. return nil, err
  267. }
  268. if taskMode == 1 {
  269. var rewards []entity.RewardStrategy
  270. for _, v := range selectionUpdateParam.RewardStrategys {
  271. reward := entity.RewardStrategy{
  272. SelectionId: selectionInfo.SelectionID,
  273. Reward: v.Reward,
  274. SaleActual: v.SaleActual,
  275. PerReward: v.PerReward,
  276. StrategyStatus: 1,
  277. }
  278. rewards = append(rewards, reward)
  279. }
  280. err = dao.RewardStrategyDao{}.CreateRewardStrategy(rewards)
  281. if err != nil {
  282. return nil, err
  283. }
  284. }
  285. }
  286. return &updateSelection.SelectionID, nil
  287. }
  288. // 电商带货任务预览
  289. func (s SelectionInfoService) GetSelectionDetail(selectionId string) (*vo.ReSelectionDetail, error) {
  290. reSelectionDetail := vo.ReSelectionDetail{}
  291. selection, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  292. if err != nil {
  293. logrus.Errorf("[selectionInfoDB service] call GetSelection error,err:%+v", err)
  294. return nil, err
  295. }
  296. reSelectionDetail.SelectionName = selection.SelectionName
  297. // 系统信息
  298. reSelectionDetail.SelectionId = selectionId
  299. reSelectionDetail.SelectionStatus = selection.SelectionStatus
  300. reSelectionDetail.SelectionPlatform = selection.Platform
  301. reSelectionDetail.CreatedAt = selection.CreatedAt.Format("2006-01-02 15:04:05")
  302. reSelectionDetail.SubmitAt = selection.SubmitAt.Format("2006-01-02 15:04:05")
  303. var creatorName, phone string
  304. var rewardSum float64
  305. if selection.SubAccountId == 0 {
  306. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(selection.EnterpriseID)
  307. if err == nil && enterprise != nil {
  308. creatorName = enterprise.BusinessName
  309. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  310. }
  311. } else {
  312. subAccount, err := dao.SubAccountDao{}.GetSubAccount(selection.SubAccountId)
  313. if err == nil && subAccount != nil {
  314. creatorName = subAccount.SubAccountName
  315. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  316. }
  317. }
  318. reSelectionDetail.CreatorName = creatorName
  319. reSelectionDetail.Phone = phone
  320. // 关联商品
  321. var reProduct vo.ReProductPreview
  322. product, err := dao.ProductDAO{}.GetProductByID(selection.ProductID)
  323. if err == nil {
  324. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(product.ProductID)
  325. if e != nil {
  326. photoUrl = ""
  327. }
  328. reProduct = vo.ReProductPreview{
  329. ProductID: product.ProductID,
  330. ProductName: product.ProductName,
  331. ProductType: product.ProductType,
  332. ProductCategory: product.ProductCategory,
  333. ProductPrice: product.ProductPrice,
  334. ProductDetail: product.ProductDetail,
  335. CreatedAt: product.CreatedAt.Format("2006-01-02 15:04:05"),
  336. PhotoUrl: photoUrl,
  337. }
  338. }
  339. reSelectionDetail.ProductInfo = &reProduct
  340. // 样品奖励
  341. reSelectionDetail.TaskDdl = selection.TaskDdl.Format("2006-01-02 15:04:05")
  342. reSelectionDetail.SampleNum = selection.SampleNum
  343. var freeStrategyPreviews []*vo.FreeStrategyPreview // 领样策略
  344. freeStrategys, err := dao.FreeStrategyDao{}.GetFreeStrategyBySelectionId(selectionId)
  345. if err != nil {
  346. logrus.Errorf("[selectionInfoDB service] call GetFreeStrategy error,err:%+v", err)
  347. return nil, err
  348. }
  349. for _, freeStrategy := range freeStrategys {
  350. freeStrategyPreview := &vo.FreeStrategyPreview{
  351. StrategyId: freeStrategy.StrategyId,
  352. FollowersLow: freeStrategy.FollowersLow,
  353. FollowersUp: freeStrategy.FollowersUp,
  354. SaleNum: freeStrategy.SaleNum,
  355. StrategyStatus: freeStrategy.StrategyStatus,
  356. }
  357. freeStrategyPreviews = append(freeStrategyPreviews, freeStrategyPreview)
  358. }
  359. reSelectionDetail.FreeStrategys = freeStrategyPreviews
  360. var rewardStrategyPreviews []*vo.RewardStrategyPreview // 悬赏策略
  361. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(selectionId)
  362. if err != nil {
  363. logrus.Errorf("[selectionInfoDB service] call GetRewardStrategy error,err:%+v", err)
  364. return nil, err
  365. }
  366. for _, rewardStrategy := range rewardStrategys {
  367. rewardStrategyPreview := &vo.RewardStrategyPreview{
  368. Reward: rewardStrategy.Reward,
  369. SaleActual: rewardStrategy.SaleActual,
  370. PerReward: rewardStrategy.PerReward,
  371. StrategyStatus: rewardStrategy.StrategyStatus,
  372. }
  373. rewardStrategyPreviews = append(rewardStrategyPreviews, rewardStrategyPreview)
  374. }
  375. reSelectionDetail.FreeStrategys = freeStrategyPreviews
  376. reSelectionDetail.RewardStrategys = rewardStrategyPreviews
  377. for _, rewardStrategy := range rewardStrategys {
  378. rewardSum += rewardStrategy.Reward
  379. }
  380. reSelectionDetail.RewardSum = rewardSum
  381. // 补充信息
  382. selectionBriefInfos, err := dao.SecBriefDao{}.GetSelectionBriefInfo(selectionId)
  383. if err != nil {
  384. logrus.Errorf("[selectionInfoDB service] call GetSelectionBriefInfo error,err:%+v", err)
  385. return nil, err
  386. }
  387. selectionMaterials, err := dao.SecMaterialDao{}.GetSelectionMaterialInfo(selectionId)
  388. if err != nil {
  389. logrus.Errorf("[selectionInfoDB service] call GetSelectionMaterialInfo error,err:%+v", err)
  390. return nil, err
  391. }
  392. reSelectionDetail.SelectionBriefs = selectionBriefInfos
  393. reSelectionDetail.SelectionMaterials = selectionMaterials
  394. return &reSelectionDetail, nil
  395. }
  396. // 电商带货提交审核
  397. func (s SelectionInfoService) SelectionToReview(param *vo.SelectionInfoUpdateParam) (*string, error) {
  398. selectionId := param.SelectionID
  399. selection, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId)
  400. if err != nil {
  401. logrus.Errorf("[selectionInfoDB service] call GetSelection error,err:%+v", err)
  402. return nil, err
  403. }
  404. selectionName := selection.SelectionName // 任务标题
  405. product, err := dao.ProductDAO{}.GetProductByID(selection.ProductID)
  406. if err != nil {
  407. return nil, err
  408. }
  409. productName := product.ProductName // 商品标题
  410. productDetail := product.ProductDetail // 卖点总结
  411. mainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(selection.ProductID)
  412. if err1 != nil {
  413. return nil, err1
  414. }
  415. var images []string
  416. var videos []string
  417. var videoJobIds []string
  418. var documents []string
  419. var documentJobIds []string
  420. reviewService := review_service.GetConfig()
  421. productPhotos, err2 := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(selection.ProductID)
  422. if err2 != nil {
  423. return nil, err2
  424. }
  425. for _, productPhoto := range productPhotos {
  426. if productPhoto.Symbol == 2 || productPhoto.Symbol == 4 {
  427. images = append(images, productPhoto.PhotoUrl)
  428. } else if productPhoto.Symbol == 3 || productPhoto.Symbol == 5 {
  429. var videoJobId *string
  430. var reviewErr error
  431. i := 10
  432. for {
  433. videoJobId, reviewErr = reviewService.CheckVideo(productPhoto.PhotoUrl)
  434. if reviewErr == nil || i == 0 {
  435. break
  436. }
  437. i -= 1
  438. }
  439. if reviewErr != nil {
  440. return nil, reviewErr
  441. }
  442. videos = append(videos, productPhoto.PhotoUrl)
  443. videoJobIds = append(videoJobIds, *videoJobId)
  444. }
  445. }
  446. selectionBriefInfos, err := dao.SecBriefDao{}.GetSelectionBriefInfo(selectionId)
  447. if err != nil {
  448. return nil, err
  449. }
  450. for _, selectionBriefInfo := range selectionBriefInfos {
  451. if selectionBriefInfo.Type == 1 {
  452. images = append(images, selectionBriefInfo.FileUrl)
  453. } else if selectionBriefInfo.Type == 2 {
  454. var documentJobId *string
  455. var reviewErr error
  456. i := 10
  457. fileType := "pdf"
  458. parts := strings.Split(selectionBriefInfo.FileName, ".")
  459. if len(parts) > 1 {
  460. fileType = parts[len(parts)-1]
  461. }
  462. for {
  463. documentJobId, reviewErr = reviewService.CheckDocument(selectionBriefInfo.FileUrl, fileType)
  464. if reviewErr == nil || i == 0 {
  465. break
  466. }
  467. i -= 1
  468. }
  469. if reviewErr != nil {
  470. return nil, reviewErr
  471. }
  472. documents = append(documents, selectionBriefInfo.FileUrl)
  473. documentJobIds = append(documentJobIds, *documentJobId)
  474. }
  475. }
  476. selectionMaterials, err := dao.SecMaterialDao{}.GetSelectionMaterialInfo(selectionId)
  477. if err != nil {
  478. return nil, err
  479. }
  480. for _, selectionMaterial := range selectionMaterials {
  481. if selectionMaterial.Type == 1 {
  482. images = append(images, selectionMaterial.FileUrl)
  483. } else if selectionMaterial.Type == 2 {
  484. var videoJobId *string
  485. var reviewErr error
  486. i := 10
  487. for {
  488. videoJobId, reviewErr = reviewService.CheckVideo(selectionMaterial.FileUrl)
  489. if reviewErr == nil || i == 0 {
  490. break
  491. }
  492. i -= 1
  493. }
  494. if reviewErr != nil {
  495. return nil, reviewErr
  496. }
  497. videos = append(videos, selectionMaterial.FileUrl)
  498. videoJobIds = append(videoJobIds, *videoJobId)
  499. }
  500. }
  501. newReviewSelection := &entity.ReviewSelection{
  502. SelectionID: selectionId,
  503. TaskName: selectionName,
  504. ProductName: productName,
  505. ProductDetail: productDetail,
  506. MainPhoto: mainPhoto,
  507. Images: strings.Join(images, ","),
  508. Videos: strings.Join(videos, ","),
  509. Documents: strings.Join(documents, ","),
  510. VideoJobIds: strings.Join(videoJobIds, ","),
  511. DocumentJobIds: strings.Join(documentJobIds, ","),
  512. Status: 1,
  513. }
  514. err5 := dao.SelectionReviewDao{}.Create(newReviewSelection)
  515. if err5 != nil {
  516. return nil, err5
  517. }
  518. t := time.Now()
  519. updateSelection := entity.SelectionInfo{
  520. SelectionID: selectionId,
  521. SelectionStatus: 2,
  522. UpdatedAt: t,
  523. }
  524. err6 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(updateSelection)
  525. if err6 != nil {
  526. return nil, err
  527. }
  528. return &selectionId, nil
  529. }
  530. // 电商带货任务列表
  531. func (s SelectionInfoService) GetSelectionTaskList(param *vo.SelectionSearchParam) (vo.ResultVO, error) {
  532. if param.Page == 0 {
  533. param.Page = 1
  534. }
  535. if param.PageSize == 0 {
  536. param.PageSize = 10
  537. }
  538. var result vo.ResultVO
  539. reSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetSelectionPreviews(param)
  540. if err != nil {
  541. return result, err
  542. }
  543. for i := range reSelectionTaskPreviews {
  544. var creatorName string
  545. var productName string
  546. var productPrice float64
  547. var mainImage string
  548. var reward float64
  549. if reSelectionTaskPreviews[i].SubAccountId == 0 {
  550. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reSelectionTaskPreviews[i].EnterpriseId)
  551. if err == nil && enterprise != nil {
  552. creatorName = enterprise.BusinessName
  553. }
  554. } else {
  555. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reSelectionTaskPreviews[i].SubAccountId)
  556. if err == nil && subAccount != nil {
  557. creatorName = subAccount.SubAccountName
  558. }
  559. }
  560. product, err := dao.ProductDAO{}.GetProductByID(reSelectionTaskPreviews[i].ProductId)
  561. if err == nil && product != nil {
  562. productName = product.ProductName
  563. productPrice = product.ProductPrice
  564. }
  565. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reSelectionTaskPreviews[i].ProductId)
  566. rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(reSelectionTaskPreviews[i].SelectionId)
  567. for _, rewardStrategy := range rewardStrategys {
  568. reward += rewardStrategy.Reward
  569. }
  570. reSelectionTaskPreviews[i].CreatorName = creatorName
  571. reSelectionTaskPreviews[i].ProductName = productName
  572. reSelectionTaskPreviews[i].ProductPrice = productPrice
  573. reSelectionTaskPreviews[i].MainImage = mainImage
  574. reSelectionTaskPreviews[i].Reward = reward
  575. }
  576. result = vo.ResultVO{
  577. Page: param.Page,
  578. PageSize: param.PageSize,
  579. Total: total,
  580. Data: reSelectionTaskPreviews,
  581. }
  582. return result, nil
  583. }
  584. // 删除带货任务
  585. func (s SelectionInfoService) DeleteSelection(selectionId string) (*string, error) {
  586. res, err := dao.SelectionInfoDAO{}.DeleteSelection(selectionId)
  587. if err != nil {
  588. logrus.Errorf("[projectDB service] call DeleteSelection error,err:%+v", err)
  589. return res, err
  590. }
  591. return res, nil
  592. }
  593. // 草稿箱——电商带货
  594. func (s SelectionInfoService) GetSelectionDraftList(param *vo.SelectionDraftParam) (vo.ResultVO, error) {
  595. if param.Page == 0 {
  596. param.Page = 1
  597. }
  598. if param.PageSize == 0 {
  599. param.PageSize = 10
  600. }
  601. var result vo.ResultVO
  602. reSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetSelectionDraftList(param)
  603. if err != nil {
  604. return result, err
  605. }
  606. for i := range reSelectionTaskPreviews {
  607. var creatorName string
  608. var productName string
  609. var productPrice float64
  610. var mainImage string
  611. if reSelectionTaskPreviews[i].SubAccountId == 0 {
  612. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reSelectionTaskPreviews[i].EnterpriseId)
  613. if err == nil && enterprise != nil {
  614. creatorName = enterprise.BusinessName
  615. }
  616. } else {
  617. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reSelectionTaskPreviews[i].SubAccountId)
  618. if err == nil && subAccount != nil {
  619. creatorName = subAccount.SubAccountName
  620. }
  621. }
  622. product, err := dao.ProductDAO{}.GetProductByID(reSelectionTaskPreviews[i].ProductId)
  623. if err == nil && product != nil {
  624. productName = product.ProductName
  625. productPrice = product.ProductPrice
  626. }
  627. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reSelectionTaskPreviews[i].ProductId)
  628. reSelectionTaskPreviews[i].CreatorName = creatorName
  629. reSelectionTaskPreviews[i].ProductName = productName
  630. reSelectionTaskPreviews[i].ProductPrice = productPrice
  631. reSelectionTaskPreviews[i].MainImage = mainImage
  632. }
  633. result = vo.ResultVO{
  634. Page: param.Page,
  635. PageSize: param.PageSize,
  636. Total: total,
  637. Data: reSelectionTaskPreviews,
  638. }
  639. return result, nil
  640. }