123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?php
- namespace App\Admin\Controllers\System;
- use App\Http\Controllers\Controller;
- use App\Models\CategoryDistrict;
- use App\Models\Subsite;
- use App\Models\Tpl;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Support\Facades\Cache;
- class SubsiteController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->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);
- }
- }
|