<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Edm\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Admin\Layout\AdminDialogPage; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\Response; use ModStart\Core\Util\CRUDUtil; use ModStart\Core\Util\FormatUtil; use ModStart\Form\Form; use ModStart\Grid\Displayer\ItemOperate; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use ModStart\Widget\TextDialogRequest; use Module\Edm\Provider\Sender\AbstractEdmMailSenderProvider; use Module\Edm\Provider\Sender\EdmMailSenderProvider; class SenderController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $JeXgT) { $JeXgT->init('edm_sender')->field(function ($JeXgT) { $JeXgT->id('id', 'ID'); $JeXgT->text('title', '名称'); $JeXgT->switch('enable', '启用'); $JeXgT->display('successCount', '发送成功'); $JeXgT->display('failCount', '发送失败'); $JeXgT->display('lastSendTime', '最近发送时间'); $oMZdb = $JeXgT->select('sender', '发送器')->options(EdmMailSenderProvider::allMap()); foreach (EdmMailSenderProvider::listAll() as $pXrNS) { $oMZdb->when('=', $pXrNS->name(), function ($JeXgT) use($pXrNS) { $pXrNS->buildParam($JeXgT); }); } })->hookItemOperateRendering(function (ItemOperate $p2Sse) { $MNZ1i = $p2Sse->item(); $p2Sse->prepend(TextDialogRequest::primary('测试发送', modstart_admin_url('edm/sender/test', array('_id' => $MNZ1i->id)))); })->gridFilter(function (GridFilter $FdfN8) { $FdfN8->eq('id', L('ID')); $FdfN8->like('title', L('Title')); })->title('EDM邮件发送'); } public function test(AdminDialogPage $yfn4d) { goto NTb1T; qKuMJ: $AyrhG->showSubmit(false)->showReset(false); goto uJMUy; TvAS9: $AyrhG->formClass('wide'); goto qKuMJ; LMYwo: $AyrhG->text('email', '测试接收邮箱')->required(); goto TvAS9; uJMUy: return $yfn4d->pageTitle('测试发送邮件')->body($AyrhG)->handleForm($AyrhG, function (Form $AyrhG) { $GpXwG = $AyrhG->dataForming(); BizException::throwsIf('邮箱格式不正确', !FormatUtil::isEmail($GpXwG['email'])); $ksviT = ModelUtil::get('edm_sender', CRUDUtil::id()); BizException::throwsIfEmpty('发送器不存在', $ksviT); $pXrNS = EdmMailSenderProvider::get($ksviT['sender']); BizException::throwsIfEmpty('发送器不存在', $pXrNS); $gMg9x = $pXrNS->send($ksviT, $GpXwG['email'], '测试邮件', '如果您能接收到此邮件，说明发送器配置正常'); BizException::throwsIfResponseError($gMg9x); return Response::generateSuccess('测试邮件发送成功'); }); goto o5xou; NTb1T: $AyrhG = Form::make(''); goto LMYwo; o5xou: } }