You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
4.2 KiB
153 lines
4.2 KiB
<?php
|
|
|
|
namespace App\AdminSupplier\Controllers;
|
|
|
|
use App\AdminSupplier\Extensions\Grid\ChangeOrderStatus;
|
|
use App\AdminSupplier\Repositories\Order;
|
|
use App\Common\OrderStatus;
|
|
use App\Common\PayType;
|
|
use App\Models\Agent;
|
|
use App\Models\OrderProductItem;
|
|
use App\Models\Supplier;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Widgets\Table;
|
|
|
|
class OrderController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Order([
|
|
'agent:id,name',
|
|
'agentProduct.product:id,title,price,pictures',
|
|
'product'
|
|
]), function (Grid $grid) {
|
|
$grid->disableCreateButton();
|
|
$grid->disableDeleteButton();
|
|
$grid->disableEditButton();
|
|
|
|
$grid->model()->where(function ($query) {
|
|
return $query->whereHas('orderProductItem', function($query) {
|
|
return $query->where('supplier_id', Admin::user()->id);
|
|
});
|
|
});
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('agent.name', '代理商');
|
|
$grid->column('title');
|
|
$grid->column('picture')->image('', 60, 60);
|
|
$grid->column('product', '订单信息')
|
|
->display('查看')
|
|
->modal('订单信息', function ($modal) {
|
|
return Table::make(['订单号', '姓名', '手机号', '订单总价', '购买数量'],
|
|
[[
|
|
$this->order_no,
|
|
$this->name,
|
|
$this->mobile,
|
|
$this->price,
|
|
$this->num,
|
|
]]);
|
|
})->xl();
|
|
$grid->column('paid_money');
|
|
$grid->column('price');
|
|
// $grid->column('refund_info');
|
|
$grid->column('pay_type')->using(PayType::array());
|
|
$grid->column('status', '订单状态')
|
|
->using(OrderStatus::array())
|
|
->if(fn() => $this->status == OrderStatus::OFFLINE_UNPAID)
|
|
->then(function (Grid\Column $column) {
|
|
return $column->action(new ChangeOrderStatus);
|
|
});
|
|
$grid->column('paid_at');
|
|
$grid->column('created_at');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
|
|
$filter->equal('id')->width(2);
|
|
$filter->equal('mobile')->width(2);
|
|
$filter->equal('order_no')->width(3);
|
|
$filter->equal('status')->select(OrderStatus::array())->width(2);
|
|
|
|
$option = Agent::query()->pluck('name', 'id');
|
|
$filter->equal('agent_id', '代理商')->select($option)->width(3);
|
|
|
|
$option = Supplier::query()->pluck('name', 'id');
|
|
$filter->equal('product.supplier_id', '供应商')->select($option)->width(3);
|
|
|
|
$filter->between('created_at')->datetime()->width(4);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Order(['agent:id,name', 'orderProductItem']), function (Show $show) {
|
|
$show->disableDeleteButton();
|
|
$show->disableQuickEdit();
|
|
$show->disableEditButton();
|
|
|
|
//不允许查看非自己的数据,$show->model()->whereHas()不起作用?
|
|
if (!OrderProductItem::where(['order_id' => $show->model()->id, 'supplier_id' => Admin::user()->id])->exists()) {
|
|
Admin::exit('数据不存在');
|
|
}
|
|
|
|
$show->field('id');
|
|
$show->field('agent.name');
|
|
$show->field('mobile');
|
|
$show->field('name');
|
|
$show->field('num');
|
|
$show->field('order_no');
|
|
$show->field('paid_at');
|
|
$show->field('paid_money');
|
|
$show->field('pay_type')->using(PayType::array());
|
|
$show->field('title');
|
|
$show->field('picture')->image('', 80, 80);
|
|
$show->field('price');
|
|
$show->field('product_id');
|
|
$show->field('status')->using(OrderStatus::array());
|
|
$show->field('title');
|
|
$show->field('user_id');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Order('orderProductItem'), function (Form $form) {
|
|
$form->disableDeleteButton();
|
|
$form->disableFooter();
|
|
$form->disableHeader();
|
|
|
|
$form->display('id')->width(2);
|
|
|
|
//订单不允许新增或编辑
|
|
return $form->response()->error('操作禁止');
|
|
})->saving(function (Form $form) {
|
|
return $form->response()->error('操作禁止');
|
|
})->deleting(function (Form $form) {
|
|
return $form->response()->error('操作禁止');
|
|
});
|
|
}
|
|
}
|