OrderRentController.php 3.8 KB

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