1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Http\Resources;
- use App\Models\OrderRent;
- use Carbon\Carbon;
- use Illuminate\Http\Resources\Json\JsonResource;
- class OrderRentResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- public function toArray($request)
- {
- $model = $this->resource;
- $now = Carbon::now();
- $carbon_start_use_bike_time = Carbon::parse($model->start_use_bike_time);
- $real_use_bike_time_length = 0;
- switch ($model->status){
- case OrderRent::STATUS_RENT_BIKE: // 租车中
- $real_use_bike_time_length = $now->diffInMinutes($carbon_start_use_bike_time);
- break;
- case OrderRent::STATUS_COMPLETE_ORDER: // 订单完成
- case OrderRent::STATUS_CLOSE_RENT_BIKE: // 待支付
- $real_use_bike_time_length = $model->use_bike_time_length;
- break;
- default :
- $real_use_bike_time_length = 0;
- }
- $real_use_bike_time_length_time = $real_use_bike_time_length;
- if ($real_use_bike_time_length > 60) {
- $real_use_bike_time_length = floor($real_use_bike_time_length / 60) . 'h' . ($real_use_bike_time_length % 60) . 'm';
- $real_use_bike_time_length_name = floor($real_use_bike_time_length_time / 60) . '小时' . ($real_use_bike_time_length_time % 60) . '分钟';
- } else {
- $real_use_bike_time_length = $real_use_bike_time_length . 'm';
- $real_use_bike_time_length_name = $real_use_bike_time_length_time . '分钟';
- }
- $order_create_time = Carbon::now()->diffInHours($model->updated_at);
- $is_return = true;
- // Log::info($order_create_time);
- if(abs($order_create_time) > 24 * 5){
- $is_return = false;
- }
- if($model->pay_money == 0){
- $is_return = false;
- }
- $is_huisu = false;
- $order_end_time = Carbon::now()->diffInHours($model->end_use_bike_time);
- if($model->status == OrderRent::STATUS_CLOSE_RENT_BIKE && $order_end_time <4){
- // 4小时内可回溯
- $is_huisu = true;
- }
- $data = [
- 'nickname' => $model->users->nickname ? ($model->users->nickname . "(" . $model->users->truename . ")") : '',
- 'mobile' => $model->users->mobile ?? '',
- 'order_id' => $model->id,
- 'area_id' => $model->area_id,
- 'orders_status' => OrderRent::$statusMaps[$model->status],
- 'area_name' => $model->area->name,
- 'real_use_bike_time_length' => $real_use_bike_time_length,
- 'is_return' => $is_return,
- 'settle_type' => OrderRent::$adminSettleOrderMaps[$model->is_admin_settle_order],
- 'no' => $model->no,
- 'id' => $model->id,
- 'bike_no' => $model->bike_no,
- 'pay_money' => $model->pay_money,
- 'status' => $model->status,
- 'start_use_bike_time' => $model->start_use_bike_time,
- 'end_use_bike_time' => $model->end_use_bike_time,
- 'order_total_money' => $model->order_total_money,
- 'total_money' => $model->total_money,
- 'time_money' => $model->time_money,
- 'rent_money' => $model->rent_money,
- 'dispatch_money' => $model->dispatch_money,
- 'use_bike_distance_length' => $model->use_bike_distance_length,
- 'pay_type' => $model->pay_type,
- 'pay_type_name' => OrderRent::$payTypeMaps[$model->pay_type],
- 'is_huisu' => $is_huisu,
- 'setting' => $model->setting,
- 'phone_detail' => $model->phone_detail ?? '',
- 'real_use_bike_time_length_name' => $real_use_bike_time_length_name,
- ];
- return $data;// array_merge(parent::toArray($request),$data);
- }
- }
|