DistAdminDistributorController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 App\Models\DistProductCategory;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. use Dcat\Admin\Layout\Content;
  13. use Dcat\Admin\Admin;
  14. use Illuminate\Support\Facades\DB;
  15. class DistAdminDistributorController extends AdminController
  16. {
  17. /**
  18. * page index
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header(admin_trans( 'admin.distro_management'))
  24. ->description('')
  25. ->breadcrumb(['text'=>'list','url'=>''])
  26. ->body($this->grid());
  27. }
  28. /**
  29. * Make a grid builder.
  30. *
  31. * @return Grid
  32. */
  33. protected function grid()
  34. {
  35. return Grid::make(DistAdminDistributor::with(['appearance']), function (Grid $grid) {
  36. //默认分页条数
  37. $grid->paginate(config('admin.per_page'));
  38. //指定视图,去掉删除按钮
  39. $grid->view('admin.grid.table');
  40. $grid->column('id')->sortable();
  41. $grid->column('client_code',admin_trans_label('client_code'))->width('15%');
  42. $grid->column('distr_email',admin_trans_label('email'));
  43. $grid->column('dist_contact_number',admin_trans_label('contact_number'));
  44. $grid->column('secondary_domain');
  45. $grid->column('country',);
  46. $grid->column('enabled')->switch();
  47. $grid->column('created_at')->sortable();
  48. // 过滤
  49. $grid->filter(function (Grid\Filter $filter) {
  50. $filter->panel();
  51. $filter->expand();
  52. $filter->equal('dist_code',admin_trans_label('client_code') )->width(2);
  53. $filter->equal('secondary_domain')->width(2);
  54. $filter->equal('enabled')->select(admin_trans_array(config('dictionary.enabled')))->width(2);
  55. });
  56. // 排序
  57. $grid->model()->orderBy("id",'desc');
  58. //按钮
  59. $grid->showQuickEditButton();
  60. $grid->enableDialogCreate();
  61. $grid->disableEditButton();
  62. $grid->disableDeleteButton();
  63. //$grid->disableBatchDelete();
  64. //批量操作
  65. $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
  66. $batch->disableDelete();
  67. $batch->add(new InitAppearance());
  68. });
  69. });
  70. }
  71. /**
  72. * Make a show builder.
  73. *
  74. * @param mixed $id
  75. *
  76. * @return Show
  77. */
  78. protected function detail($id)
  79. {
  80. return Show::make($id, DistAdminDistributor::with(['appearance']), function (Show $show) {
  81. $show->field('dist_code',admin_trans_label('client_code'));
  82. $show->field('distr_email',admin_trans_label('email'));
  83. $show->field('dist_contact_number',admin_trans_label('contact_number'));
  84. $show->field('secondary_domain');
  85. $show->field('country');
  86. $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
  87. $show->field('created_at');
  88. $show->field('updated_at');
  89. /*
  90. $show->field('company_name');
  91. $show->field('company_address');
  92. $show->field('site_name');
  93. $show->field('logo')->as(function ($image) {
  94. // 开始生成 HTML
  95. $dataImages = [$image];
  96. return CommonHelper::displayImage($dataImages,100);
  97. })->unescape();
  98. $show->field('domain_type',admin_trans_label('domain'))->as(function ($domainType) {
  99. $title = "";
  100. if ($domainType == 0) {
  101. $title = $this->secondary_domain;
  102. } else {
  103. $title = $this->custom_domain;
  104. }
  105. return "<span style='color:#586cb1'>$title</span>";
  106. })->unescape();
  107. $show->field('appearance.title' ,admin_trans_field('appearance'));
  108. $show->field('country');
  109. $show->field('contact_number');
  110. $show->field('service_hotline');
  111. $show->field('whats_app');
  112. $show->field('facebook');
  113. $show->field('instagram');
  114. $show->field('youtube');
  115. $show->field('linkedin');
  116. $show->field('tiktok');
  117. $show->field('remark');
  118. $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
  119. $show->field('created_at');
  120. $show->field('updated_at');
  121. $show->field('copy_right');
  122. $show->field('seo_title');
  123. $show->field('seo_keywords');
  124. $show->field('seo_description');
  125. */
  126. // 按钮
  127. $show->disableDeleteButton();
  128. });
  129. }
  130. /**
  131. * Make a form builder.
  132. *
  133. * @return Form
  134. */
  135. protected function form()
  136. {
  137. return Form::make(new DistAdminDistributor(), function (Form $form) {
  138. $form->text('dist_code',admin_trans_label('client_code'))->width(9,3)->required();
  139. $form->text('distr_email',admin_trans_label('email'))->width(9,3);
  140. $form->text('dist_contact_number',admin_trans_label('contact_number'))->width(9,3);
  141. $form->text('secondary_domain')->width(9,3)
  142. ->required()
  143. ->help('Please enter the domain name, such as demo.'.env('TOP_DOMAIN'));
  144. $form->text('country')->width(9,3)->required();
  145. $form->switch('enabled')->width(9,3)->default(1);
  146. /*
  147. $form->text('company_name')->width(9,3)->required();
  148. $form->text('company_address',)->width(9,3);
  149. $form->text('site_name')->width(9,3)->required();
  150. $form->image("logo")
  151. ->autoUpload()
  152. ->uniqueName()
  153. ->accept(config('distributor.upload.oss_image.accept'))
  154. ->maxSize(config('distributor.upload.oss_image.max_size'))
  155. ->dir(config("distributor.upload.directory.image").'/logo')
  156. ->width(9,3);
  157. $form->radio('domain_type')
  158. ->width(9,3)
  159. ->when(0, function (Form $form) {
  160. $form->text('secondary_domain')->width(9,3)->help('Please enter the domain name, such as demo.'.env('TOP_DOMAIN'));
  161. })
  162. ->when(1, function (Form $form) {
  163. $form->text('custom_domain')->width(9,3)->help('Please enter the domain name, such as www.example.com,and bind the domain name to the IP address '.env('DIST_SITE_IP'));
  164. })
  165. ->default(0)
  166. ->options([0=>'second-level domain',1=>'custom domain'])
  167. ->required();
  168. $form->select('appearance_id',admin_trans_field('appearance'))->width(9,3)->options(DistAppearance::selectOptions())->required();
  169. $form->text('country')->width(9,3)->required();
  170. $form->text('contact_number')->width(9,3);
  171. $form->text('service_hotline')->width(9,3);
  172. $form->text('whats_app')->width(9,3);
  173. $form->text('facebook')->width(9,3);
  174. $form->text('instagram')->width(9,3);
  175. $form->text('youtube')->width(9,3);
  176. $form->text('linkedin')->width(9,3);
  177. $form->text('tiktok')->width(9,3);
  178. $form->textarea('remark')->width(9,3);
  179. $form->switch('enabled')->width(9,3)->default(1);
  180. $form->text('copy_right')->width(9,3);
  181. $form->text('seo_title')->width(9,3)->required();
  182. $form->text('seo_keywords')->width(9,3);
  183. $form->textarea('seo_description')->width(9,3);
  184. */
  185. //保存前回调
  186. // $form->saving(function (Form $form) {
  187. // if (!$form->isCreating()) {
  188. // //如果appearance_id有变化,则更新模版与变量
  189. // if ($form->model()->appearance_id != $form->input('appearance_id')) {
  190. // $id = $form->model()->id;
  191. // //更新模版与变量
  192. // DistAppearance::switchTheme($form->input('appearance_id'), $id);
  193. // }
  194. // }
  195. // });
  196. //保存后回调
  197. // $form->saved(function (Form $form, $result) {
  198. // if ($form->isCreating()) {
  199. // //创建后创建默认分类
  200. // $newId = $form->getKey();
  201. // $appearanceId = $form->input('appearance_id');
  202. // //初始化分销商
  203. // DistAdminDistributor::initDist($appearanceId,$newId);
  204. // //更新模版与变量
  205. // DistAppearance::switchTheme($appearanceId, $newId);
  206. // }
  207. // });
  208. });
  209. }
  210. /*
  211. * 新增事件事务
  212. */
  213. // public function store()
  214. // {
  215. // try {
  216. // DB::beginTransaction();
  217. // $result = parent::store();
  218. // DB::commit();
  219. // return $result;
  220. // } catch (\Exception $e) {
  221. // DB::rollBack();
  222. // throw $e;
  223. // }
  224. // }
  225. }