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.
128 lines
4.2 KiB
128 lines
4.2 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Extensions\Grid\AuditAgentProduct;
|
|
use App\Admin\Repositories\AgentProduct;
|
|
use App\Common\ProductStatus;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class AgentProductController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new AgentProduct(['agent:id,company_name', 'guide:id,name']), function (Grid $grid) {
|
|
$grid->disableCreateButton();
|
|
$grid->disableRowSelector();
|
|
|
|
//如果是审核页面,多加where条件判断
|
|
if (strpos(Route::current()->uri, 'audit')) {
|
|
$grid->model()->where('status', ProductStatus::UNAUDITED);
|
|
}
|
|
|
|
$grid->model()->where('type', 3);
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('agent.company_name');
|
|
$grid->column('title')->limit(15);
|
|
$grid->column('picture')->image('', 60, 60);
|
|
$grid->column('price');
|
|
$grid->column('original_price');
|
|
$grid->column('sale');
|
|
$grid->column('stock');
|
|
$grid->column('guide.name');
|
|
$grid->column('status')
|
|
->if(fn() => $this->status == ProductStatus::UNAUDITED)
|
|
->display('')
|
|
->then(function ($column) {
|
|
$column->append((new AuditAgentProduct(null, 1))->setKey($this->id))->append(' ');
|
|
$column->append((new AuditAgentProduct(null, 2))->setKey($this->id));
|
|
})
|
|
->else()
|
|
->using(ProductStatus::array())
|
|
->dot([
|
|
ProductStatus::ON_SALE => 'success',
|
|
ProductStatus::UNAUDITED => '',
|
|
ProductStatus::REFUSE => 'danger',
|
|
ProductStatus::SOLD_OUT => 'warning',
|
|
], 'primary');
|
|
$grid->column('single_deposit')->editable();
|
|
$grid->column('created_at');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
|
|
$filter->equal('id')->width(2);
|
|
$filter->like('title')->width(3);
|
|
$filter->equal('status')->width(2)->select(ProductStatus::array());
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new AgentProduct(['agent:id,name', 'guide:id,name']), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('agent.name');
|
|
$show->field('title');
|
|
$show->field('pictures')->image('', 80, 80);
|
|
$show->field('price');
|
|
$show->field('original_price');
|
|
$show->field('sale');
|
|
$show->field('stock');
|
|
$show->field('guide.name');
|
|
$show->field('status')->using(ProductStatus::array());
|
|
$show->field('deposit');
|
|
$show->field('deposit_timeout');
|
|
$show->field('earnest');
|
|
$show->field('earnest_timeout');
|
|
$show->field('single_deposit');
|
|
$show->field('know')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v));
|
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v));
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new AgentProduct(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->select('status')->options(ProductStatus::array());
|
|
$form->decimal('single_deposit');
|
|
})->saving(function (Form $form) {
|
|
if ($form->isEditing() && $form->status !== null && array_key_exists($form->status, ProductStatus::array())) {
|
|
$form->model()->update(['status' => $form->status]);
|
|
return $form->response()->success('设置产品状态成功')->refresh();
|
|
}
|
|
|
|
//列表编辑交易金单价
|
|
if ($form->isEditing() && !is_null($form->single_deposit)) {
|
|
$form->model()->update(['single_deposit' => $form->single_deposit]);
|
|
return $form->response()->success('设置交易金成功')->refresh();
|
|
}
|
|
return $form->response()->error('操作禁止');
|
|
});
|
|
}
|
|
}
|