15 changed files with 271 additions and 26 deletions
@ -0,0 +1,63 @@ |
|||||
|
<?php |
||||
|
namespace app\admin\service; |
||||
|
|
||||
|
use app\admin\service\AdminBaseService; |
||||
|
use app\model\EmailTemplateModel; |
||||
|
use app\model\VideoOnDemandModel; |
||||
|
|
||||
|
class ConfigService extends AdminBaseService |
||||
|
{ |
||||
|
// 获取邮箱模板列表 |
||||
|
public function emailTemplateList($param) |
||||
|
{ |
||||
|
try { |
||||
|
if (empty($param['page']) || !is_numeric($param['page'])) { |
||||
|
return $this->toData('400', '参错错误'); |
||||
|
} |
||||
|
if (empty($param['limit']) || !is_numeric($param['limit'])) { |
||||
|
return $this->toData('400', '参错错误'); |
||||
|
} |
||||
|
$where = []; |
||||
|
if (isset($param['tpl_type'])) { |
||||
|
$where['tpl_type'] = $param['tpl_type']; |
||||
|
} |
||||
|
$list = EmailTemplateModel::where($where)->order('id', 'desc')->paginate([ |
||||
|
'list_rows' => $param['limit'], |
||||
|
'page' => $param['page'], |
||||
|
]); |
||||
|
return $this->toData('0', 'SUCCESS', [ |
||||
|
'list' => $list->items(), // 当前页的数据 |
||||
|
'page' => $list->currentPage(), // 当前页码 |
||||
|
'total' => $list->total(), // 总记录数 |
||||
|
'last_page' => $list->lastPage(), // 最后一页页码 |
||||
|
]); |
||||
|
} catch (\Exception $e) { |
||||
|
return $this->toData('500', 'The system is busy. Please try again later.', [$e->getMessage(), $e->getTrace()]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 编辑邮箱模板 |
||||
|
public function editEmailTemplate($param) |
||||
|
{ |
||||
|
try { |
||||
|
if (empty($param['id']) || !is_numeric($param['id'])) { |
||||
|
return $this->toData('400', '参错错误'); |
||||
|
} |
||||
|
if (empty($param['title']) || empty($param['content'])) { |
||||
|
return $this->toData('400', '参错错误'); |
||||
|
} |
||||
|
|
||||
|
$emailTemplate = EmailTemplateModel::where(['id'=>$param['id']])->find(); |
||||
|
if (empty($emailTemplate)) { |
||||
|
return $this->toData('500', '修改的模板数据不存在'); |
||||
|
} |
||||
|
$emailTemplate->email = $param['email'] ?? ""; |
||||
|
$emailTemplate->title = $param['title'] ?? ""; |
||||
|
$emailTemplate->content = $param['content'] ?? ""; |
||||
|
$emailTemplate->save(); |
||||
|
return $this->toData('0', 'success'); |
||||
|
} catch (\Exception $e) { |
||||
|
return $this->toData('500', 'The system is busy. Please try again later.', [$e->getMessage(), $e->getTrace()]); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
<?php |
||||
|
namespace app\home\job; |
||||
|
|
||||
|
use think\facade\Log; |
||||
|
use think\queue\Job; |
||||
|
|
||||
|
class RegDone |
||||
|
{ |
||||
|
public function fire(Job $job, $data) |
||||
|
{ |
||||
|
Log::info("think-queue 邮箱注册后的队列任务开始:" . json_encode($data)); |
||||
|
try { |
||||
|
$phpEmail = new \app\utility\SendEmail(); |
||||
|
for($times = 1; $times <= 3; $times++) { |
||||
|
$bool = $phpEmail->sendEmail($data['email'], $data['title'], $data['content']); |
||||
|
if ($bool) { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
Log::info("think-queue 邮箱注册后的队列任务正常结束." ); |
||||
|
} catch (\Exception $e) { |
||||
|
Log::info("think-queue 邮箱注册后的队列任务异常:message=".$e->getMessage().'date='.json_encode($data)); |
||||
|
} |
||||
|
|
||||
|
// 删除任务 |
||||
|
$job->delete(); |
||||
|
} |
||||
|
|
||||
|
// 任务失败后执行的方法 |
||||
|
public function failed($data) |
||||
|
{ |
||||
|
Log::info("think-queue 用户注册后的队列任务执行失败:" . json_encode($data)); |
||||
|
} |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app\model; |
||||
|
|
||||
|
use think\Model; |
||||
|
|
||||
|
/** |
||||
|
* @mixin \think\Model |
||||
|
*/ |
||||
|
class EmailTemplateModel extends BaseModel |
||||
|
{ |
||||
|
const TPL_TYPE_ONE = 1; //用户邮箱注册后发送的模板 |
||||
|
|
||||
|
protected $name = 'email_template'; |
||||
|
} |
Loading…
Reference in new issue