| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\logic;
- use app\common\logic\BaseLogic;
- use app\common\model\file\File;
- use app\common\model\file\FileCate;
- use app\common\service\ConfigService;
- use app\common\service\storage\Driver as StorageDriver;
- /**
- * 文件逻辑层
- * Class FileLogic
- * @package app\adminapi\logic
- */
- class FileLogic extends BaseLogic
- {
- /**
- * @notes 移动文件
- * @param $params
- * @author 张无忌
- * @date 2021/7/28 15:29
- */
- public static function move($params)
- {
- (new File())->whereIn('id', $params['ids'])
- ->update([
- 'cid' => $params['cid'],
- 'update_time' => time()
- ]);
- }
- /**
- * @notes 重命名文件
- * @param $params
- * @author 张无忌
- * @date 2021/7/29 17:16
- */
- public static function rename($params)
- {
- (new File())->where('id', $params['id'])
- ->update([
- 'name' => $params['name'],
- 'update_time' => time()
- ]);
- }
- /**
- * @notes 批量删除文件
- * @param $params
- * @author 张无忌
- * @date 2021/7/28 15:41
- */
- public static function delete($params)
- {
- $result = File::whereIn('id', $params['ids'])->select();
- $StorageDriver = new StorageDriver([
- 'default' => ConfigService::get('storage', 'default', 'local'),
- 'engine' => ConfigService::get('storage') ?? ['local'=>[]],
- ]);
- foreach ($result as $item) {
- $StorageDriver->delete($item['uri']);
- }
- File::destroy($params['ids']);
- }
- /**
- * @notes 添加文件分类
- * @param $params
- * @author 张无忌
- * @date 2021/7/28 11:32
- */
- public static function addCate($params)
- {
- FileCate::create([
- 'type' => $params['type'],
- 'pid' => $params['pid'],
- 'name' => $params['name']
- ]);
- }
- /**
- * @notes 编辑文件分类
- * @param $params
- * @author 张无忌
- * @date 2021/7/28 14:03
- */
- public static function editCate($params)
- {
- FileCate::update([
- 'name' => $params['name'],
- 'update_time' => time()
- ], ['id' => $params['id']]);
- }
- /**
- * @notes 删除文件分类
- * @param $params
- * @author 张无忌
- * @date 2021/7/28 14:21
- */
- public static function delCate($params)
- {
- $fileModel = new File();
- $cateModel = new FileCate();
- $cateIds = self::getCateIds($params['id']);
- array_push($cateIds, $params['id']);
- // 删除分类及子分类
- $cateModel->whereIn('id', $cateIds)->update(['delete_time' => time()]);
- // 删除文件
- $fileIds = $fileModel->whereIn('cid', $cateIds)->column('id');
- if (!empty($fileIds)) {
- self::delete(['ids' => $fileIds]);
- }
- }
- /**
- * @notes 获取所有分类id
- * @param $parentId
- * @param array $cateArr
- * @return array
- * @author 段誉
- * @date 2024/2/7 15:03
- */
- public static function getCateIds($parentId, array $cateArr = []): array
- {
- $childIds = FileCate::where(['pid' => $parentId])->column('id');
- if (empty($childIds)) {
- return $childIds;
- } else {
- $allChildIds = $childIds;
- foreach ($childIds as $childId) {
- $allChildIds = array_merge($allChildIds, static::getCateIds($childId, $cateArr));
- }
- return $allChildIds;
- }
- }
- }
|