ReBuildData.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. 'payChannels' => [
  21. 'ali' => 1,
  22. 'wechat' => 1,
  23. ],
  24. 'products' => $this->buildProducts($param['products'], $param['settingProducts'])
  25. ];
  26. return $result;
  27. }
  28. /**
  29. * @param $products
  30. * @param $settingProducts
  31. * @return array
  32. */
  33. private function buildProducts($products, $settingProducts)
  34. {
  35. if (empty($products) || empty($settingProducts)) {
  36. return [];
  37. }
  38. $result = [];
  39. foreach ($settingProducts as $settingProduct) {
  40. // 获取基本信息
  41. $productId = getProp($settingProduct, 'product_id');
  42. $limit = getProp($settingProduct, 'limit');
  43. // 支付产品信息
  44. $product = collect($products)->firstWhere('id', $productId);
  45. $price = (int)getProp($product, 'price');
  46. $total = $price * 100 + (int)getProp($product, 'given');
  47. $result[] = [
  48. 'product_id' => $productId,
  49. 'limit' => $limit,
  50. 'type' => getProp($product, 'type'),
  51. 'price' => $price,
  52. 'given' => getProp($product, 'given'),
  53. 'total' => $total,
  54. ];
  55. }
  56. return $result;
  57. }
  58. }