BusinessNoticeManager.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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:53
  9. */
  10. namespace business\common\notice;
  11. use business\common\models\MessageNotice;
  12. use Illuminate\Container\Container;
  13. use Illuminate\Support\Str;
  14. class BusinessNoticeManager extends Container
  15. {
  16. public function __construct()
  17. {
  18. $this->bind('MessageNotice',function ($messageNotice,$attributes = []) {
  19. return new MessageNotice($attributes);
  20. });
  21. $this->singleton('ProductCollection',function ($messageNotice) {
  22. return new NoticeProductCollection();
  23. });
  24. $this->setShopProduct();
  25. }
  26. private function setShopProduct()
  27. {
  28. $this->make('ProductCollection')->bind('shop', function ($manager, $params) {
  29. return new BusinessShopNotice();
  30. });
  31. }
  32. public function getAllProduct()
  33. {
  34. $allProduct = collect([]);
  35. $productContainer = app('BusinessMsgNotice')->make('ProductCollection')->getBindings();
  36. foreach ($productContainer as $key => $value) {
  37. $allProduct->push($this->getProduct($key));
  38. }
  39. return $allProduct->filter()->values();
  40. }
  41. /**
  42. * @param $code
  43. * @return BusinessMessageNoticeBase|bool
  44. * @throws \Illuminate\Contracts\Container\BindingResolutionException
  45. */
  46. public function getProduct($code)
  47. {
  48. if (app('BusinessMsgNotice')->make('ProductCollection')->bound($code)) {
  49. return app('BusinessMsgNotice')->make('ProductCollection')->make($code);
  50. }
  51. return false;
  52. }
  53. }