<?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\Exception\BizException; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; use ModStart\Core\Util\CRUDUtil; use ModStart\Field\Tags; use ModStart\Form\Form; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use ModStart\Widget\ButtonDialogRequest; use Module\Edm\Util\EdmMailUtil; class EmailController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $JeXgT) { $JeXgT->init('edm_email')->field(function ($JeXgT) { $JeXgT->id('id', 'ID'); $JeXgT->tags('tags', '标签')->tagModelField('edm_email', 'tags', Tags::SERIALIZE_TYPE_COLON_SEPARATED)->serializeType(Tags::SERIALIZE_TYPE_COLON_SEPARATED); $JeXgT->text('name', '称呼'); $JeXgT->text('email', '邮箱'); $JeXgT->display('lastSendTime', '上次发送时间'); $JeXgT->display('created_at', L('Created At'))->listable(false); $JeXgT->display('updated_at', L('Updated At'))->listable(false); })->gridOperateAppend(ButtonDialogRequest::make('primary', '<i class="iconfont icon-upload"></i> 导入邮箱', action('\\' . __CLASS__ . '@import'))->size('big'))->gridFilter(function (GridFilter $FdfN8) { $FdfN8->eq('id', L('ID')); $FdfN8->like('tags', '标签'); $FdfN8->like('email', '邮箱'); })->canBatchDelete(true)->title('客户邮箱'); } public function import(AdminDialogPage $yfn4d) { goto ZWliD; NyqBs: return $yfn4d->pageTitle('批量导入邮箱')->body($AyrhG); goto i7zKp; x6kew: if (Request::isPost()) { return $AyrhG->formRequest(function (Form $AyrhG) { $GpXwG = $AyrhG->dataForming(); $XKIVa = 0; $SaxxW = 0; switch ($GpXwG['importType']) { case '邮箱': goto SGq6Q; SGq6Q: BizException::throwsIfEmpty('邮箱为空', $GpXwG['dataEmail']); goto X1l1R; X1l1R: $IiW4A = array_filter(array_map(function ($MNZ1i) { return trim($MNZ1i); }, explode('
', $GpXwG['dataEmail']))); goto tQkBy; fC91C: break; goto y4NMG; tQkBy: BizException::throwsIfEmpty('邮箱为空', $IiW4A); goto g6vt6; g6vt6: foreach ($IiW4A as $MNZ1i) { goto U0FVA; DFQ4m: $XKIVa += $gMg9x['data']['inserted']; goto DafGz; U0FVA: $gMg9x = EdmMailUtil::insertOrUpdate($GpXwG['tags'], $MNZ1i, $MNZ1i); goto DFQ4m; DafGz: $SaxxW += $gMg9x['data']['updated']; goto dT4ul; dT4ul: } goto fC91C; y4NMG: case 'QQ号': goto isFSj; Ag_3R: break; goto O83DK; Kz20h: BizException::throwsIfEmpty('QQ号为空', $IiW4A); goto NzqxY; NzqxY: foreach ($IiW4A as $MNZ1i) { goto VAtAg; hJX1u: $XKIVa += $gMg9x['data']['inserted']; goto ezDbE; VAtAg: $gMg9x = EdmMailUtil::insertOrUpdate($GpXwG['tags'], $MNZ1i . '@qq.com', $MNZ1i); goto hJX1u; ezDbE: $SaxxW += $gMg9x['data']['updated']; goto WcD0k; WcD0k: } goto Ag_3R; isFSj: BizException::throwsIfEmpty('QQ号为空', $GpXwG['dataQq']); goto QsXK8; QsXK8: $IiW4A = array_filter(array_map(function ($MNZ1i) { return trim($MNZ1i); }, explode('
', $GpXwG['dataQq']))); goto Kz20h; O83DK: default: BizException::throws('错误的导入类型'); break; } return Response::generate(0, "导入 {$XKIVa} 条，更新 {$SaxxW} 条", null, CRUDUtil::jsDialogCloseAndParentGridRefresh()); }); } goto NyqBs; Puf3A: $AyrhG->tags('tags', '标签')->tagModelField('edm_email', 'tags', Tags::SERIALIZE_TYPE_COLON_SEPARATED)->serializeType(Tags::SERIALIZE_TYPE_COLON_SEPARATED); goto bWOM4; bWOM4: $AyrhG->select('importType', '导入类型')->options(array('邮箱' => '邮箱', 'QQ号' => 'QQ号'))->when('=', '邮箱', function (Form $AyrhG) { $AyrhG->textarea('dataEmail', '邮箱')->help('每行一个邮箱'); })->when('=', 'QQ号', function (Form $AyrhG) { $AyrhG->textarea('dataQq', 'QQ号')->help('每行一个QQ号，导入时会自动补全后缀 @qq.com'); })->defaultValue('邮箱'); goto HtKu2; HtKu2: $AyrhG->showSubmit(false)->showReset(false); goto x6kew; ZWliD: $AyrhG = Form::make(''); goto Puf3A; i7zKp: } }