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.
		
		
		
		
		
			
		
			
				
					
					
						
							142 lines
						
					
					
						
							4.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							142 lines
						
					
					
						
							4.3 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Admin\Controllers;
							 | 
						|
								
							 | 
						|
								use App\Admin\Repositories\Order;
							 | 
						|
								use App\Common\PayType;
							 | 
						|
								use App\Models\Agent;
							 | 
						|
								use App\Models\Supplier;
							 | 
						|
								use App\Common\OrderStatus;
							 | 
						|
								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,company_name',
							 | 
						|
											'agentProduct.product:id,title,price,pictures',
							 | 
						|
											'product.supplier:id,company_name'
							 | 
						|
										]), function (Grid $grid) {
							 | 
						|
											$grid->disableCreateButton();
							 | 
						|
											$grid->disableDeleteButton();
							 | 
						|
											$grid->disableEditButton();
							 | 
						|
											$grid->disableRowSelector();
							 | 
						|
								
							 | 
						|
											if ($source = request()->input('source')) {
							 | 
						|
												if ($source == 1) {
							 | 
						|
													$grid->model()->where('product_id', 0);
							 | 
						|
												} else if ($source == 2) {
							 | 
						|
													$grid->model()->where('product_id', '<>', 0);
							 | 
						|
												}
							 | 
						|
											}
							 | 
						|
								
							 | 
						|
								            $grid->column('id')->sortable();
							 | 
						|
											$grid->column('order_no')->limit(10);
							 | 
						|
											$grid->column('agent.company_name', '代理商');
							 | 
						|
											$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 ?? 0,
							 | 
						|
															$this->agent->company_name ?? '',
							 | 
						|
															$this->product->supplier->company_name ?? '',
							 | 
						|
														]]);
							 | 
						|
												})->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());
							 | 
						|
											$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('company_name', 'id');
							 | 
						|
												$filter->equal('agent_id', '代理商')->select($option)->width(3);
							 | 
						|
								
							 | 
						|
												$option = Supplier::query()->pluck('company_name', 'id');
							 | 
						|
												$filter->equal('product.supplier_id', '供应商')->select($option)->width(3);
							 | 
						|
								
							 | 
						|
												$filter->between('created_at')->datetime()->width(4);
							 | 
						|
								
							 | 
						|
												$filter->equal('source', '产品来源')->select([1 => '代理商自营', 2 => '从供应商进货'])->width(2)->ignore();
							 | 
						|
								            });
							 | 
						|
								        });
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    /**
							 | 
						|
								     * Make a show builder.
							 | 
						|
								     *
							 | 
						|
								     * @param mixed $id
							 | 
						|
								     *
							 | 
						|
								     * @return Show
							 | 
						|
								     */
							 | 
						|
								    protected function detail($id)
							 | 
						|
								    {
							 | 
						|
								        return Show::make($id, new Order(['agent:id,company_name']), function (Show $show) {
							 | 
						|
											$show->disableDeleteButton();
							 | 
						|
											$show->disableQuickEdit();
							 | 
						|
											$show->disableEditButton();
							 | 
						|
								
							 | 
						|
								            $show->field('id');
							 | 
						|
								            $show->field('agent.company_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('timeout');
							 | 
						|
								            $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();
							 | 
						|
											$form->disableFooter();
							 | 
						|
											$form->disableHeader();
							 | 
						|
								
							 | 
						|
											$form->display('id')->width(2);
							 | 
						|
								        })->saving(function (Form $form) {
							 | 
						|
											return $form->response()->error('操作禁止');
							 | 
						|
										})->deleting(function (Form $form) {
							 | 
						|
											return $form->response()->error('操作禁止');
							 | 
						|
										});
							 | 
						|
								    }
							 | 
						|
								}
							 |