1.将部门修改为渠道,并且所有dice_表关联渠道表

2.将所有配置表,记录表设置关联渠道
3.优化后台页面设置
This commit is contained in:
2026-05-19 09:49:02 +08:00
parent 085454fb78
commit dd264b1e97
143 changed files with 4741 additions and 1254 deletions

View File

@@ -6,11 +6,13 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\Log;
@@ -19,7 +21,7 @@ use support\Log;
* 奖励配置逻辑层DiceRewardConfig
* weight 1-10000各档位权重和不限制
*/
class DiceRewardConfigLogic extends BaseLogic
class DiceRewardConfigLogic extends DiceBaseLogic
{
/** weight 取值范围 */
private const WEIGHT_MIN = 1;
@@ -36,18 +38,23 @@ class DiceRewardConfigLogic extends BaseLogic
public function add(array $data): mixed
{
$result = parent::add($data);
DiceRewardConfig::refreshCache();
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 修改:保存后刷新缓存BIGWIN 的 weight 直接写入 dice_reward_config 表,抽奖时从 Config 读取
* 修改:按业务 id + 渠道更新;保存后刷新该渠道缓存
*/
public function edit($id, array $data): mixed
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$result = parent::edit($id, $data);
DiceRewardConfig::refreshCache();
return $result;
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
DiceRewardConfig::refreshCache($deptId);
return true;
}
/**
@@ -152,8 +159,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新奖励索引配置grid_number、ui_text、real_ev、tier、remark不含 weightBIGWIN 权重单独接口)
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdate(array $items): void
public function batchUpdate(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
foreach ($items as $row) {
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
@@ -167,10 +175,18 @@ class DiceRewardConfigLogic extends BaseLogic
}
}
if (! empty($data)) {
parent::edit($id, $data);
$this->updateByBusinessIdAndDept($id, $deptId, $data);
}
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 按业务 id025与渠道更新单条配置
*/
private function updateByBusinessIdAndDept(int $businessId, int $deptId, array $data): void
{
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, $businessId, $deptId, $data);
}
/**
@@ -201,8 +217,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdateBigwinWeight(array $items): void
public function batchUpdateBigwinWeight(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$weightMin = 0;
$weightMax = 10000;
@@ -213,21 +230,33 @@ class DiceRewardConfigLogic extends BaseLogic
continue;
}
$weight = max($weightMin, min($weightMax, $weight));
$this->model->where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->update(['weight' => $weight]);
$query = $this->model->where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
$exists = (clone $query)->find();
if ($exists === null) {
throw new ApiException('BIGWIN grid_number=' . $gridNumber . ' not found for current channel');
}
$query->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 删除后刷新缓存
*/
public function destroy($ids): bool
public function destroy($ids, ?array $adminInfo = null, $requestDeptId = null): bool
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
$result = parent::destroy($ids);
if ($result) {
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
return $result;
}
@@ -403,6 +432,12 @@ class DiceRewardConfigLogic extends BaseLogic
$record->lottery_config_id = $config ? (int) $config->id : null;
$record->result_counts = $counts;
$record->admin_id = $adminId;
if ($adminId > 0) {
$admin = \plugin\saiadmin\app\model\system\SystemUser::find($adminId);
if ($admin && !empty($admin->dept_id)) {
$record->dept_id = $admin->dept_id;
}
}
$record->create_time = date('Y-m-d H:i:s');
$record->save();
$recordId = (int) $record->id;