WeiXinController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace App\Admin\Controllers\System;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\WeiXin;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Layout\Content;
  9. use Encore\Admin\Show;
  10. use Illuminate\Validation\Rule;
  11. class WeiXinController extends Controller
  12. {
  13. use HasResourceActions;
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header('微信平台列表')
  24. ->description('')
  25. ->body($this->grid());
  26. }
  27. /**
  28. * Show interface.
  29. *
  30. * @param mixed $id
  31. * @param Content $content
  32. * @return Content
  33. */
  34. public function show($id, Content $content)
  35. {
  36. return $content
  37. ->header('微信平台列表')
  38. ->description('详细')
  39. ->body($this->detail($id));
  40. }
  41. /**
  42. * Edit interface.
  43. *
  44. * @param mixed $id
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function edit($id, Content $content)
  49. {
  50. return $content
  51. ->header('微信平台列表')
  52. ->description('编辑')
  53. ->body($this->editForm($id)->edit($id));
  54. }
  55. /**
  56. * Create interface.
  57. *
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function create(Content $content)
  62. {
  63. return $content
  64. ->header('微信平台列表')
  65. ->description('创建')
  66. ->body($this->createForm());
  67. }
  68. /**
  69. * Make a grid builder.
  70. *
  71. * @return Grid
  72. */
  73. protected function grid()
  74. {
  75. $grid = new Grid(new WeiXin);
  76. $grid->id('ID');
  77. $grid->name('公众号名称');
  78. $grid->number('微信号');
  79. $grid->images('微信二维码图片')->image('', 100, 100);
  80. $grid->created_at('添加时间');
  81. $grid->updated_at('更新时间');
  82. return $grid;
  83. }
  84. /**
  85. * Make a show builder.
  86. *
  87. * @param mixed $id
  88. * @return Show
  89. */
  90. protected function detail($id)
  91. {
  92. $show = new Show(WeiXin::findOrFail($id));
  93. $show->id('ID');
  94. $show->name('公众号名称');
  95. $show->number('微信号');
  96. $show->app_token('AppToken');
  97. $show->app_id('AppId');
  98. $show->encoding_ase_key('EncodingAESKey');
  99. $show->images('微信二维码图片');
  100. $show->created_at('添加时间');
  101. $show->updated_at('更新时间');
  102. return $show;
  103. }
  104. /**
  105. * Make a form builder.
  106. *
  107. * @return Form
  108. */
  109. protected function editForm($id)
  110. {
  111. $form = new Form(new WeiXin);
  112. $form->display('name', '公众号名称');
  113. $form->display('number', '微信号');
  114. $form->text('app_token', 'AppToken')->rules([
  115. 'required',
  116. ]);
  117. $form->text('app_id', 'AppId')->rules([
  118. 'required',
  119. Rule::unique('wei_xins')->ignore($id),
  120. ]);
  121. $form->password('app_secret', 'AppSecret')->rules([
  122. 'required',
  123. ]);
  124. $form->text('encoding_ase_key', 'EncodingAESKey');
  125. $form->image('images', '微信二维码图片')->uniqueName();
  126. $form->tools(function (Form\Tools $tools) {
  127. $tools->disableDelete();
  128. });
  129. return $form;
  130. }
  131. protected function createForm()
  132. {
  133. $form = new Form(new WeiXin);
  134. $form->text('name', '公众号名称')->rules([
  135. 'required',
  136. 'unique:wei_xins',
  137. ]);
  138. $form->text('number', '微信号')->rules([
  139. 'required',
  140. 'unique:wei_xins',
  141. ]);
  142. $form->text('app_token', 'AppToken')->rules([
  143. 'required',
  144. ]);
  145. $form->text('app_id', 'AppId')->rules([
  146. 'required',
  147. 'unique:wei_xins',
  148. ]);
  149. $form->text('app_secret', 'AppSecret')->rules([
  150. 'required',
  151. ]);
  152. $form->text('encoding_ase_key', 'EncodingAESKey')->placeholder('消息加解密密钥');
  153. $form->image('images', '微信二维码图片')->uniqueName();
  154. $form->tools(function (Form\Tools $tools) {
  155. $tools->disableDelete();
  156. });
  157. return $form;
  158. }
  159. /**
  160. * Store a newly created resource in storage.
  161. *
  162. * @return mixed
  163. */
  164. public function store()
  165. {
  166. return $this->createForm()->store();
  167. }
  168. /**
  169. * Update the specified resource in storage.
  170. *
  171. * @param int $id
  172. *
  173. * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
  174. */
  175. public function update($id)
  176. {
  177. return $this->editForm($id)->update($id);
  178. }
  179. /**
  180. * Make a form builder.
  181. *
  182. * @return Form
  183. */
  184. protected function form()
  185. {
  186. $form = new Form(new WeiXin);
  187. $form->display('ID');
  188. $form->display('Created at');
  189. $form->display('Updated at');
  190. return $form;
  191. }
  192. }