新增
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?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\adminapi\logic\article\ArticleCateLogic;
|
||||
use app\adminapi\logic\auth\MenuLogic;
|
||||
use app\adminapi\logic\auth\RoleLogic;
|
||||
use app\adminapi\logic\dept\DeptLogic;
|
||||
use app\adminapi\logic\dept\JobsLogic;
|
||||
use app\adminapi\logic\setting\dict\DictTypeLogic;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\auth\SystemMenu;
|
||||
use app\common\model\auth\SystemRole;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Jobs;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\dict\DictType;
|
||||
use app\common\service\{FileService, ConfigService};
|
||||
|
||||
/**
|
||||
* 配置类逻辑层
|
||||
* Class ConfigLogic
|
||||
* @package app\adminapi\logic
|
||||
*/
|
||||
class ConfigLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/31 11:03
|
||||
*/
|
||||
public static function getConfig(): array
|
||||
{
|
||||
$config = [
|
||||
// 文件域名
|
||||
'oss_domain' => FileService::getFileUrl(),
|
||||
|
||||
// 网站名称
|
||||
'web_name' => ConfigService::get('website', 'name'),
|
||||
// 网站图标
|
||||
'web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'web_favicon')),
|
||||
// 网站logo
|
||||
'web_logo' => FileService::getFileUrl(ConfigService::get('website', 'web_logo')),
|
||||
// 登录页
|
||||
'login_image' => FileService::getFileUrl(ConfigService::get('website', 'login_image')),
|
||||
// 版权信息
|
||||
'copyright_config' => ConfigService::get('copyright', 'config', []),
|
||||
// 版本号
|
||||
'version' => config('project.version')
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 根据类型获取字典类型
|
||||
* @param $type
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/27 19:09
|
||||
*/
|
||||
public static function getDictByType($type)
|
||||
{
|
||||
if (!is_string($type)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$type = explode(',', $type);
|
||||
$lists = DictData::whereIn('type_value', $type)->select()->toArray();
|
||||
|
||||
if (empty($lists)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($type as $item) {
|
||||
foreach ($lists as $dict) {
|
||||
if ($dict['type_value'] == $item) {
|
||||
$result[$item][] = $dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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\auth\Admin;
|
||||
use app\adminapi\service\AdminTokenService;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\adminapi\logic
|
||||
*/
|
||||
class LoginLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 管理员账号登录
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 令狐冲
|
||||
* @date 2021/6/30 17:00
|
||||
*/
|
||||
public function login($params)
|
||||
{
|
||||
$time = time();
|
||||
$admin = Admin::where('account', '=', $params['account'])->find();
|
||||
|
||||
//用户表登录信息更新
|
||||
$admin->login_time = $time;
|
||||
$admin->login_ip = request()->ip();
|
||||
$admin->save();
|
||||
|
||||
//设置token
|
||||
$adminInfo = AdminTokenService::setToken($admin->id, $params['terminal'], $admin->multipoint_login);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $admin->avatar ? $admin->avatar : Config::get('project.default_image.admin_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
return [
|
||||
'name' => $adminInfo['name'],
|
||||
'avatar' => $avatar,
|
||||
'role_name' => $adminInfo['role_name'],
|
||||
'token' => $adminInfo['token'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $adminInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 令狐冲
|
||||
* @date 2021/7/5 14:34
|
||||
*/
|
||||
public function logout($adminInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($adminInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
//设置token过期
|
||||
return AdminTokenService::expireToken($adminInfo['token']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?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\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* 工作台
|
||||
* Class WorkbenchLogic
|
||||
* @package app\adminapi\logic
|
||||
*/
|
||||
class WorkbenchLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 工作套
|
||||
* @param $adminInfo
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:58
|
||||
*/
|
||||
public static function index()
|
||||
{
|
||||
return [
|
||||
// 版本信息
|
||||
'version' => self::versionInfo(),
|
||||
// 今日数据
|
||||
'today' => self::today(),
|
||||
// 常用功能
|
||||
'menu' => self::menu(),
|
||||
// 近15日访客数
|
||||
'visitor' => self::visitor(),
|
||||
// 服务支持
|
||||
'support' => self::support(),
|
||||
// 销售数据
|
||||
'sale' => self::sale()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 常用功能
|
||||
* @return array[]
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:40
|
||||
*/
|
||||
public static function menu(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => '管理员',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
|
||||
'url' => '/permission/admin'
|
||||
],
|
||||
[
|
||||
'name' => '角色管理',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_role')),
|
||||
'url' => '/permission/role'
|
||||
],
|
||||
[
|
||||
'name' => '部门管理',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
|
||||
'url' => '/organization/department'
|
||||
],
|
||||
[
|
||||
'name' => '字典管理',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
|
||||
'url' => '/setting/dev_tools/dict'
|
||||
],
|
||||
[
|
||||
'name' => '代码生成器',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_generator')),
|
||||
'url' => '/dev_tools/code'
|
||||
],
|
||||
[
|
||||
'name' => '素材中心',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
|
||||
'url' => '/app/material/index'
|
||||
],
|
||||
[
|
||||
'name' => '菜单权限',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
|
||||
'url' => '/permission/menu'
|
||||
],
|
||||
[
|
||||
'name' => '网站信息',
|
||||
'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
|
||||
'url' => '/setting/website/information'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 版本信息
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:08
|
||||
*/
|
||||
public static function versionInfo(): array
|
||||
{
|
||||
return [
|
||||
'version' => config('project.version'),
|
||||
'website' => config('project.website.url'),
|
||||
'name' => ConfigService::get('website', 'name'),
|
||||
'based' => 'vue3.x、ElementUI、MySQL',
|
||||
'channel' => [
|
||||
'website' => 'https://www.likeadmin.cn',
|
||||
'gitee' => 'https://gitee.com/likeadmin/likeadmin_php',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 今日数据
|
||||
* @return int[]
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:15
|
||||
*/
|
||||
public static function today(): array
|
||||
{
|
||||
return [
|
||||
'time' => date('Y-m-d H:i:s'),
|
||||
// 今日销售额
|
||||
'today_sales' => 100,
|
||||
// 总销售额
|
||||
'total_sales' => 1000,
|
||||
|
||||
// 今日访问量
|
||||
'today_visitor' => 10,
|
||||
// 总访问量
|
||||
'total_visitor' => 100,
|
||||
|
||||
// 今日新增用户量
|
||||
'today_new_user' => 30,
|
||||
// 总用户量
|
||||
'total_new_user' => 3000,
|
||||
|
||||
// 订单量 (笔)
|
||||
'order_num' => 12,
|
||||
// 总订单量
|
||||
'order_sum' => 255
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 访问数
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:57
|
||||
*/
|
||||
public static function visitor(): array
|
||||
{
|
||||
$num = [];
|
||||
$date = [];
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$where_start = strtotime("- " . $i . "day");
|
||||
$date[] = date('m/d', $where_start);
|
||||
$num[$i] = rand(0, 100);
|
||||
}
|
||||
|
||||
return [
|
||||
'date' => $date,
|
||||
'list' => [
|
||||
['name' => '访客数', 'data' => $num]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 访问数
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:57
|
||||
*/
|
||||
public static function sale(): array
|
||||
{
|
||||
$num = [];
|
||||
$date = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$where_start = strtotime("- " . $i . "day");
|
||||
$date[] = date('m/d', $where_start);
|
||||
$num[$i] = rand(30, 200);
|
||||
}
|
||||
|
||||
return [
|
||||
'date' => $date,
|
||||
'list' => [
|
||||
['name' => '销售量', 'data' => $num]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 服务支持
|
||||
* @return array[]
|
||||
* @author 段誉
|
||||
* @date 2022/7/18 11:18
|
||||
*/
|
||||
public static function support()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'image' => FileService::getFileUrl(config('project.default_image.qq_group')),
|
||||
'title' => '官方公众号',
|
||||
'desc' => '关注官方公众号',
|
||||
],
|
||||
[
|
||||
'image' => FileService::getFileUrl(config('project.default_image.customer_service')),
|
||||
'title' => '添加企业客服微信',
|
||||
'desc' => '想了解更多请添加客服',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?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\article;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\ArticleCate;
|
||||
|
||||
/**
|
||||
* 资讯分类管理逻辑
|
||||
* Class ArticleCateLogic
|
||||
* @package app\adminapi\logic\article
|
||||
*/
|
||||
class ArticleCateLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加资讯分类
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/18 10:17
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
ArticleCate::create([
|
||||
'name' => $params['name'],
|
||||
'is_show' => $params['is_show'],
|
||||
'sort' => $params['sort'] ?? 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑资讯分类
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:50
|
||||
*/
|
||||
public static function edit(array $params) : bool
|
||||
{
|
||||
try {
|
||||
ArticleCate::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'is_show' => $params['is_show'],
|
||||
'sort' => $params['sort'] ?? 0
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除资讯分类
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:52
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
ArticleCate::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看资讯分类详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:54
|
||||
*/
|
||||
public static function detail($params) : array
|
||||
{
|
||||
return ArticleCate::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更改资讯分类状态
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 18:04
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
ArticleCate::update([
|
||||
'id' => $params['id'],
|
||||
'is_show' => $params['is_show']
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:53
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return ArticleCate::where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?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\article;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 资讯管理逻辑
|
||||
* Class ArticleLogic
|
||||
* @package app\adminapi\logic\article
|
||||
*/
|
||||
class ArticleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加资讯
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 9:57
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
Article::create([
|
||||
'title' => $params['title'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'author' => $params['author'] ?? '', //作者
|
||||
'sort' => $params['sort'] ?? 0, // 排序
|
||||
'abstract' => $params['abstract'], // 文章摘要
|
||||
'click_virtual' => $params['click_virtual'] ?? 0,
|
||||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||||
'cid' => $params['cid'],
|
||||
'is_show' => $params['is_show'],
|
||||
'content' => $params['content'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑资讯
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:12
|
||||
*/
|
||||
public static function edit(array $params) : bool
|
||||
{
|
||||
try {
|
||||
Article::update([
|
||||
'id' => $params['id'],
|
||||
'title' => $params['title'],
|
||||
'desc' => $params['desc'] ?? '', // 简介
|
||||
'author' => $params['author'] ?? '', //作者
|
||||
'sort' => $params['sort'] ?? 0, // 排序
|
||||
'abstract' => $params['abstract'], // 文章摘要
|
||||
'click_virtual' => $params['click_virtual'] ?? 0,
|
||||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||||
'cid' => $params['cid'],
|
||||
'is_show' => $params['is_show'],
|
||||
'content' => $params['content'] ?? '',
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除资讯
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:17
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
Article::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看资讯详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:15
|
||||
*/
|
||||
public static function detail($params) : array
|
||||
{
|
||||
return Article::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更改资讯状态
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:18
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
Article::update([
|
||||
'id' => $params['id'],
|
||||
'is_show' => $params['is_show']
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
<?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\auth;
|
||||
|
||||
use app\common\cache\AdminAuthCache;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminDept;
|
||||
use app\common\model\auth\AdminJobs;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\auth\AdminSession;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 管理员逻辑
|
||||
* Class AdminLogic
|
||||
* @package app\adminapi\logic\auth
|
||||
*/
|
||||
class AdminLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加管理员
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:23
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$defaultAvatar = config('project.default_image.admin_avatar');
|
||||
$avatar = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : $defaultAvatar;
|
||||
|
||||
$admin = Admin::create([
|
||||
'name' => $params['name'],
|
||||
'account' => $params['account'],
|
||||
'avatar' => $avatar,
|
||||
'password' => $password,
|
||||
'create_time' => time(),
|
||||
'disable' => $params['disable'],
|
||||
'multipoint_login' => $params['multipoint_login'],
|
||||
]);
|
||||
|
||||
// 角色
|
||||
self::insertRole($admin['id'], $params['role_id'] ?? []);
|
||||
// 部门
|
||||
self::insertDept($admin['id'], $params['dept_id'] ?? []);
|
||||
// 岗位
|
||||
self::insertJobs($admin['id'], $params['jobs_id'] ?? []);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑管理员
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:43
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 基础信息
|
||||
$data = [
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'account' => $params['account'],
|
||||
'disable' => $params['disable'],
|
||||
'multipoint_login' => $params['multipoint_login']
|
||||
];
|
||||
|
||||
// 头像
|
||||
$data['avatar'] = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : '';
|
||||
|
||||
// 密码
|
||||
if (!empty($params['password'])) {
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$data['password'] = create_password($params['password'], $passwordSalt);
|
||||
}
|
||||
|
||||
// 禁用或更换角色后.设置token过期
|
||||
$roleId = AdminRole::where('admin_id', $params['id'])->column('role_id');
|
||||
$editRole = false;
|
||||
if (!empty(array_diff_assoc($roleId, $params['role_id']))) {
|
||||
$editRole = true;
|
||||
}
|
||||
|
||||
if ($params['disable'] == 1 || $editRole) {
|
||||
$tokenArr = AdminSession::where('admin_id', $params['id'])->select()->toArray();
|
||||
foreach ($tokenArr as $token) {
|
||||
self::expireToken($token['token']);
|
||||
}
|
||||
}
|
||||
|
||||
Admin::update($data);
|
||||
(new AdminAuthCache($params['id']))->clearAuthCache();
|
||||
|
||||
// 删除旧的关联信息
|
||||
AdminRole::delByUserId($params['id']);
|
||||
AdminDept::delByUserId($params['id']);
|
||||
AdminJobs::delByUserId($params['id']);
|
||||
// 角色
|
||||
self::insertRole($params['id'], $params['role_id']);
|
||||
// 部门
|
||||
self::insertDept($params['id'], $params['dept_id'] ?? []);
|
||||
// 岗位
|
||||
self::insertJobs($params['id'], $params['jobs_id'] ?? []);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除管理员
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:45
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$admin = Admin::findOrEmpty($params['id']);
|
||||
if ($admin->root == YesNoEnum::YES) {
|
||||
throw new \Exception("超级管理员不允许被删除");
|
||||
}
|
||||
Admin::destroy($params['id']);
|
||||
|
||||
//设置token过期
|
||||
$tokenArr = AdminSession::where('admin_id', $params['id'])->select()->toArray();
|
||||
foreach ($tokenArr as $token) {
|
||||
self::expireToken($token['token']);
|
||||
}
|
||||
(new AdminAuthCache($params['id']))->clearAuthCache();
|
||||
|
||||
// 删除旧的关联信息
|
||||
AdminRole::delByUserId($params['id']);
|
||||
AdminDept::delByUserId($params['id']);
|
||||
AdminJobs::delByUserId($params['id']);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 过期token
|
||||
* @param $token
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:46
|
||||
*/
|
||||
public static function expireToken($token): bool
|
||||
{
|
||||
$adminSession = AdminSession::where('token', '=', $token)
|
||||
->with('admin')
|
||||
->find();
|
||||
|
||||
if (empty($adminSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$adminSession->expire_time = $time;
|
||||
$adminSession->update_time = $time;
|
||||
$adminSession->save();
|
||||
|
||||
return (new AdminTokenCache())->deleteAdminInfo($token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看管理员详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 11:07
|
||||
*/
|
||||
public static function detail($params, $action = 'detail'): array
|
||||
{
|
||||
$admin = Admin::field([
|
||||
'id', 'account', 'name', 'disable', 'root',
|
||||
'multipoint_login', 'avatar',
|
||||
])->findOrEmpty($params['id'])->toArray();
|
||||
|
||||
if ($action == 'detail') {
|
||||
return $admin;
|
||||
}
|
||||
|
||||
$result['user'] = $admin;
|
||||
// 当前管理员角色拥有的菜单
|
||||
$result['menu'] = MenuLogic::getMenuByAdminId($params['id']);
|
||||
// 当前管理员橘色拥有的按钮权限
|
||||
$result['permissions'] = AuthLogic::getBtnAuthByRoleId($admin);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑超级管理员
|
||||
* @param $params
|
||||
* @return Admin
|
||||
* @author 段誉
|
||||
* @date 2022/4/8 17:54
|
||||
*/
|
||||
public static function editSelf($params)
|
||||
{
|
||||
$data = [
|
||||
'id' => $params['admin_id'],
|
||||
'name' => $params['name'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
];
|
||||
|
||||
if (!empty($params['password'])) {
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$data['password'] = create_password($params['password'], $passwordSalt);
|
||||
}
|
||||
|
||||
return Admin::update($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 新增角色
|
||||
* @param $adminId
|
||||
* @param $roleIds
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/11/25 14:23
|
||||
*/
|
||||
public static function insertRole($adminId, $roleIds)
|
||||
{
|
||||
if (!empty($roleIds)) {
|
||||
// 角色
|
||||
$roleData = [];
|
||||
foreach ($roleIds as $roleId) {
|
||||
$roleData[] = [
|
||||
'admin_id' => $adminId,
|
||||
'role_id' => $roleId,
|
||||
];
|
||||
}
|
||||
(new AdminRole())->saveAll($roleData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 新增部门
|
||||
* @param $adminId
|
||||
* @param $deptIds
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/11/25 14:22
|
||||
*/
|
||||
public static function insertDept($adminId, $deptIds)
|
||||
{
|
||||
// 部门
|
||||
if (!empty($deptIds)) {
|
||||
$deptData = [];
|
||||
foreach ($deptIds as $deptId) {
|
||||
$deptData[] = [
|
||||
'admin_id' => $adminId,
|
||||
'dept_id' => $deptId
|
||||
];
|
||||
}
|
||||
(new AdminDept())->saveAll($deptData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 新增岗位
|
||||
* @param $adminId
|
||||
* @param $jobsIds
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/11/25 14:22
|
||||
*/
|
||||
public static function insertJobs($adminId, $jobsIds)
|
||||
{
|
||||
// 岗位
|
||||
if (!empty($jobsIds)) {
|
||||
$jobsData = [];
|
||||
foreach ($jobsIds as $jobsId) {
|
||||
$jobsData[] = [
|
||||
'admin_id' => $adminId,
|
||||
'jobs_id' => $jobsId
|
||||
];
|
||||
}
|
||||
(new AdminJobs())->saveAll($jobsData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?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\auth;
|
||||
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\auth\SystemMenu;
|
||||
use app\common\model\auth\SystemRoleMenu;
|
||||
|
||||
|
||||
/**
|
||||
* 权限功能类
|
||||
* Class AuthLogic
|
||||
* @package app\adminapi\logic\auth
|
||||
*/
|
||||
class AuthLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取全部权限
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/7/1 11:55
|
||||
*/
|
||||
public static function getAllAuth()
|
||||
{
|
||||
return SystemMenu::distinct(true)
|
||||
->where([
|
||||
['is_disable', '=', 0],
|
||||
['perms', '<>', '']
|
||||
])
|
||||
->column('perms');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取当前管理员角色按钮权限
|
||||
* @param $roleId
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/7/1 16:10
|
||||
*/
|
||||
public static function getBtnAuthByRoleId($admin)
|
||||
{
|
||||
if ($admin['root']) {
|
||||
return ['*'];
|
||||
}
|
||||
|
||||
$menuId = SystemRoleMenu::whereIn('role_id', $admin['role_id'])
|
||||
->column('menu_id');
|
||||
|
||||
$where[] = ['is_disable', '=', 0];
|
||||
$where[] = ['perms', '<>', ''];
|
||||
|
||||
$roleAuth = SystemMenu::distinct(true)
|
||||
->where('id', 'in', $menuId)
|
||||
->where($where)
|
||||
->column('perms');
|
||||
|
||||
$allAuth = SystemMenu::distinct(true)
|
||||
->where($where)
|
||||
->column('perms');
|
||||
|
||||
$hasAllAuth = array_diff($allAuth, $roleAuth);
|
||||
if (empty($hasAllAuth)) {
|
||||
return ['*'];
|
||||
}
|
||||
|
||||
return $roleAuth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取管理员角色关联的菜单id(菜单,权限)
|
||||
* @param int $adminId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/7/1 15:56
|
||||
*/
|
||||
public static function getAuthByAdminId(int $adminId): array
|
||||
{
|
||||
$roleIds = AdminRole::where('admin_id', $adminId)->column('role_id');
|
||||
$menuId = SystemRoleMenu::whereIn('role_id', $roleIds)->column('menu_id');
|
||||
|
||||
return SystemMenu::distinct(true)
|
||||
->where([
|
||||
['is_disable', '=', 0],
|
||||
['perms', '<>', ''],
|
||||
['id', 'in', array_unique($menuId)],
|
||||
])
|
||||
->column('perms');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?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\auth;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\SystemMenu;
|
||||
use app\common\model\auth\SystemRoleMenu;
|
||||
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
* Class MenuLogic
|
||||
* @package app\adminapi\logic\auth
|
||||
*/
|
||||
class MenuLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取管理员对应的角色菜单
|
||||
* @param $adminId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/7/1 10:50
|
||||
*/
|
||||
public static function getMenuByAdminId($adminId)
|
||||
{
|
||||
$admin = Admin::findOrEmpty($adminId);
|
||||
|
||||
$where = [];
|
||||
$where[] = ['type', 'in', ['M', 'C']];
|
||||
$where[] = ['is_disable', '=', 0];
|
||||
|
||||
if ($admin['root'] != 1) {
|
||||
$roleMenu = SystemRoleMenu::whereIn('role_id', $admin['role_id'])->column('menu_id');
|
||||
$where[] = ['id', 'in', $roleMenu];
|
||||
}
|
||||
|
||||
$menu = SystemMenu::where($where)
|
||||
->order(['sort' => 'desc', 'id' => 'asc'])
|
||||
->select();
|
||||
|
||||
return linear_to_tree($menu, 'children');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加菜单
|
||||
* @param array $params
|
||||
* @return SystemMenu|\think\Model
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 10:06
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
return SystemMenu::create([
|
||||
'pid' => $params['pid'],
|
||||
'type' => $params['type'],
|
||||
'name' => $params['name'],
|
||||
'icon' => $params['icon'] ?? '',
|
||||
'sort' => $params['sort'],
|
||||
'perms' => $params['perms'] ?? '',
|
||||
'paths' => $params['paths'] ?? '',
|
||||
'component' => $params['component'] ?? '',
|
||||
'selected' => $params['selected'] ?? '',
|
||||
'params' => $params['params'] ?? '',
|
||||
'is_cache' => $params['is_cache'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_disable' => $params['is_disable'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑菜单
|
||||
* @param array $params
|
||||
* @return SystemMenu
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 10:07
|
||||
*/
|
||||
public static function edit(array $params)
|
||||
{
|
||||
return SystemMenu::update([
|
||||
'id' => $params['id'],
|
||||
'pid' => $params['pid'],
|
||||
'type' => $params['type'],
|
||||
'name' => $params['name'],
|
||||
'icon' => $params['icon'] ?? '',
|
||||
'sort' => $params['sort'],
|
||||
'perms' => $params['perms'] ?? '',
|
||||
'paths' => $params['paths'] ?? '',
|
||||
'component' => $params['component'] ?? '',
|
||||
'selected' => $params['selected'] ?? '',
|
||||
'params' => $params['params'] ?? '',
|
||||
'is_cache' => $params['is_cache'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_disable' => $params['is_disable'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 9:54
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
return SystemMenu::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除菜单
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 9:47
|
||||
*/
|
||||
public static function delete($params)
|
||||
{
|
||||
// 删除菜单
|
||||
SystemMenu::destroy($params['id']);
|
||||
// 删除角色-菜单表中 与该菜单关联的记录
|
||||
SystemRoleMenu::where(['menu_id' => $params['id']])->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新状态
|
||||
* @param array $params
|
||||
* @return SystemMenu
|
||||
* @author 段誉
|
||||
* @date 2022/7/6 17:02
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
return SystemMenu::update([
|
||||
'id' => $params['id'],
|
||||
'is_disable' => $params['is_disable']
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 全部数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 11:03
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
$data = SystemMenu::where(['is_disable' => YesNoEnum::NO])
|
||||
->field('id,pid,name')
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return linear_to_tree($data, 'children');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?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\auth;
|
||||
|
||||
use app\common\{
|
||||
cache\AdminAuthCache,
|
||||
model\auth\SystemRole,
|
||||
logic\BaseLogic,
|
||||
model\auth\SystemRoleMenu
|
||||
};
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 角色逻辑层
|
||||
* Class RoleLogic
|
||||
* @package app\adminapi\logic\auth
|
||||
*/
|
||||
class RoleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加角色
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 11:50
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$menuId = !empty($params['menu_id']) ? $params['menu_id'] : [];
|
||||
|
||||
$role = SystemRole::create([
|
||||
'name' => $params['name'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
foreach ($menuId as $item) {
|
||||
if (empty($item)) {
|
||||
continue;
|
||||
}
|
||||
$data[] = [
|
||||
'role_id' => $role['id'],
|
||||
'menu_id' => $item,
|
||||
];
|
||||
}
|
||||
(new SystemRoleMenu)->insertAll($data);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑角色
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 14:16
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$menuId = !empty($params['menu_id']) ? $params['menu_id'] : [];
|
||||
|
||||
SystemRole::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
]);
|
||||
|
||||
if (!empty($menuId)) {
|
||||
SystemRoleMenu::where(['role_id' => $params['id']])->delete();
|
||||
$data = [];
|
||||
foreach ($menuId as $item) {
|
||||
$data[] = [
|
||||
'role_id' => $params['id'],
|
||||
'menu_id' => $item,
|
||||
];
|
||||
}
|
||||
(new SystemRoleMenu)->insertAll($data);
|
||||
}
|
||||
|
||||
(new AdminAuthCache())->deleteTag();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除角色
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 14:16
|
||||
*/
|
||||
public static function delete(int $id)
|
||||
{
|
||||
SystemRole::destroy(['id' => $id]);
|
||||
(new AdminAuthCache())->deleteTag();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 角色详情
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 14:17
|
||||
*/
|
||||
public static function detail(int $id): array
|
||||
{
|
||||
$detail = SystemRole::field('id,name,desc,sort')->find($id);
|
||||
$authList = $detail->roleMenuIndex()->select()->toArray();
|
||||
$menuId = array_column($authList, 'menu_id');
|
||||
$detail['menu_id'] = $menuId;
|
||||
return $detail->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 角色数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:39
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return SystemRole::order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* App设置逻辑层
|
||||
* Class AppSettingLogic
|
||||
* @package app\adminapi\logic\setting\app
|
||||
*/
|
||||
class AppSettingLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取App设置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:25
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'ios_download_url' => ConfigService::get('app', 'ios_download_url', ''),
|
||||
'android_download_url' => ConfigService::get('app', 'android_download_url', ''),
|
||||
'download_title' => ConfigService::get('app', 'download_title', ''),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes App设置
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:26
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
ConfigService::set('app', 'ios_download_url', $params['ios_download_url'] ?? '');
|
||||
ConfigService::set('app', 'android_download_url', $params['android_download_url'] ?? '');
|
||||
ConfigService::set('app', 'download_title', $params['download_title'] ?? '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 小程序设置逻辑
|
||||
* Class MnpSettingsLogic
|
||||
* @package app\adminapi\logic\channel
|
||||
*/
|
||||
class MnpSettingsLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取小程序配置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/16 9:38 上午
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$domainName = $_SERVER['SERVER_NAME'];
|
||||
$qrCode = ConfigService::get('mnp_setting', 'qr_code', '');
|
||||
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
|
||||
$config = [
|
||||
'name' => ConfigService::get('mnp_setting', 'name', ''),
|
||||
'original_id' => ConfigService::get('mnp_setting', 'original_id', ''),
|
||||
'qr_code' => $qrCode,
|
||||
'app_id' => ConfigService::get('mnp_setting', 'app_id', ''),
|
||||
'app_secret' => ConfigService::get('mnp_setting', 'app_secret', ''),
|
||||
'request_domain' => 'https://'.$domainName,
|
||||
'socket_domain' => 'wss://'.$domainName,
|
||||
'upload_file_domain' => 'https://'.$domainName,
|
||||
'download_file_domain' => 'https://'.$domainName,
|
||||
'udp_domain' => 'udp://'.$domainName,
|
||||
'business_domain' => $domainName,
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置小程序配置
|
||||
* @param $params
|
||||
* @author ljj
|
||||
* @date 2022/2/16 9:51 上午
|
||||
*/
|
||||
public function setConfig($params)
|
||||
{
|
||||
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
|
||||
|
||||
ConfigService::set('mnp_setting','name', $params['name'] ?? '');
|
||||
ConfigService::set('mnp_setting','original_id',$params['original_id'] ?? '');
|
||||
ConfigService::set('mnp_setting','qr_code',$qrCode);
|
||||
ConfigService::set('mnp_setting','app_id',$params['app_id']);
|
||||
ConfigService::set('mnp_setting','app_secret',$params['app_secret']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\enum\OfficialAccountEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\wechat\WeChatOaService;
|
||||
|
||||
/**
|
||||
* 微信公众号菜单逻辑层
|
||||
* Class OfficialAccountMenuLogic
|
||||
* @package app\adminapi\logic\wechat
|
||||
*/
|
||||
class OfficialAccountMenuLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 保存
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:43
|
||||
*/
|
||||
public static function save($params)
|
||||
{
|
||||
try {
|
||||
self::checkMenu($params);
|
||||
ConfigService::set('oa_setting', 'menu', $params);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
OfficialAccountMenuLogic::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 一级菜单校验
|
||||
* @param $menu
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:55
|
||||
*/
|
||||
public static function checkMenu($menu)
|
||||
{
|
||||
if (empty($menu) || !is_array($menu)) {
|
||||
throw new \Exception('请设置正确格式菜单');
|
||||
}
|
||||
|
||||
if (count($menu) > 3) {
|
||||
throw new \Exception('一级菜单超出限制(最多3个)');
|
||||
}
|
||||
|
||||
foreach ($menu as $item) {
|
||||
if (!is_array($item)) {
|
||||
throw new \Exception('一级菜单项须为数组格式');
|
||||
}
|
||||
|
||||
if (empty($item['name'])) {
|
||||
throw new \Exception('请输入一级菜单名称');
|
||||
}
|
||||
|
||||
if (mb_strlen($item['name']) > 4) {
|
||||
throw new \Exception("一级菜单名称字数不能超过4个字符");
|
||||
}
|
||||
|
||||
if (false == $item['has_menu']) {
|
||||
if (empty($item['type'])) {
|
||||
throw new \Exception('一级菜单未选择菜单类型');
|
||||
}
|
||||
if (!in_array($item['type'], OfficialAccountEnum::MENU_TYPE)) {
|
||||
throw new \Exception('一级菜单类型错误');
|
||||
}
|
||||
self::checkType($item);
|
||||
}
|
||||
|
||||
if (true == $item['has_menu'] && empty($item['sub_button'])) {
|
||||
throw new \Exception('请配置子菜单');
|
||||
}
|
||||
|
||||
if (!empty($item['sub_button'])) {
|
||||
self::checkSubButton($item['sub_button']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 二级菜单校验
|
||||
* @param $subButtion
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:55
|
||||
*/
|
||||
public static function checkSubButton($subButtion)
|
||||
{
|
||||
if (!is_array($subButtion)) {
|
||||
throw new \Exception('二级菜单须为数组格式');
|
||||
}
|
||||
|
||||
if (count($subButtion) > 5) {
|
||||
throw new \Exception('二级菜单超出限制(最多5个)');
|
||||
}
|
||||
|
||||
foreach ($subButtion as $subItem) {
|
||||
if (!is_array($subItem)) {
|
||||
throw new \Exception('二级菜单项须为数组');
|
||||
}
|
||||
|
||||
if (empty($subItem['name'])) {
|
||||
throw new \Exception('请输入二级菜单名称');
|
||||
}
|
||||
|
||||
if (mb_strlen($subItem['name']) > 8) {
|
||||
throw new \Exception("二级菜单名称字数不能超过8个字符");
|
||||
}
|
||||
|
||||
if (empty($subItem['type']) || !in_array($subItem['type'], OfficialAccountEnum::MENU_TYPE)) {
|
||||
throw new \Exception('二级未选择菜单类型或菜单类型错误');
|
||||
}
|
||||
|
||||
self::checkType($subItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 菜单类型校验
|
||||
* @param $item
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:55
|
||||
*/
|
||||
public static function checkType($item)
|
||||
{
|
||||
switch ($item['type']) {
|
||||
// 关键字
|
||||
case 'click':
|
||||
if (empty($item['key'])) {
|
||||
throw new \Exception('请输入关键字');
|
||||
}
|
||||
break;
|
||||
// 跳转网页链接
|
||||
case 'view':
|
||||
if (empty($item['url'])) {
|
||||
throw new \Exception('请输入网页链接');
|
||||
}
|
||||
break;
|
||||
// 小程序
|
||||
case 'miniprogram':
|
||||
if (empty($item['url'])) {
|
||||
throw new \Exception('请输入网页链接');
|
||||
}
|
||||
if (empty($item['appid'])) {
|
||||
throw new \Exception('请输入appid');
|
||||
}
|
||||
if (empty($item['pagepath'])) {
|
||||
throw new \Exception('请输入小程序路径');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 保存发布菜单
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:55
|
||||
*/
|
||||
public static function saveAndPublish($params)
|
||||
{
|
||||
try {
|
||||
self::checkMenu($params);
|
||||
|
||||
$result = (new WeChatOaService())->createMenu($params);
|
||||
if ($result['errcode'] == 0) {
|
||||
ConfigService::set('oa_setting', 'menu', $params);
|
||||
return true;
|
||||
}
|
||||
|
||||
self::setError('保存发布菜单失败' . json_encode($result->getContent()));
|
||||
|
||||
return false;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看菜单详情
|
||||
* @return array|int|mixed|string|null
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:56
|
||||
*/
|
||||
public static function detail()
|
||||
{
|
||||
$data = ConfigService::get('oa_setting', 'menu', []);
|
||||
|
||||
if (!empty($data)) {
|
||||
foreach ($data as &$item) {
|
||||
$item['has_menu'] = !empty($item['has_menu']);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\enum\OfficialAccountEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\channel\OfficialAccountReply;
|
||||
use app\common\service\wechat\WeChatConfigService;
|
||||
use app\common\service\wechat\WeChatOaService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信公众号回复逻辑层
|
||||
* Class OfficialAccountReplyLogic
|
||||
* @package app\adminapi\logic\channel
|
||||
*/
|
||||
class OfficialAccountReplyLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 添加回复(关注/关键词/默认)
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:57
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
try {
|
||||
// 关键字回复排序值须大于0
|
||||
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] < 0) {
|
||||
throw new \Exception('排序值须大于或等于0');
|
||||
}
|
||||
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
|
||||
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
|
||||
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
|
||||
}
|
||||
OfficialAccountReply::create($params);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看回复详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:00
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$field = 'id,name,keyword,reply_type,matching_type,content_type,content,status,sort';
|
||||
$field .= ',reply_type as reply_type_desc, matching_type as matching_type_desc, content_type as content_type_desc, status as status_desc';
|
||||
return OfficialAccountReply::field($field)->findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑回复(关注/关键词/默认)
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:01
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
try {
|
||||
// 关键字回复排序值须大于0
|
||||
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] < 0) {
|
||||
throw new \Exception('排序值须大于或等于0');
|
||||
}
|
||||
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
|
||||
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
|
||||
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
|
||||
}
|
||||
OfficialAccountReply::update($params);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除回复(关注/关键词/默认)
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:01
|
||||
*/
|
||||
public static function delete($params)
|
||||
{
|
||||
OfficialAccountReply::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新排序
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:01
|
||||
*/
|
||||
public static function sort($params)
|
||||
{
|
||||
$params['sort'] = $params['new_sort'];
|
||||
OfficialAccountReply::update($params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新状态
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:01
|
||||
*/
|
||||
public static function status($params)
|
||||
{
|
||||
$reply = OfficialAccountReply::findOrEmpty($params['id']);
|
||||
$reply->status = !$reply->status;
|
||||
$reply->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 微信公众号回调
|
||||
* @return \Psr\Http\Message\ResponseInterface|void
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \ReflectionException
|
||||
* @throws \Throwable
|
||||
* @author 段誉
|
||||
* @date 2023/2/27 14:38\
|
||||
*/
|
||||
public static function index()
|
||||
{
|
||||
$server = (new WeChatOaService())->getServer();
|
||||
// 事件
|
||||
$server->addMessageListener(OfficialAccountEnum::MSG_TYPE_EVENT, function ($message, \Closure $next) {
|
||||
switch ($message['Event']) {
|
||||
case OfficialAccountEnum::EVENT_SUBSCRIBE: // 关注事件
|
||||
$replyContent = OfficialAccountReply::where([
|
||||
'reply_type' => OfficialAccountEnum::REPLY_TYPE_FOLLOW,
|
||||
'status' => YesNoEnum::YES
|
||||
])
|
||||
->value('content');
|
||||
|
||||
if ($replyContent) {
|
||||
return $replyContent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $next($message);
|
||||
});
|
||||
|
||||
// 文本
|
||||
$server->addMessageListener(OfficialAccountEnum::MSG_TYPE_TEXT, function ($message, \Closure $next) {
|
||||
$replyList = OfficialAccountReply::where([
|
||||
'reply_type' => OfficialAccountEnum::REPLY_TYPE_KEYWORD,
|
||||
'status' => YesNoEnum::YES
|
||||
])
|
||||
->order('sort asc')
|
||||
->select();
|
||||
|
||||
$replyContent = '';
|
||||
foreach ($replyList as $reply) {
|
||||
switch ($reply['matching_type']) {
|
||||
case OfficialAccountEnum::MATCHING_TYPE_FULL:
|
||||
$reply['keyword'] === $message['Content'] && $replyContent = $reply['content'];
|
||||
break;
|
||||
case OfficialAccountEnum::MATCHING_TYPE_FUZZY:
|
||||
stripos($message['Content'], $reply['keyword']) !== false && $replyContent = $reply['content'];
|
||||
break;
|
||||
}
|
||||
if ($replyContent) {
|
||||
break; // 得到回复文本,中止循环
|
||||
}
|
||||
}
|
||||
//消息回复为空的话,找默认回复
|
||||
if (empty($replyContent)) {
|
||||
$replyContent = static::getDefaultReply();
|
||||
}
|
||||
if ($replyContent) {
|
||||
return $replyContent;
|
||||
}
|
||||
return $next($message);
|
||||
});
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 默认回复信息
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2023/2/27 14:36
|
||||
*/
|
||||
public static function getDefaultReply()
|
||||
{
|
||||
return OfficialAccountReply::where([
|
||||
'reply_type' => OfficialAccountEnum::REPLY_TYPE_DEFAULT,
|
||||
'status' => YesNoEnum::YES
|
||||
])
|
||||
->value('content');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 公众号设置逻辑
|
||||
* Class OfficialAccountSettingLogic
|
||||
* @package app\adminapi\logic\channel
|
||||
*/
|
||||
class OfficialAccountSettingLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取公众号配置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/16 10:08 上午
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$domainName = $_SERVER['SERVER_NAME'];
|
||||
$qrCode = ConfigService::get('oa_setting', 'qr_code', '');
|
||||
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
|
||||
$config = [
|
||||
'name' => ConfigService::get('oa_setting', 'name', ''),
|
||||
'original_id' => ConfigService::get('oa_setting', 'original_id', ''),
|
||||
'qr_code' => $qrCode,
|
||||
'app_id' => ConfigService::get('oa_setting', 'app_id', ''),
|
||||
'app_secret' => ConfigService::get('oa_setting', 'app_secret', ''),
|
||||
// url()方法返回Url实例,通过与空字符串连接触发该实例的__toString()方法以得到路由地址
|
||||
'url' => url('adminapi/channel.official_account_reply/index', [],'',true).'',
|
||||
'token' => ConfigService::get('oa_setting', 'token'),
|
||||
'encoding_aes_key' => ConfigService::get('oa_setting', 'encoding_aes_key', ''),
|
||||
'encryption_type' => ConfigService::get('oa_setting', 'encryption_type', 1),
|
||||
'business_domain' => $domainName,
|
||||
'js_secure_domain' => $domainName,
|
||||
'web_auth_domain' => $domainName,
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置公众号配置
|
||||
* @param $params
|
||||
* @author ljj
|
||||
* @date 2022/2/16 10:08 上午
|
||||
*/
|
||||
public function setConfig($params)
|
||||
{
|
||||
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
|
||||
|
||||
ConfigService::set('oa_setting','name', $params['name'] ?? '');
|
||||
ConfigService::set('oa_setting','original_id', $params['original_id'] ?? '');
|
||||
ConfigService::set('oa_setting','qr_code', $qrCode);
|
||||
ConfigService::set('oa_setting','app_id',$params['app_id']);
|
||||
ConfigService::set('oa_setting','app_secret',$params['app_secret']);
|
||||
ConfigService::set('oa_setting','token',$params['token'] ?? '');
|
||||
ConfigService::set('oa_setting','encoding_aes_key',$params['encoding_aes_key'] ?? '');
|
||||
ConfigService::set('oa_setting','encryption_type',$params['encryption_type']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 微信开放平台
|
||||
* Class AppSettingLogic
|
||||
* @package app\adminapi\logic\setting\app
|
||||
*/
|
||||
class OpenSettingLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取微信开放平台设置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:03
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'app_id' => ConfigService::get('open_platform', 'app_id', ''),
|
||||
'app_secret' => ConfigService::get('open_platform', 'app_secret', ''),
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 微信开放平台设置
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:03
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
ConfigService::set('open_platform', 'app_id', $params['app_id'] ?? '');
|
||||
ConfigService::set('open_platform', 'app_secret', $params['app_secret'] ?? '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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\channel;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* H5设置逻辑层
|
||||
* Class HFiveSettingLogic
|
||||
* @package app\adminapi\logic\setting\h5
|
||||
*/
|
||||
class WebPageSettingLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取H5设置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:34
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
// 渠道状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('web_page', 'status', 1),
|
||||
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
|
||||
'page_status' => ConfigService::get('web_page', 'page_status', 0),
|
||||
// 自定义链接
|
||||
'page_url' => ConfigService::get('web_page', 'page_url', ''),
|
||||
'url' => request()->domain() . '/mobile'
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes H5设置
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:34
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
ConfigService::set('web_page', 'status', $params['status']);
|
||||
ConfigService::set('web_page', 'page_status', $params['page_status']);
|
||||
ConfigService::set('web_page', 'page_url', $params['page_url']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?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\crontab;
|
||||
|
||||
use app\common\enum\CrontabEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\Crontab;
|
||||
use Cron\CronExpression;
|
||||
|
||||
/**
|
||||
* 定时任务逻辑层
|
||||
* Class CrontabLogic
|
||||
* @package app\adminapi\logic\crontab
|
||||
*/
|
||||
class CrontabLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 添加定时任务
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:41
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
try {
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
$params['params'] = $params['params'] ?? '';
|
||||
$params['last_time'] = time();
|
||||
|
||||
Crontab::create($params);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看定时任务详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:41
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$field = 'id,name,type,type as type_desc,command,params,status,status as status_desc,expression,remark';
|
||||
$crontab = Crontab::field($field)->findOrEmpty($params['id']);
|
||||
if ($crontab->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
return $crontab->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑定时任务
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:42
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
try {
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
$params['params'] = $params['params'] ?? '';
|
||||
|
||||
Crontab::update($params);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除定时任务
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:42
|
||||
*/
|
||||
public static function delete($params)
|
||||
{
|
||||
try {
|
||||
Crontab::destroy($params['id']);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 操作定时任务
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:42
|
||||
*/
|
||||
public static function operate($params)
|
||||
{
|
||||
try {
|
||||
$crontab = Crontab::findOrEmpty($params['id']);
|
||||
if ($crontab->isEmpty()) {
|
||||
throw new \Exception('定时任务不存在');
|
||||
}
|
||||
switch ($params['operate']) {
|
||||
case 'start';
|
||||
$crontab->status = CrontabEnum::START;
|
||||
break;
|
||||
case 'stop':
|
||||
$crontab->status = CrontabEnum::STOP;
|
||||
break;
|
||||
}
|
||||
$crontab->save();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取规则执行时间
|
||||
* @param $params
|
||||
* @return array|string
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 14:42
|
||||
*/
|
||||
public static function expression($params)
|
||||
{
|
||||
try {
|
||||
$cron = new CronExpression($params['expression']);
|
||||
$result = $cron->getMultipleRunDates(5);
|
||||
$result = json_decode(json_encode($result), true);
|
||||
$lists = [];
|
||||
foreach ($result as $k => $v) {
|
||||
$lists[$k]['time'] = $k + 1;
|
||||
$lists[$k]['date'] = str_replace('.000000', '', $v['date']);
|
||||
}
|
||||
$lists[] = ['time' => 'x', 'date' => '……'];
|
||||
return $lists;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?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\decorate;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
|
||||
/**
|
||||
* 装修页-数据
|
||||
* Class DecorateDataLogic
|
||||
* @package app\adminapi\logic\decorate
|
||||
*/
|
||||
class DecorateDataLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取文章列表
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 16:49
|
||||
*/
|
||||
public static function getArticleLists($limit): array
|
||||
{
|
||||
$field = 'id,title,desc,abstract,image,author,content,
|
||||
click_virtual,click_actual,create_time';
|
||||
|
||||
return Article::where(['is_show' => 1])
|
||||
->field($field)
|
||||
->order(['id' => 'desc'])
|
||||
->limit($limit)
|
||||
->append(['click'])
|
||||
->hidden(['click_virtual', 'click_actual'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes pc设置
|
||||
* @return array
|
||||
* @author mjf
|
||||
* @date 2024/3/14 18:13
|
||||
*/
|
||||
public static function pc(): array
|
||||
{
|
||||
$pcPage = DecoratePage::findOrEmpty(4)->toArray();
|
||||
$updateTime = !empty($pcPage['update_time']) ? $pcPage['update_time'] : date('Y-m-d H:i:s');
|
||||
return [
|
||||
'update_time' => $updateTime,
|
||||
'pc_url' => request()->domain() . '/pc'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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\decorate;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
|
||||
|
||||
/**
|
||||
* 装修页面
|
||||
* Class DecoratePageLogic
|
||||
* @package app\adminapi\logic\theme
|
||||
*/
|
||||
class DecoratePageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/14 18:41
|
||||
*/
|
||||
public static function getDetail($id)
|
||||
{
|
||||
return DecoratePage::findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 保存装修配置
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 9:37
|
||||
*/
|
||||
public static function save($params)
|
||||
{
|
||||
$pageData = DecoratePage::where(['id' => $params['id']])->findOrEmpty();
|
||||
if ($pageData->isEmpty()) {
|
||||
self::$error = '信息不存在';
|
||||
return false;
|
||||
}
|
||||
DecoratePage::update([
|
||||
'id' => $params['id'],
|
||||
'type' => $params['type'],
|
||||
'data' => $params['data'],
|
||||
'meta' => $params['meta'] ?? '',
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?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\decorate;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* 装修配置-底部导航
|
||||
* Class DecorateTabbarLogic
|
||||
* @package app\adminapi\logic\decorate
|
||||
*/
|
||||
class DecorateTabbarLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取底部导航详情
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 16:58
|
||||
*/
|
||||
public static function detail(): array
|
||||
{
|
||||
$list = DecorateTabbar::getTabbarLists();
|
||||
$style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style'));
|
||||
return ['style' => $style, 'list' => $list];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 底部导航保存
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 17:19
|
||||
*/
|
||||
public static function save($params): bool
|
||||
{
|
||||
$model = new DecorateTabbar();
|
||||
// 删除旧配置数据
|
||||
$model->where('id', '>', 0)->delete();
|
||||
|
||||
// 保存数据
|
||||
$tabbars = $params['list'] ?? [];
|
||||
$data = [];
|
||||
foreach ($tabbars as $item) {
|
||||
$data[] = [
|
||||
'name' => $item['name'],
|
||||
'selected' => FileService::setFileUrl($item['selected']),
|
||||
'unselected' => FileService::setFileUrl($item['unselected']),
|
||||
'link' => $item['link'],
|
||||
'is_show' => $item['is_show'] ?? 0,
|
||||
];
|
||||
}
|
||||
$model->saveAll($data);
|
||||
|
||||
if (!empty($params['style'])) {
|
||||
ConfigService::set('tabbar', 'style', $params['style']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?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\dept;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\dept\Dept;
|
||||
|
||||
|
||||
/**
|
||||
* 部门管理逻辑
|
||||
* Class DeptLogic
|
||||
* @package app\adminapi\logic\dept
|
||||
*/
|
||||
class DeptLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 部门列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/5/30 15:44
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [];
|
||||
if (!empty($params['name'])) {
|
||||
$where[] = ['name', 'like', '%' . $params['name'] . '%'];
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != '') {
|
||||
$where[] = ['status', '=', $params['status']];
|
||||
}
|
||||
$lists = Dept::where($where)
|
||||
->append(['status_desc'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$pid = 0;
|
||||
if (!empty($lists)) {
|
||||
$pid = min(array_column($lists, 'pid'));
|
||||
}
|
||||
return self::getTree($lists, $pid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 列表树状结构
|
||||
* @param $array
|
||||
* @param int $pid
|
||||
* @param int $level
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/5/30 15:44
|
||||
*/
|
||||
public static function getTree($array, $pid = 0, $level = 0)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($array as $key => $item) {
|
||||
if ($item['pid'] == $pid) {
|
||||
$item['level'] = $level;
|
||||
$item['children'] = self::getTree($array, $item['id'], $level + 1);
|
||||
$list[] = $item;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 上级部门
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/5/26 18:36
|
||||
*/
|
||||
public static function leaderDept()
|
||||
{
|
||||
$lists = Dept::field(['id', 'name'])->where(['status' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加部门
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/5/25 18:20
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
Dept::create([
|
||||
'pid' => $params['pid'],
|
||||
'name' => $params['name'],
|
||||
'leader' => $params['leader'] ?? '',
|
||||
'mobile' => $params['mobile'] ?? '',
|
||||
'status' => $params['status'],
|
||||
'sort' => $params['sort'] ?? 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑部门
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/5/25 18:39
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
try {
|
||||
$pid = $params['pid'];
|
||||
$oldDeptData = Dept::findOrEmpty($params['id']);
|
||||
if ($oldDeptData['pid'] == 0) {
|
||||
$pid = 0;
|
||||
}
|
||||
|
||||
Dept::update([
|
||||
'id' => $params['id'],
|
||||
'pid' => $pid,
|
||||
'name' => $params['name'],
|
||||
'leader' => $params['leader'] ?? '',
|
||||
'mobile' => $params['mobile'] ?? '',
|
||||
'status' => $params['status'],
|
||||
'sort' => $params['sort'] ?? 0
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除部门
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/5/25 18:40
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
Dept::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取部门详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/5/25 18:40
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Dept::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 部门数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:19
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
$data = Dept::where(['status' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$pid = min(array_column($data, 'pid'));
|
||||
return self::getTree($data, $pid);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?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\dept;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\dept\Jobs;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* 岗位管理逻辑
|
||||
* Class JobsLogic
|
||||
* @package app\adminapi\logic\dept
|
||||
*/
|
||||
class JobsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 新增岗位
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/5/26 9:58
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
Jobs::create([
|
||||
'name' => $params['name'],
|
||||
'code' => $params['code'],
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'status' => $params['status'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑岗位
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/5/26 9:58
|
||||
*/
|
||||
public static function edit(array $params) : bool
|
||||
{
|
||||
try {
|
||||
Jobs::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'code' => $params['code'],
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'status' => $params['status'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除岗位
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/5/26 9:59
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
Jobs::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取岗位详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/5/26 9:59
|
||||
*/
|
||||
public static function detail($params) : array
|
||||
{
|
||||
return Jobs::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 岗位数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:30
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return Jobs::where(['status' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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\finance;
|
||||
|
||||
|
||||
use app\common\enum\RefundEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\refund\RefundLog;
|
||||
use app\common\model\refund\RefundRecord;
|
||||
|
||||
|
||||
/**
|
||||
* 退款
|
||||
* Class RefundLogic
|
||||
* @package app\adminapi\logic\finance
|
||||
*/
|
||||
class RefundLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 退款统计
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/3/3 12:09
|
||||
*/
|
||||
public static function stat()
|
||||
{
|
||||
$records = RefundRecord::select()->toArray();
|
||||
|
||||
$total = 0;
|
||||
$ing = 0;
|
||||
$success = 0;
|
||||
$error = 0;
|
||||
|
||||
foreach ($records as $record) {
|
||||
$total += $record['order_amount'];
|
||||
switch ($record['refund_status']) {
|
||||
case RefundEnum::REFUND_ING:
|
||||
$ing += $record['order_amount'];
|
||||
break;
|
||||
case RefundEnum::REFUND_SUCCESS:
|
||||
$success += $record['order_amount'];
|
||||
break;
|
||||
case RefundEnum::REFUND_ERROR:
|
||||
$error += $record['order_amount'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'total' => round($total, 2),
|
||||
'ing' => round($ing, 2),
|
||||
'success' => round($success, 2),
|
||||
'error' => round($error, 2),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退款日志
|
||||
* @param $recordId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/3/3 14:25
|
||||
*/
|
||||
public static function refundLog($recordId)
|
||||
{
|
||||
return (new RefundLog())
|
||||
->order(['id' => 'desc'])
|
||||
->where('record_id', $recordId)
|
||||
->hidden(['refund_msg'])
|
||||
->append(['handler', 'refund_status_text'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
<?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\notice;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\notice\NoticeSetting;
|
||||
|
||||
/**
|
||||
* 通知逻辑层
|
||||
* Class NoticeLogic
|
||||
* @package app\adminapi\logic\notice
|
||||
*/
|
||||
class NoticeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 查看通知设置详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:34
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$field = 'id,type,scene_id,scene_name,scene_desc,system_notice,sms_notice,oa_notice,mnp_notice,support';
|
||||
$noticeSetting = NoticeSetting::field($field)->findOrEmpty($params['id'])->toArray();
|
||||
if (empty($noticeSetting)) {
|
||||
return [];
|
||||
}
|
||||
if (empty($noticeSetting['system_notice'])) {
|
||||
$noticeSetting['system_notice'] = [
|
||||
'title' => '',
|
||||
'content' => '',
|
||||
'status' => 0,
|
||||
];
|
||||
}
|
||||
$noticeSetting['system_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SYSTEM, $noticeSetting['scene_id']);
|
||||
if (empty($noticeSetting['sms_notice'])) {
|
||||
$noticeSetting['sms_notice'] = [
|
||||
'template_id' => '',
|
||||
'content' => '',
|
||||
'status' => 0,
|
||||
];
|
||||
}
|
||||
$noticeSetting['sms_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SMS, $noticeSetting['scene_id']);
|
||||
if (empty($noticeSetting['oa_notice'])) {
|
||||
$noticeSetting['oa_notice'] = [
|
||||
'template_id' => '',
|
||||
'template_sn' => '',
|
||||
'name' => '',
|
||||
'first' => '',
|
||||
'remark' => '',
|
||||
'tpl' => [],
|
||||
'status' => 0,
|
||||
];
|
||||
}
|
||||
$noticeSetting['oa_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
|
||||
if (empty($noticeSetting['mnp_notice'])) {
|
||||
$noticeSetting['mnp_notice'] = [
|
||||
'template_id' => '',
|
||||
'template_sn' => '',
|
||||
'name' => '',
|
||||
'tpl' => [],
|
||||
'status' => 0,
|
||||
];
|
||||
}
|
||||
$noticeSetting['mnp_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
|
||||
$noticeSetting['system_notice']['is_show'] = in_array(NoticeEnum::SYSTEM, explode(',', $noticeSetting['support']));
|
||||
$noticeSetting['sms_notice']['is_show'] = in_array(NoticeEnum::SMS, explode(',', $noticeSetting['support']));
|
||||
$noticeSetting['oa_notice']['is_show'] = in_array(NoticeEnum::OA, explode(',', $noticeSetting['support']));
|
||||
$noticeSetting['mnp_notice']['is_show'] = in_array(NoticeEnum::MNP, explode(',', $noticeSetting['support']));
|
||||
$noticeSetting['default'] = '';
|
||||
$noticeSetting['type'] = NoticeEnum::getTypeDesc($noticeSetting['type']);
|
||||
return $noticeSetting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 通知设置
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:34
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
try {
|
||||
// 校验参数
|
||||
self::checkSet($params);
|
||||
// 拼装更新数据
|
||||
$updateData = [];
|
||||
foreach ($params['template'] as $item) {
|
||||
$updateData[$item['type'] . '_notice'] = json_encode($item, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
// 更新通知设置
|
||||
NoticeSetting::where('id', $params['id'])->update($updateData);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验参数
|
||||
* @param $params
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:35
|
||||
*/
|
||||
public static function checkSet($params)
|
||||
{
|
||||
$noticeSetting = NoticeSetting::findOrEmpty($params['id'] ?? 0);
|
||||
|
||||
if ($noticeSetting->isEmpty()) {
|
||||
throw new \Exception('通知配置不存在');
|
||||
}
|
||||
|
||||
if (!isset($params['template']) || !is_array($params['template']) || count($params['template']) == 0) {
|
||||
throw new \Exception('模板配置不存在或格式错误');
|
||||
}
|
||||
|
||||
// 通知类型
|
||||
$noticeType = ['system', 'sms', 'oa', 'mnp'];
|
||||
|
||||
foreach ($params['template'] as $item) {
|
||||
if (!is_array($item)) {
|
||||
throw new \Exception('模板项格式错误');
|
||||
}
|
||||
|
||||
if (!isset($item['type']) || !in_array($item['type'], $noticeType)) {
|
||||
throw new \Exception('模板项缺少模板类型或模板类型有误');
|
||||
}
|
||||
|
||||
switch ($item['type']) {
|
||||
case "system";
|
||||
self::checkSystem($item);
|
||||
break;
|
||||
case "sms";
|
||||
self::checkSms($item);
|
||||
break;
|
||||
case "oa";
|
||||
self::checkOa($item);
|
||||
break;
|
||||
case "mnp";
|
||||
self::checkMnp($item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验系统通知参数
|
||||
* @param $item
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:35
|
||||
*/
|
||||
public static function checkSystem($item)
|
||||
{
|
||||
if (!isset($item['title']) || !isset($item['content']) || !isset($item['status'])) {
|
||||
throw new \Exception('系统通知必填参数:title、content、status');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验短信通知必填参数
|
||||
* @param $item
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:35
|
||||
*/
|
||||
public static function checkSms($item)
|
||||
{
|
||||
if (!isset($item['template_id']) || !isset($item['content']) || !isset($item['status'])) {
|
||||
throw new \Exception('短信通知必填参数:template_id、content、status');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验微信模板消息参数
|
||||
* @param $item
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:35
|
||||
*/
|
||||
public static function checkOa($item)
|
||||
{
|
||||
if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['first']) || !isset($item['remark']) || !isset($item['tpl']) || !isset($item['status'])) {
|
||||
throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、first、remark、tpl、status');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验微信小程序提醒必填参数
|
||||
* @param $item
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:35
|
||||
*/
|
||||
public static function checkMnp($item)
|
||||
{
|
||||
if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['tpl']) || !isset($item['status'])) {
|
||||
throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、tpl、status');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?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\notice;
|
||||
|
||||
use app\common\enum\notice\SmsEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 短信配置逻辑层
|
||||
* Class SmsConfigLogic
|
||||
* @package app\adminapi\logic\notice
|
||||
*/
|
||||
class SmsConfigLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取短信配置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:37
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
ConfigService::get('sms', 'ali', ['type' => 'ali', 'name' => '阿里云短信', 'status' => 1]),
|
||||
ConfigService::get('sms', 'tencent', ['type' => 'tencent', 'name' => '腾讯云短信', 'status' => 0]),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 短信配置
|
||||
* @param $params
|
||||
* @return bool|void
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:37
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
$type = $params['type'];
|
||||
$params['name'] = self::getNameDesc(strtoupper($type));
|
||||
ConfigService::set('sms', $type, $params);
|
||||
$default = ConfigService::get('sms', 'engine', false);
|
||||
if ($params['status'] == 1 && $default === false) {
|
||||
// 启用当前短信配置 并 设置当前短信配置为默认
|
||||
ConfigService::set('sms', 'engine', strtoupper($type));
|
||||
return true;
|
||||
}
|
||||
if ($params['status'] == 1 && $default != strtoupper($type)) {
|
||||
// 找到默认短信配置
|
||||
$defaultConfig = ConfigService::get('sms', strtolower($default));
|
||||
// 状态置为禁用 并 更新
|
||||
$defaultConfig['status'] = 0;
|
||||
ConfigService::set('sms', strtolower($default), $defaultConfig);
|
||||
// 设置当前短信配置为默认
|
||||
ConfigService::set('sms', 'engine', strtoupper($type));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看短信配置详情
|
||||
* @param $params
|
||||
* @return array|int|mixed|string|null
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:37
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$default = [];
|
||||
switch ($params['type']) {
|
||||
case 'ali':
|
||||
$default = [
|
||||
'sign' => '',
|
||||
'app_key' => '',
|
||||
'secret_key' => '',
|
||||
'status' => 1,
|
||||
'name' => '阿里云短信',
|
||||
];
|
||||
break;
|
||||
case 'tencent':
|
||||
$default = [
|
||||
'sign' => '',
|
||||
'app_id' => '',
|
||||
'secret_key' => '',
|
||||
'status' => 0,
|
||||
'secret_id' => '',
|
||||
'name' => '腾讯云短信',
|
||||
];
|
||||
break;
|
||||
}
|
||||
$result = ConfigService::get('sms', $params['type'], $default);
|
||||
$result['status'] = intval($result['status'] ?? 0);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取短信平台名称
|
||||
* @param $value
|
||||
* @return string
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:37
|
||||
*/
|
||||
public static function getNameDesc($value)
|
||||
{
|
||||
$desc = [
|
||||
'ALI' => '阿里云短信',
|
||||
'TENCENT' => '腾讯云短信',
|
||||
];
|
||||
return $desc[$value] ?? '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?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\recharge;
|
||||
|
||||
|
||||
use app\common\enum\RefundEnum;
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\RefundLogic;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
use app\common\model\refund\RefundRecord;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\ConfigService;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 充值逻辑层
|
||||
* Class RechargeLogic
|
||||
* @package app\adminapi\logic\recharge
|
||||
*/
|
||||
class RechargeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取充值设置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 16:54
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'status' => ConfigService::get('recharge', 'status', 0),
|
||||
'min_amount' => ConfigService::get('recharge', 'min_amount', 0)
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值设置
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 16:54
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
try {
|
||||
if (isset($params['status'])) {
|
||||
ConfigService::set('recharge', 'status', $params['status']);
|
||||
}
|
||||
if (isset($params['min_amount'])) {
|
||||
ConfigService::set('recharge', 'min_amount', $params['min_amount']);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退款
|
||||
* @param $params
|
||||
* @param $adminId
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2023/3/3 11:42
|
||||
*/
|
||||
public static function refund($params, $adminId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = RechargeOrder::findOrEmpty($params['recharge_id']);
|
||||
|
||||
// 更新订单信息, 标记已发起退款状态,具体退款成功看退款日志
|
||||
RechargeOrder::update([
|
||||
'id' => $order['id'],
|
||||
'refund_status' => YesNoEnum::YES,
|
||||
]);
|
||||
|
||||
// 更新用户余额及累计充值金额
|
||||
User::where(['id' => $order['user_id']])
|
||||
->dec('total_recharge_amount', $order['order_amount'])
|
||||
->dec('user_money', $order['order_amount'])
|
||||
->update();
|
||||
|
||||
// 记录日志
|
||||
AccountLogLogic::add(
|
||||
$order['user_id'],
|
||||
AccountLogEnum::UM_INC_ADMIN,
|
||||
AccountLogEnum::DEC,
|
||||
$order['order_amount'],
|
||||
$order['sn'],
|
||||
'充值订单退款'
|
||||
);
|
||||
|
||||
// 生成退款记录
|
||||
$recordSn = generate_sn(RefundRecord::class, 'sn');
|
||||
$record = RefundRecord::create([
|
||||
'sn' => $recordSn,
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id'],
|
||||
'order_sn' => $order['sn'],
|
||||
'order_type' => RefundEnum::ORDER_TYPE_RECHARGE,
|
||||
'order_amount' => $order['order_amount'],
|
||||
'refund_amount' => $order['order_amount'],
|
||||
'refund_type' => RefundEnum::TYPE_ADMIN,
|
||||
'transaction_id' => $order['transaction_id'] ?? '',
|
||||
'refund_way' => RefundEnum::getRefundWayByPayWay($order['pay_way']),
|
||||
]);
|
||||
|
||||
// 退款
|
||||
$result = RefundLogic::refund($order, $record['id'], $order['order_amount'], $adminId);
|
||||
|
||||
$flag = true;
|
||||
$resultMsg = '操作成功';
|
||||
if ($result !== true) {
|
||||
$flag = false;
|
||||
$resultMsg = RefundLogic::getError();
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return [$flag, $resultMsg];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return [false, $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重新退款
|
||||
* @param $params
|
||||
* @param $adminId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/3/3 11:44
|
||||
*/
|
||||
public static function refundAgain($params, $adminId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$record = RefundRecord::findOrEmpty($params['record_id']);
|
||||
$order = RechargeOrder::findOrEmpty($record['order_id']);
|
||||
|
||||
// 退款
|
||||
$result = RefundLogic::refund($order, $record['id'], $order['order_amount'], $adminId);
|
||||
|
||||
$flag = true;
|
||||
$resultMsg = '操作成功';
|
||||
if ($result !== true) {
|
||||
$flag = false;
|
||||
$resultMsg = RefundLogic::getError();
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return [$flag, $resultMsg];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return [false, $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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\setting;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 客服设置逻辑
|
||||
* Class CustomerServiceLogic
|
||||
* @package app\adminapi\logic\setting
|
||||
*/
|
||||
class CustomerServiceLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取客服设置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/15 12:05 下午
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$qrCode = ConfigService::get('customer_service', 'qr_code');
|
||||
$qrCode = empty($qrCode) ? '' : FileService::getFileUrl($qrCode);
|
||||
$config = [
|
||||
'qr_code' => $qrCode,
|
||||
'wechat' => ConfigService::get('customer_service', 'wechat', ''),
|
||||
'phone' => ConfigService::get('customer_service', 'phone', ''),
|
||||
'service_time' => ConfigService::get('customer_service', 'service_time', ''),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置客服设置
|
||||
* @param $params
|
||||
* @author ljj
|
||||
* @date 2022/2/15 12:11 下午
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
$allowField = ['qr_code','wechat','phone','service_time'];
|
||||
foreach($params as $key => $value) {
|
||||
if(in_array($key, $allowField)) {
|
||||
if ($key == 'qr_code') {
|
||||
$value = FileService::setFileUrl($value);
|
||||
}
|
||||
ConfigService::set('customer_service', $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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\setting;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\HotSearch;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* 热门搜素逻辑
|
||||
* Class HotSearchLogic
|
||||
* @package app\adminapi\logic\setting
|
||||
*/
|
||||
class HotSearchLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/5 18:48
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
return [
|
||||
// 功能状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('hot_search', 'status', 0),
|
||||
// 热门搜索数据
|
||||
'data' => HotSearch::field(['name', 'sort'])->order(['sort' => 'desc', 'id' =>'desc'])->select()->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置热门搜搜
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/5 18:58
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
try {
|
||||
if (!empty($params['data'])) {
|
||||
$model = (new HotSearch());
|
||||
$model->where('id', '>', 0)->delete();
|
||||
$model->saveAll($params['data']);
|
||||
}
|
||||
|
||||
$status = empty($params['status']) ? 0 : $params['status'];
|
||||
ConfigService::set('hot_search', 'status', $status);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?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\setting;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use think\facade\Cache;
|
||||
|
||||
|
||||
/**
|
||||
* 存储设置逻辑层
|
||||
* Class ShopStorageLogic
|
||||
* @package app\adminapi\logic\setting\
|
||||
*/
|
||||
class StorageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 存储引擎列表
|
||||
* @return array[]
|
||||
* @author 段誉
|
||||
* @date 2022/4/20 16:14
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
|
||||
$default = ConfigService::get('storage', 'default', 'local');
|
||||
|
||||
$data = [
|
||||
[
|
||||
'name' => '本地存储',
|
||||
'path' => '存储在本地服务器',
|
||||
'engine' => 'local',
|
||||
'status' => $default == 'local' ? 1 : 0
|
||||
],
|
||||
[
|
||||
'name' => '七牛云存储',
|
||||
'path' => '存储在七牛云,请前往七牛云开通存储服务',
|
||||
'engine' => 'qiniu',
|
||||
'status' => $default == 'qiniu' ? 1 : 0
|
||||
],
|
||||
[
|
||||
'name' => '阿里云OSS',
|
||||
'path' => '存储在阿里云,请前往阿里云开通存储服务',
|
||||
'engine' => 'aliyun',
|
||||
'status' => $default == 'aliyun' ? 1 : 0
|
||||
],
|
||||
[
|
||||
'name' => '腾讯云COS',
|
||||
'path' => '存储在腾讯云,请前往腾讯云开通存储服务',
|
||||
'engine' => 'qcloud',
|
||||
'status' => $default == 'qcloud' ? 1 : 0
|
||||
]
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 存储设置详情
|
||||
* @param $param
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/4/20 16:15
|
||||
*/
|
||||
public static function detail($param)
|
||||
{
|
||||
|
||||
$default = ConfigService::get('storage', 'default', '');
|
||||
|
||||
// 本地存储
|
||||
$local = ['status' => $default == 'local' ? 1 : 0];
|
||||
// 七牛云存储
|
||||
$qiniu = ConfigService::get('storage', 'qiniu', [
|
||||
'bucket' => '',
|
||||
'access_key' => '',
|
||||
'secret_key' => '',
|
||||
'domain' => '',
|
||||
'status' => $default == 'qiniu' ? 1 : 0
|
||||
]);
|
||||
|
||||
// 阿里云存储
|
||||
$aliyun = ConfigService::get('storage', 'aliyun', [
|
||||
'bucket' => '',
|
||||
'access_key' => '',
|
||||
'secret_key' => '',
|
||||
'domain' => '',
|
||||
'status' => $default == 'aliyun' ? 1 : 0
|
||||
]);
|
||||
|
||||
// 腾讯云存储
|
||||
$qcloud = ConfigService::get('storage', 'qcloud', [
|
||||
'bucket' => '',
|
||||
'region' => '',
|
||||
'access_key' => '',
|
||||
'secret_key' => '',
|
||||
'domain' => '',
|
||||
'status' => $default == 'qcloud' ? 1 : 0
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'local' => $local,
|
||||
'qiniu' => $qiniu,
|
||||
'aliyun' => $aliyun,
|
||||
'qcloud' => $qcloud
|
||||
];
|
||||
$result = $data[$param['engine']];
|
||||
if ($param['engine'] == $default) {
|
||||
$result['status'] = 1;
|
||||
} else {
|
||||
$result['status'] = 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置存储参数
|
||||
* @param $params
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/4/20 16:16
|
||||
*/
|
||||
public static function setup($params)
|
||||
{
|
||||
if ($params['status'] == 1) { //状态为开启
|
||||
ConfigService::set('storage', 'default', $params['engine']);
|
||||
} else {
|
||||
ConfigService::set('storage', 'default', 'local');
|
||||
}
|
||||
|
||||
switch ($params['engine']) {
|
||||
case 'local':
|
||||
ConfigService::set('storage', 'local', []);
|
||||
break;
|
||||
case 'qiniu':
|
||||
ConfigService::set('storage', 'qiniu', [
|
||||
'bucket' => $params['bucket'] ?? '',
|
||||
'access_key' => $params['access_key'] ?? '',
|
||||
'secret_key' => $params['secret_key'] ?? '',
|
||||
'domain' => $params['domain'] ?? ''
|
||||
]);
|
||||
break;
|
||||
case 'aliyun':
|
||||
ConfigService::set('storage', 'aliyun', [
|
||||
'bucket' => $params['bucket'] ?? '',
|
||||
'access_key' => $params['access_key'] ?? '',
|
||||
'secret_key' => $params['secret_key'] ?? '',
|
||||
'domain' => $params['domain'] ?? ''
|
||||
]);
|
||||
break;
|
||||
case 'qcloud':
|
||||
ConfigService::set('storage', 'qcloud', [
|
||||
'bucket' => $params['bucket'] ?? '',
|
||||
'region' => $params['region'] ?? '',
|
||||
'access_key' => $params['access_key'] ?? '',
|
||||
'secret_key' => $params['secret_key'] ?? '',
|
||||
'domain' => $params['domain'] ?? '',
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
Cache::delete('STORAGE_DEFAULT');
|
||||
Cache::delete('STORAGE_ENGINE');
|
||||
if ($params['engine'] == 'local' && $params['status'] == 0) {
|
||||
return '默认开启本地存储';
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 切换状态
|
||||
* @param $params
|
||||
* @author 段誉
|
||||
* @date 2022/4/20 16:17
|
||||
*/
|
||||
public static function change($params)
|
||||
{
|
||||
$default = ConfigService::get('storage', 'default', '');
|
||||
if ($default == $params['engine']) {
|
||||
ConfigService::set('storage', 'default', 'local');
|
||||
} else {
|
||||
ConfigService::set('storage', 'default', $params['engine']);
|
||||
}
|
||||
Cache::delete('STORAGE_DEFAULT');
|
||||
Cache::delete('STORAGE_ENGINE');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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\setting;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 交易设置逻辑
|
||||
* Class TransactionSettingsLogic
|
||||
* @package app\adminapi\logic\setting
|
||||
*/
|
||||
class TransactionSettingsLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取交易设置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/15 11:40 上午
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
'cancel_unpaid_orders' => ConfigService::get('transaction', 'cancel_unpaid_orders', 1),
|
||||
'cancel_unpaid_orders_times' => ConfigService::get('transaction', 'cancel_unpaid_orders_times', 30),
|
||||
'verification_orders' => ConfigService::get('transaction', 'verification_orders', 1),
|
||||
'verification_orders_times' => ConfigService::get('transaction', 'verification_orders_times', 24),
|
||||
];
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置交易设置
|
||||
* @param $params
|
||||
* @author ljj
|
||||
* @date 2022/2/15 11:49 上午
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
ConfigService::set('transaction', 'cancel_unpaid_orders', $params['cancel_unpaid_orders']);
|
||||
ConfigService::set('transaction', 'verification_orders', $params['verification_orders']);
|
||||
|
||||
if (isset($params['cancel_unpaid_orders_times'])) {
|
||||
ConfigService::set('transaction', 'cancel_unpaid_orders_times', $params['cancel_unpaid_orders_times']);
|
||||
}
|
||||
|
||||
if (isset($params['verification_orders_times'])) {
|
||||
ConfigService::set('transaction', 'verification_orders_times', $params['verification_orders_times']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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\setting\dict;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\dict\DictType;
|
||||
|
||||
|
||||
/**
|
||||
* 字典数据逻辑
|
||||
* Class DictDataLogic
|
||||
* @package app\adminapi\logic\DictData
|
||||
*/
|
||||
class DictDataLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加编辑
|
||||
* @param array $params
|
||||
* @return DictData|\think\Model
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 17:13
|
||||
*/
|
||||
public static function save(array $params)
|
||||
{
|
||||
$data = [
|
||||
'name' => $params['name'],
|
||||
'value' => $params['value'],
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'status' => $params['status'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
];
|
||||
|
||||
if (!empty($params['id'])) {
|
||||
return DictData::where(['id' => $params['id']])->update($data);
|
||||
} else {
|
||||
$dictType = DictType::findOrEmpty($params['type_id']);
|
||||
$data['type_id'] = $params['type_id'];
|
||||
$data['type_value'] = $dictType['type'];
|
||||
return DictData::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除字典数据
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 17:01
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
return DictData::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取字典数据详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 17:01
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return DictData::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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\setting\dict;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\dict\DictType;
|
||||
|
||||
|
||||
/**
|
||||
* 字典类型逻辑
|
||||
* Class DictTypeLogic
|
||||
* @package app\adminapi\logic\dict
|
||||
*/
|
||||
class DictTypeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加字典类型
|
||||
* @param array $params
|
||||
* @return DictType|\think\Model
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 16:08
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
return DictType::create([
|
||||
'name' => $params['name'],
|
||||
'type' => $params['type'],
|
||||
'status' => $params['status'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑字典类型
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 16:10
|
||||
*/
|
||||
public static function edit(array $params)
|
||||
{
|
||||
DictType::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'type' => $params['type'],
|
||||
'status' => $params['status'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
|
||||
DictData::where(['type_id' => $params['id']])
|
||||
->update(['type_value' => $params['type']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除字典类型
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 16:23
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
DictType::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取字典详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 16:23
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return DictType::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 角色数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:44
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return DictType::where(['status' => YesNoEnum::YES])
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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\setting\pay;
|
||||
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\pay\PayConfig;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 支付配置
|
||||
* Class PayConfigLogic
|
||||
* @package app\adminapi\logic\setting\pay
|
||||
*/
|
||||
class PayConfigLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 设置配置
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 16:16
|
||||
*/
|
||||
public static function setConfig($params)
|
||||
{
|
||||
$payConfig = PayConfig::find($params['id']);
|
||||
|
||||
$config = '';
|
||||
if ($payConfig['pay_way'] == PayEnum::WECHAT_PAY) {
|
||||
$config = [
|
||||
'interface_version' => $params['config']['interface_version'],
|
||||
'merchant_type' => $params['config']['merchant_type'],
|
||||
'mch_id' => $params['config']['mch_id'],
|
||||
'pay_sign_key' => $params['config']['pay_sign_key'],
|
||||
'apiclient_cert' => $params['config']['apiclient_cert'],
|
||||
'apiclient_key' => $params['config']['apiclient_key'],
|
||||
];
|
||||
}
|
||||
if ($payConfig['pay_way'] == PayEnum::ALI_PAY) {
|
||||
$config = [
|
||||
'mode' => $params['config']['mode'],
|
||||
'merchant_type' => $params['config']['merchant_type'],
|
||||
'app_id' => $params['config']['app_id'],
|
||||
'private_key' => $params['config']['private_key'],
|
||||
'ali_public_key' => $params['config']['mode'] == 'normal_mode' ? $params['config']['ali_public_key'] : '',
|
||||
'public_cert' => $params['config']['mode'] == 'certificate' ? $params['config']['public_cert'] : '',
|
||||
'ali_public_cert' => $params['config']['mode'] == 'certificate' ? $params['config']['ali_public_cert'] : '',
|
||||
'ali_root_cert' => $params['config']['mode'] == 'certificate' ? $params['config']['ali_root_cert'] : '',
|
||||
];
|
||||
}
|
||||
|
||||
$payConfig->name = $params['name'];
|
||||
$payConfig->icon = FileService::setFileUrl($params['icon']);
|
||||
$payConfig->sort = $params['sort'];
|
||||
$payConfig->config = $config;
|
||||
$payConfig->remark = $params['remark'] ?? '';
|
||||
return $payConfig->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 16:16
|
||||
*/
|
||||
public static function getConfig($params)
|
||||
{
|
||||
$payConfig = PayConfig::find($params['id'])->toArray();
|
||||
$payConfig['icon'] = FileService::getFileUrl($payConfig['icon']);
|
||||
$payConfig['domain'] = request()->domain();
|
||||
return $payConfig;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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\setting\pay;
|
||||
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\pay\PayConfig;
|
||||
use app\common\model\pay\PayWay;
|
||||
use app\common\service\FileService;
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
* Class PayWayLogic
|
||||
* @package app\adminapi\logic\setting\pay
|
||||
*/
|
||||
class PayWayLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取支付方式
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 16:25
|
||||
*/
|
||||
public static function getPayWay()
|
||||
{
|
||||
$payWay = PayWay::select()->append(['pay_way_name'])
|
||||
->toArray();
|
||||
|
||||
if (empty($payWay)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lists = [];
|
||||
for ($i = 1; $i <= max(array_column($payWay, 'scene')); $i++) {
|
||||
foreach ($payWay as $val) {
|
||||
if ($val['scene'] == $i) {
|
||||
$val['icon'] = FileService::getFileUrl(PayConfig::where('id', $val['pay_config_id'])->value('icon'));
|
||||
$lists[$i][] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置支付方式
|
||||
* @param $params
|
||||
* @return bool|string
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 16:26
|
||||
*/
|
||||
public static function setPayWay($params)
|
||||
{
|
||||
$payWay = new PayWay;
|
||||
$data = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$isDefault = array_column($value, 'is_default');
|
||||
$isDefaultNum = array_count_values($isDefault);
|
||||
$status = array_column($value, 'status');
|
||||
$sceneName = PayEnum::getPaySceneDesc($key);
|
||||
if (!in_array(YesNoEnum::YES, $isDefault)) {
|
||||
return $sceneName . '支付场景缺少默认支付';
|
||||
}
|
||||
if ($isDefaultNum[YesNoEnum::YES] > 1) {
|
||||
return $sceneName . '支付场景的默认值只能存在一个';
|
||||
}
|
||||
if (!in_array(YesNoEnum::YES, $status)) {
|
||||
return $sceneName . '支付场景至少开启一个支付状态';
|
||||
}
|
||||
|
||||
foreach ($value as $val) {
|
||||
$result = PayWay::where('id', $val['id'])->findOrEmpty();
|
||||
if ($result->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if ($val['is_default'] == YesNoEnum::YES && $val['status'] == YesNoEnum::NO) {
|
||||
return $sceneName . '支付场景的默认支付未开启支付状态';
|
||||
}
|
||||
$data[] = [
|
||||
'id' => $val['id'],
|
||||
'is_default' => $val['is_default'],
|
||||
'status' => $val['status'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$payWay->saveAll($data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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\setting\system;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 系统缓存逻辑
|
||||
* Class CacheLogic
|
||||
* @package app\adminapi\logic\setting\system
|
||||
*/
|
||||
class CacheLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 清楚系统缓存
|
||||
* @author 段誉
|
||||
* @date 2022/4/8 16:29
|
||||
*/
|
||||
public static function clear()
|
||||
{
|
||||
Cache::clear();
|
||||
del_target_dir(app()->getRootPath().'runtime/file',true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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\setting\system;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
/**
|
||||
* Class SystemLogic
|
||||
* @package app\adminapi\logic\setting\system
|
||||
*/
|
||||
class SystemLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 系统环境信息
|
||||
* @return \array[][]
|
||||
* @author 段誉
|
||||
* @date 2021/12/28 18:35
|
||||
*/
|
||||
public static function getInfo() : array
|
||||
{
|
||||
$server = [
|
||||
['param' => '服务器操作系统', 'value' => PHP_OS],
|
||||
['param' => 'web服务器环境', 'value' => $_SERVER['SERVER_SOFTWARE']],
|
||||
['param' => 'PHP版本', 'value' => PHP_VERSION],
|
||||
];
|
||||
|
||||
$env = [
|
||||
[ 'option' => 'PHP版本',
|
||||
'require' => '8.0版本以上',
|
||||
'status' => (int)compare_php('8.0.0'),
|
||||
'remark' => ''
|
||||
]
|
||||
];
|
||||
|
||||
$auth = [
|
||||
[
|
||||
'dir' => '/runtime',
|
||||
'require' => 'runtime目录可写',
|
||||
'status' => (int)check_dir_write('runtime'),
|
||||
'remark' => ''
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
'server' => $server,
|
||||
'env' => $env,
|
||||
'auth' => $auth,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?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\setting\user;
|
||||
|
||||
use app\common\service\{ConfigService, FileService};
|
||||
|
||||
/**
|
||||
* 设置-用户设置逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\adminapi\logic\config
|
||||
*/
|
||||
class UserLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取用户设置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:09
|
||||
*/
|
||||
public static function getConfig(): array
|
||||
{
|
||||
$defaultAvatar = config('project.default_image.user_avatar');
|
||||
$config = [
|
||||
//默认头像
|
||||
'default_avatar' => FileService::getFileUrl(ConfigService::get('default_image', 'user_avatar', $defaultAvatar)),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置用户设置
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:09
|
||||
*/
|
||||
public function setConfig(array $params): bool
|
||||
{
|
||||
$avatar = FileService::setFileUrl($params['default_avatar']);
|
||||
ConfigService::set('default_image', 'user_avatar', $avatar);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取注册配置
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:10
|
||||
*/
|
||||
public function getRegisterConfig(): array
|
||||
{
|
||||
$config = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置登录注册
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 10:10
|
||||
*/
|
||||
public static function setRegisterConfig(array $params): bool
|
||||
{
|
||||
// 登录方式:1-账号密码登录;2-手机短信验证码登录
|
||||
ConfigService::set('login', 'login_way', $params['login_way']);
|
||||
// 注册强制绑定手机
|
||||
ConfigService::set('login', 'coerce_mobile', $params['coerce_mobile']);
|
||||
// 政策协议
|
||||
ConfigService::set('login', 'login_agreement', $params['login_agreement']);
|
||||
// 第三方授权登录
|
||||
ConfigService::set('login', 'third_auth', $params['third_auth']);
|
||||
// 微信授权登录
|
||||
ConfigService::set('login', 'wechat_auth', $params['wechat_auth']);
|
||||
// qq登录
|
||||
ConfigService::set('login', 'qq_auth', $params['qq_auth']);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?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\setting\web;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* 网站设置
|
||||
* Class WebSettingLogic
|
||||
* @package app\adminapi\logic\setting
|
||||
*/
|
||||
class WebSettingLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取网站信息
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/28 15:43
|
||||
*/
|
||||
public static function getWebsiteInfo(): array
|
||||
{
|
||||
return [
|
||||
'name' => ConfigService::get('website', 'name'),
|
||||
'web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'web_favicon')),
|
||||
'web_logo' => FileService::getFileUrl(ConfigService::get('website', 'web_logo')),
|
||||
'login_image' => FileService::getFileUrl(ConfigService::get('website', 'login_image')),
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
|
||||
'pc_logo' => FileService::getFileUrl(ConfigService::get('website', 'pc_logo')),
|
||||
'pc_title' => ConfigService::get('website', 'pc_title', ''),
|
||||
'pc_ico' => FileService::getFileUrl(ConfigService::get('website', 'pc_ico')),
|
||||
'pc_desc' => ConfigService::get('website', 'pc_desc', ''),
|
||||
'pc_keywords' => ConfigService::get('website', 'pc_keywords', ''),
|
||||
|
||||
'h5_favicon' => FileService::getFileUrl(ConfigService::get('website', 'h5_favicon')),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置网站信息
|
||||
* @param array $params
|
||||
* @author 段誉
|
||||
* @date 2021/12/28 15:43
|
||||
*/
|
||||
public static function setWebsiteInfo(array $params)
|
||||
{
|
||||
$h5favicon = FileService::setFileUrl($params['h5_favicon']);
|
||||
$favicon = FileService::setFileUrl($params['web_favicon']);
|
||||
$logo = FileService::setFileUrl($params['web_logo']);
|
||||
$login = FileService::setFileUrl($params['login_image']);
|
||||
$shopLogo = FileService::setFileUrl($params['shop_logo']);
|
||||
$pcLogo = FileService::setFileUrl($params['pc_logo']);
|
||||
$pcIco = FileService::setFileUrl($params['pc_ico'] ?? '');
|
||||
|
||||
ConfigService::set('website', 'name', $params['name']);
|
||||
ConfigService::set('website', 'web_favicon', $favicon);
|
||||
ConfigService::set('website', 'web_logo', $logo);
|
||||
ConfigService::set('website', 'login_image', $login);
|
||||
ConfigService::set('website', 'shop_name', $params['shop_name']);
|
||||
ConfigService::set('website', 'shop_logo', $shopLogo);
|
||||
ConfigService::set('website', 'pc_logo', $pcLogo);
|
||||
|
||||
ConfigService::set('website', 'pc_title', $params['pc_title']);
|
||||
ConfigService::set('website', 'pc_ico', $pcIco);
|
||||
ConfigService::set('website', 'pc_desc', $params['pc_desc'] ?? '');
|
||||
ConfigService::set('website', 'pc_keywords', $params['pc_keywords'] ?? '');
|
||||
|
||||
ConfigService::set('website', 'h5_favicon', $h5favicon);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取版权备案
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/28 16:09
|
||||
*/
|
||||
public static function getCopyright() : array
|
||||
{
|
||||
return ConfigService::get('copyright', 'config', []);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置版权备案
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/8/8 16:33
|
||||
*/
|
||||
public static function setCopyright(array $params)
|
||||
{
|
||||
try {
|
||||
if (!is_array($params['config'])) {
|
||||
throw new \Exception('参数异常');
|
||||
}
|
||||
ConfigService::set('copyright', 'config', $params['config'] ?? []);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置政策协议
|
||||
* @param array $params
|
||||
* @author ljj
|
||||
* @date 2022/2/15 10:59 上午
|
||||
*/
|
||||
public static function setAgreement(array $params)
|
||||
{
|
||||
$serviceContent = clear_file_domain($params['service_content'] ?? '');
|
||||
$privacyContent = clear_file_domain($params['privacy_content'] ?? '');
|
||||
ConfigService::set('agreement', 'service_title', $params['service_title'] ?? '');
|
||||
ConfigService::set('agreement', 'service_content', $serviceContent);
|
||||
ConfigService::set('agreement', 'privacy_title', $params['privacy_title'] ?? '');
|
||||
ConfigService::set('agreement', 'privacy_content', $privacyContent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取政策协议
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/15 11:15 上午
|
||||
*/
|
||||
public static function getAgreement() : array
|
||||
{
|
||||
$config = [
|
||||
'service_title' => ConfigService::get('agreement', 'service_title'),
|
||||
'service_content' => ConfigService::get('agreement', 'service_content'),
|
||||
'privacy_title' => ConfigService::get('agreement', 'privacy_title'),
|
||||
'privacy_content' => ConfigService::get('agreement', 'privacy_content'),
|
||||
];
|
||||
|
||||
$config['service_content'] = get_file_domain($config['service_content']);
|
||||
$config['privacy_content'] = get_file_domain($config['privacy_content']);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取站点统计配置
|
||||
* @return array
|
||||
* @author yfdong
|
||||
* @date 2024/09/20 22:25
|
||||
*/
|
||||
public static function getSiteStatistics()
|
||||
{
|
||||
return [
|
||||
'clarity_code' => ConfigService::get('siteStatistics', 'clarity_code')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置站点统计配置
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @author yfdong
|
||||
* @date 2024/09/20 22:31
|
||||
*/
|
||||
public static function setSiteStatistics(array $params)
|
||||
{
|
||||
ConfigService::set('siteStatistics', 'clarity_code', $params['clarity_code']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
<?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\tools;
|
||||
|
||||
use app\common\enum\GeneratorEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\tools\GenerateColumn;
|
||||
use app\common\model\tools\GenerateTable;
|
||||
use app\common\service\generator\GenerateService;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 生成器逻辑
|
||||
* Class GeneratorLogic
|
||||
* @package app\adminapi\logic\tools
|
||||
*/
|
||||
class GeneratorLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 表详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 10:45
|
||||
*/
|
||||
public static function getTableDetail($params): array
|
||||
{
|
||||
$detail = GenerateTable::with('table_column')
|
||||
->findOrEmpty((int)$params['id'])
|
||||
->toArray();
|
||||
|
||||
$options = self::formatConfigByTableData($detail);
|
||||
$detail['menu'] = $options['menu'];
|
||||
$detail['delete'] = $options['delete'];
|
||||
$detail['tree'] = $options['tree'];
|
||||
$detail['relations'] = $options['relations'];
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 选择数据表
|
||||
* @param $params
|
||||
* @param $adminId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 10:44
|
||||
*/
|
||||
public static function selectTable($params, $adminId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($params['table'] as $item) {
|
||||
// 添加主表基础信息
|
||||
$generateTable = self::initTable($item, $adminId);
|
||||
// 获取数据表字段信息
|
||||
$column = self::getTableColumn($item['name']);
|
||||
// 添加表字段信息
|
||||
self::initTableColumn($column, $generateTable['id']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑表信息
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/6/20 10:44
|
||||
*/
|
||||
public static function editTable($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 格式化配置
|
||||
$options = self::formatConfigByTableData($params);
|
||||
// 更新主表-数据表信息
|
||||
GenerateTable::update([
|
||||
'id' => $params['id'],
|
||||
'table_name' => $params['table_name'],
|
||||
'table_comment' => $params['table_comment'],
|
||||
'template_type' => $params['template_type'],
|
||||
'author' => $params['author'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'generate_type' => $params['generate_type'],
|
||||
'module_name' => $params['module_name'],
|
||||
'class_dir' => $params['class_dir'] ?? '',
|
||||
'class_comment' => $params['class_comment'] ?? '',
|
||||
'menu' => $options['menu'],
|
||||
'delete' => $options['delete'],
|
||||
'tree' => $options['tree'],
|
||||
'relations' => $options['relations'],
|
||||
]);
|
||||
|
||||
// 更新从表-数据表字段信息
|
||||
foreach ($params['table_column'] as $item) {
|
||||
GenerateColumn::update([
|
||||
'id' => $item['id'],
|
||||
'column_comment' => $item['column_comment'] ?? '',
|
||||
'is_required' => $item['is_required'] ?? 0,
|
||||
'is_insert' => $item['is_insert'] ?? 0,
|
||||
'is_update' => $item['is_update'] ?? 0,
|
||||
'is_lists' => $item['is_lists'] ?? 0,
|
||||
'is_query' => $item['is_query'] ?? 0,
|
||||
'query_type' => $item['query_type'],
|
||||
'view_type' => $item['view_type'],
|
||||
'dict_type' => $item['dict_type'] ?? '',
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除表相关信息
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/6/16 9:30
|
||||
*/
|
||||
public static function deleteTable($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
GenerateTable::whereIn('id', $params['id'])->delete();
|
||||
GenerateColumn::whereIn('table_id', $params['id'])->delete();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 同步表字段
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/6/23 16:28
|
||||
*/
|
||||
public static function syncColumn($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// table 信息
|
||||
$table = GenerateTable::findOrEmpty($params['id']);
|
||||
// 删除旧字段
|
||||
GenerateColumn::whereIn('table_id', $table['id'])->delete();
|
||||
// 获取当前数据表字段信息
|
||||
$column = self::getTableColumn($table['table_name']);
|
||||
// 创建新字段数据
|
||||
self::initTableColumn($column, $table['id']);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 生成代码
|
||||
* @param $params
|
||||
* @return false|int[]
|
||||
* @author 段誉
|
||||
* @date 2022/6/24 9:43
|
||||
*/
|
||||
public static function generate($params)
|
||||
{
|
||||
try {
|
||||
// 获取数据表信息
|
||||
$tables = GenerateTable::with(['table_column'])
|
||||
->whereIn('id', $params['id'])
|
||||
->select()->toArray();
|
||||
|
||||
$generator = app()->make(GenerateService::class);
|
||||
$generator->delGenerateDirContent();
|
||||
$flag = array_unique(array_column($tables, 'table_name'));
|
||||
$flag = implode(',', $flag);
|
||||
$generator->setGenerateFlag(md5($flag . time()), false);
|
||||
|
||||
// 循环生成
|
||||
foreach ($tables as $table) {
|
||||
$generator->generate($table);
|
||||
}
|
||||
|
||||
$zipFile = '';
|
||||
// 生成压缩包
|
||||
if ($generator->getGenerateFlag()) {
|
||||
$generator->zipFile();
|
||||
$generator->delGenerateFlag();
|
||||
$zipFile = $generator->getDownloadUrl();
|
||||
}
|
||||
|
||||
return ['file' => $zipFile];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 预览
|
||||
* @param $params
|
||||
* @return false
|
||||
* @author 段誉
|
||||
* @date 2022/6/23 16:27
|
||||
*/
|
||||
public static function preview($params)
|
||||
{
|
||||
try {
|
||||
// 获取数据表信息
|
||||
$table = GenerateTable::with(['table_column'])
|
||||
->whereIn('id', $params['id'])
|
||||
->findOrEmpty()->toArray();
|
||||
|
||||
return app()->make(GenerateService::class)->preview($table);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取表字段信息
|
||||
* @param $tableName
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/6/23 16:28
|
||||
*/
|
||||
public static function getTableColumn($tableName)
|
||||
{
|
||||
$tableName = get_no_prefix_table_name($tableName);
|
||||
return Db::name($tableName)->getFields();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 初始化代码生成数据表信息
|
||||
* @param $tableData
|
||||
* @param $adminId
|
||||
* @return GenerateTable|\think\Model
|
||||
* @author 段誉
|
||||
* @date 2022/6/23 16:28
|
||||
*/
|
||||
public static function initTable($tableData, $adminId)
|
||||
{
|
||||
return GenerateTable::create([
|
||||
'table_name' => $tableData['name'],
|
||||
'table_comment' => $tableData['comment'],
|
||||
'template_type' => GeneratorEnum::TEMPLATE_TYPE_SINGLE,
|
||||
'generate_type' => GeneratorEnum::GENERATE_TYPE_ZIP,
|
||||
'module_name' => 'adminapi',
|
||||
'admin_id' => $adminId,
|
||||
// 菜单配置
|
||||
'menu' => [
|
||||
'pid' => 0, // 父级菜单id
|
||||
'type' => GeneratorEnum::GEN_SELF, // 构建方式 0-手动添加 1-自动构建
|
||||
'name' => $tableData['comment'], // 菜单名称
|
||||
],
|
||||
// 删除配置
|
||||
'delete' => [
|
||||
'type' => GeneratorEnum::DELETE_TRUE, // 删除类型
|
||||
'name' => GeneratorEnum::DELETE_NAME, // 默认删除字段名
|
||||
],
|
||||
// 关联配置
|
||||
'relations' => [],
|
||||
// 树形crud
|
||||
'tree' => []
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 初始化代码生成字段信息
|
||||
* @param $column
|
||||
* @param $tableId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/6/23 16:28
|
||||
*/
|
||||
public static function initTableColumn($column, $tableId)
|
||||
{
|
||||
$defaultColumn = ['id', 'create_time', 'update_time', 'delete_time'];
|
||||
|
||||
$insertColumn = [];
|
||||
foreach ($column as $value) {
|
||||
$required = 0;
|
||||
if ($value['notnull'] && !$value['primary'] && !in_array($value['name'], $defaultColumn)) {
|
||||
$required = 1;
|
||||
}
|
||||
|
||||
$columnData = [
|
||||
'table_id' => $tableId,
|
||||
'column_name' => $value['name'],
|
||||
'column_comment' => $value['comment'],
|
||||
'column_type' => self::getDbFieldType($value['type']),
|
||||
'is_required' => $required,
|
||||
'is_pk' => $value['primary'] ? 1 : 0,
|
||||
];
|
||||
|
||||
if (!in_array($value['name'], $defaultColumn)) {
|
||||
$columnData['is_insert'] = 1;
|
||||
$columnData['is_update'] = 1;
|
||||
$columnData['is_lists'] = 1;
|
||||
$columnData['is_query'] = 1;
|
||||
}
|
||||
$insertColumn[] = $columnData;
|
||||
}
|
||||
|
||||
(new GenerateColumn())->saveAll($insertColumn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 下载文件
|
||||
* @param $fileName
|
||||
* @return false|string
|
||||
* @author 段誉
|
||||
* @date 2022/6/24 9:51
|
||||
*/
|
||||
public static function download(string $fileName)
|
||||
{
|
||||
$cacheFileName = cache('curd_file_name' . $fileName);
|
||||
if (empty($cacheFileName)) {
|
||||
self::$error = '请重新生成代码';
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = root_path() . 'runtime/generate/' . $fileName;
|
||||
if (!file_exists($path)) {
|
||||
self::$error = '下载失败';
|
||||
return false;
|
||||
}
|
||||
|
||||
cache('curd_file_name' . $fileName, null);
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数据表字段类型
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @author 段誉
|
||||
* @date 2022/6/15 10:11
|
||||
*/
|
||||
public static function getDbFieldType(string $type): string
|
||||
{
|
||||
if (0 === strpos($type, 'set') || 0 === strpos($type, 'enum')) {
|
||||
$result = 'string';
|
||||
} elseif (preg_match('/(double|float|decimal|real|numeric)/is', $type)) {
|
||||
$result = 'float';
|
||||
} elseif (preg_match('/(int|serial|bit)/is', $type)) {
|
||||
$result = 'int';
|
||||
} elseif (preg_match('/bool/is', $type)) {
|
||||
$result = 'bool';
|
||||
} elseif (0 === strpos($type, 'timestamp')) {
|
||||
$result = 'timestamp';
|
||||
} elseif (0 === strpos($type, 'datetime')) {
|
||||
$result = 'datetime';
|
||||
} elseif (0 === strpos($type, 'date')) {
|
||||
$result = 'date';
|
||||
} else {
|
||||
$result = 'string';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes
|
||||
* @param $options
|
||||
* @param $tableComment
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/12/13 18:23
|
||||
*/
|
||||
public static function formatConfigByTableData($options)
|
||||
{
|
||||
// 菜单配置
|
||||
$menuConfig = $options['menu'] ?? [];
|
||||
// 删除配置
|
||||
$deleteConfig = $options['delete'] ?? [];
|
||||
// 关联配置
|
||||
$relationsConfig = $options['relations'] ?? [];
|
||||
// 树表crud配置
|
||||
$treeConfig = $options['tree'] ?? [];
|
||||
|
||||
$relations = [];
|
||||
foreach ($relationsConfig as $relation) {
|
||||
$relations[] = [
|
||||
'name' => $relation['name'] ?? '',
|
||||
'model' => $relation['model'] ?? '',
|
||||
'type' => $relation['type'] ?? GeneratorEnum::RELATION_HAS_ONE,
|
||||
'local_key' => $relation['local_key'] ?? 'id',
|
||||
'foreign_key' => $relation['foreign_key'] ?? 'id',
|
||||
];
|
||||
}
|
||||
|
||||
$options['menu'] = [
|
||||
'pid' => intval($menuConfig['pid'] ?? 0),
|
||||
'type' => intval($menuConfig['type'] ?? GeneratorEnum::GEN_SELF),
|
||||
'name' => !empty($menuConfig['name']) ? $menuConfig['name'] : $options['table_comment'],
|
||||
];
|
||||
$options['delete'] = [
|
||||
'type' => intval($deleteConfig['type'] ?? GeneratorEnum::DELETE_TRUE),
|
||||
'name' => !empty($deleteConfig['name']) ? $deleteConfig['name'] : GeneratorEnum::DELETE_NAME,
|
||||
];
|
||||
$options['relations'] = $relations;
|
||||
$options['tree'] = [
|
||||
'tree_id' => $treeConfig['tree_id'] ?? "",
|
||||
'tree_pid' =>$treeConfig['tree_pid'] ?? "",
|
||||
'tree_name' => $treeConfig['tree_name'] ?? '',
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取所有模型
|
||||
* @param string $module
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/12/14 11:04
|
||||
*/
|
||||
public static function getAllModels($module = 'common')
|
||||
{
|
||||
if(empty($module)) {
|
||||
return [];
|
||||
}
|
||||
$modulePath = base_path() . $module . '/model/';
|
||||
if(!is_dir($modulePath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$modulefiles = glob($modulePath . '*');
|
||||
$targetFiles = [];
|
||||
foreach ($modulefiles as $file) {
|
||||
$fileBaseName = basename($file, '.php');
|
||||
if (is_dir($file)) {
|
||||
$file = glob($file . '/*');
|
||||
foreach ($file as $item) {
|
||||
if (is_dir($item)) {
|
||||
continue;
|
||||
}
|
||||
$targetFiles[] = sprintf(
|
||||
"\\app\\" . $module . "\\model\\%s\\%s",
|
||||
$fileBaseName,
|
||||
basename($item, '.php')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if ($fileBaseName == 'BaseModel') {
|
||||
continue;
|
||||
}
|
||||
$targetFiles[] = sprintf(
|
||||
"\\app\\" . $module . "\\model\\%s",
|
||||
basename($file, '.php')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $targetFiles;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?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\user;
|
||||
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 用户逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\adminapi\logic\user
|
||||
*/
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 用户详情
|
||||
* @param int $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 16:32
|
||||
*/
|
||||
public static function detail(int $userId): array
|
||||
{
|
||||
$field = [
|
||||
'id', 'sn', 'account', 'nickname', 'avatar', 'real_name',
|
||||
'sex', 'mobile', 'create_time', 'login_time', 'channel',
|
||||
'user_money',
|
||||
];
|
||||
|
||||
$user = User::where(['id' => $userId])->field($field)
|
||||
->findOrEmpty();
|
||||
|
||||
$user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']);
|
||||
$user->sex = $user->getData('sex');
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息
|
||||
* @param array $params
|
||||
* @return User
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 16:38
|
||||
*/
|
||||
public static function setUserInfo(array $params)
|
||||
{
|
||||
return User::update([
|
||||
'id' => $params['id'],
|
||||
$params['field'] => $params['value']
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 调整用户余额
|
||||
* @param array $params
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 14:25
|
||||
*/
|
||||
public static function adjustUserMoney(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$user = User::find($params['user_id']);
|
||||
if (AccountLogEnum::INC == $params['action']) {
|
||||
//调整可用余额
|
||||
$user->user_money += $params['num'];
|
||||
$user->save();
|
||||
//记录日志
|
||||
AccountLogLogic::add(
|
||||
$user->id,
|
||||
AccountLogEnum::UM_INC_ADMIN,
|
||||
AccountLogEnum::INC,
|
||||
$params['num'],
|
||||
'',
|
||||
$params['remark'] ?? ''
|
||||
);
|
||||
} else {
|
||||
$user->user_money -= $params['num'];
|
||||
$user->save();
|
||||
//记录日志
|
||||
AccountLogLogic::add(
|
||||
$user->id,
|
||||
AccountLogEnum::UM_DEC_ADMIN,
|
||||
AccountLogEnum::DEC,
|
||||
$params['num'],
|
||||
'',
|
||||
$params['remark'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user