PaymentController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. namespace App\Admin\Controllers\Tool;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Payment;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class PaymentController 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. $js = <<<EOT
  64. $(document).ready(function() {
  65. $('.radio-inline,.iCheck-helper').click(function() {
  66. var value = $(this).closest(".radio-inline").find("input:radio").val();
  67. if(value==3){
  68. $(this).closest(".form-group").nextAll().hide();
  69. }else {
  70. $(".fields-group .form-group").show();
  71. }
  72. });
  73. });
  74. EOT;
  75. Admin::script($js);
  76. return $content
  77. ->header('支付方式')
  78. ->description('创建')
  79. ->body($this->createForm());
  80. }
  81. /**
  82. * Make a grid builder.
  83. *
  84. * @return Grid
  85. */
  86. protected function grid()
  87. {
  88. $grid = new Grid(new Payment);
  89. $grid->id('ID');
  90. $grid->name('插件名称');
  91. $grid->alias('插件别名');
  92. $grid->account('账号');
  93. $grid->s_intro('简单描述');
  94. $grid->type('类型')->display(function ($values) {
  95. switch ($values) {
  96. case 1:
  97. $values = '支付宝';
  98. break;
  99. case 2:
  100. $values = '微信';
  101. break;
  102. case 3:
  103. $values = '线下转账';
  104. break;
  105. default:
  106. $values = '支付宝';
  107. break;
  108. }
  109. return $values;
  110. });
  111. $grid->created_at('添加时间');
  112. $grid->updated_at('更新时间');
  113. $grid->disableCreateButton();
  114. $grid->actions(function ($actions) {
  115. $actions->disableDelete();
  116. $actions->disableView();
  117. });
  118. $grid->tools(function (Grid\Tools $tools) {
  119. $tools->disableFilterButton();
  120. $tools->batch(function ($batch) {
  121. $batch->disableDelete();
  122. });
  123. });
  124. return $grid;
  125. }
  126. /**
  127. * Make a show builder.
  128. *
  129. * @param mixed $id
  130. * @return Show
  131. */
  132. protected function detail($id)
  133. {
  134. $show = new Show(Payment::findOrFail($id));
  135. $Payment = Payment::findOrFail($id);
  136. $show->id('ID');
  137. $show->name('插件名称');
  138. $show->alias('插件别名');
  139. $show->s_intro('简单描述');
  140. $show->introd('描述');
  141. $show->type('类型')->as(function ($values) {
  142. switch ($values) {
  143. case 1:
  144. $values = '支付宝';
  145. break;
  146. case 2:
  147. $values = '微信';
  148. break;
  149. case 3:
  150. $values = '线下转账';
  151. break;
  152. default:
  153. $values = '支付宝';
  154. break;
  155. }
  156. return $values;
  157. });
  158. if ($Payment['type']!=3) {
  159. $show->partnerid('合作者身份(Partner ID)');
  160. $show->ytauthkey('安全校验码(Key)');
  161. $show->account('账号');
  162. }
  163. $show->created_at('添加时间');
  164. $show->updated_at('更新时间');
  165. $show->panel()
  166. ->tools(function ($tools) {
  167. $tools->disableDelete();
  168. });
  169. return $show;
  170. }
  171. /**
  172. * Make a form builder.
  173. *
  174. * @return Form
  175. */
  176. protected function form()
  177. {
  178. $form = new Form(new Payment);
  179. $form->display('ID');
  180. $form->display('添加时间');
  181. $form->display('更新时间');
  182. return $form;
  183. }
  184. /**
  185. * Make a form builder.
  186. *
  187. * @return Form
  188. */
  189. protected function editForm($id)
  190. {
  191. $form = new Form(new Payment);
  192. $Payment = Payment::findOrFail($id);
  193. switch ($Payment['type']) {
  194. case 1:
  195. $values = '支付宝';
  196. break;
  197. case 2:
  198. $values = '微信';
  199. break;
  200. case 3:
  201. $values = '线下转账';
  202. break;
  203. default:
  204. $values = '支付宝';
  205. break;
  206. }
  207. $form->text('name', '插件名称')->rules('required');
  208. $form->text('alias', '插件别名')->rules('required');
  209. $form->text('s_intro', '简单描述')->rules('required');
  210. $form->textarea('introd', '详细描述')->rules('required');
  211. $form->radio('type', '类型')->options([$Payment['type']=>$values]);
  212. if ($Payment['type']!=3) {
  213. $form->text('partnerid', '合作者身份(Partner ID)');
  214. $form->password('ytauthkey', '安全校验码(Key)');
  215. $form->text('account', '账号');
  216. }
  217. $form->tools(function (Form\Tools $tools) {
  218. $tools->disableDelete();
  219. });
  220. $form->footer(function ($footer) {
  221. // 去掉`重置`按钮
  222. $footer->disableReset();
  223. // 去掉`查看`checkbox
  224. $footer->disableViewCheck();
  225. // 去掉`继续编辑`checkbox
  226. $footer->disableEditingCheck();
  227. // 去掉`继续创建`checkbox
  228. $footer->disableCreatingCheck();
  229. });
  230. return $form;
  231. }
  232. protected function createForm()
  233. {
  234. $form = new Form(new Payment);
  235. $form->text('name', '插件名称')->rules('required');
  236. $form->text('alias', '插件别名')->rules('required');
  237. $form->text('s_intro', '简单描述')->rules('required');
  238. $form->textarea('introd', '详细描述')->rules('required');
  239. $form->radio('type', '类型')->options(['1'=>'支付宝','2'=>'微信','3'=>'线下转账'])->default(1);
  240. $form->text('partnerid', '合作者身份(Partner ID)');
  241. $form->text('ytauthkey', '安全校验码(Key)');
  242. $form->text('account', '账号');
  243. return $form;
  244. }
  245. /**
  246. * Store a newly created resource in storage.
  247. *
  248. * @return mixed
  249. */
  250. public function store()
  251. {
  252. return $this->createForm()->store();
  253. }
  254. /**
  255. * Update the specified resource in storage.
  256. *
  257. * @param int $id
  258. *
  259. * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
  260. */
  261. public function update($id)
  262. {
  263. return $this->editForm($id)->update($id);
  264. }
  265. }