|
@@ -19,9 +19,12 @@ use app\common\enum\YesNoEnum;
|
|
|
use app\common\model\notice\NoticeRecord;
|
|
use app\common\model\notice\NoticeRecord;
|
|
|
use app\common\model\notice\NoticeSetting;
|
|
use app\common\model\notice\NoticeSetting;
|
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\User;
|
|
|
|
|
+use app\common\model\user\UserAuth;
|
|
|
|
|
+use app\common\model\master_worker\MasterWorker;
|
|
|
|
|
+use app\common\model\master_worker\MasterWorkerAuth;
|
|
|
use app\common\service\sms\SmsMessageService;
|
|
use app\common\service\sms\SmsMessageService;
|
|
|
use app\common\service\wechat\WeChatOaService;
|
|
use app\common\service\wechat\WeChatOaService;
|
|
|
-
|
|
|
|
|
|
|
+use think\facade\Log;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通知逻辑层
|
|
* 通知逻辑层
|
|
@@ -45,18 +48,24 @@ class NoticeLogic extends BaseLogic
|
|
|
if (empty($noticeSetting)) {
|
|
if (empty($noticeSetting)) {
|
|
|
throw new \Exception('找不到对应场景的配置');
|
|
throw new \Exception('找不到对应场景的配置');
|
|
|
}
|
|
}
|
|
|
|
|
+ $noticeSetting['designated_user'] && $params['params']['user_id'] = $noticeSetting['designated_user'];
|
|
|
|
|
+ /*if(empty($params['params']['user_id']) && (!isset($params['params']['mobile']) && !isset($params['params']['openid']))){
|
|
|
|
|
+ throw new \Exception('发送对象不能为空');
|
|
|
|
|
+ }*/
|
|
|
// 合并额外参数
|
|
// 合并额外参数
|
|
|
- $params = self::mergeParams($params);
|
|
|
|
|
|
|
+ $params = self::mergeParams($params,$noticeSetting['recipient']);
|
|
|
$res = false;
|
|
$res = false;
|
|
|
self::setError('发送通知失败');
|
|
self::setError('发送通知失败');
|
|
|
-
|
|
|
|
|
|
|
+ Log::info('NoticeLogic-noticeByScene:'.json_encode($params));
|
|
|
// 短信验证码通知(具有时效性)
|
|
// 短信验证码通知(具有时效性)
|
|
|
if (isset($noticeSetting['sms_notice']['status']) && $noticeSetting['sms_notice']['status'] == YesNoEnum::YES && $noticeSetting['type'] == NoticeEnum::VERIFICATION_CODE) {
|
|
if (isset($noticeSetting['sms_notice']['status']) && $noticeSetting['sms_notice']['status'] == YesNoEnum::YES && $noticeSetting['type'] == NoticeEnum::VERIFICATION_CODE) {
|
|
|
$res = (new SmsMessageService())->send($params);
|
|
$res = (new SmsMessageService())->send($params);
|
|
|
|
|
+ Log::info('NoticeLogic-noticeByScene-send:'.json_encode([$res]));
|
|
|
}
|
|
}
|
|
|
// 短信业务通知
|
|
// 短信业务通知
|
|
|
if (isset($noticeSetting['sms_notice']['status']) && $noticeSetting['sms_notice']['status'] == YesNoEnum::YES && $noticeSetting['type'] == NoticeEnum::BUSINESS_NOTIFICATION) {
|
|
if (isset($noticeSetting['sms_notice']['status']) && $noticeSetting['sms_notice']['status'] == YesNoEnum::YES && $noticeSetting['type'] == NoticeEnum::BUSINESS_NOTIFICATION) {
|
|
|
$res = (new SmsMessageService())->sendBusiness($params);
|
|
$res = (new SmsMessageService())->sendBusiness($params);
|
|
|
|
|
+ Log::info('NoticeLogic-noticeByScene-sendBusiness:'.json_encode([$res]));
|
|
|
}
|
|
}
|
|
|
// 微信公众号消息模板业务通知
|
|
// 微信公众号消息模板业务通知
|
|
|
if (isset($noticeSetting['oa_notice']['status']) && $noticeSetting['oa_notice']['status'] == YesNoEnum::YES
|
|
if (isset($noticeSetting['oa_notice']['status']) && $noticeSetting['oa_notice']['status'] == YesNoEnum::YES
|
|
@@ -64,10 +73,12 @@ class NoticeLogic extends BaseLogic
|
|
|
&& isset($params['params']['openid']) && !empty($params['params']['openid'])
|
|
&& isset($params['params']['openid']) && !empty($params['params']['openid'])
|
|
|
) {
|
|
) {
|
|
|
$res = (new WeChatOaService())->sendTemplateMessage($params);
|
|
$res = (new WeChatOaService())->sendTemplateMessage($params);
|
|
|
|
|
+ Log::info('NoticeLogic-noticeByScene-sendTemplateMessage:'.json_encode([$res]));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
return $res;
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
|
+ Log::info('NoticeLogic-noticeByScene:'.$e->getMessage());
|
|
|
self::setError($e->getMessage());
|
|
self::setError($e->getMessage());
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -81,15 +92,39 @@ class NoticeLogic extends BaseLogic
|
|
|
* @author 段誉
|
|
* @author 段誉
|
|
|
* @date 2022/9/15 15:28
|
|
* @date 2022/9/15 15:28
|
|
|
*/
|
|
*/
|
|
|
- public static function mergeParams($params)
|
|
|
|
|
|
|
+ public static function mergeParams($params,$recipient)
|
|
|
{
|
|
{
|
|
|
- // 用户相关
|
|
|
|
|
- if (!empty($params['params']['user_id'])) {
|
|
|
|
|
- $user = User::findOrEmpty($params['params']['user_id'])->toArray();
|
|
|
|
|
- $params['params']['nickname'] = $user['nickname'];
|
|
|
|
|
- $params['params']['user_name'] = $user['nickname'];
|
|
|
|
|
- $params['params']['user_sn'] = $user['sn'];
|
|
|
|
|
- $params['params']['mobile'] = $params['params']['mobile'] ?? $user['mobile'];
|
|
|
|
|
|
|
+ if($recipient == 1) {
|
|
|
|
|
+ // 用户相关
|
|
|
|
|
+ if (!empty($params['params']['user_id'])) {
|
|
|
|
|
+ $user = User::findOrEmpty($params['params']['user_id'])->toArray();
|
|
|
|
|
+ $params['params']['nickname'] = $user['nickname'];
|
|
|
|
|
+ $params['params']['user_name'] = $user['nickname'];
|
|
|
|
|
+ $params['params']['user_sn'] = $user['sn'];
|
|
|
|
|
+ $params['params']['mobile'] = $user['mobile'];
|
|
|
|
|
+ $wx_user = UserAuth::where('worker_id',$params['params']['user_id'])->findOrEmpty()->toArray();
|
|
|
|
|
+ //$wx_user['openid'] $wx_user['unionid']
|
|
|
|
|
+ $params['params']['openid'] = $wx_user['openid']??'';
|
|
|
|
|
+ $params['params']['unionid'] = $wx_user['unionid']??'';
|
|
|
|
|
+ }
|
|
|
|
|
+ }elseif($recipient == 3) {
|
|
|
|
|
+ // 工程师相关
|
|
|
|
|
+ if (!empty($params['params']['user_id'])) {
|
|
|
|
|
+ $user = MasterWorker::findOrEmpty($params['params']['user_id'])->toArray();
|
|
|
|
|
+ $params['params']['nickname'] = $user['nickname'];
|
|
|
|
|
+ $params['params']['user_name'] = $user['nickname'];
|
|
|
|
|
+ $params['params']['user_sn'] = $user['sn'];
|
|
|
|
|
+ $params['params']['mobile'] = $user['mobile'];
|
|
|
|
|
+ $wx_user = MasterWorkerAuth::where('worker_id',$params['params']['user_id'])->findOrEmpty()->toArray();
|
|
|
|
|
+ //$wx_user['openid'] $wx_user['unionid']
|
|
|
|
|
+ $params['params']['openid'] = $wx_user['openid']??'';
|
|
|
|
|
+ $params['params']['unionid'] = $wx_user['unionid']??'';
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 后台账号
|
|
|
|
|
+ if (!empty($params['params']['user_id'])) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 跳转路径
|
|
// 跳转路径
|