<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Edm\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Admin\Auth\AdminPermission; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\Response; use ModStart\Core\Util\CRUDUtil; use ModStart\Field\Tags; use ModStart\Form\Form; use ModStart\Grid\Displayer\ItemOperate; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use ModStart\Widget\TextAjaxRequest; use Module\Edm\Type\EdmTaskItemStatus; use Module\Edm\Type\EdmTaskStatus; class TaskController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $JeXgT) { $JeXgT->init('edm_task')->field(function ($JeXgT) { $JeXgT->id('id', 'ID'); $JeXgT->text('title', '名称'); $JeXgT->tags('filterTags', '标签')->tagModelField('edm_email', 'tags', Tags::SERIALIZE_TYPE_COLON_SEPARATED)->serializeType(Tags::SERIALIZE_TYPE_COLON_SEPARATED)->addable(true)->editable(false)->help('创建后不可修改'); $JeXgT->checkbox('templateIds', '邮件模板')->optionModel('edm_template', 'id', 'title'); $JeXgT->switch('limitEnable', '流控')->optionsYesNo()->when('=', true, function ($JeXgT) { $JeXgT->number('limitHourly', '每小时最多发送')->help('0表示不限制'); }); $JeXgT->type('status', '状态')->type(EdmTaskStatus::class)->addable(false)->editable(false); $JeXgT->display('successCount', '发送成功'); $JeXgT->display('failCount', '发送失败'); })->gridFilter(function (GridFilter $FdfN8) { $FdfN8->eq('id', L('ID')); $FdfN8->like('title', L('Title')); })->hookItemOperateRendering(function (ItemOperate $p2Sse) { $p2Sse->getField()->width(300); $MNZ1i = $p2Sse->item(); switch ($MNZ1i->status) { case EdmTaskStatus::CREATED: case EdmTaskStatus::PAUSED: $p2Sse->prepend(TextAjaxRequest::primary('启动', action('\\' . __CLASS__ . '@start', array('_id' => $MNZ1i->id)))); break; case EdmTaskStatus::RUNNING: $p2Sse->prepend(TextAjaxRequest::primary('暂停', action('\\' . __CLASS__ . '@pause', array('_id' => $MNZ1i->id)))); break; case EdmTaskStatus::FINISHED: goto X15ic; X15ic: $p2Sse->prepend(TextAjaxRequest::primary('更新运行', action('\\' . __CLASS__ . '@restart', array('_id' => $MNZ1i->id)))); goto R8Ywl; hjB_P: break; goto I40H7; R8Ywl: $p2Sse->prepend(TextAjaxRequest::primary('重试失败', action('\\' . __CLASS__ . '@retry', array('_id' => $MNZ1i->id)))); goto hjB_P; I40H7: } })->hookDeleted(function (Form $AyrhG) { $AyrhG->item()->each(function ($MNZ1i) { ModelUtil::delete('edm_task_item', array('taskId' => $MNZ1i->id)); }); })->hookSaved(function (Form $AyrhG) { $MNZ1i = $AyrhG->item(); if ($AyrhG->isModeAdd()) { ModelUtil::update('edm_task', $MNZ1i->id, array('status' => EdmTaskStatus::CREATED)); } })->formClass('wide')->title('营销任务'); } public function start() { goto VC5NJ; w_Bj0: ModelUtil::update('edm_task', CRUDUtil::id(), array('status' => EdmTaskStatus::RUNNING, 'itemProcessed' => false)); goto qmWxu; qmWxu: return Response::redirect(CRUDUtil::jsGridRefresh()); goto c7lHq; VC5NJ: AdminPermission::demoCheck(); goto w_Bj0; c7lHq: } public function pause() { goto JQnGt; ocIKk: ModelUtil::update('edm_task', CRUDUtil::id(), array('status' => EdmTaskStatus::PAUSED)); goto T58Sa; T58Sa: return Response::redirect(CRUDUtil::jsGridRefresh()); goto iZf38; JQnGt: AdminPermission::demoCheck(); goto ocIKk; iZf38: } public function restart() { goto q0QVy; eru4W: return Response::redirect(CRUDUtil::jsGridRefresh()); goto DXH6v; q0QVy: AdminPermission::demoCheck(); goto gTmC3; gTmC3: ModelUtil::update('edm_task', CRUDUtil::id(), array('status' => EdmTaskStatus::RUNNING, 'itemProcessed' => false)); goto eru4W; DXH6v: } public function retry() { goto bn72V; bn72V: AdminPermission::demoCheck(); goto Fnlj1; Fnlj1: ModelUtil::update('edm_task_item', array('taskId' => CRUDUtil::id(), 'status' => EdmTaskItemStatus::FAIL), array('status' => EdmTaskItemStatus::CREATED)); goto T_fi_; Yld2J: return Response::redirect(CRUDUtil::jsGridRefresh()); goto jL_5X; T_fi_: ModelUtil::update('edm_task', CRUDUtil::id(), array('status' => EdmTaskStatus::RUNNING)); goto Yld2J; jL_5X: } }