12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Http\Resources\App;
- use App\Models\WorkOrder;
- use Carbon\Carbon;
- use Illuminate\Http\Resources\Json\JsonResource;
- class WorkOrderResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- public function toArray($request)
- {
- $model = $this->resource;
- $reason = $model->reason ?? '';
- $type = $model->type;
- // if($type === WorkOrder::TYPE_TROUBLE){
- $str = '';
- if(is_serialized($reason)){
- $reasonArr = unserialize($reason);
- foreach ($reasonArr as $k=>$v){
- if($v == 1){
- $str .= WorkOrder::$warningMaps[$k]."、";
- }
- }
- $str = rtrim($str,'、');
- $reason = $str;
- }
- // }
- $worker = $model->worker->name ?? '';
- if($model->planned == WorkOrder::PLANNED_STATUS_WORKED || $model->planned == WorkOrder::PLANNED_STATUS_OVER){
- $worker = $model->worker->name ?? '系统';
- }
- $data = [
- 'id' => $model->id,
- 'source' => WorkOrder::$sourceMaps[$model->source],
- 'planned' => WorkOrder::$plannedMaps[$model->planned],
- 'bike_no' => $model->bike_no,
- 'created_at' => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($model->updated_at)->format('Y-m-d H:i:s'),
- 'worker' => $worker,
- 'type_name' => $model->type_name,
- 'type' => $model->type,
- 'times' => $model->times,
- 'reason' => $reason,
- ];
- // return parent::toArray($request);
- return $data;
- }
- }
|