ReBuildData.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Activity\Transformers;
  3. class ReBuildData
  4. {
  5. /**
  6. * 组装活动详情页数据
  7. * @param $param
  8. * @return array
  9. */
  10. public function buildActivityDetail($param)
  11. {
  12. $activity = $param['activity'];
  13. $result = [
  14. 'uid' => $param['uid'],
  15. 'name' => getProp($activity, 'name'),
  16. 'startTime' => getProp($activity, 'start_time'),
  17. 'endTime' => getProp($activity, 'end_time'),
  18. 'from' => $param['from'],
  19. 'activityId' => getProp($activity, 'id'),
  20. 'isForever' => getProp($activity, 'end_time') === '9999-12-30 23:59:59' ? 1 : 0,
  21. 'payChannels' => [
  22. 'ali' => 1,
  23. 'wechat' => 1,
  24. ],
  25. 'products' => $this->buildProducts($param['products'], $param['settingProducts'])
  26. ];
  27. return $result;
  28. }
  29. /**
  30. * @param $products
  31. * @param $settingProducts
  32. * @return array
  33. */
  34. private function buildProducts($products, $settingProducts)
  35. {
  36. if (empty($products) || empty($settingProducts)) {
  37. return [];
  38. }
  39. $result = [];
  40. foreach ($settingProducts as $settingProduct) {
  41. // 获取基本信息
  42. $productId = getProp($settingProduct, 'product_id');
  43. $limit = getProp($settingProduct, 'limit');
  44. // 支付产品信息
  45. $product = collect($products)->firstWhere('id', $productId);
  46. $price = (float)getProp($product, 'price');
  47. $total = $price * 100 + (int)getProp($product, 'given');
  48. $result[] = [
  49. 'product_id' => $productId,
  50. 'limit' => $limit,
  51. 'type' => getProp($product, 'type'),
  52. 'price' => $price,
  53. 'given' => getProp($product, 'given'),
  54. 'total' => $total,
  55. ];
  56. }
  57. return $result;
  58. }
  59. }