Skip to content

Commit

Permalink
refactor(签到): 重构签到配置及相关逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Nov 13, 2018
1 parent ffebef8 commit c427f76
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ class DatabaseSeeder extends Seeder
public function run()
{
$this->call(AbilitySeeder::class);
$this->call(SettingsTableSeeder::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,24 @@
* +----------------------------------------------------------------------+
*/

return [
namespace SlimKit\PlusCheckIn\Seeds;

'open' => false,
'attach_balance' => 1,
use Illuminate\Database\Seeder;
use function Zhiyi\Plus\setting;

];
class SettingsTableSeeder extends Seeder
{
/**
* Run the package seeder.
*
* @return void
* @author Seven Du <[email protected]>
*/
public function run()
{
setting('checkin')->set([
'switch' => true,
'attach-balance' => 1,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace SlimKit\PlusCheckIn\API\Controllers;

use Illuminate\Http\Request;
use function Zhiyi\Plus\setting;
use Zhiyi\Plus\Models\WalletCharge as WalletChargeModel;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use SlimKit\PlusCheckIn\Models\CheckinLog as CheckinLogModel;
Expand All @@ -44,7 +45,7 @@ class CheckInController extends Controller
*/
public function __construct(ConfigRepository $config)
{
$this->attach_balance = $config->get('checkin.attach_balance');
$this->attach_balance = setting('checkin', 'attach-balance', 1);
}

/**
Expand Down
22 changes: 2 additions & 20 deletions packages/slimkit-plus-checkin/src/API/Middleware/CheckInSwitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,11 @@
namespace SlimKit\PlusCheckIn\API\Middleware;

use Closure;
use function Zhiyi\Plus\setting;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Config\Repository as ConfigRepository;

class CheckInSwitch
{
/**
* ThinkSNS+ config repository.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;

/**
* Create the middleware.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @author Seven Du <[email protected]>
*/
public function __construct(ConfigRepository $config)
{
$this->config = $config;
}

/**
* The middleware handle.
*
Expand All @@ -54,7 +36,7 @@ public function __construct(ConfigRepository $config)
*/
public function handle($request, Closure $next)
{
if (! $this->config->get('checkin.open')) {
if (! setting('checkin', 'switch', false)) {
throw new AuthorizationException(
trans('plus-checkin::messages.checkin-closed')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace SlimKit\PlusCheckIn\Admin\Controllers;

use Zhiyi\Plus\Support\Configuration;
use function Zhiyi\Plus\setting;
use SlimKit\PlusCheckIn\Admin\Requests\StoreConfig as StoreConfigRequest;

class HomeController
Expand All @@ -34,27 +34,23 @@ class HomeController
public function index()
{
return view('plus-checkin::admin', [
'switch' => config('checkin.open'),
'balance' => config('checkin.attach_balance'),
'switch' => setting('checkin', 'switch'),
'balance' => setting('checkin', 'attach-balance'),
]);
}

/**
* Store checkin config.
*
* @param \SlimKit\PlusCheckIn\Admin\Requests\StoreConfig $request
* @param \Zhiyi\Plus\Support\Configuration $config
* @return mixed
* @author Seven Du <[email protected]>
*/
public function store(StoreConfigRequest $request, Configuration $config)
public function store(StoreConfigRequest $request)
{
$switch = (bool) $request->input('switch');
$balance = (int) $request->input('balance');

$config->set([
'checkin.open' => $switch,
'checkin.attach_balance' => $balance,
setting('checkin')->set([
'switch' => (bool) $request->input('switch'),
'attach-balance' => (int) $request->input('balance'),
]);

return redirect()->back()->with('message', trans('plus-checkin::messages.success'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public function boot()
// Publish public resource.
$this->publishes([
$this->app->make('path.checkin.assets') => $this->app->publicPath().'/assets/checkin',
], 'public');

// Publish config.
$this->publishes([
$this->app->make('path.checkin.config') => $this->app->configPath('checkin.php'),
], 'config');
], 'checkin:assets');
}

/**
Expand All @@ -62,11 +57,7 @@ public function register()
$this->app->instance('path.checkin', $path = dirname(dirname(__DIR__)));
$this->app->instance('path.checkin.migrations', $path.'/database/migrations');
$this->app->instance('path.checkin.assets', $path.'/assets');
$this->app->instance('path.checkin.config', $configFilename = $path.'/config/checkin.php');
$this->app->instance('path.checkin.lang', $path.'/resource/lang');
$this->app->instance('path.checkin.view', $path.'/resource/views');

// Merge config.
$this->mergeConfigFrom($configFilename, 'checkin');
}
}

0 comments on commit c427f76

Please sign in to comment.