6 changed files with 202 additions and 1 deletions
-
100app/Admin/Controllers/OrderChangedController.php
-
35app/Admin/Controllers/OrderNotifyController.php
-
3app/Admin/routes.php
-
19app/Models/OrderChanged.php
-
31database/migrations/2025_08_30_125154_create_order_changed_table.php
-
15lang/zh_CN/order-changed.php
@ -0,0 +1,100 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\OrderChanged; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class OrderChangedController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new OrderChanged(), function (Grid $grid) { |
||||
|
$grid->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 = '推送数据:<pre>'.e($this->push_body).'</pre><br/>PHP数组:<pre>'.var_export($r, true).'</pre>'; |
||||
|
$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 '推送数据:<pre>'.e($v).'</pre><br/>PHP数组:<pre>'.var_export($r, true).'</pre>'; |
||||
|
}); |
||||
|
$show->field('created_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new OrderChanged(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class OrderChanged extends Model |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
|
||||
|
protected $casts = [ |
||||
|
'receive_time' => 'datetime', |
||||
|
]; |
||||
|
|
||||
|
protected $table = 'order_changed'; |
||||
|
|
||||
|
const UPDATED_AT = null; |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Database\Migrations\Migration; |
||||
|
use Illuminate\Database\Schema\Blueprint; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
return new class extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* Run the migrations. |
||||
|
*/ |
||||
|
public function up(): void |
||||
|
{ |
||||
|
Schema::create('order_changed', function (Blueprint $table) { |
||||
|
$table->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'); |
||||
|
} |
||||
|
}; |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'OrderChanged' => '变更记录', |
||||
|
'order-changed' => '变更记录', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'order_id' => '订单ID', |
||||
|
'state' => '订单状态', |
||||
|
'receive_time' => '接收时间', |
||||
|
'receive_body' => '接收内容', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue