277 lines
11 KiB
PHP
277 lines
11 KiB
PHP
|
<?php
|
|||
|
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
|
|||
|
namespace app\common\repositories\system\notice;
|
|||
|
|
|||
|
|
|||
|
use app\common\dao\system\notice\SystemNoticeConfigDao;
|
|||
|
use app\common\repositories\BaseRepository;
|
|||
|
use crmeb\exceptions\WechatException;
|
|||
|
use crmeb\services\MiniProgramService;
|
|||
|
use crmeb\services\WechatService;
|
|||
|
use FormBuilder\Factory\Elm;
|
|||
|
use think\exception\ValidateException;
|
|||
|
use think\facade\Route;
|
|||
|
|
|||
|
/**
|
|||
|
* 通知管理
|
|||
|
*/
|
|||
|
class SystemNoticeConfigRepository extends BaseRepository
|
|||
|
{
|
|||
|
public function __construct(SystemNoticeConfigDao $dao)
|
|||
|
{
|
|||
|
$this->dao = $dao;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public function getList(array $where, $page, $limit)
|
|||
|
{
|
|||
|
$query = $this->dao->getSearch($where);
|
|||
|
$count = $query->count();
|
|||
|
$list = $query->page($page, $limit)->order('create_time ASC')->select();
|
|||
|
return compact('count', 'list');
|
|||
|
}
|
|||
|
|
|||
|
public function form(?int $id)
|
|||
|
{
|
|||
|
$formData = [];
|
|||
|
if ($id) {
|
|||
|
$data = $this->dao->get($id);
|
|||
|
if (!$data) throw new ValidateException('数据不存在');
|
|||
|
$formData = $data->toArray();
|
|||
|
$form = Elm::createForm(Route::buildUrl('systemNoticeConfigUpdate', ['id' => $id])->build());
|
|||
|
} else {
|
|||
|
$form = Elm::createForm(Route::buildUrl('systemNoticeConfigCreate')->build());
|
|||
|
}
|
|||
|
|
|||
|
$form->setRule([
|
|||
|
Elm::input('notice_title', '通知名称:')->placeholder('请输入通知名称')->required(),
|
|||
|
Elm::input('notice_info', '通知说明:')->placeholder('请输入通知说明')->required(),
|
|||
|
Elm::input('notice_key', '通知KEY:')->placeholder('请输入通知KEY')->required(),
|
|||
|
Elm::radio('notice_sys', '站内消息:', -1)->options([
|
|||
|
['value' => 0, 'label' => '关闭'],
|
|||
|
['value' => 1, 'label' => '开启'],
|
|||
|
['value' => -1, 'label' => '无'],
|
|||
|
])->requiredNum(),
|
|||
|
Elm::radio('notice_wechat', '公众号模板消息:', -1)->options([
|
|||
|
['value' => 0, 'label' => '关闭'],
|
|||
|
['value' => 1, 'label' => '开启'],
|
|||
|
['value' => -1, 'label' => '无'],
|
|||
|
])->requiredNum(),
|
|||
|
Elm::radio('notice_routine', '小程序订阅消息:', -1)->options([
|
|||
|
['value' => 0, 'label' => '关闭'],
|
|||
|
['value' => 1, 'label' => '开启'],
|
|||
|
['value' => -1, 'label' => '无'],
|
|||
|
])->requiredNum(),
|
|||
|
Elm::radio('notice_sms', '短信消息:', -1)->options([
|
|||
|
['value' => 0, 'label' => '关闭'],
|
|||
|
['value' => 1, 'label' => '开启'],
|
|||
|
['value' => -1, 'label' => '无'],
|
|||
|
])->requiredNum(),
|
|||
|
Elm::radio('type', '通知类型:', 0)->options([
|
|||
|
['value' => 0, 'label' => '用户'],
|
|||
|
['value' => 1, 'label' => '商户'],
|
|||
|
])->requiredNum(),
|
|||
|
Elm::textarea('sms_content','短信内容:')->placeholder('请输入短信内容'),
|
|||
|
Elm::textarea('wechat_content','公众号模板内容:')->placeholder('请输入公众号模板内容'),
|
|||
|
Elm::textarea('routine_content','小程序订阅消息内容:')->placeholder('请输入小程序订阅消息内容'),
|
|||
|
]);
|
|||
|
|
|||
|
return $form->setTitle(is_null($id) ? '添加通知' : '编辑通知')->formData($formData);
|
|||
|
}
|
|||
|
|
|||
|
public function swithStatus($id, $filed, $status)
|
|||
|
{
|
|||
|
$data = $this->dao->get($id);
|
|||
|
if ($data[$filed] == -1) throw new ValidateException('该消息无此通知类型');
|
|||
|
$data->$filed = $status;
|
|||
|
$data->save();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TODO
|
|||
|
* @param $key
|
|||
|
* @return bool
|
|||
|
* @author Qinii
|
|||
|
* @day 11/19/21
|
|||
|
*/
|
|||
|
public function getNoticeSys($key)
|
|||
|
{
|
|||
|
return $this->dao->getNoticeStatusByKey($key, 'notice_sys');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TODO
|
|||
|
* @param $key
|
|||
|
* @return bool
|
|||
|
* @author Qinii
|
|||
|
* @day 11/19/21
|
|||
|
*/
|
|||
|
public function getNoticeSms($key)
|
|||
|
{
|
|||
|
return $this->dao->getNoticeStatusByKey($key, 'notice_sms');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TODO
|
|||
|
* @param $key
|
|||
|
* @return bool
|
|||
|
* @author Qinii
|
|||
|
* @day 11/19/21
|
|||
|
*/
|
|||
|
public function getNoticeWechat($key)
|
|||
|
{
|
|||
|
return $this->dao->getNoticeStatusByKey($key, 'notice_wechat');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TODO
|
|||
|
* @param $key
|
|||
|
* @return bool
|
|||
|
* @author Qinii
|
|||
|
* @day 11/19/21
|
|||
|
*/
|
|||
|
public function getNoticeRoutine($key)
|
|||
|
{
|
|||
|
return $this->dao->getNoticeStatusByKey($key, 'notice_routine');
|
|||
|
}
|
|||
|
|
|||
|
public function getSmsTemplate(string $key)
|
|||
|
{
|
|||
|
$temp = $this->dao->getWhere(['const_key' => $key]);
|
|||
|
|
|||
|
if ($temp && $temp['notice_sms'] == 1) {
|
|||
|
return systemConfig('sms_use_type') == 2 ? $temp['sms_ali_tempid'] : $temp['sms_tempid'];
|
|||
|
}
|
|||
|
return '';
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TODO 编辑消息模板ID
|
|||
|
* @param $id
|
|||
|
* @return \FormBuilder\Form
|
|||
|
* @author Qinii
|
|||
|
* @day 6/9/22
|
|||
|
*/
|
|||
|
public function changeForm($id)
|
|||
|
{
|
|||
|
$formData = $this->dao->get($id);
|
|||
|
if (!$formData) throw new ValidateException('数据不存在');
|
|||
|
$form = Elm::createForm(Route::buildUrl('systemNoticeConfigSetChangeTempId', ['id' => $id])->build());
|
|||
|
$children = [];
|
|||
|
$value = '';
|
|||
|
if ($formData->notice_sms != -1) {
|
|||
|
$value = 'sms';
|
|||
|
if (systemConfig('sms_use_type') == 2) {
|
|||
|
$sms = [
|
|||
|
'type' => 'el-tab-pane',
|
|||
|
'props' => [
|
|||
|
'label' => '阿里云短信',
|
|||
|
'name' => 'sms'
|
|||
|
],
|
|||
|
'children' =>[
|
|||
|
Elm::input('title','通知类型:', $formData->notice_title)->placeholder('请输入通知类型')->disabled(true),
|
|||
|
Elm::input('info','场景说明:', $formData->notice_info)->disabled(true)->placeholder('请输入场景说明'),
|
|||
|
Elm::input('sms_ali_tempid','短信模板ID:')->placeholder('请输入短信模板ID'),
|
|||
|
Elm::input('notice_info','短信说明:')->disabled(true)->placeholder('请输入短信说明'),
|
|||
|
Elm::textarea('sms_content','短信内容:')->disabled(true),
|
|||
|
Elm::switches('notice_sms', '是否开启:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
|||
|
]
|
|||
|
];
|
|||
|
} else {
|
|||
|
$sms = [
|
|||
|
'type' => 'el-tab-pane',
|
|||
|
'props' => [
|
|||
|
'label' => '一号通短信',
|
|||
|
'name' => 'sms'
|
|||
|
],
|
|||
|
'children' =>[
|
|||
|
Elm::input('title','通知类型:', $formData->notice_title)->disabled(true),
|
|||
|
Elm::input('info','场景说明:', $formData->notice_info)->disabled(true),
|
|||
|
Elm::input('sms_tempid','短信模板ID:'),
|
|||
|
Elm::input('notice_info','短信说明:')->disabled(true),
|
|||
|
Elm::textarea('sms_content','短信内容:')->disabled(true),
|
|||
|
Elm::switches('notice_sms', '是否开启:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
|||
|
]
|
|||
|
];
|
|||
|
}
|
|||
|
$children[] = $sms;
|
|||
|
}
|
|||
|
if ($formData->notice_wechat != -1 ) {
|
|||
|
if (!$value) $value = 'wechat';
|
|||
|
$children[] = [
|
|||
|
'type' => 'el-tab-pane',
|
|||
|
'props' => [
|
|||
|
'label' => '模板消息',
|
|||
|
'name' => 'wechat'
|
|||
|
],
|
|||
|
'children' =>[
|
|||
|
Elm::input('title1','通知类型:', $formData->notice_title)->disabled(true),
|
|||
|
Elm::input('info1','场景说明:', $formData->notice_info)->disabled(true),
|
|||
|
Elm::input('wechat_tempkey','模板消息编号:', $formData->wechat_tempkey)->disabled(true),
|
|||
|
Elm::input('wechat_tempid','模板消息ID:', $formData->wechat_tempid),
|
|||
|
Elm::textarea('wechat_content','模板消息内容:', $formData->wechat_content)->disabled(true),
|
|||
|
Elm::switches('notice_wechat', '是否开启:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
|||
|
]
|
|||
|
];
|
|||
|
}
|
|||
|
if ($formData->notice_routine != -1) {
|
|||
|
if (!$value) $value = 'routine';
|
|||
|
$children[] = [
|
|||
|
'type' => 'el-tab-pane',
|
|||
|
'props' => [
|
|||
|
'label' => '订阅消息',
|
|||
|
'name' => 'routine'
|
|||
|
],
|
|||
|
'children' =>[
|
|||
|
Elm::input('title2','通知类型:', $formData->notice_title)->disabled(true),
|
|||
|
Elm::input('info2','场景说明:', $formData->notice_info)->disabled(true),
|
|||
|
Elm::input('routine_tempkey','订阅消息编号:', $formData->routine_tempkey)->disabled(true),
|
|||
|
Elm::input('routine_tempid','订阅消息ID:', $formData->routine_tempid),
|
|||
|
Elm::textarea('routine_content','订阅消息内容:', $formData->routine_content)->disabled(true),
|
|||
|
Elm::switches('notice_routine', '是否开启:', $formData->notice_routine)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
|||
|
]
|
|||
|
];
|
|||
|
}
|
|||
|
$form->setRule([
|
|||
|
[
|
|||
|
'type' => 'el-tabs',
|
|||
|
'native' => true,
|
|||
|
'props' => [
|
|||
|
'value' => $value
|
|||
|
],
|
|||
|
'children' => $children
|
|||
|
]
|
|||
|
]);
|
|||
|
return $form->setTitle( '编辑消息模板')->formData($formData->toArray());
|
|||
|
}
|
|||
|
|
|||
|
public function getTemplateList($type)
|
|||
|
{
|
|||
|
if ($type) {
|
|||
|
$where['is_wechat'] = 1;
|
|||
|
$field = 'notice_title,notice_config_id,notice_wechat,wechat_tempkey tempkey,wechat_content content,wechat_tempid tempid,type,kid';
|
|||
|
} else {
|
|||
|
$where['is_routine'] = 1;
|
|||
|
$field = 'notice_title,notice_config_id,notice_routine,routine_tempkey tempkey,routine_content content,routine_tempid tempid,type,kid';
|
|||
|
}
|
|||
|
$query = $this->dao->search($where);
|
|||
|
$count = $query->count();
|
|||
|
$list = $query->setOption('field',[])->field($field)->field($field)->select();
|
|||
|
foreach ($list as &$item) {
|
|||
|
if ($item['content']) $item['content'] = explode("\n", $item['content']);
|
|||
|
}
|
|||
|
return compact('list', 'count');
|
|||
|
}
|
|||
|
}
|