208 lines
9.2 KiB
PHP
208 lines
9.2 KiB
PHP
<?php
|
|
|
|
namespace Peidikeji\Order\Http\Admin;
|
|
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Grid\Displayers\Modal;
|
|
use Dcat\Admin\Grid\Filter;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Layout\Column;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Models\Administrator;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Show\Tools;
|
|
use Dcat\Admin\Widgets\Box;
|
|
use Illuminate\Support\Arr;
|
|
use Peidikeji\Order\Action\ShowCancel;
|
|
use Peidikeji\Order\Action\ShowDelete;
|
|
use Peidikeji\Order\Action\ShowPay;
|
|
use Peidikeji\Order\Action\ShowPayQuery;
|
|
use Peidikeji\Order\Action\ShowPrice;
|
|
use Peidikeji\Order\Action\ShowReceive;
|
|
use Peidikeji\Order\Action\ShowRemarks;
|
|
use Peidikeji\Order\Action\ShowShip;
|
|
use Peidikeji\Order\Enums\OrderStatus;
|
|
use Peidikeji\Order\Enums\PayStatus;
|
|
use Peidikeji\Order\Models\Order;
|
|
use Peidikeji\Order\Models\OrderGoods;
|
|
use Peidikeji\Order\Models\OrderOption;
|
|
use Peidikeji\Order\Models\OrderShip;
|
|
use Peidikeji\Order\Renderable\ShipLog;
|
|
use Peidikeji\User\Models\User;
|
|
|
|
class OrderController extends AdminController
|
|
{
|
|
protected $translation = 'dcat-admin-order::order';
|
|
|
|
protected function grid()
|
|
{
|
|
return Grid::make(Order::with(['user']), function (Grid $grid) {
|
|
$grid->disableRowSelector();
|
|
$grid->model()->sort();
|
|
|
|
$grid->filter(function (Filter $filter) {
|
|
$filter->panel();
|
|
$filter->like('sn')->width(4);
|
|
$filter->equal('user_id')->select()->ajax('api/user?_paginate=1')->model(User::class, 'id', 'phone')->width(4);
|
|
$filter->where('order_status', fn($q) => $q->filter(['status' => $this->input]))->select(OrderStatus::options())->width(4);
|
|
$filter->whereBetween('created_at', function ($q) {
|
|
$start = data_get($this->input, 'start');
|
|
$start = $start ? Carbon::createFromFormat('Y-m-d', $start) : null;
|
|
$end = data_get($this->input, 'end');
|
|
$end = $end ? Carbon::createFromFormat('Y-m-d', $end) : null;
|
|
if ($start) {
|
|
if ($end) {
|
|
$q->whereBetween('created_at', [$start, $end]);
|
|
}
|
|
$q->where('created_at', '>=', $start);
|
|
} else if ($end) {
|
|
$q->where('created_at', '<=', $end);
|
|
}
|
|
})->date()->width(4);
|
|
});
|
|
|
|
$grid->column('sn')->copyable();
|
|
$grid->column('user.phone');
|
|
$grid->column('total_money');
|
|
$grid->column('order_status')->display(fn() => $this->status()->dot());
|
|
$grid->column('created_at');
|
|
|
|
$user = Admin::user();
|
|
|
|
$grid->showViewButton($user->can('dcat.admin.orders.show'));
|
|
$grid->disableCreateButton();
|
|
$grid->disableEditButton();
|
|
$grid->disableDeleteButton();
|
|
});
|
|
}
|
|
|
|
protected function detail($id)
|
|
{
|
|
$info = Order::with(['user'])->findOrFail($id);
|
|
$row = new Row();
|
|
$row->column(6, Show::make($info, function (Show $show) {
|
|
$show->disableEditButton();
|
|
$show->disableDeleteButton();
|
|
$info = $show->model();
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->field('user.phone');
|
|
$show->width(6)->field('sn');
|
|
$show->width(6)->field('status', '状态')->as(fn() => $this->status()->label())->unescape();
|
|
$show->width(6)->field('created_at');
|
|
});
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->field('total_money');
|
|
$show->width(6)->field('user_remarks');
|
|
});
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->field('score_discount_money');
|
|
$show->width(6)->field('score_discount_amount');
|
|
});
|
|
if ($info->coupon_money > 0) {
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->field('coupon_money')->as(fn ($v) => '<span class="text-danger">-'.floatval($v).'</span>')->unescape();
|
|
$show->width(6)->field('coupon.name', '优惠券');
|
|
});
|
|
}
|
|
$show->row(function (Show\Row $show) use ($info) {
|
|
$show->width(6)->field('pay_money')->as(function ($value) {
|
|
return '<span>'.$value.'</span>' . ($this->discount_price > 0 ? '(<span class="text-danger">-'.$this->discount_price.'</span>)' : '');
|
|
})->unescape();
|
|
$show->width(6)->field('pay_way')->as(fn() => $this->pay_way?->label())->unescape();
|
|
if ($info->pay_status === PayStatus::Success) {
|
|
$show->width(6)->field('pay_at');
|
|
$show->width(6)->field('pay_no');
|
|
}
|
|
});
|
|
|
|
$show->row(function (Show\Row $show) use ($info) {
|
|
// $show->width(6)->field('ship_status')->as(fn() => $this->ship_status->label())->unescape();
|
|
$show->width(6)->field('ship_money');
|
|
$show->width(6)->field('ship_address')->as(fn($v) => $v ? implode(',', Arr::only($v, ['name', 'phone', 'address'])) : '');
|
|
$show->width(6)->field('ship_way')->as(fn() => $this->ship_way?->label())->unescape();
|
|
$show->width(6)->field('ship_at');
|
|
});
|
|
$show->row(function (Show\Row $show) use ($info) {
|
|
$show->width(6)->field('remarks');
|
|
});
|
|
$show->tools(function (Tools $tools) {
|
|
$tools->append(new ShowCancel());
|
|
$tools->append(new ShowPay());
|
|
$tools->append(new ShowPayQuery());
|
|
$tools->append(new ShowShip());
|
|
$tools->append(new ShowReceive());
|
|
$tools->append(new ShowDelete());
|
|
$tools->append(new ShowPrice());
|
|
$tools->append(new ShowRemarks());
|
|
});
|
|
}));
|
|
|
|
$row->column(6, function (Column $column) use ($info) {
|
|
$column->row(Box::make('订单商品', Grid::make(OrderGoods::where('order_id', $info->id), function (Grid $grid) {
|
|
$grid->disableRowSelector();
|
|
$grid->disableCreateButton();
|
|
$grid->disablePagination();
|
|
$grid->disableActions();
|
|
$grid->disableRefreshButton();
|
|
$grid->column('goods_name', '商品');
|
|
$grid->column('price', '价格');
|
|
$grid->column('amount', '数量');
|
|
$grid->column('ship_amount', '已发');
|
|
$grid->column('spec', '规格')->display(fn($v) => $v ? array_column($v, 'value') : '')->label();
|
|
$grid->column('money', '合计');
|
|
})));
|
|
$column->row(Box::make('发货单', Grid::make(OrderShip::with(['goods'])->where('order_id', $info->id)->sort(), function (Grid $grid) {
|
|
$grid->disableRowSelector();
|
|
$grid->disableCreateButton();
|
|
$grid->disablePagination();
|
|
$grid->disableActions();
|
|
$grid->disableRefreshButton();
|
|
|
|
$grid->column('company', '物流公司')->display(fn() => data_get($this->ship_data, 'company'));
|
|
$grid->column('sn', '运单号')->copyable();
|
|
$grid->column('goods', '商品')->display(function () {
|
|
$html = '';
|
|
foreach($this->goods as $item) {
|
|
$html .= <<<HTML
|
|
<div>
|
|
$item->goods_name
|
|
<span class="badge bg-primary">$item->amount</span>
|
|
</div>
|
|
HTML;
|
|
}
|
|
return $html;
|
|
});
|
|
$grid->column('ship_status', '状态')->display(fn() => $this->ship_status->text())->modal(function (Modal $modal) {
|
|
$modal->icon('fa-truck');
|
|
$modal->title('物流信息');
|
|
return ShipLog::make(['id' => $this->id, 'ship' => $this->ship_data])->render();
|
|
});
|
|
$grid->column('created_at', '发货时间');
|
|
$grid->column('finish_at', '收货时间');
|
|
})));
|
|
$column->row(Box::make('操作记录', Grid::make(OrderOption::with(['user'])->where('order_id', $info->id)->orderBy('created_at', 'desc'), function (Grid $grid) {
|
|
|
|
$grid->disableRowSelector();
|
|
$grid->disableCreateButton();
|
|
$grid->disablePagination();
|
|
$grid->disableActions();
|
|
$grid->disableRefreshButton();
|
|
|
|
$grid->column('user_id', '操作人')->display(function () {
|
|
return match($this->user_type) {
|
|
Administrator::class => $this->user->name,
|
|
User::class => $this->user->phone,
|
|
null => '',
|
|
default => $this->user_type.': '.$this->user_id
|
|
};
|
|
});
|
|
$grid->column('description', '描述');
|
|
$grid->column('created_at', '时间');
|
|
})));
|
|
});
|
|
return $row;
|
|
}
|
|
}
|