NoticeService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\message;
  12. use app\jobs\notice\EnterpriseWechatJob;
  13. use app\jobs\notice\PrintJob;
  14. use app\services\activity\collage\UserCollagePartakeServices;
  15. use app\services\activity\collage\UserCollageServices;
  16. use app\services\BaseServices;
  17. use app\services\order\StoreOrderCartInfoServices;
  18. use app\services\order\StoreOrderServices;
  19. use app\services\system\config\ConfigServices;
  20. use app\services\wechat\WechatUserServices;
  21. use crmeb\services\CacheService;
  22. use think\exception\ValidateException;
  23. class NoticeService extends BaseServices
  24. {
  25. /**
  26. * 发送消息类型
  27. * @var array
  28. */
  29. // protected $type = [
  30. // 'is_sms' => NoticeSmsService::class,
  31. // 'is_system' => SystemSendServices::class,
  32. // 'is_wechat' => WechatTemplateService::class,
  33. // 'is_routine' => RoutineTemplateServices::class,
  34. // 'is_ent_wechat' => EntWechatServices::class,
  35. // ];
  36. /**
  37. * @var array
  38. */
  39. protected $noticeInfo = [];
  40. /**
  41. * @var string
  42. */
  43. protected $event;
  44. /**
  45. * @param string $event
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function setEvent(string $event)
  51. {
  52. if ($this->event != $event) {
  53. $this->noticeInfo = CacheService::redisHandler('NOTCEINFO')->remember('NOTCE_' . $event, function () use ($event) {
  54. /** @var SystemNotificationServices $services */
  55. $services = app()->make(SystemNotificationServices::class);
  56. $noticeInfo = $services->getOneNotce(['mark' => $event]);
  57. if ($noticeInfo) {
  58. return $noticeInfo->toArray();
  59. } else {
  60. return [];
  61. }
  62. });
  63. $this->event = $event;
  64. }
  65. return $this;
  66. }
  67. /**
  68. * @param array $notceinfo
  69. * @param $data
  70. * @param string $msgtype
  71. */
  72. //企业微信群机器人
  73. public function EnterpriseWechatSend($data)
  74. {
  75. if ($this->noticeInfo['is_ent_wechat'] == 1 && $this->noticeInfo['url'] !== '') {
  76. $url = $this->noticeInfo['url'];
  77. $ent_wechat_text = $this->noticeInfo['ent_wechat_text'];
  78. EnterpriseWechatJob::dispatchDo('doJob', [$data, $url, $ent_wechat_text]);
  79. }
  80. }
  81. /**
  82. * 根据UID,user_type获取openid
  83. * @param int $uid
  84. * @param string $userType
  85. * @return mixed
  86. */
  87. public function getOpenidByUid(int $uid, string $userType = 'wechat')
  88. {
  89. /** @var WechatUserServices $wechatServices */
  90. $wechatServices = app()->make(WechatUserServices::class);
  91. return $wechatServices->uidToOpenid($uid, $userType);
  92. }
  93. }