DistSiteController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Grid\InitAppearance;
  4. use App\Admin\Repositories\DistAdminDistributor;
  5. use App\Admin\Repositories\DistAppearance;
  6. use App\Libraries\CommonHelper;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. use Dcat\Admin\Layout\Content;
  11. use Dcat\Admin\Show;
  12. use Illuminate\Support\Facades\DB;
  13. class DistSiteController extends AdminController
  14. {
  15. /**
  16. * page index
  17. */
  18. public function index(Content $content)
  19. {
  20. return $content
  21. ->header(admin_trans( 'admin.site_management'))
  22. ->description('')
  23. ->breadcrumb(['text'=>'list','url'=>''])
  24. ->body($this->grid());
  25. }
  26. /**
  27. * Make a grid builder.
  28. *
  29. * @return Grid
  30. */
  31. protected function grid()
  32. {
  33. return Grid::make(DistAdminDistributor::with(['appearance']), function (Grid $grid) {
  34. //默认分页条数
  35. $grid->paginate(config('admin.per_page'));
  36. //指定视图,去掉删除按钮
  37. $grid->view('admin.grid.table');
  38. $grid->column('id')->sortable();
  39. $grid->column('client_code',admin_trans_label('distributor_code'))->width('15%');
  40. $grid->column('site_name');
  41. $grid->column('appearance.title' ,admin_trans_field('appearance'));
  42. $grid->column('secondary_domain');
  43. $grid->column('custom_domain');
  44. $grid->column('updated_at')->sortable();
  45. // 过滤
  46. $grid->filter(function (Grid\Filter $filter) {
  47. $filter->panel();
  48. $filter->expand();
  49. $filter->equal('dist_code',admin_trans_label('client_code') )->width(2);
  50. $filter->equal('site_name' )->width(2);
  51. });
  52. // 排序
  53. $grid->model()->where('enabled',1)->orderBy("id",'desc');
  54. //按钮
  55. $grid->enableDialogCreate();
  56. $grid->disableDeleteButton();
  57. $grid->disableCreateButton();
  58. //批量操作
  59. $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
  60. $batch->disableDelete();
  61. });
  62. });
  63. }
  64. /**
  65. * Make a show builder.
  66. *
  67. * @param mixed $id
  68. *
  69. * @return Show
  70. */
  71. protected function detail($id)
  72. {
  73. return Show::make($id, DistAdminDistributor::with(['appearance']), function (Show $show) {
  74. $show->field('site_name');
  75. $show->field('appearance.title' ,admin_trans_field('appearance'));
  76. $show->field('copy_right');
  77. $show->field('logo')->as(function ($image) {
  78. // 开始生成 HTML
  79. $dataImages = [$image];
  80. return CommonHelper::displayImage($dataImages,100);
  81. })->unescape();
  82. $show->field('domain_type',admin_trans_label('domain_type'))->using(admin_trans_array(config('dictionary.domain_type')));
  83. $show->field('secondary_domain');
  84. $show->field('custom_domain');
  85. // $show->field('domain_type',admin_trans_label('domain'))->as(function ($domainType) {
  86. // $title = "";
  87. // if ($domainType == 0) {
  88. // $title = $this->secondary_domain;
  89. // } else {
  90. // $title = $this->custom_domain;
  91. // }
  92. // return "<span style='color:#586cb1'>$title</span>";
  93. // })->unescape();
  94. $show->field('seo_title');
  95. $show->field('seo_keywords');
  96. $show->field('seo_description');
  97. $show->divider();
  98. $show->field('company_name');
  99. $show->field('company_address');
  100. $show->field('country');
  101. $show->field('contact_number');
  102. $show->field('service_hotline');
  103. $show->field('whats_app');
  104. $show->field('facebook');
  105. $show->field('instagram');
  106. $show->field('youtube');
  107. $show->field('linkedin');
  108. $show->field('tiktok');
  109. $show->field('remark');
  110. $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
  111. $show->field('created_at');
  112. $show->field('updated_at');
  113. // 按钮
  114. $show->disableDeleteButton();
  115. });
  116. }
  117. /**
  118. * Make a form builder.
  119. *
  120. * @return Form
  121. */
  122. protected function form()
  123. {
  124. return Form::make(new DistAdminDistributor(), function (Form $form) {
  125. $form->column(6, function (Form $form) {
  126. $form->text('site_name')->width(9,3)->required();
  127. $form->text('seo_title')->width(9,3)->required();
  128. $form->text('seo_keywords')->width(9,3);
  129. $form->textarea('seo_description')->width(9,3);
  130. $form->select('appearance_id',admin_trans_field('appearance'))->width(9,3)->options(DistAppearance::selectOptions())->required();
  131. $form->image("logo")
  132. ->autoUpload()
  133. ->uniqueName()
  134. ->accept(config('distributor.upload.oss_image.accept'))
  135. ->maxSize(config('distributor.upload.oss_image.max_size'))
  136. ->dir(config("distributor.upload.directory.image").'/logo')
  137. ->width(4,3);
  138. });
  139. $form->column(6, function (Form $form) {
  140. $form->text('company_name')->width(9,3);
  141. $form->text('company_address',)->width(9,3);
  142. $form->text('service_hotline')->width(9,3);
  143. $form->text('whats_app')->width(9,3);
  144. $form->text('facebook')->width(9,3);
  145. $form->text('instagram')->width(9,3);
  146. $form->text('youtube')->width(9,3);
  147. $form->text('linkedin')->width(9,3);
  148. $form->text('tiktok')->width(9,3);
  149. $form->text('copy_right')->width(9,3);
  150. $form->textarea('statistics_js')->width(9,3);
  151. });
  152. //保存前回调
  153. $form->saving(function (Form $form) {
  154. if (!$form->isCreating()) {
  155. //如果appearance_id有变化,则更新模版与变量
  156. if ($form->model()->appearance_id != $form->input('appearance_id')) {
  157. $id = $form->model()->id;
  158. //更新模版与变量
  159. DistAppearance::switchTheme($form->input('appearance_id'), $id);
  160. }
  161. }
  162. });
  163. //
  164. //保存后回调
  165. $form->saved(function (Form $form, $result) {
  166. if ($form->isCreating()) {
  167. //创建后创建默认分类
  168. $newId = $form->getKey();
  169. $appearanceId = $form->input('appearance_id');
  170. //更新模版与变量
  171. DistAppearance::switchTheme($appearanceId, $newId);
  172. }
  173. });
  174. $form->disableDeleteButton();
  175. });
  176. }
  177. }