| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | 
							- <?php
 
- namespace App\Admin\Controllers\System;
 
- use Aix\Sms\Contracts\Smser;
 
- use App\Http\Controllers\Controller;
 
- use App\Models\Sms;
 
- use App\Models\SmsRule;
 
- use App\Services\Common\SmsService;
 
- 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;
 
- use Illuminate\Http\Request;
 
- class SmsController 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)
 
-     {
 
-         return $content
 
-             ->header('短信服务商')
 
-             ->description('创建')
 
-             ->body($this->createForm());
 
-     }
 
-     /**
 
-      * Make a grid builder.
 
-      *
 
-      * @return Grid
 
-      */
 
-     protected function grid()
 
-     {
 
-         $grid = new Grid(new Sms);
 
-         $grid->model()->orderBy('order', 'desc');
 
-         $grid->id('ID');
 
-         $grid->name('接口名称')->width(200);
 
-         $grid->alias('接口标识')->width(200);
 
-         $grid->order('排序')->width(200);
 
-         $states = [
 
-             'on'  => ['value' => 1, 'text' => '启用', 'color' => 'primary'],
 
-             'off' => ['value' => 0, 'text' => '禁止', 'color' => 'default'],
 
-         ];
 
-         $grid->status('是否启用')->switch($states);
 
-         $grid->remark('接口描述')->width(300);
 
-         $grid->created_at('添加时间');
 
-         $grid->updated_at('更新时间');
 
-         $grid->actions(function ($actions) {
 
-             if (Admin::user()->can('system_sms_service_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-         });
 
-         if (Admin::user()->can('system_sms_service_create')) {
 
-             $grid->disableCreateButton(false);
 
-         }
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(Sms::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->name('接口名称');
 
-         $show->alias('接口标识');
 
-         $show->app_key('appkey');
 
-         $show->signature_key('signature');
 
-         $show->status('是否启用')->as(function ($status) {
 
-             return $status ? '启用' : '禁止';
 
-         });
 
-         $show->remark('接口描述');
 
-         $show->order('排序');
 
-         $show->created_at('添加时间');
 
-         $show->updated_at('更新时间');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function editForm($id)
 
-     {
 
-         $form = new Form(new Sms);
 
-         $form->display('name', '接口名称')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->display('alias', '接口标识')->rules([
 
-             'required',
 
-             'unique:smss',
 
-         ])->setWidth(2)->setMustMark();
 
-         $form->text('app_key', 'appkey')->placeholder('短信接口帐号')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->password('secret_Key', 'secretKey')->placeholder('短信接口密钥')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('signature_key', 'signature')->placeholder('短信接口签名')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->radio('status', '是否启用')->options([0=>'禁止',1=>'启用']);
 
-         $form->text('remark', '接口描述')->rules([
 
-             'required',
 
-         ])->setWidth(8)->setMustMark();
 
-         $form->number('order', '排序')->min(0)->default(0)->rules([
 
-             'required',
 
-         ]);
 
-         $form->saving(function (Form $form) {
 
-             if ($form->status=='on') {
 
-                 $form->status=1;
 
-             } elseif ($form->status=='off') {
 
-                 $form->status=0;
 
-             }
 
-         });
 
-         return $form;
 
-     }
 
-     protected function createForm()
 
-     {
 
-         $form = new Form(new Sms);
 
-         $form->text('name', '接口名称')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('alias', '接口标识')->rules([
 
-             'required',
 
-             'unique:smss',
 
-         ])->setWidth(2)->setMustMark();
 
-         $form->text('app_key', 'appkey')->placeholder('短信接口帐号')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->password('secret_Key', 'secretKey')->placeholder('短信接口密钥')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('signature_key', 'signature')->placeholder('短信接口签名')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->radio('status', '是否启用')->options([0=>'禁止',1=>'启用'])->default(1);
 
-         $form->text('remark', '接口描述')->rules([
 
-             'required',
 
-         ])->setWidth(8)->setMustMark();
 
-         $form->number('order', '排序')->min(0)->default(0)->rules([
 
-             'required',
 
-         ])->setMustMark();
 
-         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);
 
-     }
 
-     /**
 
-      * 短信测试.
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function test(Content $content)
 
-     {
 
-         return $content
 
-             ->header('短信测试')
 
-             ->description('创建')
 
-             ->body($this->testForm());
 
-     }
 
-     protected function testForm()
 
-     {
 
-         $form = new Form(new Sms);
 
-         $form->setAction("");
 
-         $form->mobile('phone', '接受手机')->rules([
 
-             'required',
 
-         ])->setWidth('4');
 
-         $form->disableReset();
 
-         $form->tools(function (Form\Tools $tools) {
 
-             // 去掉跳转列表按钮
 
-             $tools->disableListButton();
 
-             // 去掉删除按钮
 
-             $tools->disableDelete();
 
-             // 去掉查看按钮
 
-             $tools->disableView();
 
-         });
 
-         $form->footer(function (Form\Footer $Footer) {
 
-             $Footer->disableEditingCheck();
 
-             $Footer->disableViewCheck();
 
-             $Footer->disableCreatingCheck();
 
-         });
 
-         return $form;
 
-     }
 
-     public function testPost(SmsService $smsService)
 
-     {
 
-         $smsService->sendSms(request()->phone, Smser::TEMPLATE_TEST);
 
-         admin_toastr('操作成功,可在发送记录里查看', 'success');
 
-         return redirect(route('admin.sys.queue.index'));
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new Sms);
 
-         $form->display('ID');
 
-         $form->display('Created at');
 
-         $form->display('Updated at');
 
-         return $form;
 
-     }
 
- }
 
 
  |