3 changed files with 128 additions and 0 deletions
-
111app/AdminSupplier/Controllers/AgentController.php
-
16app/AdminSupplier/Repositories/Agent.php
-
1app/AdminSupplier/routes.php
@ -0,0 +1,111 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminSupplier\Repositories\Agent; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Models\Agent as AgentModel; |
||||
|
use App\Common\AgentType; |
||||
|
use App\Common\UserStatus; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
|
||||
|
class AgentController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$model = AgentModel::whereHas('agentProduct', function($query) { |
||||
|
//只统计在售产品的代理商
|
||||
|
return $query->where('status', ProductStatus::ON_SALE) |
||||
|
->whereHas('product', function ($query) { |
||||
|
return $query->where(['supplier_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]); |
||||
|
}); |
||||
|
}); |
||||
|
return Grid::make($model, function (Grid $grid) { |
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableActions(); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('name'); |
||||
|
$grid->column('type')->using(AgentType::array()); |
||||
|
$grid->column('company_name'); |
||||
|
$grid->column('address'); |
||||
|
$grid->column('director'); |
||||
|
$grid->column('contact_phone'); |
||||
|
$grid->column('logo')->image(60, 60); |
||||
|
$grid->column('license_pic')->image(60, 60); |
||||
|
$grid->column('status')->using(UserStatus::array()); |
||||
|
$grid->column('created_at', '注册时间'); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->panel(); |
||||
|
|
||||
|
$filter->equal('id')->width(2); |
||||
|
$filter->like('name')->width(2); |
||||
|
$filter->like('company_name')->width(3); |
||||
|
$filter->equal('contact_phone')->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Agent(), function (Show $show) { |
||||
|
$show->disableDeleteButton(); |
||||
|
$show->disableEditButton(); |
||||
|
|
||||
|
//目前逻辑是不允许供应商查看详情页,若需要打开详情页查看,需要再判断是不是当前供应商所属的代理商
|
||||
|
$show->field('id'); |
||||
|
/*$show->field('address'); |
||||
|
$show->field('avatar'); |
||||
|
$show->field('company_name'); |
||||
|
$show->field('contact_phone'); |
||||
|
$show->field('director'); |
||||
|
$show->field('license_pic'); |
||||
|
$show->field('logo'); |
||||
|
$show->field('name'); |
||||
|
$show->field('rate'); |
||||
|
$show->field('status'); |
||||
|
$show->field('type'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at');*/ |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Agent(), function (Form $form) { |
||||
|
$form->disableFooter(); |
||||
|
$form->disableHeader(); |
||||
|
$form->disableDeleteButton(); |
||||
|
|
||||
|
$form->display('id'); |
||||
|
})->saving(function (Form $form) { |
||||
|
return $form->response()->error('禁止操作'); |
||||
|
})->deleting(function (Form $form) { |
||||
|
return $form->response()->error('禁止删除'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\Agent as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class Agent extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue