OrderRentController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\App;
  3. use App\Filters\OrderRentFilter;
  4. use App\Http\Resources\App\OrderRentResource;
  5. use App\Models\LocationsLog;
  6. use App\Models\OrderRent;
  7. use Illuminate\Http\Request;
  8. use App\Http\Controllers\Controller;
  9. class OrderRentController extends AppBaseController
  10. {
  11. //
  12. /**
  13. * 日租订单列表
  14. * */
  15. public function orderRentList(OrderRentFilter $filter)
  16. {
  17. $area_ids = self::$areaIds;
  18. $order = OrderRent::query()
  19. ->whereIn('area_id', $area_ids)
  20. ->filter($filter)
  21. ->where('status', '!=', OrderRent::STATUS_CLOSE_ORDER)
  22. ->with('users')
  23. ->orderByDesc('id')
  24. ->paginate();
  25. return $this->ok(OrderRentResource::collection($order));
  26. }
  27. /**
  28. * 日租订单详情
  29. * */
  30. public function orderRentDetail(Request $request)
  31. {
  32. $order_id = $request->get('order_id') ?? '';
  33. if (empty($order_id)) return $this->error('参数错误');
  34. $order = OrderRent::query()->find($order_id);
  35. if (empty($order)) return $this->error('找不到该订单,参数错误');
  36. $orderLocations = [];
  37. $wx_orderLocations = [];
  38. // 订单轨迹
  39. $locationsLog = LocationsLog::where('order_id', (int)$order_id)->where('is_rent', LocationsLog::RENT_YES)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderBy('created_at', 'asc')->get();
  40. if (!empty($locationsLog)) {
  41. foreach ($locationsLog as $vv) {
  42. $orderLocations[] = [$vv->longitude, $vv->latitude];
  43. $wx_orderLocations[] = ['longitude' => $vv->longitude, 'latitude' => $vv->latitude];
  44. }
  45. }
  46. // Log::info($orderLocations);
  47. $data = [
  48. 'order_status' => OrderRent::$statusMaps[$order->status],
  49. 'start_use_bike_time' => date('Y-m-d H:i:s', strtotime($order->start_use_bike_time)),
  50. 'end_use_bike_time' => $order->end_use_bike_time ? date('Y-m-d H:i:s', strtotime($order->end_use_bike_time)) : '',
  51. 'pay_money' => $order->pay_money,
  52. 'time_money' => $order->time_money,
  53. 'dispatch_money' => $order->dispatch_money,
  54. 'bike_no' => $order->bike_no,
  55. 'bike_id' => $order->bike_id,
  56. 'user_id' => $order->user_id,
  57. 'nickname' => $order->users->nickname ?? '',
  58. 'mobile' => $order->users->mobile ?? '',
  59. 'orderLocations' => $orderLocations,
  60. 'start_location' => empty($orderLocations) ? [] : current($orderLocations),
  61. 'end_location' => empty($orderLocations) ? [] : end($orderLocations),
  62. 'wx_orderLocations' => $wx_orderLocations,
  63. 'wx_start_location' => empty($wx_orderLocations) ? [] : current($wx_orderLocations),
  64. 'wx_end_location' => empty($wx_orderLocations) ? [] : end($wx_orderLocations),
  65. //'center_location' => GetCenterFromDegrees([['lat'=>$orderLocations[0][1],'lng'=>$orderLocations[0][0]],['lat'=>end($orderLocations)[1],'lng'=>end($orderLocations)[0]]])
  66. ];
  67. return $this->ok($data);
  68. }
  69. }