1.优化开奖和推送
2.新增控制连续开奖赔率
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\game\DepositTier;
|
||||
use app\common\library\game\StreakWinReward;
|
||||
use app\common\library\game\ZiHuaDictionary as ZiHuaDictionaryLib;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
@@ -33,7 +35,19 @@ class GameConfig extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表:排除独立表单维护的 36 字花字典
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function excludedConfigKeys(): array
|
||||
{
|
||||
return [
|
||||
ZiHuaDictionaryLib::CONFIG_KEY,
|
||||
DepositTier::CONFIG_KEY,
|
||||
StreakWinReward::CONFIG_KEY,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表:排除独立表单维护的配置键
|
||||
*/
|
||||
protected function _index(): Response
|
||||
{
|
||||
@@ -45,7 +59,7 @@ class GameConfig extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '') {
|
||||
$where[] = [$mainShort . '.config_key', '<>', ZiHuaDictionaryLib::CONFIG_KEY];
|
||||
$where[] = [$mainShort . '.config_key', 'not in', $this->excludedConfigKeys()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -63,4 +77,51 @@ class GameConfig extends Backend
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉:排除独立维护的配置键
|
||||
*/
|
||||
protected function _select(): Response
|
||||
{
|
||||
if (empty($this->model)) {
|
||||
return $this->success('', [
|
||||
'list' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$pk = $this->model->getPk();
|
||||
|
||||
$fields = [$pk];
|
||||
$quickSearchArr = is_array($this->quickSearchField) ? $this->quickSearchField : explode(',', (string) $this->quickSearchField);
|
||||
foreach ($quickSearchArr as $f) {
|
||||
$f = trim((string) $f);
|
||||
if ($f === '') {
|
||||
continue;
|
||||
}
|
||||
$f = str_contains($f, '.') ? substr($f, strrpos($f, '.') + 1) : $f;
|
||||
if ($f !== '' && !in_array($f, $fields, true)) {
|
||||
$fields[] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '') {
|
||||
$where[] = [$mainShort . '.config_key', 'not in', $this->excludedConfigKeys()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
->field($fields)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
121
app/admin/controller/config/StreakWinReward.php
Normal file
121
app/admin/controller/config/StreakWinReward.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\game\StreakWinReward as StreakWinRewardLib;
|
||||
use support\think\Db;
|
||||
use support\Response;
|
||||
use Throwable;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
/**
|
||||
* 连胜奖励(game_config.streak_win_reward)
|
||||
*/
|
||||
class StreakWinReward extends Backend
|
||||
{
|
||||
protected bool $modelValidate = false;
|
||||
|
||||
protected array $noNeedPermission = ['index', 'save'];
|
||||
|
||||
private function hasNodePermission(WebmanRequest $request, string $action): bool
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return false;
|
||||
}
|
||||
$controllerPath = get_controller_path($request);
|
||||
if (!$controllerPath) {
|
||||
return false;
|
||||
}
|
||||
$paths = [];
|
||||
$paths[] = $controllerPath . '/' . $action;
|
||||
$parts = explode('/', $controllerPath);
|
||||
foreach ($parts as &$part) {
|
||||
if (str_contains($part, '_')) {
|
||||
$part = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $part))));
|
||||
}
|
||||
}
|
||||
$paths[] = implode('/', $parts) . '/' . $action;
|
||||
foreach (array_values(array_unique($paths)) as $path) {
|
||||
if ($this->auth->check($path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if (!$this->hasNodePermission($request, 'index')) {
|
||||
return $this->error(__('You have no permission'), [], 401);
|
||||
}
|
||||
if ($request->method() !== 'GET') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$row = Db::name('game_config')->where('config_key', StreakWinRewardLib::CONFIG_KEY)->find();
|
||||
$rows = StreakWinRewardLib::parseFromConfigValue($row['config_value'] ?? null);
|
||||
|
||||
return $this->success('', [
|
||||
'rows' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if (!$this->hasNodePermission($request, 'save')) {
|
||||
return $this->error(__('You have no permission'), [], 401);
|
||||
}
|
||||
if ($request->method() !== 'POST') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$payload = $request->post('rows');
|
||||
if (!is_array($payload)) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
$encoded = StreakWinRewardLib::encodeForDb($payload);
|
||||
$now = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$exists = Db::name('game_config')->where('config_key', StreakWinRewardLib::CONFIG_KEY)->find();
|
||||
if ($exists) {
|
||||
Db::name('game_config')->where('config_key', StreakWinRewardLib::CONFIG_KEY)->update([
|
||||
'config_value' => $encoded,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
} else {
|
||||
Db::name('game_config')->insert([
|
||||
'config_key' => StreakWinRewardLib::CONFIG_KEY,
|
||||
'config_value' => $encoded,
|
||||
'value_type' => 'json',
|
||||
'remark' => '连胜奖励',
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
StreakWinRewardLib::clearCache();
|
||||
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user