- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\services\system;
|
|
|
|
use app\dao\system\SystemMenusRelevanceDao;
|
|
use app\services\BaseServices;
|
|
use crmeb\services\CacheService;
|
|
use think\annotation\Inject;
|
|
|
|
/**
|
|
* 权限菜单关联
|
|
* Class SystemMenusRelevanceServices
|
|
* @package app\services\system
|
|
* @mixin SystemMenusRelevanceDao
|
|
*/
|
|
class SystemMenusRelevanceServices extends BaseServices
|
|
{
|
|
|
|
/**
|
|
* @var SystemMenusRelevanceDao
|
|
*/
|
|
#[Inject]
|
|
protected SystemMenusRelevanceDao $dao;
|
|
|
|
/**
|
|
* 添加关键词
|
|
* @param $menuId
|
|
* @param $data
|
|
* @return true
|
|
* @throws \ReflectionException
|
|
* User: liusl
|
|
* DateTime: 2024/12/25 上午10:04
|
|
*/
|
|
public function updateData($menuId, $data)
|
|
{
|
|
$haveData = $this->search(['menu_id' => $menuId])->column('keyword');
|
|
|
|
$delData = array_diff($haveData, $data);
|
|
$newData = array_diff($data, $haveData);
|
|
|
|
if ($delData) {
|
|
$this->dao->delete(['menu_id' => $menuId, 'keyword' => $delData]);
|
|
}
|
|
|
|
if ($newData) {
|
|
$newData = array_map(function ($item) use ($menuId) {
|
|
return ['menu_id' => $menuId, 'keyword' => $item];
|
|
}, $newData);
|
|
$this->dao->saveAll($newData);
|
|
}
|
|
CacheService::redisHandler('system_menus')->clear();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 获取关键词
|
|
* @param $menuId
|
|
* @return array
|
|
* @throws \ReflectionException
|
|
* User: liusl
|
|
* DateTime: 2024/12/25 上午10:04
|
|
*/
|
|
public function getKeyword($menuId): array
|
|
{
|
|
return $this->search(['menu_id' => $menuId])->column('keyword');
|
|
}
|
|
}
|