header('分站管理') ->description('') ->body($this->grid()); } /** * Show interface. * * @param mixed $id * @param Content $content * @return Content */ public function show($id, Content $content) { return $content ->header('分站管理') ->description('详细') ->body($this->detail($id)); } /** * Edit interface. * * @param mixed $id * @param Content $content * @return Content */ public function edit($id, Content $content) { return $content ->header('分站管理') ->description('编辑') ->body($this->editForm($id)->edit($id)); } /** * Create interface. * * @param Content $content * @return Content */ public function create(Content $content) { return $content ->header('分站管理') ->description('创建') ->body($this->createForm()); } /** * Make a grid builder. * * @return Grid */ protected function grid() { $grid = new Grid(new Subsite); $grid->id('ID'); $grid->sitename('分站名称')->width(150); $grid->domain('分站域名')->width(150); /*$grid->m_domain('触屏版域名');*/ $grid->districtname('地区')->width(150); $states = [ 'on' => ['value' => 1, 'text' => '可用', 'color' => 'primary'], 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'default'], ]; $grid->effective('状态')->switch($states); $grid->created_at('添加时间'); $grid->updated_at('更新时间'); $grid->actions(function ($actions) use ($grid) { if (Admin::user()->can('system_subsite_edit')) { $actions->disableEdit(false); } if (Admin::user()->can('system_subsite_delete')) { $actions->disableDelete(false); } }); if (Admin::user()->can('system_subsite_delete')) { $grid->tools(function ($tools) { $tools->batch(function ($batch) { $batch->disableDelete(false); }); }); $grid->disableRowSelector(false); } if (Admin::user()->can('system_subsite_create')) { $grid->disableCreateButton(false); } return $grid; } /** * Make a show builder. * * @param mixed $id * @return Show */ protected function detail($id) { $show = new Show(Subsite::findOrFail($id)); $show->id('ID'); $show->sitename('分站名称'); $show->domain('分站域名'); $show->districtname('地区'); $show->effective('状态')->as(function ($effective) { return $effective ? '可用' : '禁用'; }); $show->created_at('添加时间'); $show->updated_at('更新时间'); return $show; } /** * Make a form builder. * * @return Form */ protected function form() { $form = new Form(new Subsite); $form->display('ID'); $form->display('添加时间'); $form->display('更新时间'); return $form; } /** * Make a form builder. * * @return Form */ protected function editForm($id) { $form = new Form(new Subsite); $subsite = Subsite::find($id); $form->text('sitename', '分站名称')->rules([ 'required', ])->setWidth(2)->setMustMark(); $form->radio('effective', '分站状态')->options([0=>'禁用',1=>'可用'])->default(1); $province_ids = CategoryDistrict::where(['parent_id'=>0])->pluck('id')->toArray(); $citys = CategoryDistrict::whereIn('parent_id', $province_ids)->selectRaw("name,concat_ws('.',parent_id, id) as id")->pluck('name', 'id'); $form->select('district', '所在地区')->options($citys)->rules(['required',])->setWidth(2)->setMustMark(); $form->hidden('districtname'); $form->text('domain', '域名绑定')->rules([ 'required', ])->setWidth(2)->setMustMark(); $defaultSubsite = Tpl::List()->where('tpl_type', 4)->pluck('name', 'id')->toArray(); $defaultSubsite[0] = '默认'; $form->select('tpl', 'PC端风格模版')->options($defaultSubsite)->rules([ 'required', ])->setWidth(2)->setMustMark()->default($subsite->tpl); $form->number('order', '排序')->min(0)->default(0); $form->image('logo', '网站logo')->uniqueName()->setWidth(4); $form->image('logo_white', '网站Logo(白底)')->uniqueName()->setWidth(4); $form->image('logo_mini', '网站Logo mini')->uniqueName()->setWidth(4); $form->image('logo_white_mini', '网站Logo mini(白底)')->uniqueName()->setWidth(4); $form->text('site_name', '网站名称')->setWidth(4); $form->text('site_keyword', '网站默认关键字')->setWidth(4); $form->textarea('site_description', '网站默认描述')->setWidth(8); $form->text('map_ak', '百度地图AK')->setWidth(4); $form->text('map_x', '默认中心点X坐标')->setWidth(2); $form->text('map_y', '默认中心点Y坐标')->setWidth(2); $form->text('max_level', '默认缩放级别')->setWidth(2); $open_option = [ 'on' => ['value' => 1], 'off' => ['value' => 0], ]; $form->switch('is_open', '是否开启微信公众号平台')->states($open_option); $form->text('app_id', '微信AppID')->setWidth(4); $form->text('app_secret', 'AppSecret')->setWidth(4); $form->text('app_token', 'AppToken')->setWidth(4); $form->text('aes_key', 'EncodingAESKey, 消息加密密钥')->setWidth(4); $form->text('wechat_name', '公众号名称')->setWidth(4); $form->text('wechat_id', '微信号')->setWidth(4); $form->image('wechat_qrcode', '微信二维码')->uniqueName()->setWidth(4); $form->saving(function (Form $form) { $district = explode('.', $form->district); if (array_has($district, 1)) { $city_id = $district[1]; $city_info = CategoryDistrict::find($city_id); $province_info = CategoryDistrict::find($city_info->parent_id); $form->districtname = $province_info->name.'/'.$city_info->name; } if ($form->effective=='on') { $form->effective=1; } elseif ($form->effective=='off') { $form->effective=0; } }); $form->saved(function (Form $form) { Cache::forget('subsites_list'); }); return $form; } protected function createForm() { $form = new Form(new Subsite); $form->text('sitename', '分站名称')->rules([ 'required', ])->setWidth(2)->setMustMark(); $form->radio('effective', '分站状态')->options([0=>'禁用',1=>'可用'])->default(1); /*$form->select('province', '省')->options( CategoryDistrict::List()->pluck('name', 'id') )->load('district', '/admin/sys/category/categoryDis')->rules([ 'required', ]); $form->select('district', '市')->rules([ 'required', ]);*/ //获取二级地区(市级) $province_ids = CategoryDistrict::where(['parent_id'=>0])->pluck('id')->toArray(); //$citys = CategoryDistrict::whereIn('parent_id', $province_ids)->get()->pluck('name', 'id'); $citys = CategoryDistrict::whereIn('parent_id', $province_ids)->selectRaw("name,concat_ws('.',parent_id, id) as id")->pluck('name', 'id'); $form->select('district', '所在地区')->options($citys)->rules([ 'required', ])->setWidth(2)->setMustMark(); $form->hidden('districtname'); $form->text('domain', '域名绑定')->rules([ 'required', ])->setWidth(3)->setMustMark(); $defaultSubsite = Tpl::List()->where('tpl_type', 4)->pluck('name', 'id')->toArray(); $defaultSubsite[0] = '默认'; $form->select('tpl', 'PC端风格模版')->options($defaultSubsite)->rules([ 'required', ])->setWidth(2)->setMustMark()->default(0); $form->number('order', '排序')->min(0)->default(0); $form->image('logo', '网站logo')->uniqueName()->setWidth(4); $form->image('logo_white', '网站Logo(白底)')->uniqueName()->setWidth(4); $form->image('logo_mini', '网站Logo mini')->uniqueName()->setWidth(4); $form->image('logo_white_mini', '网站Logo mini(白底)')->uniqueName()->setWidth(4); $form->text('site_name', '网站名称')->setWidth(4); $form->text('site_keyword', '网站默认关键字')->setWidth(4); $form->textarea('site_description', '网站默认描述')->setWidth(8); $form->text('map_ak', '百度地图AK')->setWidth(4); $form->text('map_x', '默认中心点X坐标')->setWidth(2); $form->text('map_y', '默认中心点Y坐标')->setWidth(2); $form->text('max_level', '默认缩放级别')->setWidth(2); $open_option = [ 'on' => ['value' => 1], 'off' => ['value' => 0], ]; $form->switch('is_open', '是否开启微信公众号平台')->states($open_option)->default('1'); $form->text('app_id', '微信AppID')->setWidth(4); $form->text('app_secret', 'AppSecret')->setWidth(4); $form->text('app_token', 'AppToken')->setWidth(4); $form->text('aes_key', 'EncodingAESKey, 消息加密密钥')->setWidth(4); $form->text('wechat_name', '公众号名称')->setWidth(4); $form->text('wechat_id', '微信号')->setWidth(4); $form->image('wechat_qrcode', '微信二维码')->uniqueName()->setWidth(4); $form->saving(function (Form $form) { $district = explode('.', $form->district); if (array_has($district, 1)) { $city_id = $district[1]; $city_info = CategoryDistrict::find($city_id); $province_info = CategoryDistrict::find($city_info->parent_id); $form->districtname = $province_info->name.'/'.$city_info->name; } }); return $form; } /** * Store a newly created resource in storage. * * @return mixed */ public function store() { return $this->createForm()->store(); } /** * Update the specified resource in storage. * * @param int $id * * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response */ public function update($id) { return $this->editForm($id)->update($id); } }