| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- /**
- * Created by PhpStorm.
- * Name: 芸众商城系统
- * Author: 广州市芸众信息科技有限公司
- * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
- * Date: 2022/8/3
- * Time: 16:48
- */
- namespace business\common\notice;
- use app\common\exceptions\ApiException;
- use app\common\exceptions\AppException;
- use business\common\models\MessageNotice;
- use business\common\models\Staff;
- use business\common\services\SettingService;
- class BusinessNoticeFactory
- {
- protected static $loginUserStaffId;
- public static function getFormatAllType($plugin = null)
- {
- if(!$plugin){
- return [];
- }
-
- $allType = app('BusinessMsgNotice')->getProduct($plugin)->getAllType();
- $type = [];
- foreach ($allType as $k => $v) {
- $type[] = [
- 'code' => $k,
- 'mane' => $v,
- ];
- }
- return $type;
- }
- public static function allModule()
- {
- $allProduct = app('BusinessMsgNotice')->getAllProduct();
- $appModule = $allProduct->map(function (BusinessMessageNoticeBase $product) {
- return [
- 'code' => $product->getPlugin(),
- 'name' => $product->getPluginName(),
- ];
- })->all();
- return $appModule;
- }
- public static function loginUserStaffId()
- {
- if (empty(self::$loginUserStaffId)) {
- $staff = Staff::uniacid()
- ->select('id')
- ->where('business_id',SettingService::getBusinessId())
- ->where('uid',\YunShop::app()->getMemberId())
- ->first();
- self::$loginUserStaffId = $staff?$staff->id:0;
- }
- return self::$loginUserStaffId;
- }
- /**
- * @param $containerCode
- * @param $noticeType
- * @return BusinessMessageNoticeBase
- * @throws AppException
- */
- public static function createInstance($containerCode, $noticeType)
- {
- /**
- * @var BusinessMessageNoticeBase $appointProduct
- */
- $appointProduct = app('BusinessMsgNotice')->getProduct($containerCode);
- if (!$appointProduct) {
- throw new ApiException("不存在{$containerCode}这个消息通知类");
- }
- // if (self::loginUserStaffId()) {
- // throw new ApiException("员工信息不存在,无法获取发送通知人");
- // }
- /**
- * @var MessageNotice $messageNotice
- */
- $messageNotice = app('BusinessMsgNotice')->make('MessageNotice',[
- 'uniacid' => \YunShop::app()->uniacid,
- 'operate_id' => self::loginUserStaffId(),
- 'business_id' => SettingService::getBusinessId(),
- 'plugin' => $containerCode,
- 'notice_type' => $noticeType,
- ]);
- $appointProduct->setMessageNotice($messageNotice);
- return $appointProduct;
- }
- /**
- * @param MessageNotice $messageNoticee
- * @return BusinessMessageNoticeBase
- */
- public static function selectInstance(MessageNotice $messageNotice)
- {
- /**
- * @var BusinessMessageNoticeBase $appointProduct
- */
- $appointProduct = app('BusinessMsgNotice')->getProduct($messageNotice->plugin);
- $appointProduct->setMessageNotice($messageNotice);
- return $appointProduct;
- }
- }
|