YunShopServiceProvider.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/8/17
  8. * Time: 17:29
  9. */
  10. namespace app\common\providers;
  11. use app\common\facades\RichText;
  12. use app\common\facades\Setting;
  13. use app\common\models\AccountWechats;
  14. use app\platform\modules\system\models\SystemSetting;
  15. use Illuminate\Support\Facades\Cookie;
  16. use Illuminate\Support\ServiceProvider;
  17. use app\common\services\Utils;
  18. class YunShopServiceProvider extends ServiceProvider
  19. {
  20. public function boot()
  21. {
  22. if (config('app.framework') != 'platform' || (!\YunShop::isWeb() && !\YunShop::isWechatApi())) {
  23. Setting::$uniqueAccountId = \YunShop::app()->uniacid;
  24. RichText::$uniqueAccountId = \YunShop::app()->uniacid;
  25. return;
  26. }
  27. global $_W;
  28. $uniacid = request()->uniacid ?:request()->cookie('uniacid');
  29. Utils::addUniacid($uniacid);
  30. $account = AccountWechats::getAccountByUniacid($uniacid);
  31. $remote = $this->getRemoteInfo();
  32. $_W = [
  33. 'uniacid' => $uniacid,
  34. 'acid' => $uniacid,
  35. 'account' => $account ? $account->toArray() : [],
  36. 'openid' => '',
  37. 'uid' => \Auth::guard('admin')->user()->uid,
  38. 'username' => \Auth::guard('admin')->user()->username,
  39. 'siteroot' => request()->getSchemeAndHttpHost() . '/',
  40. 'siteurl' => request()->getUri(),
  41. 'attachurl' => $remote['attachurl'],
  42. 'attachurl_local' => request()->getSchemeAndHttpHost() . '/static/upload/',
  43. 'attachurl_remote' => $remote['attachurl_remote'],
  44. 'charset' => 'utf-8'
  45. ];
  46. //设置uniacid
  47. Setting::$uniqueAccountId = \YunShop::app()->uniacid;
  48. RichText::$uniqueAccountId = \YunShop::app()->uniacid;
  49. }
  50. private function getRemoteInfo()
  51. {
  52. $type = [
  53. 2 => 'alioss',
  54. 4 => 'cos'
  55. ];
  56. $remote = SystemSetting::settingLoad('remote');
  57. if ($remote['type'] != 0) {
  58. return [
  59. 'attachurl' => $remote[$type[$remote['type']]]['url'],
  60. 'attachurl_remote' => $remote[$type[$remote['type']]]['url']
  61. ];
  62. }
  63. return [
  64. 'attachurl' => request()->getSchemeAndHttpHost() . '/static/upload/',
  65. 'attachurl_remote' => ''
  66. ];
  67. }
  68. }