114 lines
3.3 KiB
PHP
114 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Admin\Layout\Menu;
|
|
use App\Services\SettingService;
|
|
use EasyWeChat\Factory as EasyWeChatFactory;
|
|
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Overtrue\EasySms\EasySms;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
// Schema::defaultStringLength(191);
|
|
$this->registerEasySms();
|
|
$this->registerEasyWeChat();
|
|
$this->registerRequestRealIp();
|
|
$this->registerSettings();
|
|
// $this->registerAdminMenu();
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
Relation::enforceMorphMap([
|
|
'user' => \App\Models\User::class,
|
|
'order' => \App\Models\Order::class,
|
|
'order_refund_log' => \App\Models\OrderRefundLog::class,
|
|
'after_sale' => \App\Models\AfterSale::class,
|
|
'wallet_to_bank_log' => \App\Models\WalletToBankLog::class,
|
|
'balance_log' => \App\Models\BalanceLog::class,
|
|
'distribution_pre_income' => \App\Models\DistributionPreIncome::class,
|
|
'admin_users' => \App\Models\Admin\Administrator::class,
|
|
'quota_v1_send_logs' => \App\Models\QuotaV1SendLog::class,
|
|
'dealer_order' => \App\Models\DealerOrder::class,
|
|
'dealer_manager_subsidy' => \App\Models\DealerManagerSubsidy::class,
|
|
'dealer_manage_subsidy' => \App\Models\DealerManageSubsidy::class,
|
|
'dealer_channel_subsidy_log' => \App\Models\DealerChannelSubsidyLog::class,
|
|
'dealer_purchase_subsidy' => \App\Models\DealerPurchaseSubsidy::class,
|
|
'dealer_wallet_to_bank_log' => \App\Models\DealerWalletToBankLog::class,
|
|
]);
|
|
|
|
JsonResource::withoutWrapping();
|
|
}
|
|
|
|
protected function registerAdminMenu()
|
|
{
|
|
$this->app->singleton('admin.menu', Menu::class);
|
|
}
|
|
|
|
/**
|
|
* 注册微信服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerEasyWeChat()
|
|
{
|
|
$this->app->singleton(EasyWeChatPaymentApplication::class, function ($app) {
|
|
return EasyWeChatFactory::payment($app['config']->get('wechat.payment.default'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 注册短信发送服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerEasySms()
|
|
{
|
|
$this->app->singleton(EasySms::class, function ($app) {
|
|
return new EasySms($app['config']->get('easysms'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 在请求上注册 realIp 宏
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerRequestRealIp()
|
|
{
|
|
Request::macro('realIp', function () {
|
|
return $this->ip();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 注册应用设置服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerSettings()
|
|
{
|
|
$this->app->singleton(SettingService::class, function ($app) {
|
|
return new SettingService($app['cache.store']);
|
|
});
|
|
}
|
|
}
|