NoticeService.php 3.9 KB

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