修复翻译BUG
This commit is contained in:
@@ -283,8 +283,54 @@ class Channel extends Backend
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
$items = $res->items();
|
||||
$channelIds = [];
|
||||
foreach ($items as $item) {
|
||||
$cid = intval($item['id'] ?? 0);
|
||||
if ($cid > 0) {
|
||||
$channelIds[] = $cid;
|
||||
}
|
||||
}
|
||||
$channelIds = array_values(array_unique($channelIds));
|
||||
if ($channelIds !== []) {
|
||||
$userCountMap = Db::name('user')
|
||||
->where('channel_id', 'in', $channelIds)
|
||||
->group('channel_id')
|
||||
->column('COUNT(*) AS c', 'channel_id');
|
||||
$now = time();
|
||||
foreach ($channelIds as $channelId) {
|
||||
$latestCount = intval($userCountMap[$channelId] ?? 0);
|
||||
Db::name('channel')
|
||||
->where('id', intval($channelId))
|
||||
->update([
|
||||
'user_count' => $latestCount,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
}
|
||||
$profitMap = Db::name('bet_order')
|
||||
->where('channel_id', 'in', $channelIds)
|
||||
->where('status', 2)
|
||||
->group('channel_id')
|
||||
->column('SUM(total_amount - win_amount - jackpot_extra_amount) AS p', 'channel_id');
|
||||
foreach ($items as $k => $item) {
|
||||
$cid = intval($item['id'] ?? 0);
|
||||
if ($cid <= 0) {
|
||||
continue;
|
||||
}
|
||||
$items[$k]['user_count'] = intval($userCountMap[$cid] ?? 0);
|
||||
$profit = strval($profitMap[$cid] ?? '0.00');
|
||||
$items[$k]['profit_amount'] = bcadd($profit, '0', 2);
|
||||
if (!isset($items[$k]['total_profit_amount']) || $items[$k]['total_profit_amount'] === null || $items[$k]['total_profit_amount'] === '') {
|
||||
$items[$k]['total_profit_amount'] = $items[$k]['profit_amount'];
|
||||
}
|
||||
if (!isset($items[$k]['commission_pool_amount']) || $items[$k]['commission_pool_amount'] === null || $items[$k]['commission_pool_amount'] === '') {
|
||||
$items[$k]['commission_pool_amount'] = '0.00';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'list' => $items,
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
@@ -636,7 +682,8 @@ class Channel extends Backend
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
$res = ChannelSettlementService::settleAllDueChannels(intval($this->auth->id));
|
||||
// 批量按钮语义:手动触发“待结算渠道”结算,不受结算周期到点限制。
|
||||
$res = ChannelSettlementService::settleAllDueChannels(intval($this->auth->id), false);
|
||||
return $this->success('批量结算完成', $res);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,10 +251,11 @@ class Rule extends Backend
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$toEnglish = !$this->shouldForceMenuTitleZh($request) && $this->shouldTranslateMenuToEnglish();
|
||||
foreach ($rules as $idx => $rule) {
|
||||
$title = $rule['title'] ?? '';
|
||||
if (is_string($title) && $title !== '') {
|
||||
$rules[$idx]['title'] = $this->menuTitleToZh($title);
|
||||
$rules[$idx]['title'] = $toEnglish ? $this->menuTitleToEn($title) : $this->menuTitleToZh($title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +273,30 @@ class Rule extends Backend
|
||||
return isset($zhMap[$title]) && is_string($zhMap[$title]) ? $zhMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function menuTitleToEn(string $title): string
|
||||
{
|
||||
static $enMap = null;
|
||||
if (!is_array($enMap)) {
|
||||
$mapFile = app_path() . '/common/lang/en/admin_rule_title.php';
|
||||
$loaded = is_file($mapFile) ? include $mapFile : [];
|
||||
$enMap = is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
return isset($enMap[$title]) && is_string($enMap[$title]) ? $enMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function shouldTranslateMenuToEnglish(): bool
|
||||
{
|
||||
$lang = function_exists('locale') ? locale() : '';
|
||||
$normalized = is_string($lang) ? strtolower(str_replace('_', '-', trim($lang))) : '';
|
||||
return str_starts_with($normalized, 'en');
|
||||
}
|
||||
|
||||
private function shouldForceMenuTitleZh(Request $request): bool
|
||||
{
|
||||
$flag = $request->get('force_menu_zh') ?? $request->post('force_menu_zh');
|
||||
return in_array($flag, [1, '1', true, 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
private function autoAssignPermission(int $id, int $pid): void
|
||||
{
|
||||
$groups = AdminGroup::where('rules', '<>', '*')->select();
|
||||
|
||||
@@ -278,24 +278,27 @@ class Auth extends \ba\Auth
|
||||
public function getMenus(int $uid = 0): array
|
||||
{
|
||||
$menus = parent::getMenus($uid ?: $this->id);
|
||||
return $this->translateMenuRuleTitles($menus);
|
||||
return $this->translateMenuRuleTitles($menus, $this->shouldTranslateMenuToEnglish());
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单标题统一按中文显示(不随语言切换)。
|
||||
* 若 title 为英文动作名/英文菜单名,按中文映射表转换。
|
||||
* 菜单标题按当前语言展示:
|
||||
* - 英文环境:中文标题映射为英文
|
||||
* - 其他环境:英文标题映射为中文
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $menus
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function translateMenuRuleTitles(array $menus): array
|
||||
private function translateMenuRuleTitles(array $menus, bool $toEnglish): array
|
||||
{
|
||||
foreach ($menus as $k => $item) {
|
||||
if (isset($item['title']) && is_string($item['title']) && $item['title'] !== '') {
|
||||
$menus[$k]['title'] = $this->menuTitleToZh($item['title']);
|
||||
$menus[$k]['title'] = $toEnglish
|
||||
? $this->menuTitleToEn($item['title'])
|
||||
: $this->menuTitleToZh($item['title']);
|
||||
}
|
||||
if (!empty($item['children']) && is_array($item['children'])) {
|
||||
$menus[$k]['children'] = $this->translateMenuRuleTitles($item['children']);
|
||||
$menus[$k]['children'] = $this->translateMenuRuleTitles($item['children'], $toEnglish);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +316,24 @@ class Auth extends \ba\Auth
|
||||
return isset($zhMap[$title]) && is_string($zhMap[$title]) ? $zhMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function menuTitleToEn(string $title): string
|
||||
{
|
||||
static $enMap = null;
|
||||
if (!is_array($enMap)) {
|
||||
$mapFile = app_path() . '/common/lang/en/admin_rule_title.php';
|
||||
$loaded = is_file($mapFile) ? include $mapFile : [];
|
||||
$enMap = is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
return isset($enMap[$title]) && is_string($enMap[$title]) ? $enMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function shouldTranslateMenuToEnglish(): bool
|
||||
{
|
||||
$lang = function_exists('locale') ? locale() : '';
|
||||
$normalized = is_string($lang) ? strtolower(str_replace('_', '-', trim($lang))) : '';
|
||||
return str_starts_with($normalized, 'en');
|
||||
}
|
||||
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return in_array('*', $this->getRuleIds());
|
||||
|
||||
@@ -87,6 +87,8 @@ return [
|
||||
'推送-用户私有频道' => 'Push: user private',
|
||||
'渠道管理' => 'Channel management',
|
||||
'管理员提现记录' => 'Admin withdraw records',
|
||||
'管理员钱包' => 'Admin wallets',
|
||||
'管理员钱包流水' => 'Admin wallet records',
|
||||
'一键批量结算待结算渠道' => 'Batch settle pending channels',
|
||||
'渠道结算统计' => 'Channel settlement statistics',
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class ChannelSettlementService
|
||||
return ['ok' => false, 'msg' => '当前流程为超管结算后自动发放,渠道管理员无需二次结算'];
|
||||
}
|
||||
|
||||
public static function settleAllDueChannels(int $operatorAdminId): array
|
||||
public static function settleAllDueChannels(int $operatorAdminId, bool $respectCycle = true): array
|
||||
{
|
||||
$channels = Db::name('channel')->where('status', 1)->select()->toArray();
|
||||
$ok = 0;
|
||||
@@ -106,7 +106,7 @@ class ChannelSettlementService
|
||||
if ($channelId <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (!self::isChannelDueForAutoSettle($channel, $now)) {
|
||||
if ($respectCycle && !self::isChannelDueForAutoSettle($channel, $now)) {
|
||||
continue;
|
||||
}
|
||||
$res = self::settleBySuperAdmin($channelId, $operatorAdminId, '周期自动结算', true);
|
||||
|
||||
Reference in New Issue
Block a user