初始化本地仓库

This commit is contained in:
2026-08-31 11:33:59 +08:00
commit 663f74b633
2390 changed files with 402918 additions and 0 deletions
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: https://madong.tech
*/
namespace app\service\api\web;
use app\dao\web\AdvDao;
use core\base\BaseService;
use support\Redis;
/**
* 广告服务
*/
class AdvertisementService extends BaseService
{
public function __construct(AdvDao $dao)
{
$this->dao = $dao;
}
/**
* 获取广告列表
*
* @return array
* @throws \Exception
*/
public function getAds(): array
{
$map = [
['enabled', 'eq', 1],
];
$advs = $this->dao->selectList($map, ['*'], 0, 0, 'sort asc, id asc');
// 过滤时间范围内有效的广告
$now = time();
return $advs->filter(function($adv) use ($now) {
$startTime = $adv->getOriginal('start_time');
$endTime = $adv->getOriginal('end_time');
return $startTime <= $now && $endTime >= $now;
})->toArray();
}
/**
* 获取广告位信息(兼容旧版本,已废弃)
*
* @param array $_params 参数
* @return array
*/
public function getAdvertisementInfo(array $_params): array
{
return $this->getAds();
}
/**
* 清除广告缓存
*
* @return void
*/
public function clearAdCache(): void
{
// 清除所有广告缓存
$keys = Redis::keys('web_ads_*');
if (!empty($keys)) {
Redis::del($keys);
}
}
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: https://madong.tech
*/
namespace app\service\api\web;
use app\dao\web\LinkDao;
use core\base\BaseService;
/**
* 友情链接服务
*/
class LinkService extends BaseService
{
public function __construct(LinkDao $dao)
{
$this->dao = $dao;
}
/**
* 根据类型获取链接
*
* @param string $type 链接类型
*
* @return array|null
* @throws \Exception
*/
public function getLinksByType(string $type): ?array
{
$map = [
['category', 'eq', $type],
['enabled', 'eq', 1],
];
return $this->dao->selectList($map, ['*'], 0, 0, 'sort asc')->toArray();
}
/**
* 获取所有链接
*
* @return array
* @throws \Exception
*/
public function getAllLinks(): array
{
$map = [
['enabled', '=', 1],
['deleted_at', '=', null],
];
return $this->dao->selectList($map, ['*'], 0, 0, 'category asc, sort asc')->toArray();
}
}
+133
View File
@@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: https://madong.tech
*/
namespace app\service\api\web;
use app\api\CurrentMember;
use app\dao\web\MenuDao;
use app\enum\common\EnabledStatus;
use core\base\BaseService;
use support\Container;
/**
* 菜单服务
*/
class MenuService extends BaseService
{
// 缓存键前缀
public const CACHE_PREFIX = 'web_navigation_list';
// 缓存过期时间(秒)
public const CACHE_EXPIRE = 3600;
public function __construct(MenuDao $dao)
{
$this->dao = $dao;
}
/**
* 获取导航菜单列表(带权限过滤)
*
* @return array
* @throws \Exception
*/
public function getNavigationList(): array
{
$map = [
['enabled', 'eq', EnabledStatus::ENABLED->value],
['is_show', 'eq', 1],
];
$allMenus = $this->dao->selectList($map, ['*'], 0, 0, 'sort asc, id asc');
$allMenus = $allMenus->toArray();
$userPermissions = $this->getUserPermissions();
$isLogin = !empty($userPermissions);
$filteredMenus = [];
foreach ($allMenus as $menu) {
$code = $menu['code'] ?? '';
if (empty($code)) {
$filteredMenus[] = $menu;
continue;
}
if (!$isLogin) {
continue;
}
if (in_array($code, $userPermissions, true)) {
$filteredMenus[] = $menu;
}
}
return $this->parseExtra($filteredMenus);
}
/**
* 获取当前用户的权限码列表
*
* @return array
*/
private function getUserPermissions(): array
{
try {
/** @var CurrentMember $currentMember */
$currentMember = Container::make(CurrentMember::class);
return $currentMember->getPermissions();
} catch (\Exception) {
// 未登录或获取权限失败,返回空数组,只显示公开菜单
return [];
}
}
/**
* 解析 extra 扩展字段
* 将 JSON 字符串转换为数组并合并到菜单数据
*
* @param array $menus
* @return array
*/
protected function parseExtra(array $menus): array
{
return array_map(function ($menu) {
// 解析 extra JSON
if (!empty($menu['extra']) && is_string($menu['extra'])) {
$extra = json_decode($menu['extra'], true);
if (json_last_error() === JSON_ERROR_NONE) {
$menu['extra'] = $extra;
} else {
$menu['extra'] = [];
}
} elseif (empty($menu['extra'])) {
$menu['extra'] = [];
}
// 将常用字段映射到 extra(便于前端使用)
$menu['extra'] = array_merge([
'type' => $menu['type'] ?? 1,
'target' => $menu['target'] ?? 1,
], $menu['extra']);
return $menu;
}, $menus);
}
/**
* 清除菜单缓存
*
* @return void
*/
public function clearMenuCache(): void
{
$this->cacheDriver()->delete(self::CACHE_PREFIX . '_all');
}
}