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.
		
		
		
		
		
			
		
			
				
					
					
						
							122 lines
						
					
					
						
							3.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							122 lines
						
					
					
						
							3.8 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Admin\Controllers;
							 | 
						|
								
							 | 
						|
								use App\Admin\Extensions\Grid\AuditIndustryProduct;
							 | 
						|
								use App\Admin\Repositories\IndustryProduct;
							 | 
						|
								use App\Common\ProductStatus;
							 | 
						|
								use App\Common\UserStatus;
							 | 
						|
								use Dcat\Admin\Form;
							 | 
						|
								use Dcat\Admin\Grid;
							 | 
						|
								use Dcat\Admin\Show;
							 | 
						|
								use Dcat\Admin\Http\Controllers\AdminController;
							 | 
						|
								use Illuminate\Support\Facades\Route;
							 | 
						|
								
							 | 
						|
								class IndustryProductController extends AdminController
							 | 
						|
								{
							 | 
						|
								    /**
							 | 
						|
								     * Make a grid builder.
							 | 
						|
								     *
							 | 
						|
								     * @return Grid
							 | 
						|
								     */
							 | 
						|
								    protected function grid()
							 | 
						|
								    {
							 | 
						|
								        return Grid::make(new IndustryProduct(['category']), function (Grid $grid) {
							 | 
						|
											$grid->disableCreateButton();
							 | 
						|
											$grid->disableDeleteButton();
							 | 
						|
											$grid->disableEditButton();
							 | 
						|
								
							 | 
						|
											//如果是审核页面,多加where条件判断
							 | 
						|
											if (strpos(Route::current()->uri, 'audit')) {
							 | 
						|
												$grid->model()->where('status', UserStatus::UNAUDITED);
							 | 
						|
											}
							 | 
						|
								
							 | 
						|
											$grid->column('id')->sortable();
							 | 
						|
											$grid->column('type')->using(admin_trans('product.options.publish_type'));
							 | 
						|
											$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('status')
							 | 
						|
												->if(fn() => $this->status == ProductStatus::UNAUDITED)
							 | 
						|
												->display('')
							 | 
						|
												->then(function ($column) {
							 | 
						|
													$column->append((new AuditIndustryProduct(null, 1))->setKey($this->id))->append(' ');
							 | 
						|
													$column->append((new AuditIndustryProduct(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('service_persons');
							 | 
						|
											$grid->column('min_sale');
							 | 
						|
											$grid->column('created_at');
							 | 
						|
								
							 | 
						|
											$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,name,contact_phone']), function (Show $show) {
							 | 
						|
											$show->disableDeleteButton();
							 | 
						|
											$show->disableEditButton();
							 | 
						|
								
							 | 
						|
											$show->field('id');
							 | 
						|
											$show->field('supplier.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('service_persons');
							 | 
						|
											$show->field('min_sale');
							 | 
						|
											$show->field('verify_mobile');
							 | 
						|
											$show->field('created_at');
							 | 
						|
											$show->field('updated_at');
							 | 
						|
								        });
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    /**
							 | 
						|
								     * Make a form builder.
							 | 
						|
								     *
							 | 
						|
								     * @return Form
							 | 
						|
								     */
							 | 
						|
								    protected function form()
							 | 
						|
								    {
							 | 
						|
								        return Form::make(new IndustryProduct(['supplier:id,name', 'category:id,name']), function (Form $form) {
							 | 
						|
											$form->disableDeleteButton();
							 | 
						|
								
							 | 
						|
								            $form->display('id');
							 | 
						|
								            $form->select('status')->options(ProductStatus::array());
							 | 
						|
								        })->saving(function (Form $form) {
							 | 
						|
											return $form->response()->error('操作禁止!')->refresh(); //禁止编辑,如果非要编辑的话,记录冻结和解决交易金
							 | 
						|
										})->deleting(function (Form $form) {
							 | 
						|
											return $form->response()->error('操作禁止!')->refresh();
							 | 
						|
										});
							 | 
						|
								    }
							 | 
						|
								}
							 |