| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 | 
							- <?php
 
- namespace App\Admin\Controllers\Company;
 
- use App\Http\Controllers\Controller;
 
- 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\Storage;
 
- class HomeTemplateController 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 Tpl);
 
-         $grid->model()->where('tpl_type', 4)->orderBy('id', 'desc');
 
-         $grid->id('ID');
 
-         $grid->images('模板缩略图')->image('', '150', '150');
 
-         $grid->name('模板名称')->width(200);
 
-         
 
-         $grid->blade_name('压缩包名称');
 
-         
 
-         $grid->created_at('创建时间')->sortable();
 
-         
 
-         $grid->actions(function ($actions) use ($grid) {
 
-             if (Admin::user()->can('template_home_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-             if (Admin::user()->can('template_home_delete')) {
 
-                 $actions->disableDelete(false);
 
-             }
 
-             $actions->disableView(true);
 
-         });
 
-         
 
-         if (Admin::user()->can('template_home_delete')) {
 
-             $grid->tools(function ($tools) {
 
-                 $tools->batch(function ($batch) {
 
-                     $batch->disableDelete(false);
 
-                 });
 
-             });
 
-             $grid->disableRowSelector(false);
 
-         }
 
-         
 
-         if (Admin::user()->can('template_home_create')) {
 
-             $grid->disableCreateButton(false);
 
-         }
 
-         
 
-         $grid->disableFilter();
 
-         return $grid;
 
-     }
 
-     
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-     
 
-     }
 
-     
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function editForm($id)
 
-     {
 
-         $form = new Form(new Tpl);
 
-         
 
-         $form->text('name', '模板名称')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         
 
-         $form->image('images','模板缩略图')->setWidth(8)->setMustMark()->options(['layoutTemplates' => ['actionDelete'=>'']]);
 
-         
 
-         $form->file('blade_name','模板压缩包')->help('上传相同的ZIP压缩包会覆盖之前的文件!')->uniqueName()->setWidth(8)->setMustMark()->options(['layoutTemplates' => ['actionDelete'=>'']]);
 
-         
 
-         $form->saving(function (Form $form) use($id) {
 
-             $form->old_blade_name = Tpl::find($id)->blade_name;
 
-         });
 
-         
 
-         $form->saved(function (Form $form) {
 
-             if($form->blade_name!=null && $form->blade_name!='_file_del_'){
 
-                 Storage::disk('public')->deleteDirectory('template/home/'.$form->old_blade_name);
 
-                 $model = $form->model();
 
-                 $new_blade = $model->blade_name;
 
-                 $zip = new \Chumper\Zipper\Zipper();
 
-                 $zip->zip(Storage::disk('public')->path($new_blade))->extractTo(Storage::disk('public')->path('template/home/'.$form->old_blade_name));
 
-                 $zip->close();
 
-                 $model->blade_name = $form->old_blade_name;
 
-                 $model->save();
 
-                 Storage::disk('public')->delete($new_blade);
 
-             }
 
-         });
 
-         return $form;
 
-     }
 
-     
 
-     protected function createForm()
 
-     {
 
-         $form = new Form(new Tpl);
 
-         
 
-         $form->text('name', '模板名称')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         
 
-         $form->image('images','模板缩略图')->setWidth(8)->setMustMark()->rules([
 
-             'required',
 
-         ]);
 
-         $form->file('blade_name','模板压缩包')->help('上传相同的ZIP压缩包会覆盖之前的文件!')->rules('mimes:zip')->uniqueName()
 
-             ->setWidth(8)->setMustMark()->rules([
 
-                 'required',
 
-             ]);
 
-         $form->hidden('tpl_type')->default(4);
 
-     
 
-         $form->hidden('display')->default(1);
 
-         $form->hidden('price')->default(0);
 
-         
 
-         $form->saved(function (Form $form) {
 
-             $model = $form->model();
 
-             $new_blade = $model->blade_name;
 
-             $template_dir=uniqid();
 
-             $zip = new \Chumper\Zipper\Zipper();
 
-             $zip->zip(Storage::disk('public')->path($new_blade))->extractTo(Storage::disk('public')->path('template/home/'.$template_dir));
 
-             $zip->close();
 
-             $model->blade_name = $template_dir;
 
-             $model->save();
 
-             Storage::disk('public')->delete($new_blade);
 
-         });
 
-         
 
-         return $form;
 
-     }
 
-     
 
-     public function store()
 
-     {
 
-         return $this->createForm()->store();
 
-     }
 
-     
 
-     
 
-     public function update($id)
 
-     {
 
-         return $this->editForm($id)->update($id);
 
-     }
 
-     
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new Tpl);
 
-         
 
-         $form->display('ID');
 
-         $form->display('Created at');
 
-         $form->display('Updated at');
 
-         
 
-         return $form;
 
-     }
 
-     
 
-     public function destroy($id)
 
-     {
 
-         if (!$id) {
 
-             $data = [
 
-                 'status'  => false,
 
-                 'message' => '模板不存在!!',
 
-             ];
 
-             return response()->json($data);
 
-         }
 
-         $id_arr =  explode(',', $id);
 
-         
 
-         \DB::beginTransaction();
 
-         try {
 
-             Tpl::whereIn('id', $id_arr)->delete();
 
-             
 
-             Subsite::whereIn('tpl', $id_arr)->update(['tpl'=>0]);
 
-             
 
-             $data = [
 
-                 'status'  => true,
 
-                 'message' => '删除成功!',
 
-             ];
 
-             \DB::commit();
 
-             return response()->json($data);
 
-         } catch (\Exception $e) {
 
-             \DB::rollback();
 
-             $data = [
 
-                 'status'  => false,
 
-                 'message' => '删除失败!',
 
-             ];
 
-             return response()->json($data);
 
-         }
 
-     }
 
-     
 
-     
 
- }
 
 
  |