123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- namespace App\Admin\Controllers\Tool;
- use App\Http\Controllers\Controller;
- use App\Models\Payment;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class PaymentController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('支付方式')
- ->description('')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('支付方式')
- ->description('详细')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('支付方式')
- ->description('编辑')
- ->body($this->editForm($id)->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- $js = <<<EOT
- $(document).ready(function() {
- $('.radio-inline,.iCheck-helper').click(function() {
- var value = $(this).closest(".radio-inline").find("input:radio").val();
- if(value==3){
- $(this).closest(".form-group").nextAll().hide();
- }else {
- $(".fields-group .form-group").show();
- }
- });
- });
- EOT;
- Admin::script($js);
- return $content
- ->header('支付方式')
- ->description('创建')
- ->body($this->createForm());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Payment);
- $grid->id('ID');
- $grid->name('插件名称');
- $grid->alias('插件别名');
- $grid->account('账号');
- $grid->s_intro('简单描述');
- $grid->type('类型')->display(function ($values) {
- switch ($values) {
- case 1:
- $values = '支付宝';
- break;
- case 2:
- $values = '微信';
- break;
- case 3:
- $values = '线下转账';
- break;
- default:
- $values = '支付宝';
- break;
- }
- return $values;
- });
- $grid->created_at('添加时间');
- $grid->updated_at('更新时间');
- $grid->disableCreateButton();
- $grid->actions(function ($actions) {
- $actions->disableDelete();
- $actions->disableView();
- });
- $grid->tools(function (Grid\Tools $tools) {
- $tools->disableFilterButton();
- $tools->batch(function ($batch) {
- $batch->disableDelete();
- });
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Payment::findOrFail($id));
- $Payment = Payment::findOrFail($id);
- $show->id('ID');
- $show->name('插件名称');
- $show->alias('插件别名');
- $show->s_intro('简单描述');
- $show->introd('描述');
- $show->type('类型')->as(function ($values) {
- switch ($values) {
- case 1:
- $values = '支付宝';
- break;
- case 2:
- $values = '微信';
- break;
- case 3:
- $values = '线下转账';
- break;
- default:
- $values = '支付宝';
- break;
- }
- return $values;
- });
- if ($Payment['type']!=3) {
- $show->partnerid('合作者身份(Partner ID)');
- $show->ytauthkey('安全校验码(Key)');
- $show->account('账号');
- }
- $show->created_at('添加时间');
- $show->updated_at('更新时间');
- $show->panel()
- ->tools(function ($tools) {
- $tools->disableDelete();
- });
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Payment);
- $form->display('ID');
- $form->display('添加时间');
- $form->display('更新时间');
- return $form;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function editForm($id)
- {
- $form = new Form(new Payment);
- $Payment = Payment::findOrFail($id);
- switch ($Payment['type']) {
- case 1:
- $values = '支付宝';
- break;
- case 2:
- $values = '微信';
- break;
- case 3:
- $values = '线下转账';
- break;
- default:
- $values = '支付宝';
- break;
- }
- $form->text('name', '插件名称')->rules('required');
- $form->text('alias', '插件别名')->rules('required');
- $form->text('s_intro', '简单描述')->rules('required');
- $form->textarea('introd', '详细描述')->rules('required');
- $form->radio('type', '类型')->options([$Payment['type']=>$values]);
- if ($Payment['type']!=3) {
- $form->text('partnerid', '合作者身份(Partner ID)');
- $form->password('ytauthkey', '安全校验码(Key)');
- $form->text('account', '账号');
- }
- $form->tools(function (Form\Tools $tools) {
- $tools->disableDelete();
- });
- $form->footer(function ($footer) {
- // 去掉`重置`按钮
- $footer->disableReset();
- // 去掉`查看`checkbox
- $footer->disableViewCheck();
- // 去掉`继续编辑`checkbox
- $footer->disableEditingCheck();
- // 去掉`继续创建`checkbox
- $footer->disableCreatingCheck();
- });
- return $form;
- }
- protected function createForm()
- {
- $form = new Form(new Payment);
- $form->text('name', '插件名称')->rules('required');
- $form->text('alias', '插件别名')->rules('required');
- $form->text('s_intro', '简单描述')->rules('required');
- $form->textarea('introd', '详细描述')->rules('required');
- $form->radio('type', '类型')->options(['1'=>'支付宝','2'=>'微信','3'=>'线下转账'])->default(1);
- $form->text('partnerid', '合作者身份(Partner ID)');
- $form->text('ytauthkey', '安全校验码(Key)');
- $form->text('account', '账号');
- return $form;
- }
- /**
- * Store a newly created resource in storage.
- *
- * @return mixed
- */
- public function store()
- {
- return $this->createForm()->store();
- }
- /**
- * Update the specified resource in storage.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
- */
- public function update($id)
- {
- return $this->editForm($id)->update($id);
- }
- }
|