BusinessNoticeFactory.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/8/3
  8. * Time: 16:48
  9. */
  10. namespace business\common\notice;
  11. use app\common\exceptions\ApiException;
  12. use app\common\exceptions\AppException;
  13. use business\common\models\MessageNotice;
  14. use business\common\models\Staff;
  15. use business\common\services\SettingService;
  16. class BusinessNoticeFactory
  17. {
  18. protected static $loginUserStaffId;
  19. public static function getFormatAllType($plugin = null)
  20. {
  21. if(!$plugin){
  22. return [];
  23. }
  24. $allType = app('BusinessMsgNotice')->getProduct($plugin)->getAllType();
  25. $type = [];
  26. foreach ($allType as $k => $v) {
  27. $type[] = [
  28. 'code' => $k,
  29. 'mane' => $v,
  30. ];
  31. }
  32. return $type;
  33. }
  34. public static function allModule()
  35. {
  36. $allProduct = app('BusinessMsgNotice')->getAllProduct();
  37. $appModule = $allProduct->map(function (BusinessMessageNoticeBase $product) {
  38. return [
  39. 'code' => $product->getPlugin(),
  40. 'name' => $product->getPluginName(),
  41. ];
  42. })->all();
  43. return $appModule;
  44. }
  45. public static function loginUserStaffId()
  46. {
  47. if (empty(self::$loginUserStaffId)) {
  48. $staff = Staff::uniacid()
  49. ->select('id')
  50. ->where('business_id',SettingService::getBusinessId())
  51. ->where('uid',\YunShop::app()->getMemberId())
  52. ->first();
  53. self::$loginUserStaffId = $staff?$staff->id:0;
  54. }
  55. return self::$loginUserStaffId;
  56. }
  57. /**
  58. * @param $containerCode
  59. * @param $noticeType
  60. * @return BusinessMessageNoticeBase
  61. * @throws AppException
  62. */
  63. public static function createInstance($containerCode, $noticeType)
  64. {
  65. /**
  66. * @var BusinessMessageNoticeBase $appointProduct
  67. */
  68. $appointProduct = app('BusinessMsgNotice')->getProduct($containerCode);
  69. if (!$appointProduct) {
  70. throw new ApiException("不存在{$containerCode}这个消息通知类");
  71. }
  72. // if (self::loginUserStaffId()) {
  73. // throw new ApiException("员工信息不存在,无法获取发送通知人");
  74. // }
  75. /**
  76. * @var MessageNotice $messageNotice
  77. */
  78. $messageNotice = app('BusinessMsgNotice')->make('MessageNotice',[
  79. 'uniacid' => \YunShop::app()->uniacid,
  80. 'operate_id' => self::loginUserStaffId(),
  81. 'business_id' => SettingService::getBusinessId(),
  82. 'plugin' => $containerCode,
  83. 'notice_type' => $noticeType,
  84. ]);
  85. $appointProduct->setMessageNotice($messageNotice);
  86. return $appointProduct;
  87. }
  88. /**
  89. * @param MessageNotice $messageNoticee
  90. * @return BusinessMessageNoticeBase
  91. */
  92. public static function selectInstance(MessageNotice $messageNotice)
  93. {
  94. /**
  95. * @var BusinessMessageNoticeBase $appointProduct
  96. */
  97. $appointProduct = app('BusinessMsgNotice')->getProduct($messageNotice->plugin);
  98. $appointProduct->setMessageNotice($messageNotice);
  99. return $appointProduct;
  100. }
  101. }