6
0
Fork 0

调整配置管理

release
vine_liutk 2021-12-27 11:43:12 +08:00
parent 2598a8d187
commit 05f01969fd
18 changed files with 280 additions and 137 deletions

View File

@ -2,13 +2,20 @@
namespace App\Admin\Controllers;
use App\Admin\Forms\Settings\App;
use App\Admin\Forms\Settings\Kuaidi100;
use App\Admin\Forms\Settings\Unipush;
use App\Admin\Repositories\Setting;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\Column;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Tab;
use Illuminate\Support\Facades\Request;
class SettingController extends AdminController
{
@ -88,4 +95,34 @@ class SettingController extends AdminController
$form->display('updated_at');
});
}
public function index(Content $content): Content
{
return $content->header('配置管理')
->description('配置管理')
->body(function (Row $row) {
$type = Request::query('type', 'app');
$tab = new Tab();
switch ($type) {
case 'app':
$tab->add('系统配置', new App(), true);
$tab->addLink('快递100配置', admin_route('settings.index', ['type'=>'kuaidi100']));
$tab->addLink('Uni-push配置', admin_route('settings.index', ['type'=>'unipush']));
break;
case 'kuaidi100':
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
$tab->add('快递100配置', new Kuaidi100(), true);
$tab->addLink('Uni-push配置', admin_route('settings.index', ['type'=>'unipush']));
break;
case 'unipush':
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
$tab->addLink('快递100配置', admin_route('settings.index', ['type'=>'kuaidi100']));
$tab->add('Uni-push配置', new Unipush(), true);
break;
default:
break;
}
$row->column(12, $tab->withCard());
});
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace App\Admin\Forms\Settings;
use App\Models\ArticleCategory;
use App\Models\Setting;
use Dcat\Admin\Widgets\Form;
class App extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
Setting::where('key', 'app')->updateOrCreate([
'key' => 'app',
], ['value' => $input]);
return $this
->response()
->success('配置更新成功!')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$appSettings = Setting::where('key', 'app')->first();
$this->text('app_name', 'APP名称')->value($appSettings?->value['app_name']);
$this->divider();
$this->text('search_hot_keys', '搜索热词(英文半角逗号隔开)')->value($appSettings?->value['search_hot_keys']);
$this->divider();
$this->number('order_payment_expires_at', '订单支付过期时间(秒)')->value($appSettings?->value['order_payment_expires_at']);
$this->number('sale_after_expire_days', '售后过期时间(天)')->value($appSettings?->value['sale_after_expire_days']);
$this->divider();
$this->number('sign_click_points', '签到送积分(分)')->value($appSettings?->value['sign_click_points']);
$this->number('sign_click_continue', '每连续签到额外奖励(天)')->value($appSettings?->value['sign_click_continue']);
$this->number('sign_click_continue_points', '每连续签到额外奖励(分)')->value($appSettings?->value['sign_click_continue_points']);
$this->divider();
$this->select('article_help', '帮助文章指定分类')->options(ArticleCategory::whereNull('parent_id')->pluck('name', 'id'))->value($appSettings?->value['article_help']);
$this->select('article_agreement', '协议文章指定分类')->options(ArticleCategory::whereNull('parent_id')->pluck('name', 'id'))->value($appSettings?->value['article_agreement']);
$this->select('article_health', '健康文章指定分类')->options(ArticleCategory::whereNull('parent_id')->pluck('name', 'id'))->value($appSettings?->value['article_health']);
$this->text('article_about_us', '关于我们文章指定(链接)')->value($appSettings?->value['article_about_us']);
$this->text('article_user_promotion_agreement', '服务协议文章指定(链接)')->value($appSettings?->value['article_user_promotion_agreement']);
$this->text('article_user_hide_agreement', '隐私协议文章指定(链接)')->value($appSettings?->value['article_user_hide_agreement']);
$this->divider();
$this->text('invite_uri', '分享邀请地址(链接)')->value($appSettings?->value['article_about_us']);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Admin\Forms\Settings;
use App\Models\Setting;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;
class Kuaidi100 extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
Setting::where('key', 'kuaidi100')->updateOrCreate([
'key' => 'kuaidi100',
], ['value' => $input]);
return $this
->response()
->success('配置更新成功!')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$appSettings = Setting::where('key', 'kuaidi100')->first();
$this->switch('is_use', '是否启用')->value(Arr::get($appSettings?->value, 'is_use', 0));
$this->divider();
$this->text('app_key', 'APP_KEY')->value(Arr::get($appSettings?->value, 'app_key', ''));
$this->text('customer', 'CUSTOMER')->value(Arr::get($appSettings?->value, 'customer', ''));
$this->text('secret', 'SECRET')->value(Arr::get($appSettings?->value, 'secret', ''));
$this->text('userid', 'USER_ID')->value(Arr::get($appSettings?->value, 'userid', ''));
$this->text('callback_uri', '回调地址(链接)')->value(Arr::get($appSettings?->value, 'callback_uri', ''));
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Admin\Forms\Settings;
use App\Models\Setting;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;
class Unipush extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
Setting::where('key', 'unipush')->updateOrCreate([
'key' => 'unipush',
], ['value' => $input]);
return $this
->response()
->success('配置更新成功!')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$appSettings = Setting::where('key', 'unipush')->first();
$this->switch('is_use', '是否启用')->value(Arr::get($appSettings?->value, 'is_use', 0));
$this->text('mall_app_id', '商城APP_ID')->value(Arr::get($appSettings?->value, 'mall_app_id', ''));
$this->text('mall_app_key', '商城APP_KEY')->value(Arr::get($appSettings?->value, 'mall_app_key', ''));
$this->text('mall_app_secret', '商城APP_SECRET')->value(Arr::get($appSettings?->value, 'mall_app_secret', ''));
$this->text('mall_master_secret', '商城APP_MASTER_SECRET')->value(Arr::get($appSettings?->value, 'mall_master_secret', ''));
$this->divider();
$this->switch('merchant_is_use', '是否启用')->value(Arr::get($appSettings?->value, 'merchant_is_use', 0));
$this->text('merchant_app_id', '商户APP_ID')->value(Arr::get($appSettings?->value, 'merchant_app_id', ''));
$this->text('merchant_app_key', '商户APP_KEY')->value(Arr::get($appSettings?->value, 'merchant_app_key', ''));
$this->text('merchant_app_secret', '商户APP_SECRET')->value(Arr::get($appSettings?->value, 'merchant_app_secret', ''));
$this->text('merchant_master_secret', '商户APP_MASTER_SECRET')->value(Arr::get($appSettings?->value, 'merchant_master_secret', ''));
}
}

View File

@ -74,7 +74,7 @@ class OrderPackageService
'updated_at' => $package->created_at,
]);
}, $packageProducts));
if (app_settings('kuaidi100_is_use')) {
if (app_settings('kuaidi100.is_use')) {
$kuaidi100Service = new Kuaidi100Service();
$kuaidi100Service->poll($package->shipping_number, $package->shipping_code, $package->consignee_telephone);
}

View File

@ -40,7 +40,9 @@ class PushMessageCommand extends Command
$status = 2; //默认失败
//如果是系统消息
if ($task->message instanceof Message) {
$status = $mallPushService->push($task->sn, $task->message) ? 1 : 2;
if ((bool) app_settings('nuipush.is_use')) {//如果开启了推送
$status = $mallPushService->push($task->sn, $task->message) ? 1 : 2;
}
}
$task->update([

View File

@ -26,9 +26,9 @@ class ArticleController extends Controller
public function config(Request $request)
{
return response()->json([
'about_us'=>app_settings('article_about_us', ''),
'user_promotion_agreement'=> app_settings('article_user_promotion_agreement', ''),
'user_hide_agreement' => app_settings('article_user_hide_agreement', ),
'about_us'=>app_settings('app.article_about_us', ''),
'user_promotion_agreement'=> app_settings('app.article_user_promotion_agreement', ''),
'user_hide_agreement' => app_settings('app.article_user_hide_agreement', ),
]);
}
@ -43,9 +43,9 @@ class ArticleController extends Controller
$cate = (string) $request->query('cate');
$key = (string) $request->query('key');
$categoryId = Arr::get([
'help'=> app_settings('article_help'),
'agreement'=> app_settings('article_agreement'),
'health'=> app_settings('article_health'),
'help'=> app_settings('app.article_help'),
'agreement'=> app_settings('app.article_agreement'),
'health'=> app_settings('app.article_health'),
], $cate);
$query = Article::query()->with(['likesInfo'=>function ($q) use ($request) {
$user_id = $request->user()?->id;

View File

@ -63,12 +63,12 @@ class ClickController extends Controller
]);
//发放当天签到积分
$points = app_settings('sign_click_points');
$points = app_settings('app.sign_click_points');
$pointsService->sendPoints(1, $user, $points, '签到奖励');
//发放额外的奖励积分
$continueClickDays = app_settings('sign_click_continue', 0);
$continueClickPoints = app_settings('sign_click_continue_points');
$continueClickDays = app_settings('app.sign_click_continue', 0);
$continueClickPoints = app_settings('app.sign_click_continue_points');
if (($continueClickDays > 0 && $click->continue_click_times % $continueClickDays) == 0) {
$pointsService->sendPoints(1, $user, $continueClickPoints, '连续签到奖励');
}

View File

@ -45,7 +45,7 @@ class ProductSkuController extends Controller
public function searchHotKeys(Request $request)
{
return response()->json([
'keys' => explode(',', app_settings('search_hot_keys')),
'keys' => explode(',', app_settings('app.search_hot_keys')),
]);
}

View File

@ -22,7 +22,7 @@ class ShareBgController extends Controller
public function userQrCode(Request $request)
{
$inviteUri = app_settings('invite_uri').'/register?code=';
$inviteUri = app_settings('app.invite_uri').'/register?code=';
return response()->json([
'qr_code' => base64_encode(QrCode::format('png')->size(100)->margin(0)->generate($inviteUri.$request->user()->userInfo?->code)),
]);

View File

@ -20,13 +20,13 @@ class ArticleController extends Controller
$view = '';
//区分文章分类ID
switch ($article->category_id) {
case app_settings('article_agreement'): //如果是协议分类
case app_settings('app.article_agreement'): //如果是协议分类
$view = 'endpoint.article.agreement';
break;
default:
//区分文章的分类祖先ID
switch ($article->category->ancestors->first()?->id) {
case app_settings('article_agreement'): //如果是协议
case app_settings('app.article_agreement'): //如果是协议
$view = 'endpoint.article.agreement';
break;
default:

View File

@ -90,7 +90,7 @@ class Order extends Model
public function scopeExpired()
{
return $this->where('status', static::STATUS_PENDING)
->where('created_at', '<=', now()->subSeconds(app_settings('order_payment_expires_at')));
->where('created_at', '<=', now()->subSeconds(app_settings('app.order_payment_expires_at')));
}
/**
@ -320,7 +320,7 @@ class Order extends Model
}
$seconds = now()->diffInSeconds(
$this->created_at->addSeconds(app_settings('order_payment_expires_at')), false
$this->created_at->addSeconds(app_settings('app.order_payment_expires_at')), false
);
return $seconds > 0 ? $seconds : 0;

View File

@ -1328,12 +1328,12 @@ class Kuaidi100Service
public function setAppKey($appKey = null)
{
$this->appKey = $appKey ??app_settings('kuaidi100_app_key');
$this->appKey = $appKey ??app_settings('kuaidi100.app_key');
}
public function setCustomer($customer = null)
{
$this->customer = $customer ??app_settings('kuaidi100_customer');
$this->customer = $customer ??app_settings('kuaidi100.customer');
}
/**
@ -1344,7 +1344,7 @@ class Kuaidi100Service
public function poll(string $number, string $code, string $phone)
{
$uri = '/poll';
$callbackUrl = app_settings('kuaidi100_callback');
$callbackUrl = app_settings('kuaidi100.callback');
if (empty($callbackUrl)) {
throw new BizException('未配置推送回调地址');
@ -1357,7 +1357,7 @@ class Kuaidi100Service
'key' => $this->appKey,
'parameters'=> [
'callbackurl'=> $callbackUrl,
'salt' => app_settings('kuaidi100_secret'),
'salt' => app_settings('kuaidi100.secret'),
'phone' => $phone,
'resultv2' => '1',
'autoCom' => empty($code) ? 1 : 0,
@ -1488,7 +1488,7 @@ class Kuaidi100Service
*/
public function unPollSign(string $sign, array $params)
{
return $sign === strtoupper(md5(json_encode($params, JSON_UNESCAPED_UNICODE).app_settings('kuaidi100_secret')));
return $sign === strtoupper(md5(json_encode($params, JSON_UNESCAPED_UNICODE).app_settings('kuaidi100.secret')));
}
public function getStatusName($state = 0)

View File

@ -65,7 +65,7 @@ class OrderPackageService
// 更新商品的售后过期时间
$package->orderProducts()->update([
'after_expire_at'=> $package->checked_at->addDays(app_settings('sale_after_expire_days', 7)),
'after_expire_at'=> $package->checked_at->addDays(app_settings('app.sale_after_expire_days', 7)),
]);
}
}

View File

@ -713,7 +713,7 @@ class OrderService
'attach' => json_encode([
'pay_way' => $payWay,
]),
'body' => app_settings('app_name').'-商城订单',
'body' => app_settings('app.app_name').'-商城订单',
'out_trade_no' => $order->sn,
'total_fee' => $order->total_amount,
'notify_url' => url(route('wxpay.order_paid_notify', [], false), [], true),

View File

@ -16,10 +16,10 @@ class MallUnipushService extends UniPushService
public function __construct()
{
$this->appId = app_settings('mall_push_app_id', '');
$this->appKey = app_settings('mall_push_app_key', '');
$this->appSecret = app_settings('mall_push_app_secret', '');
$this->masterSecret = app_settings('mall_push_master_secret', '');
$this->appId = app_settings('unipush.mall_app_id', '');
$this->appKey = app_settings('unipush.mall_app_key', '');
$this->appSecret = app_settings('unipush.mall_app_secret', '');
$this->masterSecret = app_settings('unipush.mall_master_secret', '');
parent::__construct($this->appId, $this->appKey, $this->appSecret, $this->masterSecret);
}

View File

@ -5,6 +5,8 @@ namespace App\Services;
use App\Models\Setting;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Arr;
use Throwable;
class SettingService
{
@ -40,12 +42,15 @@ class SettingService
if (! array_key_exists($key, $this->items)) {
try {
$this->items[$key] = $this->cache->remember($this->cacheKey($key), $this->ttl, function () use ($key) {
$settings = Setting::where('key', $key)->firstOrFail();
$_key = $this->keyHandle($key);
$settings = Setting::where('key', $_key[0])->firstOrFail();
return $settings->value;
return Arr::get($settings->value, $_key[1]);
});
} catch (ModelNotFoundException $e) {
return $default;
} catch (Throwable $th) {
return $default;
}
}
@ -81,11 +86,8 @@ class SettingService
$keys = is_array($key) ? $key : [$key => $value];
foreach ($keys as $key => $value) {
Setting::updateOrCreate([
'key' => $key,
], [
'value' => $value,
]);
$_key = $this->keyHandle($key);
Setting::where('key', $_key[0])->update(['value->'.$_key[1] => $value]);
$this->cleanCache($key);
}
@ -95,7 +97,7 @@ class SettingService
* @param string $key
* @return void
*/
protected function cleanCache(string $key): void
public function cleanCache(string $key): void
{
unset($this->items[$key]);
@ -110,4 +112,9 @@ class SettingService
{
return "settings.{$key}";
}
protected function keyHandle(string $key)
{
return explode('.', $key);
}
}

View File

@ -15,110 +15,51 @@ class AppSettingSeeder extends Seeder
public function run()
{
foreach ([
'app_name' => [
'value' => '子春生',
'remarks'=>'应用名称',
'app'=> [
'value'=> [
'app_name' => '子春生',
'order_payment_expires_at' => 1800,
'sale_after_expire_days' => 7,
'sign_click_points' => 5,
'sign_click_continue' => 7,
'sign_click_continue_points' => 10,
'article_help' => 1,
'article_agreement' => 2,
'article_health' => 3,
'article_about_us' => env('APP_URL', '').'/h5/articles/1',
'article_user_promotion_agreement' => env('APP_URL', '').'/h5/articles/2',
'article_user_hide_agreement' => env('APP_URL', '').'/h5/articles/3',
'invite_uri' => '',
'search_hot_keys' => '搜索热词,分词1,分词2,分词3',
],
'remarks' => '系统配置',
],
'order_payment_expires_at' => [
'value' => 1800,
'remarks' => '订单支付过期时间(秒)',
'kuaidi100' => [
'value' => [
'is_use' => true,
'callback_uri' => env('APP_URL', '').'/callback/kuaidi100',
'app_key' => 'BTvgbjti4727',
'customer' => '064109188EC4D85DA655DFC342144C6A',
'secret' => '1bd287d1981749f2a30ea74cac0ab99c',
'userid' => 'ec0b6ec7729d4f22824cfd3c519dd45b',
],
'remarks' => '快递100配置',
],
'sale_after_expire_days' => [
'value' => 7,
'remarks' => '售后过期时间(天)',
'unipush' => [
'value' =>[
'is_use' => true,
'mall_app_id' => 'iikmCoESID8bC1LhOPG1r8',
'mall_app_key' => 'JX33P0wP8bAQprI953hpN6',
'mall_app_secret' => 'a3u3B6lXjq6fPTBlOGiOc9',
'mall_master_secret' => 'MAxmqomwo597xJeDuMCvx1',
'merchant_is_use' => false,
'merchant_app_id' => '',
'merchant_app_key' => '',
'merchant_app_secret' => '',
'merchant_master_secret' => '',
],
'remarks' => '个推配置',
],
'sign_click_points' => [
'value' => 5,
'remarks' => '签到送积分(分)',
],
'sign_click_continue' => [
'value' => 7,
'remarks' => '每连续N天签到额外奖励',
],
'sign_click_continue_points' => [
'value' => 10,
'remarks' => '每连续签到额外奖励(分)',
],
'article_help' => [
'value' => 1,
'remarks' => '帮助文章指定分类ID',
],
'article_agreement' => [
'value' => 2,
'remarks' => '协议文章指定分类ID',
],
'article_agreement' => [
'value' => 3,
'remarks' => '健康文章指定分类ID',
],
'article_about_us' => [
'value' => env('APP_URL', '').'/h5/articles/1',
'remarks' => '关于我们文章指定(链接)',
],
'article_user_promotion_agreement' => [
'value' => env('APP_URL', '').'/h5/articles/2',
'remarks' => '服务协议文章指定(链接)',
],
'article_user_hide_agreement' => [
'value' => env('APP_URL', '').'/h5/articles/3',
'remarks' => '隐私协议文章指定(链接)',
],
'kuaidi100_is_use' => [
'value' => true,
'remarks' => '快递100是否开启',
],
'kuaidi100_callback' => [
'value' => env('APP_URL', '').'/callback/kuaidi100',
'remarks' => '快递100回调地址链接',
],
'kuaidi100_app_key' => [
'value' => 'BTvgbjti4727',
'remarks' => '快递100APP_KEY',
],
'kuaidi100_customer' => [
'value' => '064109188EC4D85DA655DFC342144C6A',
'remarks' => '快递100CUSTOMER',
],
'kuaidi100_secret' => [
'value' => '1bd287d1981749f2a30ea74cac0ab99c',
'remarks' => '快递100SECRET',
],
'kuaidi100_userid' => [
'value' => 'ec0b6ec7729d4f22824cfd3c519dd45b',
'remarks' => '快递100USER_ID',
],
'mall_push_app_id' => [
'value' => 'iikmCoESID8bC1LhOPG1r8',
'remarks' => '个推APP_ID',
],
'mall_push_app_key' => [
'value' => 'JX33P0wP8bAQprI953hpN6',
'remarks' => '个推APP_KEY',
],
'mall_push_app_secret' => [
'value' => 'a3u3B6lXjq6fPTBlOGiOc9',
'remarks' => '个推APP_SECRET',
],
'mall_push_master_secret' => [
'value' => 'MAxmqomwo597xJeDuMCvx1',
'remarks' => '个推APP_MASTER_SECRET',
],
'invite_uri' => [
'value' => '',
'remarks' => '分享邀请地址(链接)',
],
'search_hot_keys' => [
'value' => '搜索热词,分词1,分词2,分词3',
'remarks'=>'搜索热词(半角逗号,隔开)',
],
] as $key => $values) {
Setting::firstOrCreate(['key' => $key], $values);
}