DistSiteController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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('domain_type')->using(admin_trans_array(config('dictionary.domain_type')));
  43. $grid->column('secondary_domain');
  44. $grid->column('custom_domain');
  45. $grid->column('updated_at')->sortable();
  46. // 过滤
  47. $grid->filter(function (Grid\Filter $filter) {
  48. $filter->panel();
  49. $filter->expand();
  50. $filter->equal('dist_code',admin_trans_label('client_code') )->width(2);
  51. $filter->equal('site_name' )->width(2);
  52. });
  53. // 排序
  54. $grid->model()->where('enabled',1)->orderBy("id",'desc');
  55. //按钮
  56. $grid->enableDialogCreate();
  57. $grid->disableDeleteButton();
  58. $grid->disableCreateButton();
  59. //批量操作
  60. $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
  61. $batch->disableDelete();
  62. });
  63. });
  64. }
  65. /**
  66. * Make a show builder.
  67. *
  68. * @param mixed $id
  69. *
  70. * @return Show
  71. */
  72. protected function detail($id)
  73. {
  74. return Show::make($id, DistAdminDistributor::with(['appearance']), function (Show $show) {
  75. $show->field('site_name');
  76. $show->field('appearance.title' ,admin_trans_field('appearance'));
  77. $show->field('copy_right');
  78. $show->field('logo')->as(function ($image) {
  79. // 开始生成 HTML
  80. $dataImages = [$image];
  81. return CommonHelper::displayImage($dataImages,100);
  82. })->unescape();
  83. $show->field('domain_type',admin_trans_label('domain_type'))->using(admin_trans_array(config('dictionary.domain_type')));
  84. $show->field('secondary_domain');
  85. $show->field('custom_domain');
  86. // $show->field('domain_type',admin_trans_label('domain'))->as(function ($domainType) {
  87. // $title = "";
  88. // if ($domainType == 0) {
  89. // $title = $this->secondary_domain;
  90. // } else {
  91. // $title = $this->custom_domain;
  92. // }
  93. // return "<span style='color:#586cb1'>$title</span>";
  94. // })->unescape();
  95. $show->field('seo_title');
  96. $show->field('seo_keywords');
  97. $show->field('seo_description');
  98. $show->divider();
  99. $show->field('company_name');
  100. $show->field('company_address');
  101. $show->field('country');
  102. $show->field('contact_number');
  103. $show->field('service_hotline');
  104. $show->field('whats_app');
  105. $show->field('facebook');
  106. $show->field('instagram');
  107. $show->field('youtube');
  108. $show->field('linkedin');
  109. $show->field('tiktok');
  110. $show->field('remark');
  111. $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
  112. $show->field('created_at');
  113. $show->field('updated_at');
  114. // 按钮
  115. $show->disableDeleteButton();
  116. });
  117. }
  118. /**
  119. * Make a form builder.
  120. *
  121. * @return Form
  122. */
  123. protected function form()
  124. {
  125. return Form::make(new DistAdminDistributor(), function (Form $form) {
  126. $form->column(6, function (Form $form) {
  127. $form->radio('domain_type')->width(9,3)
  128. ->options([0=>admin_trans_field('secondary_domain'),1=>admin_trans_field('custom_domain')])
  129. ->default(0)
  130. ->required();
  131. $form->text('secondary_domain')->width(9,3)
  132. ->required()
  133. ->help('Please enter the domain name, such as demo.'.env('TOP_DOMAIN'));
  134. $form->text('custom_domain')->width(9,3)->help('Please enter the domain name, such as www.example.com');
  135. $form->text('site_name')->width(9,3)->required();
  136. $form->text('seo_title')->width(9,3)->required();
  137. $form->text('seo_keywords')->width(9,3);
  138. $form->textarea('seo_description')->width(9,3);
  139. $form->select('appearance_id',admin_trans_field('appearance'))->width(9,3)->options(DistAppearance::selectOptions())->required();
  140. $form->image("logo")
  141. ->autoUpload()
  142. ->uniqueName()
  143. ->accept(config('distributor.upload.oss_image.accept'))
  144. ->maxSize(config('distributor.upload.oss_image.max_size'))
  145. ->dir(config("distributor.upload.directory.image").'/logo')
  146. ->width(4,3);
  147. });
  148. $form->column(6, function (Form $form) {
  149. $form->text('company_name')->width(9,3);
  150. $form->text('company_address',)->width(9,3);
  151. $form->text('service_hotline')->width(9,3);
  152. $form->text('whats_app')->width(9,3);
  153. $form->text('facebook')->width(9,3);
  154. $form->text('instagram')->width(9,3);
  155. $form->text('youtube')->width(9,3);
  156. $form->text('linkedin')->width(9,3);
  157. $form->text('tiktok')->width(9,3);
  158. $form->text('copy_right')->width(9,3);
  159. $form->textarea('statistics_js')->width(9,3);
  160. });
  161. //保存前回调
  162. $form->saving(function (Form $form) {
  163. if (!$form->isCreating()) {
  164. //如果appearance_id有变化,则更新模版与变量
  165. if ($form->model()->appearance_id != $form->input('appearance_id')) {
  166. $id = $form->model()->id;
  167. //更新模版与变量
  168. DistAppearance::switchTheme($form->input('appearance_id'), $id);
  169. }
  170. }
  171. });
  172. //
  173. //保存后回调
  174. $form->saved(function (Form $form, $result) {
  175. if ($form->isCreating()) {
  176. //创建后创建默认分类
  177. $newId = $form->getKey();
  178. $appearanceId = $form->input('appearance_id');
  179. //更新模版与变量
  180. DistAppearance::switchTheme($appearanceId, $newId);
  181. }
  182. });
  183. $form->disableDeleteButton();
  184. });
  185. }
  186. }