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
5.0 KiB
142 lines
5.0 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Repositories\v3\LanzuEmployees;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\v3\LanzuEmployees as EmployeesModel;
|
|
use App\Models\v3\User as UserModel;
|
|
use App\Models\v3\Store as StoreModel;
|
|
use App\Models\v3\ServicePersonnel as ServicePersonnelModel;
|
|
use App\Models\v3\Market as MarketModel;
|
|
|
|
class LanzuEmployeesController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new LanzuEmployees(), function (Grid $grid) {
|
|
//市场
|
|
$marketList = MarketModel::getMarketArray();
|
|
$roleList = config('role.position');
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('market_id')->display(function($marketId) use($marketList){
|
|
return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
|
|
});
|
|
$grid->column('user_id')->display(function($userId){
|
|
$item = UserModel::getUserInfo($userId,'real_name');
|
|
return empty($item) ? '' : $item->real_name;
|
|
});
|
|
$grid->column('store_id')->display(function($storeId){
|
|
$item = StoreModel::getStoreInfo($storeId,'name');
|
|
return empty($item) ? '' : $item->name;
|
|
});
|
|
|
|
$grid->column('role')->display(function($role) use($roleList){
|
|
$item = '';
|
|
if(!empty($role) && is_array($role)){
|
|
foreach($role as $key => $value){
|
|
$item .= '【'.$roleList[$value].'】';
|
|
}
|
|
}
|
|
return $item;
|
|
});
|
|
$grid->column('status')->width(3)->select(EmployeesModel::$_STATUS);
|
|
|
|
$grid->filter(function (Grid\Filter $filter) use($marketList,$roleList){
|
|
$filter->equal('id');
|
|
$filter->equal('market_id')->select($marketList);
|
|
$filter->equal('role')->select($roleList);
|
|
});
|
|
$grid->model()->orderBy('status','desc');
|
|
$grid->model()->orderBy('id','desc');
|
|
// 每页10条
|
|
$grid->paginate(10);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new LanzuEmployees(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('user_id')->as(function($userId){
|
|
$item = UserModel::getUserInfo($userId,'real_name');
|
|
return empty($item) ? '' : $item->real_name;
|
|
});
|
|
$show->field('store_id')->as(function($storeId){
|
|
$item = StoreModel::getStoreInfo($storeId,'name');
|
|
return empty($item) ? '' : $item->name;
|
|
});
|
|
$show->field('market_id')->as(function($marketId){
|
|
$item = MarketModel::getMarketInfo($marketId,'name');
|
|
return empty($item) ? '' : $item->name;
|
|
});
|
|
$show->field('role')->as(function($role){
|
|
$roleList = config('role.position');
|
|
$item = '';
|
|
if(!empty($role) && is_array($role)){
|
|
foreach($role as $key => $value){
|
|
$item .= ' 【'.$roleList[$value].'】';
|
|
}
|
|
}
|
|
return $item;
|
|
});
|
|
$show->field('status_text');
|
|
$show->field('note');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new LanzuEmployees(), function (Form $form) {
|
|
$userId = $form->model()->user_id;
|
|
//市场
|
|
$marketList = MarketModel::getMarketArray();
|
|
//店铺
|
|
$storeList = StoreModel::getStoreArray();
|
|
// 用户
|
|
$userList = UserModel::getUserArray();
|
|
// 已绑定的用户
|
|
$userHas = EmployeesModel::pluck('user_id')->toArray();
|
|
foreach($userList as $ku => $uv){
|
|
if($ku != 0 && in_array($ku,$userHas) && !in_array($userId,$userHas)){
|
|
unset($userList[$ku]);
|
|
}
|
|
}
|
|
$form->hidden('id');
|
|
$form->select('user_id')->required()->options($userList);
|
|
$form->select('market_id')->required()->options($marketList);
|
|
$form->multipleSelect('role')->required()->options(config('role.position'));
|
|
$form->select('store_id')->options($storeList);
|
|
$form->text('note')->maxLength(200);
|
|
|
|
$form->hidden('status')->default(1);
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
});
|
|
}
|
|
}
|