NoticeService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\exceptions\AdminException;
  17. use crmeb\services\CacheService;
  18. /**
  19. * 站内信services类
  20. * Class MessageSystemServices
  21. */
  22. class NoticeService extends BaseServices
  23. {
  24. /**
  25. * 发送消息类型
  26. * @var array
  27. */
  28. // protected $type = [
  29. // 'is_sms' => SmsService::class,
  30. // 'is_system' => SystemSendServices::class,
  31. // 'is_wechat' => WechatTemplateService::class,
  32. // 'is_routine' => RoutineTemplateServices::class,
  33. // 'is_ent_wechat' => EntWechatServices::class,
  34. // ];
  35. /**
  36. * @var array
  37. */
  38. protected $notceinfo;
  39. /**
  40. * @var string
  41. */
  42. protected $event;
  43. /**
  44. * @param string $event
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function setEvent(string $event)
  50. {
  51. if ($this->event != $event) {
  52. $this->notceinfo = CacheService::get('NOTCE_' . $event);
  53. if (!$this->notceinfo) {
  54. /** @var SystemNotificationServices $services */
  55. $services = app()->make(SystemNotificationServices::class);
  56. $notceinfo = $services->getOneNotce(['mark' => $event]);
  57. $this->notceinfo = $notceinfo ? $notceinfo->toArray() : [];
  58. CacheService::set('NOTCE_' . $event, $this->notceinfo);
  59. }
  60. $this->event = $event;
  61. }
  62. return $this;
  63. }
  64. /**
  65. * 打印订单
  66. * @param $order
  67. * @param array $cartId
  68. */
  69. public function orderPrint($order)
  70. {
  71. /** @var StoreOrderCartInfoServices $cartServices */
  72. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  73. $product = $cartServices->getCartInfoPrintProduct($order['id']);
  74. if (!$product) {
  75. throw new AdminException(400463);
  76. }
  77. $switch = (bool)sys_config('pay_success_printing_switch');
  78. if (!$switch) {
  79. throw new AdminException(400464);
  80. }
  81. if (sys_config('print_type', 1) == 1) {
  82. $name = 'yi_lian_yun';
  83. $configData = [
  84. 'clientId' => sys_config('printing_client_id', ''),
  85. 'apiKey' => sys_config('printing_api_key', ''),
  86. 'partner' => sys_config('develop_id', ''),
  87. 'terminal' => sys_config('terminal_number', '')
  88. ];
  89. if (!$configData['clientId'] || !$configData['apiKey'] || !$configData['partner'] || !$configData['terminal']) {
  90. throw new AdminException(400465);
  91. }
  92. } else {
  93. $name = 'fei_e_yun';
  94. $configData = [
  95. 'feyUser' => sys_config('fey_user', ''),
  96. 'feyUkey' => sys_config('fey_ukey', ''),
  97. 'feySn' => sys_config('fey_sn', '')
  98. ];
  99. if (!$configData['feyUser'] || !$configData['feyUkey'] || !$configData['feySn']) {
  100. throw new AdminException(400465);
  101. }
  102. }
  103. PrintJob::dispatch('doJob', [$name, $configData, $order, $product]);
  104. }
  105. }