diff --git a/beike/Admin/Http/Controllers/RmaController.php b/beike/Admin/Http/Controllers/RmaController.php index 212febde..ef65ad67 100644 --- a/beike/Admin/Http/Controllers/RmaController.php +++ b/beike/Admin/Http/Controllers/RmaController.php @@ -11,6 +11,7 @@ namespace Beike\Admin\Http\Controllers; +use Beike\Admin\Http\Resources\RmaDetail; use Beike\Models\Rma; use Beike\Repositories\RmaReasonRepo; use Beike\Repositories\RmaRepo; @@ -24,6 +25,7 @@ class RmaController extends Controller $rmas = RmaRepo::list($request->only('name', 'email', 'telephone', 'product_name', 'sku', 'type', 'status')); $data = [ 'rmas' => $rmas, + 'rmas_format' => RmaDetail::collection($rmas)->jsonSerialize(), ]; return view('admin::pages.rmas.index', $data); @@ -48,7 +50,7 @@ class RmaController extends Controller RmaRepo::addHistory($id, $request->only('status', 'notify', 'comment')); $data = [ - 'rma' => RmaRepo::find($id), + 'rma' => (new RmaDetail(RmaRepo::find($id)))->jsonSerialize(), 'statuses' => RmaRepo::getStatuses(), ]; return json_success(trans('common.updated_success'), $data); diff --git a/beike/Admin/Http/Resources/RmaDetail.php b/beike/Admin/Http/Resources/RmaDetail.php new file mode 100644 index 00000000..b66f11b5 --- /dev/null +++ b/beike/Admin/Http/Resources/RmaDetail.php @@ -0,0 +1,43 @@ + + * @created 2022-08-31 11:56:28 + * @modified 2022-08-31 11:56:28 + */ + +namespace Beike\Admin\Http\Resources; + +use Beike\Repositories\RmaRepo; +use Illuminate\Http\Resources\Json\JsonResource; + +class RmaDetail extends JsonResource +{ + public function toArray($request): array + { + $types = RmaRepo::getTypes(); + $statuses = RmaRepo::getStatuses(); + + return [ + 'id' => $this->id, + 'order_product_id' => $this->order_product_id, + 'quantity' => $this->quantity, + 'opened' => $this->opened, + 'type' => $types[$this->type], + 'comment' => $this->comment, + 'status' => $statuses[$this->status], + 'created_at' => time_format($this->created_at), + 'email' => $this->email, + 'telephone' => $this->telephone, + 'product_name' => $this->product_name, + 'name' => $this->name, + 'sku' => $this->sku, + 'model' => $this->model, + 'reason' => $this->reason->name ?? '', + 'type_text' => $this->type_text, + ]; + } +} diff --git a/beike/Shop/Http/Resources/RmaDetail.php b/beike/Shop/Http/Resources/RmaDetail.php index 63451e0c..13d76e63 100644 --- a/beike/Shop/Http/Resources/RmaDetail.php +++ b/beike/Shop/Http/Resources/RmaDetail.php @@ -19,6 +19,7 @@ class RmaDetail extends JsonResource public function toArray($request): array { $types = RmaRepo::getTypes(); + $statuses = RmaRepo::getStatuses(); return [ 'id' => $this->id, @@ -27,7 +28,7 @@ class RmaDetail extends JsonResource 'opened' => $this->opened, 'type' => $types[$this->type], 'comment' => $this->comment, - 'status' => $this->status, + 'status' => $statuses[$this->status], 'created_at' => time_format($this->created_at), 'email' => $this->email, 'telephone' => $this->telephone, diff --git a/resources/beike/admin/views/pages/rmas/index.blade.php b/resources/beike/admin/views/pages/rmas/index.blade.php index 0798b197..800847af 100644 --- a/resources/beike/admin/views/pages/rmas/index.blade.php +++ b/resources/beike/admin/views/pages/rmas/index.blade.php @@ -21,16 +21,16 @@ - @foreach ($rmas as $rma) + @foreach ($rmas_format as $rma) - {{ $rma->name }} - {{ $rma->email }} - {{ $rma->telephone }} - {{ $rma->product_name }} - {{ $rma->model }} - {{ $rma->quantity }} - {{ $rma->type }} - {{ $rma->status }} + {{ $rma['name'] }} + {{ $rma['email'] }} + {{ $rma['telephone'] }} + {{ $rma['product_name'] }} + {{ $rma['model'] }} + {{ $rma['quantity'] }} + {{ $rma['type'] }} + {{ $rma['status'] }} {{ __('common.view') }}