diff --git a/app/Admin/Controllers/OrderChangedController.php b/app/Admin/Controllers/OrderChangedController.php new file mode 100644 index 0000000..f948c18 --- /dev/null +++ b/app/Admin/Controllers/OrderChangedController.php @@ -0,0 +1,100 @@ +model()->orderBy('id', 'desc'); + + $grid->column('id')->sortable(); + $grid->column('order_id'); + + $grid->column('state') + ->using(admin_trans('order.options.state')) + ->label([ + 0 => 'primary', + 1 => 'warning', + 2 => 'success', + 3 => 'danger', + 4 => 'gray', + ]); + + $grid->column('receive_time'); + + $grid->column('receive_body') + ->width('20%') + ->display(fn($v) => e(Str::limit($v, 20))) + ->modal(function (Grid\Displayers\Modal $modal) { + $modal->title(admin_trans('order-notify.fields.push_body')); + parse_str($this->push_body, $r); + $html = '推送数据:
'.e($this->push_body).'

PHP数组:
'.var_export($r, true).'
'; + $card = new Card(null, $html); + return $card->render(); + }); + + $grid->column('created_at'); + + $grid->disableCreateButton(); + $grid->disableEditButton(); + $grid->disableDeleteButton(); + $grid->disableBatchDelete(); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('order_id')->width(3); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new OrderChanged(), function (Show $show) { + $show->disableEditButton(); + $show->disableDeleteButton(); + $show->field('id'); + $show->field('order_id'); + $show->field('state')->using(admin_trans('order.options.state')); + $show->field('receive_time'); + $show->field('receive_body')->unescape()->as(function ($v) { + parse_str($v, $r); + return '推送数据:
'.e($v).'

PHP数组:
'.var_export($r, true).'
'; + }); + $show->field('created_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new OrderChanged(), function (Form $form) { + $form->display('id'); + }); + } +} diff --git a/app/Admin/Controllers/OrderNotifyController.php b/app/Admin/Controllers/OrderNotifyController.php index 36a26ec..d6bc96e 100644 --- a/app/Admin/Controllers/OrderNotifyController.php +++ b/app/Admin/Controllers/OrderNotifyController.php @@ -7,6 +7,7 @@ use Dcat\Admin\Form; use Dcat\Admin\Grid; use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Show; +use Dcat\Admin\Widgets\Card; use Illuminate\Support\Str; class OrderNotifyController extends AdminController @@ -23,6 +24,7 @@ class OrderNotifyController extends AdminController $grid->column('id')->sortable(); $grid->column('order_id'); + $grid->column('state') ->using(admin_trans('order.options.state')) ->label([ @@ -32,10 +34,41 @@ class OrderNotifyController extends AdminController 3 => 'danger', 4 => 'gray', ]); + $grid->column('push_time'); + + $grid->column('push_body') + ->width('15%') + ->display(fn($v) => e(Str::limit($v, 20))) + ->modal(function (Grid\Displayers\Modal $modal) { + $modal->title(admin_trans('order-notify.fields.push_body')); + parse_str($this->push_body, $r); + $html = '推送数据:
'.e($this->push_body).'

PHP数组:
'.var_export($r, true).'
'; + $card = new Card(null, $html); + return $card->render(); + }); + $grid->column('response_time'); $grid->column('response_code'); - $grid->column('response_body')->display(fn($v) => e(Str::limit($v, 15)))->width('15%'); + + $grid->column('response_body') + ->width('15%') + ->if(function (Grid\Column $column) { + return mb_strlen($this->response_body) > 20; + }) + ->then(function (Grid\Column $column) { + $column + ->display(fn($v) => e(Str::limit($v, 20))) + ->modal(function (Grid\Displayers\Modal $modal) { + $modal->title(admin_trans('order-notify.fields.response_body')); + $card = new Card(null, '
'.e($this->response_body).'
'); + return $card->render(); + }); + }) + ->else(function (Grid\Column $column) { + $column->display($this->response_body); + }); + $grid->column('push_duration')->display(function ($v) { if ($this->response_code === null) { return ''; diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 858b8b9..aea52b0 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -2,6 +2,7 @@ use App\Admin\Controllers\MchAppController; use App\Admin\Controllers\MerchantController; +use App\Admin\Controllers\OrderChangedController; use App\Admin\Controllers\OrderController; use App\Admin\Controllers\OrderNotifyController; use Illuminate\Routing\Router; @@ -24,5 +25,7 @@ Route::group([ $router->resource('order', OrderController::class)->only(['index', 'show']); + $router->resource('order-changed', OrderChangedController::class)->only(['index', 'show']); + $router->resource('order-notify', OrderNotifyController::class)->only(['index', 'show']); }); diff --git a/app/Models/OrderChanged.php b/app/Models/OrderChanged.php new file mode 100644 index 0000000..6c14011 --- /dev/null +++ b/app/Models/OrderChanged.php @@ -0,0 +1,19 @@ + 'datetime', + ]; + + protected $table = 'order_changed'; + + const UPDATED_AT = null; +} diff --git a/database/migrations/2025_08_30_125154_create_order_changed_table.php b/database/migrations/2025_08_30_125154_create_order_changed_table.php new file mode 100644 index 0000000..461b078 --- /dev/null +++ b/database/migrations/2025_08_30_125154_create_order_changed_table.php @@ -0,0 +1,31 @@ +id(); + $table->unsignedBigInteger('order_id')->index()->comment('订单ID'); + $table->tinyInteger('state')->comment('订单状态'); + $table->timestamp('receive_time')->nullable()->comment('接收时间'); + $table->text('receive_body')->nullable()->comment('接收内容'); + $table->timestamp('created_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('order_changed'); + } +}; diff --git a/lang/zh_CN/order-changed.php b/lang/zh_CN/order-changed.php new file mode 100644 index 0000000..8ef3550 --- /dev/null +++ b/lang/zh_CN/order-changed.php @@ -0,0 +1,15 @@ + [ + 'OrderChanged' => '变更记录', + 'order-changed' => '变更记录', + ], + 'fields' => [ + 'order_id' => '订单ID', + 'state' => '订单状态', + 'receive_time' => '接收时间', + 'receive_body' => '接收内容', + ], + 'options' => [ + ], +];