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.
103 lines
3.2 KiB
103 lines
3.2 KiB
<?php
|
|
|
|
namespace App\AdminAgent\Controllers;
|
|
|
|
use App\AdminAgent\Forms\IndustryProductBuy;
|
|
use App\AdminAgent\Repositories\IndustryProduct;
|
|
use App\Common\ProductStatus;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Widgets\Card;
|
|
|
|
class IndustryProductController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new IndustryProduct(['category:id,name', 'supplier:id,company_name']), function (Grid $grid) {
|
|
$grid->disableDeleteButton();
|
|
$grid->disableRowSelector();
|
|
$grid->disableCreateButton();
|
|
$grid->disableEditButton();
|
|
$grid->disableActions();
|
|
|
|
$grid->model()->where('status', ProductStatus::ON_SALE);
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('supplier.company_name', '供应商')->limit(10);
|
|
$grid->column('category.name', '分类');
|
|
$grid->column('title')->limit(15);
|
|
$grid->column('picture')->image('', 60,60);
|
|
$grid->column('price');
|
|
$grid->column('original_price');
|
|
$grid->column('stock');
|
|
$grid->column('sale');
|
|
$grid->column('min_sale');
|
|
$grid->column('created_at');
|
|
$grid->column('op', '操作')
|
|
->if(fn() => true)
|
|
->then(function ($column) {
|
|
$column->append('<a class="btn btn-sm" href="' . admin_url('industry_product/list', $this->id) . '">查看</a> ');
|
|
$column->append('<a class="btn btn-sm btn-success" href="' . admin_url('industry_product/buy?pid=' . $this->id) . '">购买</a>');
|
|
});
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id')->width(2);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new IndustryProduct(['category:id,name', 'supplier:id,company_name,contact_phone']), function (Show $show) {
|
|
$show->disableEditButton();
|
|
$show->disableDeleteButton();
|
|
|
|
$show->field('id');
|
|
$show->field('supplier.company_name', '供应商');
|
|
$show->field('supplier.contact_phone', '供应商联系电话');
|
|
$show->field('category.name', '分类');
|
|
$show->field('type')->using(admin_trans('product.options.publish_type'));
|
|
$show->field('title');
|
|
$show->field('pictures')->image('', 80, 80);
|
|
$show->field('price');
|
|
$show->field('original_price');
|
|
$show->field('stock');
|
|
$show->field('sale');
|
|
$show->field('status')->using(ProductStatus::array());
|
|
$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('min_sale');
|
|
$show->field('verify_mobile');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
//购买行业产品
|
|
public function buy(Content $content): Content
|
|
{
|
|
$pid = request()->input('pid');
|
|
if (!$pid) {
|
|
Admin::exit('未指定要购买的产品');
|
|
}
|
|
return $content
|
|
->title('购买行业产品')
|
|
->body(new Card(new IndustryProductBuy()));
|
|
}
|
|
}
|