| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\logic\notice;
- use app\common\enum\NoticeEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\NoticeSetting;
- /**
- * 通知逻辑层
- * Class NoticeLogic
- * @package app\adminapi\logic\notice
- */
- class NoticeLogic extends BaseLogic
- {
- /**
- * @notes 查看通知设置详情
- * @param $params
- * @return array
- * @author Tab
- * @date 2021/8/18 19:01
- */
- public static function detail($params)
- {
- $field = 'id,scene_id,scene_name,scene_desc,system_notice,sms_notice,oa_notice,mnp_notice,support';
- $noticeSetting = NoticeSetting::field($field)->findOrEmpty($params['id'])->toArray();
- if(empty($noticeSetting)) {
- return [];
- }
- if(empty($noticeSetting['system_notice'])) {
- $noticeSetting['system_notice'] = [
- 'title' => '',
- 'content' => '',
- 'status' => "0",
- ];
- }
- $noticeSetting['system_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SYSTEM, $noticeSetting['scene_id']);
- if(empty($noticeSetting['sms_notice'])) {
- $noticeSetting['sms_notice'] = [
- 'template_id' => '',
- 'content' => '',
- 'status' => "0",
- ];
- }
- $noticeSetting['sms_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SMS, $noticeSetting['scene_id']);
- if(empty($noticeSetting['oa_notice'])) {
- $noticeSetting['oa_notice'] = [
- 'template_id' => '',
- 'template_sn' => '',
- 'name' => '',
- 'first' => '',
- 'remark' => '',
- 'tpl' => [],
- 'status' => "0",
- ];
- }
- $noticeSetting['oa_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
- if(empty($noticeSetting['mnp_notice'])) {
- $noticeSetting['mnp_notice'] = [
- 'template_id' => '',
- 'template_sn' => '',
- 'name' => '',
- 'tpl' => [],
- 'status' => "0",
- ];
- }
- $noticeSetting['mnp_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
- $noticeSetting['system_notice']['is_show'] = in_array(NoticeEnum::SYSTEM, explode(',', $noticeSetting['support'])) ? true : false;
- $noticeSetting['sms_notice']['is_show'] = in_array(NoticeEnum::SMS, explode(',', $noticeSetting['support'])) ? true : false;
- $noticeSetting['oa_notice']['is_show'] = in_array(NoticeEnum::OA, explode(',', $noticeSetting['support'])) ? true : false;
- $noticeSetting['mnp_notice']['is_show'] = in_array(NoticeEnum::MNP, explode(',', $noticeSetting['support'])) ? true : false;
- $noticeSetting['default'] = '';
- return $noticeSetting;
- }
- /**
- * @notes 通知设置
- * @param $params
- * @return bool
- * @author Tab
- * @date 2021/8/18 18:00
- */
- public static function set($params)
- {
- try {
- // 校验参数
- self::checkSet($params);
- // 拼装更新数据
- $updateData = [];
- foreach($params['template'] as $item) {
- $updateData[$item['type'] . '_notice'] = json_encode($item, JSON_UNESCAPED_UNICODE);
- }
- // 更新通知设置
- NoticeSetting::where('id', $params['id'])->update($updateData);
- return true;
- } catch(\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- /**
- * @notes 校验参数
- * @param $params
- * @throws \Exception
- * @author Tab
- * @date 2021/8/18 17:53
- */
- public static function checkSet($params)
- {
- if(!isset($params['id'])) {
- throw new \Exception('参数缺失');
- }
- $noticeSetting = NoticeSetting::findOrEmpty($params['id']);
- if($noticeSetting->isEmpty()) {
- throw new \Exception('通知配置不存在');
- }
- if(!isset($params['template']) || !is_array($params['template']) || count($params['template']) == 0) {
- throw new \Exception('模板配置不存在或格式错误');
- }
- foreach($params['template'] as $item) {
- if(!is_array($item)) {
- throw new \Exception('模板项格式错误');
- }
- if(!isset($item['type']) || !in_array($item['type'], ['system', 'sms', 'oa', 'mnp'])) {
- throw new \Exception('模板项缺少模板类型或模板类型有误');
- }
- switch ($item['type']) {
- case "system";
- self::checkSystem($item);
- break;
- case "sms";
- self::checkSms($item);
- break;
- case "oa";
- self::checkOa($item);
- break;
- case "mnp";
- self::checkMnp($item);
- break;
- }
- }
- }
- /**
- * @notes 校验系统通知参数
- * @param $item
- * @throws \Exception
- * @author Tab
- * @date 2021/8/18 17:30
- */
- public static function checkSystem($item)
- {
- if(!isset($item['title']) || !isset($item['content']) || !isset($item['status'])) {
- throw new \Exception('系统通知必填参数:title、content、status');
- }
- }
- /**
- * @notes 校验短信通知必填参数
- * @param $item
- * @throws \Exception
- * @author Tab
- * @date 2021/8/18 17:47
- */
- public static function checkSms($item)
- {
- if(!isset($item['template_id']) || !isset($item['content']) || !isset($item['status'])) {
- throw new \Exception('短信通知必填参数:template_id、content、status');
- }
- }
- /**
- * @notes 校验微信模板消息参数
- * @param $item
- * @throws \Exception
- * @author Tab
- * @date 2021/8/18 17:51
- */
- public static function checkOa($item)
- {
- if( !isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['first']) || !isset($item['remark']) || !isset($item['tpl']) || !isset($item['status'])) {
- throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、first、remark、tpl、status');
- }
- }
- /**
- * @notes 校验微信小程序提醒必填参数
- * @param $item
- * @throws \Exception
- * @author Tab
- * @date 2021/8/18 17:53
- */
- public static function checkMnp($item)
- {
- if( !isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['tpl']) || !isset($item['status'])) {
- throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、tpl、status');
- }
- }
- }
|