|
|
@@ -0,0 +1,123 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Admin;
|
|
|
+
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use App\Http\helper\NumConfig;
|
|
|
+use stdClass;
|
|
|
+
|
|
|
+class ProtectLevelController extends Controller
|
|
|
+{
|
|
|
+ protected $table = 'QPAccountsDB.dbo.ProtectLevel';
|
|
|
+
|
|
|
+ // 列表
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $list = DB::connection('read')->table($this->table)
|
|
|
+ ->orderBy('VIP')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ return view('admin.protect_level.index', compact('list'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 增加
|
|
|
+ public function add(Request $request)
|
|
|
+ {
|
|
|
+ if ($request->isMethod('get')) {
|
|
|
+ return view('admin.protect_level.add');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $request->only([
|
|
|
+ 'ID','Recharge','GrantNum','VIP','LevelUpBonus',
|
|
|
+ 'MinRecharge','WithdrawLimit','DailyWithdraws',
|
|
|
+ 'WithdrawFeeRate','SignAlpha','CustomServiceType',
|
|
|
+ 'RechargeExtraSendRate','SuperballNum','BirthdayValue',
|
|
|
+ ]);
|
|
|
+ // 将 GrantNum 存储为原值 * NumConfig::NUM_VALUE
|
|
|
+ if (isset($data['GrantNum'])) {
|
|
|
+ $data['GrantNum'] = intval($data['GrantNum'] * NumConfig::NUM_VALUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 简单验证(ID唯一性后面手动检查)
|
|
|
+ $this->validate($request, [
|
|
|
+ 'ID' => 'required|integer',
|
|
|
+ 'Recharge' => 'required|numeric|min:0',
|
|
|
+ 'GrantNum' => 'required|integer|min:0',
|
|
|
+ 'VIP' => 'required|integer|min:0',
|
|
|
+ 'LevelUpBonus' => 'required|integer|min:0',
|
|
|
+ 'MinRecharge' => 'required|integer|min:0',
|
|
|
+ 'WithdrawLimit' => 'required|integer|min:0',
|
|
|
+ 'DailyWithdraws'=> 'required|integer|min:0|max:255',
|
|
|
+ 'WithdrawFeeRate'=> 'required|numeric|min:0',
|
|
|
+ 'SignAlpha' => 'required|integer|min:0',
|
|
|
+ 'CustomServiceType' => 'required|integer|in:1,2',
|
|
|
+ 'RechargeExtraSendRate' => 'required|numeric|min:0',
|
|
|
+ 'SuperballNum' => 'required|integer|min:0',
|
|
|
+ 'BirthdayValue' => 'required|integer|min:0',
|
|
|
+ ]);
|
|
|
+ // 唯一性检查
|
|
|
+ if (DB::connection('read')->table($this->table)->where('ID', $data['ID'])->exists()) {
|
|
|
+ return apiReturnFail('ID already exists');
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::connection('write')->table($this->table)->insert($data);
|
|
|
+ return apiReturnSuc();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改
|
|
|
+ public function edit(Request $request, $id)
|
|
|
+ {
|
|
|
+ if ($request->isMethod('get')) {
|
|
|
+ $info = DB::connection('read')->table($this->table)
|
|
|
+ ->where('ID', $id)
|
|
|
+ ->first();
|
|
|
+ return view('admin.protect_level.edit', compact('info'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = $request->only([
|
|
|
+ 'Recharge','GrantNum','VIP','LevelUpBonus',
|
|
|
+ 'MinRecharge','WithdrawLimit','DailyWithdraws',
|
|
|
+ 'WithdrawFeeRate','SignAlpha','CustomServiceType',
|
|
|
+ 'RechargeExtraSendRate','SuperballNum','BirthdayValue',
|
|
|
+ ]);
|
|
|
+ // GrantNum 乘以系数保存
|
|
|
+ if (isset($post['GrantNum'])) {
|
|
|
+ $post['GrantNum'] = intval($post['GrantNum'] * NumConfig::NUM_VALUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 字段校验
|
|
|
+ $this->validate($request, [
|
|
|
+ 'Recharge' => 'required|numeric|min:0',
|
|
|
+ 'GrantNum' => 'required|integer|min:0',
|
|
|
+ 'VIP' => 'required|integer|min:0',
|
|
|
+ 'LevelUpBonus' => 'required|integer|min:0',
|
|
|
+ 'MinRecharge' => 'required|integer|min:0',
|
|
|
+ 'WithdrawLimit' => 'required|integer|min:0',
|
|
|
+ 'DailyWithdraws'=> 'required|integer|min:0|max:255',
|
|
|
+ 'WithdrawFeeRate'=> 'required|numeric|min:0',
|
|
|
+ 'SignAlpha' => 'required|integer|min:0',
|
|
|
+ 'CustomServiceType' => 'required|integer|in:1,2',
|
|
|
+ 'RechargeExtraSendRate' => 'required|numeric|min:0',
|
|
|
+ 'SuperballNum' => 'required|integer|min:0',
|
|
|
+ 'BirthdayValue' => 'required|integer|min:0',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ DB::connection('write')->table($this->table)
|
|
|
+ ->where('ID', $id)
|
|
|
+ ->update($post);
|
|
|
+
|
|
|
+ return apiReturnSuc();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除
|
|
|
+ public function delete($id)
|
|
|
+ {
|
|
|
+ DB::connection('write')->table($this->table)
|
|
|
+ ->where('ID', $id)
|
|
|
+ ->delete();
|
|
|
+
|
|
|
+ return apiReturnSuc();
|
|
|
+ }
|
|
|
+}
|