3 changed files with 185 additions and 0 deletions
			
			
		- 
					139app/Admin/Controllers/OrderController.php
 - 
					16app/Admin/Repositories/Order.php
 - 
					30resources/lang/zh_CN/order.php
 
@ -0,0 +1,139 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Controllers; | 
				
			|||
 | 
				
			|||
use App\Admin\Repositories\Order; | 
				
			|||
use App\Models\Agent; | 
				
			|||
use App\Models\Supplier; | 
				
			|||
use App\Service\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,agent_name', | 
				
			|||
			'agentProduct.product:id,title,price,pictures', | 
				
			|||
			'product.supplier:id,supplier_name' | 
				
			|||
		]), function (Grid $grid) { | 
				
			|||
			$grid->disableCreateButton(); | 
				
			|||
			$grid->disableDeleteButton(); | 
				
			|||
 | 
				
			|||
            $grid->column('id')->sortable(); | 
				
			|||
			$grid->column('order_no'); | 
				
			|||
			$grid->column('agent.agent_name'); | 
				
			|||
            $grid->column('mobile'); | 
				
			|||
            $grid->column('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, | 
				
			|||
						$this->agent->agent_name, | 
				
			|||
						$this->product->supplier->supplier_name, | 
				
			|||
					]]); | 
				
			|||
				})->xl(); | 
				
			|||
            $grid->column('paid_money'); | 
				
			|||
            $grid->column('price'); | 
				
			|||
//            $grid->column('refund_info');
 | 
				
			|||
			$grid->column('pay_type') | 
				
			|||
				->using([0 => '在线支付', 1 => '定金支付', 2 => '首款支付', 3 => '线下支付']); | 
				
			|||
			$grid->column('status', '订单状态') | 
				
			|||
				->select(OrderStatus::array()); | 
				
			|||
			$grid->column('paid_at')->display(fn($v) => date('Y-m-d H:i:s', $v)); | 
				
			|||
            $grid->column('created_at')->display(fn($v) => $v); | 
				
			|||
			$grid->column('updated_at')->display(fn($v) => $v); | 
				
			|||
 | 
				
			|||
            $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('agent_name', 'id'); | 
				
			|||
				$filter->equal('agent_id', '代理商')->select($option)->width(3); | 
				
			|||
 | 
				
			|||
				$option = Supplier::query()->pluck('supplier_name', 'id'); | 
				
			|||
				$filter->equal('product.supplier_id', '供应商')->select($option)->width(3); | 
				
			|||
 | 
				
			|||
				$filter->between('created_at')->width(4); | 
				
			|||
            }); | 
				
			|||
        }); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Make a show builder. | 
				
			|||
     * | 
				
			|||
     * @param mixed $id | 
				
			|||
     * | 
				
			|||
     * @return Show | 
				
			|||
     */ | 
				
			|||
    protected function detail($id) | 
				
			|||
    { | 
				
			|||
        return Show::make($id, new Order(), function (Show $show) { | 
				
			|||
			$show->disableDeleteButton(); | 
				
			|||
			$show->disableQuickEdit(); | 
				
			|||
 | 
				
			|||
            $show->field('id'); | 
				
			|||
            $show->field('agent.agent_name'); | 
				
			|||
            $show->field('mobile'); | 
				
			|||
            $show->field('name'); | 
				
			|||
            $show->field('num'); | 
				
			|||
            $show->field('order_no'); | 
				
			|||
            $show->field('paid_at')->as(fn ($v) => date('Y-m-d H:i:s', $v)); | 
				
			|||
            $show->field('paid_money'); | 
				
			|||
            $show->field('pay_type'); | 
				
			|||
			$show->field('title'); | 
				
			|||
			$show->field('picture')->image(); | 
				
			|||
            $show->field('price'); | 
				
			|||
            $show->field('product_id'); | 
				
			|||
			$show->field('status')->using(OrderStatus::array()); | 
				
			|||
            $show->field('title'); | 
				
			|||
            $show->field('user_id'); | 
				
			|||
            $show->field('created_at')->as(fn ($v) => date('Y-m-d H:i:s', $v)); | 
				
			|||
            $show->field('updated_at')->as(fn ($v) => date('Y-m-d H:i:s', $v)); | 
				
			|||
        }); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Make a form builder. | 
				
			|||
     * | 
				
			|||
     * @return Form | 
				
			|||
     */ | 
				
			|||
    protected function form() | 
				
			|||
    { | 
				
			|||
        return Form::make(new Order(), function (Form $form) { | 
				
			|||
			$form->disableDeleteButton(); | 
				
			|||
 | 
				
			|||
			$form->display('id')->width(2); | 
				
			|||
            $form->mobile('mobile'); | 
				
			|||
            $form->text('name')->width(2); | 
				
			|||
            $form->select('status')->options(OrderStatus::array())->width(2); | 
				
			|||
        }); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
	public function destroy($id) | 
				
			|||
	{ | 
				
			|||
		return false; | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -0,0 +1,16 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Repositories; | 
				
			|||
 | 
				
			|||
use App\Models\Order as Model; | 
				
			|||
use Dcat\Admin\Repositories\EloquentRepository; | 
				
			|||
 | 
				
			|||
class Order extends EloquentRepository | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * Model. | 
				
			|||
     * | 
				
			|||
     * @var string | 
				
			|||
     */ | 
				
			|||
    protected $eloquentClass = Model::class; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,30 @@ | 
				
			|||
<?php | 
				
			|||
return [ | 
				
			|||
    'labels' => [ | 
				
			|||
        'Order' => '订单', | 
				
			|||
        'order' => '订单', | 
				
			|||
    ], | 
				
			|||
    'fields' => [ | 
				
			|||
        'agent_id' => '代理商ID', | 
				
			|||
		'agent' => ['agent_name' => '代理商名称'], | 
				
			|||
        'agent_product_id' => '代理商产品', | 
				
			|||
        'coupon_id' => '优惠券', | 
				
			|||
        'mobile' => '手机号', | 
				
			|||
        'name' => '客户姓名', | 
				
			|||
        'num' => '购买数量', | 
				
			|||
        'order_no' => '订单号', | 
				
			|||
        'paid_at' => '付款时间', | 
				
			|||
        'paid_money' => '已付款金额', | 
				
			|||
        'pay_type' => '支付方式', | 
				
			|||
        'picture' => '产品图片', | 
				
			|||
        'price' => '订单总价格', | 
				
			|||
        'product_id' => '供应商产品ID', | 
				
			|||
        'refund_info' => '退款信息', | 
				
			|||
        'status' => '订单状态', | 
				
			|||
        'title' => '产品名称', | 
				
			|||
        'user_id' => '用户ID', | 
				
			|||
		'created_at' => '下单时间', | 
				
			|||
    ], | 
				
			|||
    'options' => [ | 
				
			|||
    ], | 
				
			|||
]; | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue