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.
197 lines
6.8 KiB
197 lines
6.8 KiB
<?php
|
|
|
|
namespace App\AdminAgent\Controllers;
|
|
|
|
use App\AdminAgent\Extensions\Grid\AuditRefund;
|
|
use App\AdminAgent\Extensions\Grid\ChangeOrderStatus;
|
|
use App\AdminAgent\Repositories\Order;
|
|
use App\Common\OrderStatus;
|
|
use App\Common\PayType;
|
|
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', 'product']), function (Grid $grid) {
|
|
$grid->disableDeleteButton();
|
|
$grid->disableBatchDelete();
|
|
$grid->disableCreateButton();
|
|
$grid->disableRowSelector();
|
|
|
|
$grid->model()->where('agent_id', Admin::user()->id);
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('order_no')->limit(10);
|
|
$grid->column('name');
|
|
$grid->column('mobile');
|
|
$grid->column('product', '产品信息')
|
|
->display('查看')
|
|
->modal('购买产品信息', function ($modal) {
|
|
return Table::make(['产品名称', '产品图片', '购买数量', '所属供应商'],
|
|
[[
|
|
$this->title,
|
|
'<img data-action="preview-img" src="'.$this->picture.'" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail">',
|
|
$this->num,
|
|
$this->product->supplier->name,
|
|
]]);
|
|
})->xl();
|
|
|
|
//状态及退款处理
|
|
$grid->column('status')
|
|
->using(OrderStatus::array())
|
|
->if(fn() => in_array($this->status, [OrderStatus::REFUNDING, OrderStatus::REFUNDED, OrderStatus::REFUSED_REFUND]))
|
|
->display('<a style="cursor: pointer;" class="btn btn-sm btn-info" href="javascript:;">退款详情</a> ')
|
|
->modal('查看退款详情', function (Grid\Displayers\Modal $modal) {
|
|
$modal->icon('');
|
|
if (!$this->refund_info) {
|
|
return '';
|
|
}
|
|
$html = '';
|
|
$pictures = $this->refund_info['pictures'] ?? [];
|
|
if (count($pictures) > 0) {
|
|
$html = '<div class="box-body">';
|
|
foreach ($pictures as $value) {
|
|
$html .= '<img data-action="preview-img" src="' . $value . '" style="max-width:80px;max-height:80px" class="img"> ';
|
|
}
|
|
$html .= '</div>';
|
|
}
|
|
$refund_info = [
|
|
'退款单号' => $this->refund_info['refund_no'] ?? '',
|
|
'退款说明' => $this->refund_info['desc'] ?? '',
|
|
'退款前状态' => isset($this->refund_info['old_status']) ? OrderStatus::array()[$this->refund_info['old_status']] : '',
|
|
'退款凭据' => $html,
|
|
];
|
|
return Table::make($refund_info);
|
|
})
|
|
->then(function (Grid\Column $column) {
|
|
if ($this->status == OrderStatus::REFUNDING) {
|
|
$column->append((new AuditRefund(null, 1))->setKey($this->id))->append(' ');
|
|
$column->append((new AuditRefund(null, 2))->setKey($this->id));
|
|
} else if ($this->status == OrderStatus::REFUNDED) {
|
|
$column->append('<a style="cursor: pointer;" class="btn btn-sm btn-success" href="javascript:;">已同意退款</a>');
|
|
} else if ($this->status == OrderStatus::REFUSED_REFUND) {
|
|
$column->append('<a style="cursor: pointer;" class="btn btn-sm btn-danger" href="javascript:;">已拒绝退款</a>');
|
|
}
|
|
})
|
|
->if(fn() => $this->status == OrderStatus::OFFLINE_UNPAID)
|
|
->then(function (Grid\Column $column) {
|
|
return $column->action(new ChangeOrderStatus);
|
|
});
|
|
|
|
$grid->column('pay_type')->using(PayType::array());
|
|
$grid->column('price');
|
|
$grid->column('paid_money');
|
|
$grid->column('paid_at');
|
|
$grid->column('created_at');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
|
|
$filter->model()->where('agent_id', Admin::user()->id);
|
|
|
|
$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 = 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(['product.supplier:id,name']), function (Show $show) {
|
|
$show->disableDeleteButton();
|
|
|
|
//不允许查看非自己的数据
|
|
if ($show->model()->agent_id != Admin::user()->id) {
|
|
Admin::exit('数据不存在');
|
|
}
|
|
|
|
$show->field('id');
|
|
$show->field('user_id');
|
|
$show->field('order_no');
|
|
$show->field('agent_product_id', '代理商产品ID');
|
|
$show->field('product.supplier.name', '供应商');
|
|
$show->field('price');
|
|
$show->field('paid_money');
|
|
$show->field('paid_at');
|
|
$show->field('num');
|
|
$show->field('name');
|
|
$show->field('mobile');
|
|
$show->field('title');
|
|
$show->field('picture')->image('', 80, 80);
|
|
$show->field('status')->using(OrderStatus::array());
|
|
$show->field('pay_type')->using(PayType::array());
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Order(), function (Form $form) {
|
|
$form->disableDeleteButton();
|
|
|
|
//不允许查看非自己的数据
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
$form->display('id');
|
|
$form->text('name');
|
|
$form->text('mobile');
|
|
})->saving(function (Form $form) {
|
|
//不允许修改非自己的数据
|
|
if ($form->isCreating()) {
|
|
return $form->response()->error('操作禁止');
|
|
}
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
//不允许编辑的字段
|
|
$form->ignore(['id', 'user_id', 'agent_id', 'agent_product_id', 'product_id', 'product_ids', 'order_no',
|
|
'pay_type', 'paid_money', 'created_at', 'updated_at', 'deleted_at']);
|
|
|
|
//退款不能直接编辑
|
|
if (in_array($form->status, [OrderStatus::REFUNDED, OrderStatus::REFUSED_REFUND])) {
|
|
return $form->response()->error('请通过订单列表的”通过“和”拒绝“按钮来审核退款');
|
|
} else if ($form->status != OrderStatus::OFFLINE_PAID) {
|
|
return $form->response()->error('操作禁止');
|
|
}
|
|
})->saved(function (Form $form) {
|
|
return $form->response()->success('更新成功')->refresh();
|
|
})->deleting(function (Form $form) {
|
|
return $form->response()->error('操作禁止');
|
|
});
|
|
}
|
|
}
|