NoticeService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\BaseServices;
  15. use app\services\order\StoreOrderCartInfoServices;
  16. use app\services\system\SystemNotificationServices;
  17. use crmeb\services\CacheService;
  18. use think\exception\ValidateException;
  19. class NoticeService extends BaseServices
  20. {
  21. /**
  22. * 发送消息类型
  23. * @var array
  24. */
  25. // protected $type = [
  26. // 'is_sms' => NoticeSmsService::class,
  27. // 'is_system' => SystemSendServices::class,
  28. // 'is_wechat' => WechatTemplateService::class,
  29. // 'is_routine' => RoutineTemplateServices::class,
  30. // 'is_ent_wechat' => EntWechatServices::class,
  31. // ];
  32. /**
  33. * @var array
  34. */
  35. protected $notceinfo;
  36. /**
  37. * @var string
  38. */
  39. protected $event;
  40. /**
  41. * @param string $event
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. */
  46. public function setEvent(string $event)
  47. {
  48. if ($this->event != $event) {
  49. $this->notceinfo = CacheService::get('NOTCE_' . $event);
  50. if (!$this->notceinfo) {
  51. /** @var SystemNotificationServices $services */
  52. $services = app()->make(SystemNotificationServices::class);
  53. $notceinfo = $services->getOneNotce(['mark' => $event]);
  54. $this->notceinfo = $notceinfo ? $notceinfo->toArray() : [];
  55. CacheService::set('NOTCE_' . $event, $this->notceinfo);
  56. }
  57. $this->event = $event;
  58. }
  59. return $this;
  60. }
  61. /**
  62. * @param array $notceinfo
  63. * @param $data
  64. * @param string $msgtype
  65. */
  66. //企业微信群机器人
  67. public function EnterpriseWechatSend($data)
  68. {
  69. if ($this->notceinfo['is_ent_wechat'] == 1 && $this->notceinfo['url'] !== '') {
  70. $url = $this->notceinfo['url'];
  71. $ent_wechat_text = $this->notceinfo['ent_wechat_text'];
  72. EnterpriseWechatJob::dispatchDo('doJob', [$data, $url, $ent_wechat_text]);
  73. }
  74. }
  75. /**
  76. * 打印订单
  77. * @param $order
  78. * @param array $cartId
  79. */
  80. public function orderPrint($order)
  81. {
  82. /** @var StoreOrderCartInfoServices $cartServices */
  83. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  84. $product = $cartServices->getCartInfoPrintProduct($order['cart_id']);
  85. if (!$product) {
  86. throw new ValidateException('订单商品获取失败,无法打印!');
  87. }
  88. $configdata = [
  89. 'clientId' => sys_config('printing_client_id', ''),
  90. 'apiKey' => sys_config('printing_api_key', ''),
  91. 'partner' => sys_config('develop_id', ''),
  92. 'terminal' => sys_config('terminal_number', '')
  93. ];
  94. $switch = sys_config('pay_success_printing_switch') ? true : false;
  95. if (!$switch) {
  96. throw new ValidateException('小票打印未开启!');
  97. }
  98. if (!$configdata['clientId'] || !$configdata['apiKey'] || !$configdata['partner'] || !$configdata['terminal']) {
  99. throw new ValidateException('请先配置小票打印开发者');
  100. }
  101. PrintJob::dispatch('doJob', ['yi_lian_yun', $configdata, $order, $product]);
  102. }
  103. }