first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
<?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
{
$translation = ConfigService::get('website', 'translation');
$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', []),
// 订单提醒
'warm' => ConfigService::get('website', 'warm'),
// 自动翻译
'trans_auto' => $translation['auto'],
// 谷歌验证
'google_auth' => ConfigService::get('website', 'google_auth'),
// 服务器时间
'server_date' => date('Y/m/d H:i:s'),
];
return $config;
}
/**
* @notes 获取代理配置
* @return array
* @author 段誉
* @date 2021/12/31 11:03
*/
public static function getAgentConfig(): array
{
$config = [
// 文件域名
'oss_domain' => FileService::getFileUrl(),
// 网站名称
'web_name' => ConfigService::get('website', 'agent_name'),
// 网站图标
'web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'agent_web_favicon')),
// 网站logo
'web_logo' => FileService::getFileUrl(ConfigService::get('website', 'agent_web_logo')),
// 登录页
'login_image' => FileService::getFileUrl(ConfigService::get('website', 'agent_login_image')),
//国家区号
'region_codes' => ConfigService::get('website', 'regioncode'),
// 谷歌验证
'agent_google_auth' => ConfigService::get('website', 'agent_google_auth'),
];
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)->where(['status'=>1])->order(['sort' => 'desc'])->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;
}
}

View File

@@ -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;
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)
{
FileCate::destroy($params['id']);
}
}

View File

@@ -0,0 +1,116 @@
<?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\common\model\user\{User};
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 $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 loginAgent($params)
{
$time = time();
$user = User::where('account', '=', $params['account'])->find();
//查询关联管理员
$admin = Admin::where('id', '=', $user['agent_id'])->find();
//设置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']);
}
}

View File

@@ -0,0 +1,410 @@
<?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;
use app\common\model\user\{User,UserLog,UserMineRecord};
use app\common\model\finance\{WithdrawRecord,RechargeRecord};
use app\common\model\goods\{GoodsRecord};
use app\common\model\lh\{LhRecord};
use app\common\model\item\ItemRecord;
use app\common\model\finance\UserFinance;
/**
* 工作台
* 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 [
// 今日数据
'report' => self::report(),
// 常用功能
'menu' => self::menu(),
// 近15日注册量
'visitor' => self::visitor(),
];
}
/**
* @notes 代理工作台
* @param $params
* @return array
* @author 段誉
* @date 2021/12/29 15:58
*/
public static function agent($params)
{
return [
// 今日数据
'report' => self::agentReport($params),
];
}
/**
* @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_role')),
'url' => '/consumer/lists'
],
[
'name' => '用户关系',
'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
'url' => '/consumer/user_relation'
],
[
'name' => '资金明细',
'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
'url' => '/finance/user_finance'
],
[
'name' => '素材中心',
'image' => FileService::getFileUrl(config('project.default_image.menu_generator')),
'url' => '/material/index'
],
[
'name' => '文章资讯',
'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
'url' => '/article/lists'
],
[
'name' => '网站配置',
'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
'url' => '/app/information'
],
[
'name' => '管理员',
'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
'url' => '/permission/admin'
],
];
}
/**
* @notes 今日数据
* @return int[]
* @author 段誉
* @date 2021/12/29 16:15
*/
public static function report(): array
{
$time = time();
$start_time = strtotime(date('Y-m-d 00:00:00', time()));//0点
$end_time = strtotime(date('Y-m-d 23:59:59', time()));//24点
//昨日
$start_time_yes = strtotime("yesterday");//昨日0点
$end_time_yes = strtotime("today") - 1;//昨日24点
return [
'time' => date('Y-m-d H:i:s'),
'totoal' => WorkbenchLogic::reportData(0,$end_time),
'today' => WorkbenchLogic::reportData($start_time,$end_time),
'yes' => WorkbenchLogic::reportData($start_time_yes,$end_time_yes),
];
}
/**
* @notes 访问数据
* @return array
* @author 段誉
* @date 2021/12/29 16:57
*/
public static function reportData($start_time,$end_time): array
{
$time = time();
$online_time = $time - 60*60;
$user_money_sum = User::where(" user_money > 0 ")->sum('user_money');
$user_money_frozen_sum = UserFinance::where(" change_amount > 0 ")->where(['frozen' => 1])->sum('change_amount');
$user_online_count= User::where("last_time >= $online_time")->count();
$user_count= User::where("create_time >= $start_time AND create_time <= $end_time")->count();
//活跃人数
$user_active_count= UserLog::where("create_time >= $start_time AND create_time <= $end_time")->where(['type' => 1])->group("user_id")->count();
$recharge_sum= RechargeRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->sum('amount');
$recharge_count= RechargeRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->count();
$recharge_first_num= RechargeRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->group("user_id")->having(1)->count();
$recharge_num= RechargeRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->group("user_id")->count();
$recharge_first_num= RechargeRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->group("user_id")->having('count(*) = 1')->count();
$withdraw_sum= WithdrawRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->sum('amount');
$withdraw_count= WithdrawRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->count();
$withdraw_num= WithdrawRecord::where("status = 1 AND create_time >= $start_time AND create_time <= $end_time")->group("user_id")->count();
$user_reward_sum = UserFinance::where(" change_amount > 0 AND change_type IN (4,14,15) AND create_time >= $start_time AND create_time <= $end_time")->sum('change_amount');
// $order_sum= LhRecord::where("create_time >= $start_time AND create_time <= $end_time")->sum('money');
// $order_num= LhRecord::where("create_time >= $start_time AND create_time <= $end_time")->group("user_id")->count();
// $order_com_sum= LhRecord::where("create_time >= $start_time AND create_time <= $end_time")->sum('income');
$order_sum= ItemRecord::where("create_time >= $start_time AND create_time <= $end_time")->sum('money');
$order_ing_sum = ItemRecord::where(['status' => 1])->where(" create_time >= $start_time AND create_time <= $end_time ")->sum('money');
$order_num= ItemRecord::where("create_time >= $start_time AND create_time <= $end_time")->group("user_id")->count();
$order_com_sum= ItemRecord::where("create_time >= $start_time AND create_time <= $end_time")->sum('total_income');
$mine_com_sum = UserMineRecord::where(" create_time >= $start_time AND create_time <= $end_time ")->sum('amount');
$mine_num= UserMineRecord::where("create_time >= $start_time AND create_time <= $end_time")->group("user_id")->count();
return [
'user_money_sum' => $user_money_sum,
'user_money_frozen_sum' => $user_money_frozen_sum,
'user_online_count' => $user_online_count,
'user_count' => $user_count,
'user_active_count' => $user_active_count,
'recharge_count' => $recharge_count,
'recharge_num' => $recharge_num,
'recharge_first_num' => $recharge_first_num,
'recharge_sum' => round($recharge_sum, 2),
'withdraw_sum' => round($withdraw_sum, 2),
'withdraw_count' => $withdraw_count,
'withdraw_num' => $withdraw_num,
'user_reward_sum' => $user_reward_sum,
'order_sum' => round($order_sum, 2),
'order_ing_sum' => round($order_ing_sum, 2),
'order_num' => $order_num,
'order_com_sum' => round($order_com_sum, 2),
'mine_com_sum' => round($mine_com_sum, 2),
'mine_num' => $mine_num,
];
}
/**
* @notes 今日数据
* @return int[]
* @author 段誉
* @date 2021/12/29 16:15
*/
public static function agentReport($params): array
{
$time = time();
$start_time = strtotime(date('Y-m-d 00:00:00', time()));//0点
$end_time = strtotime(date('Y-m-d 23:59:59', time()));//24点
//昨日
$start_time_yes = strtotime("yesterday");//昨日0点
$end_time_yes = strtotime("today") - 1;//昨日24点
return [
'time' => date('Y-m-d H:i:s'),
'totoal' => WorkbenchLogic::agentReportData(0,$end_time,$params),
'today' => WorkbenchLogic::agentReportData($start_time,$end_time,$params),
'yes' => WorkbenchLogic::agentReportData($start_time_yes,$end_time_yes,$params),
];
}
/**
* @notes 访问数据
* @return array
* @author 段誉
* @date 2021/12/29 16:57
*/
public static function agentReportData($start_time,$end_time,$params): array
{
//根据管理员ID获取代理
$user = User::where(['agent_id' => $params['admin_id']])->findOrEmpty();
$where = " 1 = 2 ";
if (!$user->isEmpty()) {
$user_id = $user['id'];
$where = " ur.parent_id = $user_id ";
}
$time = time();
$online_time = $time - 60*60;
$user_money_sum = User::alias('u')->join('user_relation_agent ur', 'u.id = ur.user_id')->where($where)->where(" u.user_money > 0 ")->sum('u.user_money');
$user_money_frozen_sum = UserFinance::alias('uf')->join('user_relation_agent ur', 'uf.user_id = ur.user_id')->where($where)->where(" uf.change_amount > 0 ")->where(['uf.frozen' => 1])->sum('uf.change_amount');
$user_online_count= User::alias('u')->join('user_relation_agent ur', 'u.id = ur.user_id')->where($where)->where("u.last_time >= $online_time")->count();
$user_count= User::alias('u')->join('user_relation_agent ur', 'u.id = ur.user_id')->where($where)->where("u.create_time >= $start_time AND u.create_time <= $end_time")->count();
//活跃人数
$user_active_count= UserLog::alias('ul')->join('user_relation_agent ur', 'ul.user_id = ur.user_id')->where($where)->where("ul.create_time >= $start_time AND ul.create_time <= $end_time")->where(['ul.type' => 1])->group("ul.user_id")->count();
$recharge_sum= RechargeRecord::alias('rr')->join('user_relation_agent ur', 'rr.user_id = ur.user_id')->where($where)->where("rr.status = 1 AND rr.create_time >= $start_time AND rr.create_time <= $end_time")->sum('rr.amount');
$recharge_count= RechargeRecord::alias('rr')->join('user_relation_agent ur', 'rr.user_id = ur.user_id')->where($where)->where("rr.status = 1 AND rr.create_time >= $start_time AND rr.create_time <= $end_time")->count();
$recharge_first_num= RechargeRecord::alias('rr')->join('user_relation_agent ur', 'rr.user_id = ur.user_id')->where($where)->where("rr.status = 1 AND rr.create_time >= $start_time AND rr.create_time <= $end_time")->group("rr.user_id")->having(1)->count();
$recharge_num= RechargeRecord::alias('rr')->join('user_relation_agent ur', 'rr.user_id = ur.user_id')->where($where)->where("rr.status = 1 AND rr.create_time >= $start_time AND rr.create_time <= $end_time")->group("rr.user_id")->count();
$recharge_first_num= RechargeRecord::alias('rr')->join('user_relation_agent ur', 'rr.user_id = ur.user_id')->where($where)->where("rr.status = 1 AND rr.create_time >= $start_time AND rr.create_time <= $end_time")->group("rr.user_id")->having('count(*) = 1')->count();
$withdraw_sum= WithdrawRecord::alias('wr')->join('user_relation_agent ur', 'wr.user_id = ur.user_id')->where($where)->where("wr.status = 1 AND wr.create_time >= $start_time AND wr.create_time <= $end_time")->sum('wr.amount');
$withdraw_count= WithdrawRecord::alias('wr')->join('user_relation_agent ur', 'wr.user_id = ur.user_id')->where($where)->where("wr.status = 1 AND wr.create_time >= $start_time AND wr.create_time <= $end_time")->count();
$withdraw_num= WithdrawRecord::alias('wr')->join('user_relation_agent ur', 'wr.user_id = ur.user_id')->where($where)->where("wr.status = 1 AND wr.create_time >= $start_time AND wr.create_time <= $end_time")->group("wr.user_id")->count();
$user_reward_sum = UserFinance::alias('uf')->join('user_relation_agent ur', 'uf.user_id = ur.user_id')->where($where)->where(" uf.change_amount > 0 AND uf.change_type IN (4,14,15) AND uf.create_time >= $start_time AND uf.create_time <= $end_time")->sum('uf.change_amount');
// $order_sum= LhRecord::alias('lr')->join('user_relation_agent ur', 'lr.user_id = ur.user_id')->where($where)->where("lr.create_time >= $start_time AND lr.create_time <= $end_time")->sum('lr.money');
// $order_num= LhRecord::alias('lr')->join('user_relation_agent ur', 'lr.user_id = ur.user_id')->where("lr.create_time >= $start_time AND lr.create_time <= $end_time")->group("lr.user_id")->count();
// $order_com_sum= LhRecord::alias('lr')->join('user_relation_agent ur', 'lr.user_id = ur.user_id')->where("lr.create_time >= $start_time AND lr.create_time <= $end_time")->sum('lr.income');
$order_sum= ItemRecord::alias('ir')->join('user_relation_agent ur', 'ir.user_id = ur.user_id')->where($where)->where("ir.create_time >= $start_time AND ir.create_time <= $end_time")->sum('ir.money');
$order_num= ItemRecord::alias('ir')->join('user_relation_agent ur', 'ir.user_id = ur.user_id')->where($where)->where("ir.create_time >= $start_time AND ir.create_time <= $end_time")->group("ir.user_id")->count();
$order_com_sum= ItemRecord::alias('ir')->join('user_relation_agent ur', 'ir.user_id = ur.user_id')->where($where)->where("ir.create_time >= $start_time AND ir.create_time <= $end_time")->sum('ir.total_income');
$mine_com_sum = UserMineRecord::alias('umr')->join('user_relation_agent ur', 'umr.user_id = ur.user_id')->where($where)->where("umr.create_time >= $start_time AND umr.create_time <= $end_time")->sum('umr.amount');
$mine_num= UserMineRecord::alias('umr')->join('user_relation_agent ur', 'umr.user_id = ur.user_id')->where($where)->where("umr.create_time >= $start_time AND umr.create_time <= $end_time")->group("umr.user_id")->count();
return [
'user_money_sum' => $user_money_sum,
'user_money_frozen_sum' => $user_money_frozen_sum,
'user_online_count' => $user_online_count,
'user_count' => $user_count,
'user_active_count' => $user_active_count,
'recharge_count' => $recharge_count,
'recharge_num' => $recharge_num,
'recharge_first_num' => $recharge_first_num,
'recharge_sum' => round($recharge_sum, 2),
'withdraw_sum' => round($withdraw_sum, 2),
'withdraw_count' => $withdraw_count,
'withdraw_num' => $withdraw_num,
'user_reward_sum' => $user_reward_sum,
'order_sum' => round($order_sum, 2),
'order_num' => $order_num,
'order_com_sum' => round($order_com_sum, 2),
'mine_com_sum' => round($mine_com_sum, 2),
'mine_num' => $mine_num,
];
}
/**
* @notes 访问数
* @return array
* @author 段誉
* @date 2021/12/29 16:57
*/
public static function visitor(): array
{
$num = [];
$date = [];
for ($i = 0; $i < 30; $i++) {
$where_start = strtotime("- " . $i . "day");
$date[] = date('Y/m/d', $where_start);
$start_time = strtotime(date('Y-m-d 00:00:00', strtotime(date('Y-m-d', $where_start))));//0点
$end_time = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-d', $where_start))));//12点
$num[] = User::where("create_time >= $start_time AND create_time <= $end_time")->count();
}
return [
'date' => $date,
'list' => [
['name' => '注册数', 'data' => array_reverse($num)]
]
];
}
}

View File

@@ -0,0 +1,137 @@
<?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,
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
}
/**
* @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,
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
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
{
$articleCate = ArticleCate::findOrEmpty($params['id'])->toArray();
$langs = json_decode($articleCate['langs'], true);
if(empty($langs)){
$langs = [];
}
$articleCate['langs'] = $langs;
return $articleCate;
}
/**
* @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();
}
}

View File

@@ -0,0 +1,201 @@
<?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;
use app\common\model\user\{User,UserNotice};
/**
* 资讯管理逻辑
* 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)
{
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
$article = 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'],
'is_popup' => $params['is_popup'],
'is_notice' => $params['is_notice'],
'is_sys_notice' => $params['is_sys_notice'],
'content' => $params['content'] ?? '',
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
if($params['is_sys_notice'] == 1){
$users = User::select()->toArray();
foreach ($users as &$user) {
UserNotice::create([
'user_id' => $user['id'],
'article_id' => $article['id'],
'title' => $article['title'],
'content' => $article['content'] ?? '',
'langs' => $article['langs'],
]);
}
}
}
/**
* @notes 编辑资讯
* @param array $params
* @return bool
* @author heshihu
* @date 2022/2/22 10:12
*/
public static function edit(array $params) : bool
{
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
$article = 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'],
'is_popup' => $params['is_popup'],
'is_notice' => $params['is_notice'],
'is_sys_notice' => $params['is_sys_notice'],
'content' => $params['content'] ?? '',
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
if($params['is_sys_notice'] == 1){
$notices = UserNotice::where(['article_id' => $params['id']])->select()->toArray();
foreach ($notices as &$notice) {
UserNotice::update([
'id' => $notice['id'],
'title' => $article['title'],
'content' => $article['content'] ?? '',
'langs' => $article['langs'],
]);
}
}
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
{
$article = Article::findOrEmpty($params['id'])->toArray();
$langs = json_decode($article['langs'], true);
if(!empty($langs)){
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::getFileUrl($content_lang['image']);
$content_lang['content'] = get_file_domain($content_lang['content']);
}
}else{
$langs = [];
}
$article['langs'] = $langs;
return $article;
}
/**
* @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;
}
/**
* @notes 资讯列表
* @param $params
* @return array
* @author BD
* @date 2024/03/17 17:01
*/
public static function all($params) : array
{
$field = ['id', 'title'];
$articles = Article::field($field)
->where(['cid' => $params['cid'],'is_show' => 1])
->order(['sort' => 'desc','id' => 'desc'])
->select()->toArray();
return $articles;
}
}

View File

@@ -0,0 +1,411 @@
<?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\model\user\User;
use app\common\cache\AdminTokenCache;
use app\common\service\{FileService,UtilsService,ConfigService};
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;
}
//代理登录,则用户名替换为代理账户
$user = User::where(['agent_id' => $admin['id']])->findOrEmpty();
if (!$user->isEmpty()) {
$admin['account'] = $user['account'];
$admin['name'] = $user['account'];
}
$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);
}
}
/**
* @notes 编辑超级管理员
* @param $params
* @return Admin
* @author 段誉
* @date 2022/4/8 17:54
*/
public static function google($params)
{
$admin = Admin::findOrEmpty($params['id'])->toArray();
$show_google = false;
$google_auth = ConfigService::get('website', 'google_auth');
//代理登录
$user = User::where(['agent_id' => $admin['id']])->findOrEmpty();
if (!$user->isEmpty()) {
$google_auth = ConfigService::get('website', 'agent_google_auth');
}
if($google_auth == 0){
$show_google = false;
}else{
if(!$admin['google_key']){
$show_google = true;
$secretKey = UtilsService::get_google_secretKey();
Admin::update([
'id' => $admin['id'],
'google_key' => $secretKey,
'google_qrcode' => UtilsService::get_google_qrcode($admin['account'],'',$secretKey),
]);
$admin = Admin::findOrEmpty($params['id'])->toArray();
}
}
return [
"show_google" => $show_google,
"key" => $admin['google_key'],
"qrcode" => $admin['google_qrcode'],
];
}
/**
* @notes 重置谷歌验证
* @param $params
* @return bool
* @author 段誉
* @date 2021/12/29 11:07
*/
public static function resetGoogle($params)
{
$admin = Admin::where(['id' => ($params['id'])])->findOrEmpty();
if ($admin->isEmpty()) {
throw new \Exception("用户不存在");
}
Admin::update([
'id' => $admin['id'],
'google_key' => "",
'google_qrcode' => "",
]);
return true;
}
}

View File

@@ -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');
}
}

View File

@@ -0,0 +1,199 @@
<?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 更新排序
* @param array $params
* @return SystemMenu
* @author 段誉
* @date 2022/7/6 17:02
*/
public static function updateSort(array $params)
{
return SystemMenu::update([
'id' => $params['id'],
'sort' => $params['sort']
]);
}
/**
* @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' => 'asc'])
->select()
->toArray();
return linear_to_tree($data, 'children');
}
}

View File

@@ -0,0 +1,171 @@
<?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'])
->where(' id <> 6')
->select()
->toArray();
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,193 @@
<?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\model\decorate\DecorateHint;
use app\common\logic\BaseLogic;
use app\common\model\user\{User,UserNotice};
use think\facade\Db;
use app\common\service\FileService;
/**
* 提示内容逻辑
* Class DecorateHintLogic
* @package app\adminapi\logic\decorate
*/
class DecorateHintLogic extends BaseLogic
{
/**
* @notes 添加提示内容
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 17:01
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
if(!empty($content_lang['image'])){
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
if(!empty($content_lang['content'])){
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
}
$hint = DecorateHint::create([
'cid' => $params['cid'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '',
'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '',
'text' => $params['text'],
'content' => $params['content'] ?? '',
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
// //系统消息则创建用户消息记录
// if($params['cid'] == 5){
// $users = User::select()->toArray();
// foreach ($users as &$user) {
// UserNotice::create([
// 'user_id' => $user['id'],
// 'hint_id' => $hint['id'],
// 'title' => $params['text'],
// 'content' => $params['content'] ?? '',
// 'notice_type' => 3,
// 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
// ]);
// }
// }
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑提示内容
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 17:01
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
if(!empty($content_lang['image'])){
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
if(!empty($content_lang['content'])){
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
}
DecorateHint::update([
'id' => $params['id'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '',
'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '',
'text' => $params['text'],
'content' => $params['content'] ?? '',
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
// $hint = DecorateHint::where(['id' => $params['id']])->findOrEmpty();
// //系统消息则创建用户消息记录
// $cidArr = array(5,6,7);
// if(in_array($hint['cid'], $cidArr)){
// $notices = UserNotice::where(['hint_id' => $params['id']])->select()->toArray();
// foreach ($notices as &$notice) {
// UserNotice::update([
// 'id' => $notice['id'],
// 'title' => $params['text'],
// 'content' => $params['content'] ?? '',
// 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
// ]);
// }
// }
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除提示内容
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 17:01
*/
public static function delete(array $params): bool
{
return DecorateHint::destroy($params['id']);
}
/**
* @notes 获取提示内容详情
* @param $params
* @return array
* @author BD
* @date 2024/03/17 17:01
*/
public static function detail($params): array
{
return DecorateHint::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 消息列表
* @param $params
* @return array
* @author BD
* @date 2024/03/17 17:01
*/
public static function allByType($params) : array
{
$field = ['id', 'text'];
$notices = DecorateHint::field($field)
->where(['cid' => $params['cid'],'is_show' => 1])
->order(['sort' => 'desc','id' => 'desc'])
->select()->toArray();
return $notices;
}
}

View File

@@ -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\decorate;
use app\common\model\decorate\DecorateNav;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
/**
* 菜单按钮逻辑
* Class DecorateNavLogic
* @package app\adminapi\logic\decorate
*/
class DecorateNavLogic extends BaseLogic
{
/**
* @notes 添加菜单按钮
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 16:41
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
DecorateNav::create([
'name' => $params['name'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'image_ext' => $params['image_ext'],
'link' => $params['link'],
'loca' => $params['loca'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑菜单按钮
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 16:41
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
DecorateNav::where('id', $params['id'])->update([
'name' => $params['name'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'image_ext' => $params['image_ext'],
'link' => $params['link'],
'loca' => $params['loca'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除菜单按钮
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 16:41
*/
public static function delete(array $params): bool
{
return DecorateNav::destroy($params['id']);
}
/**
* @notes 获取菜单按钮详情
* @param $params
* @return array
* @author BD
* @date 2024/03/17 16:41
*/
public static function detail($params): array
{
return DecorateNav::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,135 @@
<?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\model\decorate\DecorateSwiper;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
/**
* 轮播图逻辑
* Class DecorateSwiperLogic
* @package app\adminapi\logic\decorate
*/
class DecorateSwiperLogic extends BaseLogic
{
/**
* @notes 添加轮播图
* @param array $params
* @return bool
* @author BD
* @date 2024/03/16 17:34
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
DecorateSwiper::create([
'name' => $params['name'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'image_ext' => $params['image_ext'],
'link' => $params['link'],
'loca' => $params['loca'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑轮播图
* @param array $params
* @return bool
* @author BD
* @date 2024/03/16 17:34
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
DecorateSwiper::where('id', $params['id'])->update([
'name' => $params['name'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'image_ext' => $params['image_ext'],
'link' => $params['link'],
'loca' => $params['loca'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除轮播图
* @param array $params
* @return bool
* @author BD
* @date 2024/03/16 17:34
*/
public static function delete(array $params): bool
{
return DecorateSwiper::destroy($params['id']);
}
/**
* @notes 获取轮播图详情
* @param $params
* @return array
* @author BD
* @date 2024/03/16 17:34
*/
public static function detail($params): array
{
return DecorateSwiper::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace app\adminapi\logic\feedback;
use app\common\model\feedback\FeedbackCate;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 意见反馈类型逻辑
* Class FeedbackCateLogic
* @package app\adminapi\logic\feedback
*/
class FeedbackCateLogic extends BaseLogic
{
/**
* @notes 添加意见反馈类型
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 00:12
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
FeedbackCate::create([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑意见反馈类型
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 00:12
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
FeedbackCate::where('id', $params['id'])->update([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除意见反馈类型
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 00:12
*/
public static function delete(array $params): bool
{
return FeedbackCate::destroy($params['id']);
}
/**
* @notes 获取意见反馈类型详情
* @param $params
* @return array
* @author BD
* @date 2024/06/06 00:12
*/
public static function detail($params): array
{
return FeedbackCate::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace app\adminapi\logic\feedback;
use app\common\model\feedback\FeedbackRecord;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 意见反馈记录逻辑
* Class FeedbackRecordLogic
* @package app\adminapi\logic\feedback
*/
class FeedbackRecordLogic extends BaseLogic
{
/**
* @notes 添加意见反馈记录
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 01:11
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
FeedbackRecord::create([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑意见反馈记录
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 01:11
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
FeedbackRecord::where('id', $params['id'])->update([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除意见反馈记录
* @param array $params
* @return bool
* @author BD
* @date 2024/06/06 01:11
*/
public static function delete(array $params): bool
{
return FeedbackRecord::destroy($params['id']);
}
/**
* @notes 获取意见反馈记录详情
* @param $params
* @return array
* @author BD
* @date 2024/06/06 01:11
*/
public static function detail($params): array
{
return FeedbackRecord::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,279 @@
<?php
namespace app\adminapi\logic\finance;
use app\common\service\{UtilsService};
use app\common\model\finance\{RechargeRecord,WithdrawRecord};
use app\common\model\goods\{GoodsRecord};
use app\common\model\user\{User,UserRelationAgent};
use app\common\model\setting\RechargeMethod;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 充值记录逻辑
* Class RechargeRecordLogic
* @package app\adminapi\logic\finance
*/
class RechargeRecordLogic extends BaseLogic
{
/**
* @notes 删除充值记录
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function delete(array $params): bool
{
return RechargeRecord::destroy($params['id']);
}
/**
* @notes 同意充值
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function agree(array $params): bool
{
Db::startTrans();
try {
$record = RechargeRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($record->isEmpty()) {
throw new \Exception('用户不存在');
}
RechargeRecord::update([
'id' => $params['id'],
'status' => 1
]);
//记录日志
UtilsService::user_finance_add(
$record['user_id'],
1,
1,
$record['amount'],
$record['sn'],
'',
1//冻结
);
//用户资金修改
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'user_money');
//充值金额增加
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'total_recharge');
//团队充值奖励
// UtilsService::team_reward_add($record['user_id'],$record['amount'],1);
//充值活动奖励
UtilsService::activity_reward_add($record['user_id'],$record['amount']);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
//充值次数+1
User::update([
'id' => $user['id'],
'recharge_num' => $user['recharge_num'] + 1
]);
RechargeRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 拒绝充值
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function refuse(array $params): bool
{
Db::startTrans();
try {
$record = RechargeRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
RechargeRecord::update([
'id' => $params['id'],
'status' => 2
]);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
RechargeRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 充值记录备注
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function remark(array $params): bool
{
Db::startTrans();
try {
$record = RechargeRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
//代理操作需查询是否有权限
$user = User::where(['agent_id' => $params['admin_id']])->findOrEmpty();
if (!$user->isEmpty()) {
$userRelation = UserRelationAgent::where(['user_id' => $record['user_id'],'parent_id' => $user['id']])->findOrEmpty();
if ($userRelation->isEmpty()) {
throw new \Exception('参数异常');
}
}
RechargeRecord::update([
'id' => $params['id'],
'remark2' => $params['content']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 修改充值金额
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function changeAmount(array $params): bool
{
Db::startTrans();
try {
$record = RechargeRecord::where(['status' => 0])->find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if($params['amount'] <= 0){
throw new \Exception('请输入正确的金额');
}
$precision = 2;
$method = RechargeMethod::find($record['method_id']);
if (!$method->isEmpty()) {
$precision = $method['precision'];
}
$amount_act = round($params['amount'] * $method['rate'] , $precision);
RechargeRecord::update([
'id' => $params['id'],
'amount' => $params['amount'],
'amount_act' => $amount_act,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 新充值提现条数
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author bd
* @date 2024/01/31 14:07
*/
public static function warmCount()
{
$rechargeCount = RechargeRecord::where(['status' => 0])->count();
$withdrawCount = WithdrawRecord::where(['status' => 0])->count();
// $orderCount = GoodsRecord::where(['status' => 5])->count();
return [
'recharge' => $rechargeCount,
'withdraw' => $withdrawCount,
// 'order' => $orderCount
];
}
/**
* @notes 充值统计
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author bd
* @date 2024/01/31 14:07
*/
public static function stat()
{
$total = RechargeRecord::sum('amount');
$ing = RechargeRecord::where(['status' => 0])->sum('amount');
$success = RechargeRecord::where(['status' => 1])->sum('amount');
$error = RechargeRecord::where(['status' => 2])->sum('amount');
return [
'total' => round($total, 2),
'ing' => round($ing, 2),
'success' => round($success, 2),
'error' => round($error, 2),
];
}
}

View File

@@ -0,0 +1,157 @@
<?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\model\finance\UserFinance;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 资金明细逻辑
* Class UserFinanceLogic
* @package app\adminapi\logic\finance
*/
class UserFinanceLogic extends BaseLogic
{
/**
* @notes 添加资金明细
* @param array $params
* @return bool
* @author BD
* @date 2024/03/07 13:10
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserFinance::create([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'change_object' => $params['change_object'],
'change_type' => $params['change_type'],
'action' => $params['action'],
'change_amount' => $params['change_amount'],
'left_amount' => $params['left_amount'],
'source_sn' => $params['source_sn'],
'remark' => $params['remark'],
'extra' => $params['extra']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑资金明细
* @param array $params
* @return bool
* @author BD
* @date 2024/03/07 13:10
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserFinance::where('id', $params['id'])->update([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'change_object' => $params['change_object'],
'change_type' => $params['change_type'],
'action' => $params['action'],
'change_amount' => $params['change_amount'],
'left_amount' => $params['left_amount'],
'source_sn' => $params['source_sn'],
'remark' => $params['remark'],
'extra' => $params['extra']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除资金明细
* @param array $params
* @return bool
* @author BD
* @date 2024/03/07 13:10
*/
public static function delete(array $params): bool
{
return UserFinance::destroy($params['id']);
}
/**
* @notes 获取资金明细详情
* @param $params
* @return array
* @author BD
* @date 2024/03/07 13:10
*/
public static function detail($params): array
{
return UserFinance::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 解冻
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function unfrozen(array $params): bool
{
Db::startTrans();
try {
$record = UserFinance::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['frozen']!=1) {
throw new \Exception('状态异常');
}
UserFinance::update([
'id' => $params['id'],
'frozen' => 0,
'thaw_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,292 @@
<?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\model\finance\WithdrawRecord;
use app\common\service\{ConfigService,UtilsService};
use app\common\model\user\{User,UserRelationAgent};
use app\common\model\withdraw\WithdrawMethod;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 提现记录逻辑
* Class WithdrawRecordLogic
* @package app\adminapi\logic\finance
*/
class WithdrawRecordLogic extends BaseLogic
{
/**
* @notes 删除提现记录
* @param array $params
* @return bool
* @author BD
* @date 2024/02/25 12:35
*/
public static function delete(array $params): bool
{
return WithdrawRecord::destroy($params['id']);
}
/**
* @notes udun代付
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function udunPay(array $params)
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
//重新发起代付需修改订单号
if($record['remark_df'] != ''){
$record['sn'] = generate_sn(WithdrawRecord::class, 'sn');
}
$udun = ConfigService::get('website', 'udun');
if($udun['is_open_df'] == 0){
throw new \Exception('请先开启代付');
}
$method = WithdrawMethod::where(['id' => $record['method_id']])->findOrEmpty();
if ($method->isEmpty()) {
throw new \Exception('提现方式不存在');
}
if ($method['is_open_df'] == 0) {
throw new \Exception('该记录提现方式未开启代付');
}
$main_coin_type = $method['main_coin_type'];
$coin_type = $method['coin_type'];
$udunDispatch = UtilsService::get_udunDispatch();
//验证地址合法性
$result1 = $udunDispatch->checkAddress($main_coin_type,$record['account']);
if($result1['code'] == 200){
//申请提币
$amount_df = round($record['amount']- $record['charge'],2);
$result2 = $udunDispatch->withdraw($record['sn'],$main_coin_type,$coin_type,$record['account'],$amount_df);
if($result2['code'] == 200){
WithdrawRecord::update([
'id' => $record['id'],
'status2' => 1,
'remark_df' => '',
'sn' => $record['sn']
]);
}
}
Db::commit();
return 'success';
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return 'fail';
}
}
/**
* @notes 同意提现
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function agree(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
WithdrawRecord::update([
'id' => $params['id'],
'status' => 1,
'status2' => 0,
'remark_df' => '',
]);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
//提现次数+1
User::update([
'id' => $user['id'],
'withdraw_num' => $user['withdraw_num'] + 1
]);
WithdrawRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 拒绝提现
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function refuse(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
WithdrawRecord::update([
'id' => $params['id'],
'status' => 2,
'remark' => $params['remark'],
'status2' => 0,
'remark_df' => '',
]);
//返还提现金额
//记录日志
UtilsService::user_finance_add(
$record['user_id'],
3,
1,
$record['amount'],
$record['sn'],
$params['remark']
);
//用户资金修改
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'user_money');
//提现金额修改
UtilsService::user_money_change($record['user_id'], 2, $record['amount'],'total_withdraw');
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
WithdrawRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 提现记录备注
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function remark(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
//代理操作需查询是否有权限
$user = User::where(['agent_id' => $params['admin_id']])->findOrEmpty();
if (!$user->isEmpty()) {
$userRelation = UserRelationAgent::where(['user_id' => $record['user_id'],'parent_id' => $user['id']])->findOrEmpty();
if ($userRelation->isEmpty()) {
throw new \Exception('参数异常');
}
}
WithdrawRecord::update([
'id' => $params['id'],
'remark2' => $params['content']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 提现统计
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author bd
* @date 2024/01/31 14:07
*/
public static function stat()
{
$total = WithdrawRecord::sum('amount');
$ing = WithdrawRecord::where(['status' => 0])->sum('amount');
$success = WithdrawRecord::where(['status' => 1])->sum('amount');
$error = WithdrawRecord::where(['status' => 2])->sum('amount');
return [
'total' => round($total, 2),
'ing' => round($ing, 2),
'success' => round($success, 2),
'error' => round($error, 2),
];
}
}

View File

@@ -0,0 +1,129 @@
<?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\goods;
use app\common\enum\YesNoEnum;
use app\common\model\goods\GoodsCate;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 商品分类逻辑
* Class GoodsCateLogic
* @package app\adminapi\logic\goods
*/
class GoodsCateLogic extends BaseLogic
{
/**
* @notes 添加商品分类
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
GoodsCate::create([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑商品分类
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
GoodsCate::where('id', $params['id'])->update([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除商品分类
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function delete(array $params): bool
{
return GoodsCate::destroy($params['id']);
}
/**
* @notes 获取商品分类详情
* @param $params
* @return array
* @author BD
* @date 2024/03/11 01:58
*/
public static function detail($params): array
{
return GoodsCate::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 商品分类数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/03/11 01:58
*/
public static function getAllData()
{
return GoodsCate::where(['is_show' => YesNoEnum::YES])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -0,0 +1,132 @@
<?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\goods;
use app\common\model\goods\Goods;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
/**
* 商品逻辑
* Class GoodsLogic
* @package app\adminapi\logic\goods
*/
class GoodsLogic extends BaseLogic
{
/**
* @notes 添加商品
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
// foreach ($langs as &$content_lang) {
// $content_lang['image'] = FileService::setFileUrl($content_lang['image']);
// }
Goods::create([
'cid' => $params['cid'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'money' => $params['money'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑商品
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
// foreach ($langs as &$content_lang) {
// $content_lang['image'] = FileService::setFileUrl($content_lang['image']);
// }
Goods::where('id', $params['id'])->update([
'cid' => $params['cid'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'money' => $params['money'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除商品
* @param array $params
* @return bool
* @author BD
* @date 2024/03/11 01:58
*/
public static function delete(array $params): bool
{
return Goods::destroy($params['id']);
}
/**
* @notes 获取商品详情
* @param $params
* @return array
* @author BD
* @date 2024/03/11 01:58
*/
public static function detail($params): array
{
return Goods::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,101 @@
<?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\goods;
use app\common\model\goods\{GoodsRecord,Goods};
use app\common\model\member\UserMember;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{UtilsService,FileService};
/**
* 抢单记录逻辑
* Class GoodsRecordLogic
* @package app\adminapi\logic\goods
*/
class GoodsRecordLogic extends BaseLogic
{
/**
* @notes 删除抢单记录
* @param array $params
* @return bool
* @author BD
* @date 2024/03/19 02:29
*/
public static function delete(array $params): bool
{
return GoodsRecord::destroy($params['id']);
}
/**
* @notes 派单
* @param array $params
* @return bool
* @author BD
* @date 2024/03/19 02:29
*/
public static function dispatch(array $params): bool
{
Db::startTrans();
try {
$order = GoodsRecord::where(['id' => $params['id']])->findOrEmpty();
if ($order->isEmpty()) {
throw new \Exception('订单不存在');
}
$goods = Goods::where(['id' => $params['goods_id']])->findOrEmpty();
if ($goods->isEmpty()) {
throw new \Exception('商品不存在');
}
//多语言替换
$data = UtilsService::get_langs_data($goods['langs'],$order['lang']);
$goods['title'] = $data['title'];
//查询会员等级
//查询会员等级
$member_id = UtilsService::get_user_member_id($order['user_id']);
$member = UserMember::where(['id' => $member_id])->findOrEmpty();
//数量
$num = $params['num'];
//计算佣金
$commission = round($goods['money'] * $num * $member['commission']/100,2);
GoodsRecord::update([
'id' => $params['id'],
'goods_id' => $goods['id'],
'goods_title' => $goods['title'],
'goods_image' => FileService::setFileUrl($goods['image']) ,
'unit_price' => $goods['money'],
'num' => $num,
'money' => $goods['money'] * $num,
'commission' => $commission,
'status' => 4
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,152 @@
<?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\item;
use app\common\enum\YesNoEnum;
use app\common\model\item\ItemCate;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目分类逻辑
* Class ItemCateLogic
* @package app\adminapi\logic\item
*/
class ItemCateLogic extends BaseLogic
{
/**
* @notes 添加项目分类
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 13:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ItemCate::create([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目分类
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 13:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ItemCate::where('id', $params['id'])->update([
'name' => $params['name'],
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目分类
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 13:23
*/
public static function delete(array $params): bool
{
return ItemCate::destroy($params['id']);
}
/**
* @notes 获取项目分类详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/16 13:23
*/
public static function detail($params): array
{
$itemCate = ItemCate::findOrEmpty($params['id'])->toArray();
$langs = json_decode($articleCate['langs'], true);
if(empty($langs)){
$langs = [];
}
$itemCate['langs'] = $langs;
return $itemCate;
}
/**
* @notes 更改项目分类状态
* @param array $params
* @return bool
* @author heshihu
* @date 2022/2/21 18:04
*/
public static function updateStatus(array $params)
{
ItemCate::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 ItemCate::where(['is_show' => YesNoEnum::YES])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -0,0 +1,173 @@
<?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\item;
use app\common\model\item\Item;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
/**
* 项目逻辑
* Class ItemLogic
* @package app\adminapi\logic\item
*/
class ItemLogic extends BaseLogic
{
/**
* @notes 添加项目
* @param array $params
* @return bool
* @author BD
* @date 2024/01/16 13:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
Item::create([
'cid' => $params['cid'],
'type' => $params['type'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'content' => $params['content'],
'min_money' => $params['min_money'],
'max_money' => $params['max_money'],
'rate' => $params['rate'],
'cycle' => $params['cycle'],
'point' => $params['point'],
'member_id' => $params['member_id'],
'progress' => $params['progress'],
'progress_auto' => $params['progress_auto'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目
* @param array $params
* @return bool
* @author BD
* @date 2024/01/16 13:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
Item::update([
'id' => $params['id'],
'cid' => $params['cid'],
'type' => $params['type'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'content' => $params['content'],
'min_money' => $params['min_money'],
'max_money' => $params['max_money'],
'rate' => $params['rate'],
'cycle' => $params['cycle'],
'point' => $params['point'],
'member_id' => $params['member_id'],
'progress' => $params['progress'],
'progress_auto' => $params['progress_auto'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目
* @param array $params
* @return bool
* @author BD
* @date 2024/01/16 13:23
*/
public static function delete(array $params): bool
{
return Item::destroy($params['id']);
}
/**
* @notes 获取项目详情
* @param $params
* @return array
* @author BD
* @date 2024/01/16 13:23
*/
public static function detail($params): array
{
$item = Item::findOrEmpty($params['id'])->toArray();
$langs = json_decode($item['langs'], true);
if(empty($langs)){
$langs = [];
}
$item['langs'] = $langs;
return $item;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateIndexStatus(array $params)
{
Item::update([
'id' => $params['id'],
'is_index' => $params['is_index']
]);
return true;
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace app\adminapi\logic\item;
use app\common\model\item\ItemRecord;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目记录逻辑
* Class ItemRecordLogic
* @package app\adminapi\logic\item
*/
class ItemRecordLogic extends BaseLogic
{
/**
* @notes 添加项目记录
* @param array $params
* @return bool
* @author BD
* @date 2024/08/07 15:42
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ItemRecord::create([
'sn' => $params['sn'],
'contract_no' => $params['contract_no'],
'user_id' => $params['user_id'],
'item_id' => $params['item_id'],
'item_title' => $params['item_title'],
'item_image' => $params['item_image'],
'money' => $params['money'],
'rate' => $params['rate'],
'cycle' => $params['cycle'],
'total_num' => $params['total_num'],
'wait_num' => $params['wait_num'],
'type' => $params['type'],
'status' => $params['status'],
'remark' => $params['remark'],
'end_time' => strtotime($params['end_time'])
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目记录
* @param array $params
* @return bool
* @author BD
* @date 2024/08/07 15:42
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ItemRecord::where('id', $params['id'])->update([
'sn' => $params['sn'],
'contract_no' => $params['contract_no'],
'user_id' => $params['user_id'],
'item_id' => $params['item_id'],
'item_title' => $params['item_title'],
'item_image' => $params['item_image'],
'money' => $params['money'],
'rate' => $params['rate'],
'cycle' => $params['cycle'],
'total_num' => $params['total_num'],
'wait_num' => $params['wait_num'],
'type' => $params['type'],
'status' => $params['status'],
'remark' => $params['remark'],
'end_time' => strtotime($params['end_time'])
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目记录
* @param array $params
* @return bool
* @author BD
* @date 2024/08/07 15:42
*/
public static function delete(array $params): bool
{
return ItemRecord::destroy($params['id']);
}
/**
* @notes 获取项目记录详情
* @param $params
* @return array
* @author BD
* @date 2024/08/07 15:42
*/
public static function detail($params): array
{
return ItemRecord::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace app\adminapi\logic\lh;
use app\common\model\lh\LhCoin;
use app\common\logic\BaseLogic;
use app\common\service\FileService;
use think\facade\Db;
/**
* 量化货币逻辑
* Class LhCoinLogic
* @package app\adminapi\logic\lh
*/
class LhCoinLogic extends BaseLogic
{
/**
* @notes 添加量化货币
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
LhCoin::create([
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'symbol_market' => $params['symbol_market'],
'price' => $params['price'],
'buy_name' => $params['buy_name'],
'sale_name' => $params['sale_name'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑量化货币
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
LhCoin::where('id', $params['id'])->update([
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'symbol_market' => $params['symbol_market'],
'price' => $params['price'],
'buy_name' => $params['buy_name'],
'sale_name' => $params['sale_name'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除量化货币
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function delete(array $params): bool
{
return LhCoin::destroy($params['id']);
}
/**
* @notes 获取量化货币详情
* @param $params
* @return array
* @author BD
* @date 2024/05/19 21:13
*/
public static function detail($params): array
{
return LhCoin::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace app\adminapi\logic\lh;
use app\common\model\lh\LhRecord;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 量化记录逻辑
* Class LhRecordLogic
* @package app\adminapi\logic\lh
*/
class LhRecordLogic extends BaseLogic
{
/**
* @notes 添加量化记录
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
LhRecord::create([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑量化记录
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
LhRecord::where('id', $params['id'])->update([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除量化记录
* @param array $params
* @return bool
* @author BD
* @date 2024/05/19 21:13
*/
public static function delete(array $params): bool
{
return LhRecord::destroy($params['id']);
}
/**
* @notes 获取量化记录详情
* @param $params
* @return array
* @author BD
* @date 2024/05/19 21:13
*/
public static function detail($params): array
{
return LhRecord::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace app\adminapi\logic\mall;
use app\common\model\mall\MallGoods;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
/**
* 积分、抽奖奖品逻辑
* Class MallGoodsLogic
* @package app\adminapi\logic\mall
*/
class MallGoodsLogic extends BaseLogic
{
/**
* @notes 添加积分、抽奖奖品
* @param array $params
* @return bool
* @author BD
* @date 2024/10/14 23:57
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
MallGoods::create([
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'price' => $params['price'],
'money' => $params['money'],
'point' => $params['point'],
'win_rate' => $params['win_rate'],
'num' => $params['num'],
'type' => $params['type'],
'type2' => $params['type2'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑积分、抽奖奖品
* @param array $params
* @return bool
* @author BD
* @date 2024/10/14 23:57
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
MallGoods::where('id', $params['id'])->update([
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'price' => $params['price'],
'money' => $params['money'],
'point' => $params['point'],
'win_rate' => $params['win_rate'],
'num' => $params['num'],
'type' => $params['type'],
'type2' => $params['type2'],
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除积分、抽奖奖品
* @param array $params
* @return bool
* @author BD
* @date 2024/10/14 23:57
*/
public static function delete(array $params): bool
{
return MallGoods::destroy($params['id']);
}
/**
* @notes 获取积分、抽奖奖品详情
* @param $params
* @return array
* @author BD
* @date 2024/10/14 23:57
*/
public static function detail($params): array
{
return MallGoods::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace app\adminapi\logic\mall;
use app\common\model\mall\MallGoodsRecord;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 奖品记录逻辑
* Class MallGoodsRecordLogic
* @package app\adminapi\logic\mall
*/
class MallGoodsRecordLogic extends BaseLogic
{
/**
* @notes 添加奖品记录
* @param array $params
* @return bool
* @author BD
* @date 2024/10/15 14:00
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
MallGoodsRecord::create([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'm_goods_id' => $params['m_goods_id'],
'm_goods_title' => $params['m_goods_title'],
'm_goods_image' => $params['m_goods_image'],
'm_goods_langs' => $params['m_goods_langs'],
'price' => $params['price'],
'money' => $params['money'],
'point' => $params['point'],
'status' => $params['status'],
'type' => $params['type'],
'type2' => $params['type2']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑奖品记录
* @param array $params
* @return bool
* @author BD
* @date 2024/10/15 14:00
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
MallGoodsRecord::where('id', $params['id'])->update([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'm_goods_id' => $params['m_goods_id'],
'm_goods_title' => $params['m_goods_title'],
'm_goods_image' => $params['m_goods_image'],
'm_goods_langs' => $params['m_goods_langs'],
'price' => $params['price'],
'money' => $params['money'],
'point' => $params['point'],
'status' => $params['status'],
'type' => $params['type'],
'type2' => $params['type2']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除奖品记录
* @param array $params
* @return bool
* @author BD
* @date 2024/10/15 14:00
*/
public static function delete(array $params): bool
{
return MallGoodsRecord::destroy($params['id']);
}
/**
* @notes 获取奖品记录详情
* @param $params
* @return array
* @author BD
* @date 2024/10/15 14:00
*/
public static function detail($params): array
{
return MallGoodsRecord::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,209 @@
<?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\member;
use app\common\model\member\{UserMember,UserMemberRecord};
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\FileService;
use app\common\model\user\{User};
/**
* 会员等级逻辑
* Class UserMemberLogic
* @package app\adminapi\logic\member
*/
class UserMemberLogic extends BaseLogic
{
/**
* @notes 添加会员等级
* @param array $params
* @return bool
* @author BD
* @date 2024/03/14 00:28
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserMember::create([
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'bg_img' => $params['bg_img'] ? FileService::setFileUrl($params['bg_img']) : '',
'text_color' => $params['text_color'],
'money' => $params['money'],
'level1_num' => $params['level1_num'],
'level1_vip_id' => $params['level1_vip_id'],
'lh_min' => $params['lh_min'],
'lh_max' => $params['lh_max'],
'rate_min' => $params['rate_min'],
'rate_max' => $params['rate_max'],
'item_add_rate' => $params['item_add_rate'],
'lh_num' => $params['lh_num'],
'item_num' => $params['item_num'],
'is_show' => $params['is_show'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑会员等级
* @param array $params
* @return bool
* @author BD
* @date 2024/03/14 00:28
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
//会员次数
if($params['is_show'] == 0){
$count = UserMemberRecord::where(['member_id' => $params['id']])->count();
if($count > 0){
throw new \Exception('该会员等级下存在用户,不可隐藏');
}
}
UserMember::where('id', $params['id'])->update([
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'bg_img' => $params['bg_img'] ? FileService::setFileUrl($params['bg_img']) : '',
'text_color' => $params['text_color'],
'money' => $params['money'],
'level1_num' => $params['level1_num'],
'level1_vip_id' => $params['level1_vip_id'],
'lh_min' => $params['lh_min'],
'lh_max' => $params['lh_max'],
'rate_min' => $params['rate_min'],
'rate_max' => $params['rate_max'],
'item_add_rate' => $params['item_add_rate'],
'lh_num' => $params['lh_num'],
'item_num' => $params['item_num'],
'is_show' => $params['is_show'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除会员等级
* @param array $params
* @return bool
* @author BD
* @date 2024/03/14 00:28
*/
public static function delete(array $params): bool
{
return UserMember::destroy($params['id']);
}
/**
* @notes 获取会员等级详情
* @param $params
* @return array
* @author BD
* @date 2024/03/14 00:28
*/
public static function detail($params): array
{
return UserMember::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 设置用户会员等级
* @param array $params
* @return bool
* @author BD
* @date 2024/03/19 02:29
*/
public static function setUserMember(array $params): bool
{
Db::startTrans();
try {
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
$member = UserMember::where(['id' => $params['member_id']])->findOrEmpty();
if ($member->isEmpty()) {
throw new \Exception('会员等级不存在');
}
$data = [
'user_id' => $params['user_id'],
'member_id' => $params['member_id'],
];
//查询用户会员等级
$record = UserMemberRecord::where(['user_id' => $params['user_id']])->findOrEmpty();
if ($record->isEmpty()) {
UserMemberRecord::create($data);
}else{
$data['id'] = $record['id'];
UserMemberRecord::update($data);
}
User::where('id',$params['user_id'])->update(['auto_member' => 0]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 会员等级数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/03/11 01:58
*/
public static function getAllData()
{
return UserMember::field(['id', 'name', 'logo', 'bg_img', 'text_color', 'money', 'level1_num', 'level1_vip_id', 'item_num', 'item_add_rate'])
->append(['vip_name'])
->where(['is_show' => 1])
->order(['money' => 'desc','id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -0,0 +1,226 @@
<?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' => '',
'content_en' => '',
'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');
}
}
}

View File

@@ -0,0 +1,140 @@
<?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]),
ConfigService::get('sms', 'smsbao', ['type' => 'smsbao', '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;
case 'smsbao':
$default = [
'sign' => '',
'username' => '',
'url_cn' => '',
'url_go' => '',
'status' => 0,
'api_key' => '',
'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' => '腾讯云短信',
'SMSBAO' => '短信宝短信',
];
return $desc[$value] ?? '';
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,157 @@
<?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\enum\YesNoEnum;
use app\common\model\setting\Language;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 语言包逻辑
* Class LanguageLogic
* @package app\adminapi\logic\setting
*/
class LanguageLogic extends BaseLogic
{
/**
* @notes 添加语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Language::create([
'name' => $params['name'],
'name_loc' => $params['name_loc'],
'symbol' => $params['symbol'],
'trans_symbol' => $params['trans_symbol'],
'logo' => $params['logo'],
'precision' => $params['precision'],
'time_format' => $params['time_format'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Language::where('id', $params['id'])->update([
'name' => $params['name'],
'name_loc' => $params['name_loc'],
'symbol' => $params['symbol'],
'trans_symbol' => $params['trans_symbol'],
'logo' => $params['logo'],
'precision' => $params['precision'],
'time_format' => $params['time_format'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function delete(array $params): bool
{
return Language::destroy($params['id']);
}
/**
* @notes 获取语言包详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function detail($params): array
{
return Language::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author heshihu
* @date 2022/2/22 10:18
*/
public static function updateStatus(array $params)
{
Language::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 Language::where(['is_show' => YesNoEnum::YES])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -0,0 +1,236 @@
<?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\service\{UtilsService};
use app\common\model\setting\{LanguagePag,Language};
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 语言包逻辑
* Class LanguagePagLogic
* @package app\adminapi\logic\setting
*/
class LanguagePagLogic extends BaseLogic
{
/**
* @notes 添加语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
//查询是否存在
$pag = LanguagePag::where(['lang' => $params['lang'],'type' => $params['type'],'name' => $params['name']])->findOrEmpty();
if (!$pag->isEmpty()) {
throw new \Exception('语言包已存在');
}
LanguagePag::create([
'lang' => $params['lang'],
'type' => $params['type'],
'name' => $params['name'],
'value' => $params['value']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
LanguagePag::where('id', $params['id'])->update([
'lang' => $params['lang'],
'type' => $params['type'],
'name' => $params['name'],
'value' => $params['value']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function delete(array $params): bool
{
return LanguagePag::destroy($params['id']);
}
/**
* @notes 获取语言包详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function detail($params): array
{
return LanguagePag::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 同步语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function sync(array $params): bool
{
Db::startTrans();
try {
//获取源语言
$from = Language::find($params['from_id']);
if ($from->isEmpty()) {
throw new \Exception('源语言不存在');
}
//获取目标语言
$to = Language::find($params['to_id']);
if ($to->isEmpty()) {
throw new \Exception('目标语言不存在');
}
//获取源语言
$pags = LanguagePag::where(['lang' => $from['symbol']])
->order(['type' => 'desc','name' => 'desc'])
->select()
->toArray();
foreach ($pags as &$pag) {
//查询是否存在
$to_pag = LanguagePag::where(['lang' => $to['symbol'],'type' => $pag['type'],'name' => $pag['name']])->findOrEmpty();
if ($to_pag->isEmpty()) {
LanguagePag::create([
'lang' => $to['symbol'],
'type' => $pag['type'],
'name' => $pag['name'],
]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 翻译语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/14 13:50
*/
public static function trans(array $params): bool
{
Db::startTrans();
try {
//获取源语言
$from = Language::find($params['from_id']);
if ($from->isEmpty()) {
throw new \Exception('源语言不存在');
}
//获取目标语言
$to = Language::find($params['to_id']);
if ($to->isEmpty()) {
throw new \Exception('目标语言不存在');
}
//获取待翻译目标语言
$pags = LanguagePag::where(['lang' => $to['symbol']])
->where(" value IS NULL OR value='' ")
->order(['type' => 'desc','name' => 'desc'])
->select()
->toArray();
$qArray = array();
$idArray = array();
foreach ($pags as &$pag) {
//查询源语言
$from_pag = LanguagePag::where(['lang' => $from['symbol'],'type' => $pag['type'],'name' => $pag['name']])->where(" value IS NOT NULL OR value='' ")->findOrEmpty();
if($from_pag->isEmpty()){
continue;
}else{
array_push($qArray, $from_pag['value']);
array_push($idArray, $pag['id']);
}
}
if(count($qArray) == 0) throw new \Exception('不存在待翻译的内容');
$ret = UtilsService::do_translate($qArray,$from['trans_symbol'],$to['trans_symbol']);
$ret = json_decode($ret, true);
if($ret['errorCode'] != 0){
throw new \Exception('错误代码:'.$ret['errorCode'].',请核对错误代码列表');
}
foreach ($idArray as $key=>$id) {
LanguagePag::update([
'id' => $id,
'value' => $ret['translateResults'][$key]['translation'],
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace app\adminapi\logic\setting;
use app\common\model\setting\RechargeMethod;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{ConfigService, FileService};
use app\common\model\setting\Language;
use app\common\enum\YesNoEnum;
/**
* 充值方式逻辑
* Class RechargeMethodLogic
* @package app\adminapi\logic\setting
*/
class RechargeMethodLogic extends BaseLogic
{
/**
* @notes 添加充值方式
* @param array $params
* @return bool
* @author BD
* @date 2023/11/30 15:22
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
RechargeMethod::create([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'account' => $params['account'],
'img' => $params['img'] ? FileService::setFileUrl($params['img']) : '',
'bank_name' => $params['bank_name'],
'bank_username' => $params['bank_username'],
'main_coin_type' => $params['main_coin_type'],
'coin_type' => $params['coin_type'],
'protocol' => $params['protocol'],
'address' => $params['address'],
'member_id' => $params['member_id'],
'avail_num' => $params['avail_num'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'symbol' => $params['symbol'],
'is_show' => $params['is_show'],
'is_voucher' => $params['is_voucher'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑充值方式
* @param array $params
* @return bool
* @author BD
* @date 2023/11/30 15:22
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
RechargeMethod::where('id', $params['id'])->update([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'account' => $params['account'],
'img' => $params['img'] ? FileService::setFileUrl($params['img']) : '',
'bank_name' => $params['bank_name'],
'bank_username' => $params['bank_username'],
'main_coin_type' => $params['main_coin_type'],
'coin_type' => $params['coin_type'],
'protocol' => $params['protocol'],
'address' => $params['address'],
'member_id' => $params['member_id'],
'avail_num' => $params['avail_num'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'symbol' => $params['symbol'],
'is_show' => $params['is_show'],
'is_voucher' => $params['is_voucher'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除充值方式
* @param array $params
* @return bool
* @author BD
* @date 2023/11/30 15:22
*/
public static function delete(array $params): bool
{
return RechargeMethod::destroy($params['id']);
}
/**
* @notes 获取充值方式详情
* @param $params
* @return array
* @author BD
* @date 2023/11/30 15:22
*/
public static function detail($params): array
{
$method = RechargeMethod::findOrEmpty($params['id'])->toArray();
$method['logo'] = FileService::getFileUrl($method['logo']);
$method['img'] = FileService::getFileUrl($method['img']);
return $method;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author heshihu
* @date 2022/2/22 10:18
*/
public static function updateStatus(array $params)
{
RechargeMethod::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()
{
$field = 'id,name,lang_id';
$methods = RechargeMethod::field($field)
->where(['is_show' => YesNoEnum::YES])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
foreach ($methods as &$method) {
$method['lang_name'] = '通用';
if($method['lang_id'] != 0){
$language = Language::where(['id' => $method['lang_id']])->findOrEmpty();
if(!$language->isEmpty()){
$method['lang_name'] = $language['name'];
}
}
}
return $methods;
}
}

View File

@@ -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');
}
}

View File

@@ -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']);
}
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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\setting\system;
use app\common\logic\BaseLogic;
use app\common\model\setting\OperationLog;
use think\facade\Db;
/**
* 生成器逻辑
* Class OperationLogLogic
* @package app\adminapi\logic\setting\system
*/
class OperationLogLogic extends BaseLogic
{
/**
* @notes 删除表相关信息
* @param $params
* @return bool
* @author 段誉
* @date 2022/6/16 9:30
*/
public static function deleteTable($params)
{
Db::startTrans();
try {
OperationLog::whereIn('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/16 9:30
*/
public static function deleteAll()
{
Db::startTrans();
try {
OperationLog::where('create_time > 0')->delete();
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
}

View File

@@ -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,
];
}
}

View File

@@ -0,0 +1,120 @@
<?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 = FileService::getFileUrl(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')),
// 国家区号
'country_code' => ConfigService::get('login', 'country_code', config('project.login.country_code')),
// 初始支付密码
'password_pay' => ConfigService::get('login', 'password_pay', config('project.login.password_pay')),
// 邀请码
'invite_code' => ConfigService::get('login', 'invite_code', config('project.login.invite_code')),
];
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']);
// 国家区号
ConfigService::set('login', 'country_code', $params['country_code']);
// 初始支付密码
ConfigService::set('login', 'password_pay', $params['password_pay']);
// 邀请码
ConfigService::set('login', 'invite_code', $params['invite_code']);
return true;
}
}

View File

@@ -0,0 +1,357 @@
<?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;
use app\common\model\withdraw\WithdrawMethod;
use think\facade\Config;
/**
* 网站设置
* Class WebSettingLogic
* @package app\adminapi\logic\setting
*/
class WebSettingLogic extends BaseLogic
{
/**
* @notes 获取网站信息
* @return array
* @author BD
* @date 2023/12/28 15:43
*/
public static function getWebsiteInfo(): array
{
$defaultAvatar = FileService::getFileUrl(config('project.default_image.user_avatar'));
return [
'name' => ConfigService::get('website', 'name'),
'log_way' => ConfigService::get('website', 'log_way'),
'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')),
// 订单提醒
'warm' => ConfigService::get('website', 'warm', config('project.website.warm')),
'shop_name' => ConfigService::get('website', 'shop_name'),
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
'shop_logo2' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo2')),
'google_auth' => ConfigService::get('website', 'google_auth'),
'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', ''),
'currency' => ConfigService::get('website', 'currency', ''),
'currency2' => ConfigService::get('website', 'currency2', ''),
'precision' => ConfigService::get('website', 'precision', ''),
//默认头像
'default_avatar' => FileService::getFileUrl(ConfigService::get('default_image', 'user_avatar', $defaultAvatar)),
// 登录方式
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
// 注册强制绑定手机
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
// 国家区号
// 'country_code' => ConfigService::get('login', 'country_code', config('project.login.country_code')),
// 初始支付密码
'password_pay' => ConfigService::get('login', 'password_pay', config('project.login.password_pay')),
// 邀请码
'invite_code' => ConfigService::get('login', 'invite_code', config('project.login.invite_code')),
// 多处登录
'multipoint_login' => ConfigService::get('login', 'multipoint_login', config('project.login.multipoint_login')),
// app下载地址
'down_link' => ConfigService::get('website', 'down_link'),
// app下载状态
'is_down' => ConfigService::get('website', 'is_down'),
// IP可注册数量
'ip_num' => ConfigService::get('login', 'ip_num'),
// 前台链接
'front_link' => ConfigService::get('website', 'front_link'),
'agent_name' => ConfigService::get('website', 'agent_name'),
'agent_web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'agent_web_favicon')),
'agent_web_logo' => FileService::getFileUrl(ConfigService::get('website', 'agent_web_logo')),
'agent_login_image' => FileService::getFileUrl(ConfigService::get('website', 'agent_login_image')),
'agent_google_auth' => ConfigService::get('website', 'agent_google_auth'),
'kefu_logo' => FileService::getFileUrl(ConfigService::get('website', 'kefu_logo')),
'show_kefu' => ConfigService::get('website', 'show_kefu'),
'kefu_link' => ConfigService::get('website', 'kefu_link'),
'contract_y_logo' => FileService::getFileUrl(ConfigService::get('contract', 'contract_y_logo')),
'contract_b_logo' => FileService::getFileUrl(ConfigService::get('contract', 'contract_b_logo')),
];
}
/**
* @notes 设置网站信息
* @param array $params
* @author BD
* @date 2023/12/28 15:43
*/
public static function setWebsiteInfo(array $params)
{
$favicon = FileService::setFileUrl($params['web_favicon']);
$logo = FileService::setFileUrl($params['web_logo']);
$login = FileService::setFileUrl($params['login_image']);
$shopLogo = FileService::setFileUrl($params['shop_logo']);
$shopLogo2 = FileService::setFileUrl($params['shop_logo2']);
$pcLogo = FileService::setFileUrl($params['pc_logo']);
$pcIco = FileService::setFileUrl($params['pc_ico'] ?? '');
$avatar = FileService::setFileUrl($params['default_avatar']);
ConfigService::set('website', 'name', $params['name']);
ConfigService::set('website', 'log_way', $params['log_way']);
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', 'shop_logo2', $shopLogo2);
// 订单提醒
ConfigService::set('website', 'warm', $params['warm']);
ConfigService::set('website', 'google_auth', $params['google_auth']);
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', 'currency', $params['currency'] ?? '');
ConfigService::set('website', 'currency2', $params['currency2'] ?? '');
ConfigService::set('website', 'precision', $params['precision'] ?? '');
ConfigService::set('default_image', 'user_avatar', $avatar);
// 登录方式1-账号密码登录2-手机短信验证码登录
ConfigService::set('login', 'login_way', $params['login_way']);
// 注册强制绑定手机
ConfigService::set('login', 'coerce_mobile', $params['coerce_mobile']);
// 国家区号
// ConfigService::set('login', 'country_code', $params['country_code']);
// 初始支付密码
ConfigService::set('login', 'password_pay', $params['password_pay']);
// 邀请码
ConfigService::set('login', 'invite_code', $params['invite_code']);
// 多处登录
ConfigService::set('login', 'multipoint_login', $params['multipoint_login']);
// app下载地址
ConfigService::set('website', 'down_link', $params['down_link']);
// app下载状态
ConfigService::set('website', 'is_down', $params['is_down']);
// IP可注册数量
ConfigService::set('login', 'ip_num', $params['ip_num']);
// 前台链接
ConfigService::set('website', 'front_link', $params['front_link']);
ConfigService::set('website', 'agent_name', $params['agent_name']);
ConfigService::set('website', 'agent_web_favicon', FileService::setFileUrl($params['agent_web_favicon']));
ConfigService::set('website', 'agent_web_logo', FileService::setFileUrl($params['agent_web_logo']));
ConfigService::set('website', 'agent_login_image', FileService::setFileUrl($params['agent_login_image']));
ConfigService::set('website', 'agent_google_auth', $params['agent_google_auth']);
ConfigService::set('website', 'kefu_logo', FileService::setFileUrl($params['kefu_logo']));
ConfigService::set('website', 'show_kefu', $params['show_kefu']);
ConfigService::set('website', 'kefu_link', $params['kefu_link']);
ConfigService::set('contract', 'contract_y_logo', FileService::setFileUrl($params['contract_y_logo']));
ConfigService::set('contract', 'contract_b_logo', FileService::setFileUrl($params['contract_b_logo']));
}
/**
* @notes 获取网站配置
* @param array $params
* @return array
* @author BD
* @date 2023/12/28 15:43
*/
public static function getWebsiteProject(array $params)
{
try {
$element = $params['name'];
$array = ['distribute','reward','udun','email','trade','market','translation','kefu','tron','regioncode','mine'];
if (!in_array($element, $array)) {
throw new \Exception('参数异常');
}
$data = ConfigService::get('website', $params['name']);
//有logo替换域名
if($element == 'market' || $element == 'kefu' || $element == 'regioncode'){
if(!empty($data)){
foreach ($data as &$item) {
$item['logo'] = FileService::getFileUrl($item['logo']);
}
}
}
//Udun提现方式
if($element == 'udun'){
$field = 'id,name,is_open_df,main_coin_type,coin_type';
$methods = WithdrawMethod::field($field)
->where(['is_show' => 1,'type' => 1])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
$data['methods'] = $methods;
}
return ['data' => $data];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 设置网站配置
* @param array $params
* @author BD
* @date 2023/12/28 15:43
*/
public static function setWebsiteProject(array $params)
{
try {
$element = $params['name'];
$array = ['distribute','reward','udun','email','trade','market','translation','kefu','tron','regioncode','mine'];
if (!in_array($element, $array)) {
throw new \Exception('参数异常');
}
$content = $params['content'];
//有logo替换域名
if($element == 'market' || $element == 'kefu' || $element == 'regioncode'){
foreach ($content as &$item) {
$item['logo'] = FileService::setFileUrl($item['logo']);
}
}
//Udun提现方式
if($element == 'udun'){
$methods = $content['methods'];
foreach ($methods as &$method) {
WithdrawMethod::update([
'id' => $method['id'],
'is_open_df' => $method['is_open_df'],
'main_coin_type' => $method['main_coin_type'],
'coin_type' => $method['coin_type'],
]);
}
unset($content['methods']);
}
ConfigService::set('website', $params['name'], $content);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 获取国际区号
* @return array
* @author BD
* @date 2023/12/28 16:09
*/
public static function getRegioncodeAll() : array
{
return ConfigService::get('website', 'regioncode');
}
/**
* @notes 获取版权备案
* @return array
* @author BD
* @date 2023/12/28 16:09
*/
public static function getCopyright() : array
{
return ConfigService::get('copyright', 'config', []);
}
/**
* @notes 设置版权备案
* @param array $params
* @return bool
* @author BD
* @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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace app\adminapi\logic\translation;
use app\common\service\{ConfigService,UtilsService};
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 翻译逻辑
* Class TranslationLogic
* @package app\adminapi\logic\translation
*/
class TranslationLogic extends BaseLogic
{
/**
* @notes 翻译
* @param array $params
* @return array
* @author BD
* @date 2024/04/25 01:30
*/
public static function translation(array $params)
{
// 输入
$qArray = $params['qArray'];
$ret = UtilsService::do_translate($qArray,$params['from'],$params['to']);
$ret = json_decode($ret, true);
if($ret['errorCode'] != 0){
throw new \Exception('错误代码:'.$ret['errorCode'].',请核对错误代码列表');
}
return ['result' => $ret['translateResults']];
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\{User,UserGroup,UserGroupRecord};
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 用户分组逻辑
* Class UserGroupLogic
* @package app\adminapi\logic\user
*/
class UserGroupLogic extends BaseLogic
{
/**
* @notes 添加用户分组
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:04
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserGroup::create([
'name' => $params['name']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑用户分组
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:04
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserGroup::where('id', $params['id'])->update([
'name' => $params['name']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除用户分组
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:04
*/
public static function delete(array $params): bool
{
return UserGroup::destroy($params['id']);
}
/**
* @notes 获取用户分组详情
* @param $params
* @return array
* @author BD
* @date 2024/04/25 01:04
*/
public static function detail($params): array
{
return UserGroup::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 用户分组
* @param array $params
* @return bool
* @author BD
* @date 2024/03/19 02:29
*/
public static function setUserGroup(array $params): bool
{
Db::startTrans();
try {
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
$group = UserGroup::where(['id' => $params['group_id']])->findOrEmpty();
if ($group->isEmpty() && $params['group_id'] != 0) {
throw new \Exception('分组不存在');
}
$data = [
'user_id' => $params['user_id'],
'group_id' => $params['group_id'],
];
//查询用户分组
$record = UserGroupRecord::where(['user_id' => $params['user_id']])->findOrEmpty();
if($params['group_id'] != 0){
if ($record->isEmpty()) {
UserGroupRecord::create($data);
}else{
$data['id'] = $record['id'];
UserGroupRecord::update($data);
}
}else{
UserGroupRecord::destroy($record['id']);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserGroupRule;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 分组规则逻辑
* Class UserGroupRuleLogic
* @package app\adminapi\logic\user
*/
class UserGroupRuleLogic extends BaseLogic
{
/**
* @notes 添加分组规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:30
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserGroupRule::create([
'group_id' => $params['group_id'],
'num' => $params['num'],
'money_type' => $params['money_type'],
'money' => $params['money'],
'money_percentage' => $params['money_percentage'],
'commission_type' => $params['commission_type'],
'commission' => $params['commission'],
'commission_percentage' => $params['commission_percentage']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑分组规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:30
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserGroupRule::where('id', $params['id'])->update([
'group_id' => $params['group_id'],
'num' => $params['num'],
'money_type' => $params['money_type'],
'money' => $params['money'],
'money_percentage' => $params['money_percentage'],
'commission_type' => $params['commission_type'],
'commission' => $params['commission'],
'commission_percentage' => $params['commission_percentage']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除分组规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/25 01:30
*/
public static function delete(array $params): bool
{
return UserGroupRule::destroy($params['id']);
}
/**
* @notes 获取分组规则详情
* @param $params
* @return array
* @author BD
* @date 2024/04/25 01:30
*/
public static function detail($params): array
{
return UserGroupRule::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserInfo;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 用户信息逻辑
* Class UserInfoLogic
* @package app\adminapi\logic\user
*/
class UserInfoLogic extends BaseLogic
{
/**
* @notes 同意实名
* @param array $params
* @return bool
* @author BD
* @date 2024/06/08 17:51
*/
public static function agree(array $params): bool
{
Db::startTrans();
try {
$record = UserInfo::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['auth_card']!=2) {
throw new \Exception('状态异常');
}
UserInfo::update([
'id' => $params['id'],
'auth_card' => 1
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 拒绝实名
* @param array $params
* @return bool
* @author BD
* @date 2024/06/08 17:51
*/
public static function refuse(array $params): bool
{
Db::startTrans();
try {
$record = UserInfo::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['auth_card']!=2) {
throw new \Exception('状态异常');
}
UserInfo::update([
'id' => $params['id'],
'auth_card' => 3,
'card_remark' => $params['remark']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserKadan;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 卡单规则逻辑
* Class UserKadanLogic
* @package app\adminapi\logic\user
*/
class UserKadanLogic extends BaseLogic
{
/**
* @notes 添加卡单规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/24 17:00
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserKadan::create([
'user_id' => $params['user_id'],
'sn' => generate_sn(UserKadan::class, 'sn'),
'num' => $params['num'],
'money' => $params['money'],
'commission' => $params['commission']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑卡单规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/24 17:00
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserKadan::where('id', $params['id'])->update([
'num' => $params['num'],
'money' => $params['money'],
'commission' => $params['commission']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除卡单规则
* @param array $params
* @return bool
* @author BD
* @date 2024/04/24 17:00
*/
public static function delete(array $params): bool
{
return UserKadan::destroy($params['id']);
}
/**
* @notes 获取卡单规则详情
* @param $params
* @return array
* @author BD
* @date 2024/04/24 17:00
*/
public static function detail($params): array
{
return UserKadan::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,601 @@
<?php
namespace app\adminapi\logic\user;
use app\common\enum\user\UserTerminalEnum;
use app\common\logic\BaseLogic;
use app\common\model\user\{User,UserInfo,UserNotice,UserRelation,UserRelationAgent};
use app\common\model\decorate\DecorateHint;
use app\common\model\finance\RechargeRecord;
use app\common\model\setting\RechargeMethod;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminRole;
use app\common\model\article\Article;
use app\common\utils\Common;
use app\common\service\{
ConfigService,UtilsService
};
use app\common\cache\UserTokenCache;
use app\common\model\user\UserSession;
use think\facade\{Db, Config};
/**
* 用户逻辑层
* Class UserLogic
* @package app\adminapi\logic\user
*/
class UserLogic extends BaseLogic
{
/**
* @notes 添加用户
* @param array $params
* @return bool|string
* @author BD
* @date 2023/9/22 16:38
*/
public static function add(array $params)
{
Db::startTrans();
try {
$userSn = User::createUserSn();
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
$password_pay_ = ConfigService::get('login', 'password_pay');
$password_pay = create_password($password_pay_, $passwordSalt);
$avatar = ConfigService::get('default_image', 'user_avatar');
//判断上级
//邀请码
$top_sn = $params['invite_code'];
$top_User = User::where(['sn' => $top_sn,'is_sn' => 1])->findOrEmpty();
if(isset($params['invite_code']) && $params['invite_code'] != ''){
if ($top_User->isEmpty()) {
throw new \Exception('邀请码不存在,请重新输入');
}
}
$mobile = $params['account'];
if($params['login_way'] == 1){
$mobile = $params['country_code'] . ' ' .$params['account'];
}
$is_transfer = 0;
$trade = ConfigService::get('website', 'trade');
if($trade['is_transfer'] != 0) $is_transfer = 1;
$user = User::create([
'sn' => $userSn,
'avatar' => $avatar,
'nickname' => '' . $userSn,
'account' => $params['account'],
'mobile' => $mobile,
'country_code' => $params['country_code'],
'password' => $password,
'password_pay' => $password_pay,
'channel' => $params['channel'],
'is_transfer' => $is_transfer,
'act_time' => time()
]);
//创建用户关系
if (!$top_User->isEmpty()) {
UtilsService::create_user_relation($user['id'],$top_User['id'],UtilsService::get_distribute_level());
}
//创建系统消息记录
UtilsService::create_user_notice($user['id']);
//创建初始会员等级
UtilsService::set_user_member($user['id']);
//创建用户信息
UserInfo::create(['user_id' => $user['id']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 调整用户余额
* @param array $params
* @return bool|string
* @author BD
* @date 2023/2/23 14:25
*/
public static function adjustUserMoney(array $params)
{
Db::startTrans();
try {
$user = User::find($params['user_id']);
$action = $params['action'];//1增加余额2扣减余额3手动充值
$finance_action = 1;//1增加2减少
$change_type = 0;//变动类型
$params['num'] = floatval($params['num']);
if (1 == $action) {
//调整可用余额
$user->save();
$finance_action = 1;
$change_type = 5;
}elseif (2 == $action) {
//调整可用余额
$user->save();
$finance_action = 2;
$change_type = 6;
}elseif (3 == $action){
$user->save();
$finance_action = 1;
$change_type = 1;
}
//记录日志
UtilsService::user_finance_add(
$user['id'],
$change_type,
$finance_action,
$params['num'],
'',
$params['remark'],
1 //冻结
);
//用户资金修改
UtilsService::user_money_change($params['user_id'], $finance_action, $params['num'],'user_money');
//手动充值
if($action == 3){
$method = RechargeMethod::where(['id' => $params['method_id']])->findOrEmpty();
if($method->isEmpty()){
throw new \Exception('充值方式不存在');
}
$order_amount_act = round($params['num'] * $method['rate'] , $method['precision']);
//判断充值金额
$config = ConfigService::get('website', 'trade');
if ($params['num'] < $config['recharge_min']) {
throw new \Exception('该充值方式最小充值金额:' . $config['recharge_min']);
}
$data = [
'sn' => generate_sn(RechargeRecord::class, 'sn'),
'user_id' => $user['id'],
'method_id' => $params['method_id'],
'amount' => $params['num'],
'amount_act' => $order_amount_act,
'account' => $method['account'],
'rate' => $method['rate'],
'symbol' => $method['symbol'],
'status' => 1,
];
$record = RechargeRecord::create($data);
//充值金额增加
UtilsService::user_money_change($params['user_id'], $finance_action, $params['num'],'total_recharge');
//充值活动奖励
UtilsService::activity_reward_add($params['user_id'],$params['num']);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if (!$user->isEmpty()) {
RechargeRecord::update([
'id' => $record['id'],
'user_money' => $user['user_money']
]);
//充值次数+1
User::update([
'id' => $user['id'],
'recharge_num' => $user['recharge_num'] + 1
]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 修改密码
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function changePwd(array $params)
{
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['pwd'], $passwordSalt);
return User::update([
'id' => $params['id'],
'password' => $password
]);
}
/**
* @notes 重置支付密码
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function resetPayPwd(array $params)
{
$passwordSalt = Config::get('project.unique_identification');
$password_pay_ = ConfigService::get('login', 'password_pay');
$password_pay = create_password($password_pay_, $passwordSalt);
return User::update([
'id' => $params['id'],
'password_pay' => $password_pay
]);
}
/**
* @notes 修改邮箱
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function changeEmail(array $params)
{
$userInfo = UserInfo::where(['user_id' => $params['id']])->findOrEmpty();
return UserInfo::update([
'id' => $userInfo['id'],
'email' => $params['email'],
'auth_email' => 1
]);
}
/**
* @notes 重置邮箱验证
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function resetEmail(array $params)
{
$userInfo = UserInfo::where(['user_id' => $params['id']])->findOrEmpty();
return UserInfo::update([
'id' => $userInfo['id'],
'email' => "",
'auth_email' => 0
]);
}
/**
* @notes 重置谷歌验证
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function resetGoogle(array $params)
{
$userInfo = UserInfo::where(['user_id' => $params['id']])->findOrEmpty();
return UserInfo::update([
'id' => $userInfo['id'],
'google_key' => "",
'google_qrcode' => "",
'auth_google' => 0
]);
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateMemberStatus(array $params)
{
User::update([
'id' => $params['id'],
'auto_member' => $params['auto_member']
]);
return true;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateLhStatus(array $params)
{
User::update([
'id' => $params['id'],
'is_lh' => $params['is_lh']
]);
return true;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateTransferStatus(array $params)
{
User::update([
'id' => $params['id'],
'is_transfer' => $params['is_transfer']
]);
return true;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateSnStatus(array $params)
{
User::update([
'id' => $params['id'],
'is_sn' => $params['is_sn']
]);
return true;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateOpenStatus(array $params)
{
User::update([
'id' => $params['id'],
'is_open' => $params['is_open']
]);
return true;
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author BD
* @date 2023/9/22 16:38
*/
public static function updateAgentStatus(array $params)
{
try {
if($params['is_agent'] == 1){
$top_relation = UserRelation::where(['user_id' => $params['id']])->order('level desc')->findOrEmpty();
if (!$top_relation->isEmpty()) {
throw new \Exception('顶级用户才可设置为代理');
}
}
$user = User::where(['id' => $params['id']])->findOrEmpty();
if($user['agent_id'] == 0){
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($user['sn'].mt_rand(10, 100), $passwordSalt);
$admin = Admin::create([
'name' => 'agent_'.$user['sn'],
'account' => 'agent_'.$user['sn'],
'password' => $password,
'is_agent' => 1,
'multipoint_login' => 1,
]);
AdminRole::create([
'admin_id' => $admin['id'],
'role_id' => 6,
]);
User::update([
'id' => $params['id'],
'agent_id' => $admin['id']
]);
}
User::update([
'id' => $params['id'],
'is_agent' => $params['is_agent']
]);
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 修改代理名称
* @param array $params
* @return User
* @author BD
* @date 2023/9/22 16:38
*/
public static function changeAgentName(array $params)
{
try {
$user = User::where(['id' => $params['id']])->findOrEmpty();
if($user['is_agent'] != 1){
throw new \Exception('代理才可设置代理名称');
}
User::update([
'id' => $params['id'],
'agent_name' => $params['name']
]);
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* @notes 发送站内信
* @param array $params
* @return bool|string
* @author BD
* @date 2023/9/22 16:38
*/
public static function sendNotice(array $params)
{
Db::startTrans();
try {
$article= Article::where(['id' => $params['article_id']])->findOrEmpty();
if ($article->isEmpty()) {
throw new \Exception('发送内容不存在');
}
$accounts = $substr = explode(",", $params['accounts']);
foreach ($accounts as $account) {
$user = User::where(['account' => $account])->findOrEmpty();
if ($user->isEmpty()) {
continue;
}
UserNotice::create([
'user_id' => $user['id'],
'article_id' => $article['id'],
'title' => $article['title'],
'content' => $article['content'],
'langs' => $article['langs'],
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 彩金赠送
* @param array $params
* @return bool|string
* @author BD
* @date 2023/9/22 16:38
*/
public static function caijin(array $params)
{
Db::startTrans();
try {
$accounts = $substr = explode(",", $params['accounts']);
$money = $params['money'];
if($money <= 0){
throw new \Exception('请输入正确的金额');
}
foreach ($accounts as $account) {
$user = User::where(['account' => $account])->findOrEmpty();
if ($user->isEmpty()) {
continue;
}
//记录日志
UtilsService::user_finance_add(
$user['id'],
4,
1,
$money,
'',
$params['remark'],
1 //冻结
);
//用户资金修改
UtilsService::user_money_change($user['id'], 1, $money,'user_money');
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 备注
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function remark(array $params): bool
{
Db::startTrans();
try {
$record = User::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('用户不存在');
}
//代理操作需查询是否有权限
$user = User::where(['agent_id' => $params['admin_id']])->findOrEmpty();
if (!$user->isEmpty()) {
$userRelation = UserRelationAgent::where(['user_id' => $record['id'],'parent_id' => $user['id']])->findOrEmpty();
if ($userRelation->isEmpty()) {
throw new \Exception('参数异常');
}
}
User::update([
'id' => $params['id'],
'remark2' => $params['content']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserMineRecord;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 挖矿记录逻辑
* Class UserMineRecordLogic
* @package app\adminapi\logic\user
*/
class UserMineRecordLogic extends BaseLogic
{
/**
* @notes 添加挖矿记录
* @param array $params
* @return bool
* @author BD
* @date 2025/01/01 15:47
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserMineRecord::create([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑挖矿记录
* @param array $params
* @return bool
* @author BD
* @date 2025/01/01 15:47
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserMineRecord::where('id', $params['id'])->update([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除挖矿记录
* @param array $params
* @return bool
* @author BD
* @date 2025/01/01 15:47
*/
public static function delete(array $params): bool
{
return UserMineRecord::destroy($params['id']);
}
/**
* @notes 获取挖矿记录详情
* @param $params
* @return array
* @author BD
* @date 2025/01/01 15:47
*/
public static function detail($params): array
{
return UserMineRecord::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserNotice;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 用户消息逻辑
* Class UserNoticeLogic
* @package app\adminapi\logic\user
*/
class UserNoticeLogic extends BaseLogic
{
/**
* @notes 添加用户消息
* @param array $params
* @return bool
* @author BD
* @date 2024/05/26 00:36
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserNotice::create([
'user_id' => $params['user_id'],
'title' => $params['title'],
'content' => $params['content'],
'notice_type' => $params['notice_type']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑用户消息
* @param array $params
* @return bool
* @author BD
* @date 2024/05/26 00:36
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserNotice::where('id', $params['id'])->update([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除用户消息
* @param array $params
* @return bool
* @author BD
* @date 2024/05/26 00:36
*/
public static function delete(array $params): bool
{
return UserNotice::destroy($params['id']);
}
/**
* @notes 获取用户消息详情
* @param $params
* @return array
* @author BD
* @date 2024/05/26 00:36
*/
public static function detail($params): array
{
return UserNotice::findOrEmpty($params['id'])->toArray();
}
}

View File

@@ -0,0 +1,30 @@
<?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\model\user\UserRelation;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 用户关系逻辑
* Class UserRelationLogic
* @package app\adminapi\logic\user
*/
class UserRelationLogic extends BaseLogic
{
}

View File

@@ -0,0 +1,273 @@
<?php
namespace app\adminapi\logic\user;
use app\common\model\user\UserTron;
use app\common\service\{UtilsService};
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 波场钱包逻辑
* Class UserTronLogic
* @package app\adminapi\logic\user
*/
class UserTronLogic extends BaseLogic
{
/**
* @notes 添加波场钱包
* @return bool
* @author BD
* @date 2024/05/04 23:38
*/
public static function add(): bool
{
Db::startTrans();
try {
//创建地址
$tronData = [
'action' => 'reg'
];
$response = UtilsService::usdt_request($tronData, 'POST');
$response = json_decode($response, true);
if($response['code'] == 200){
$data['type'] = 2;
$data['address'] = $response['data']['addr'];
$data['qrcode'] = UtilsService::get_qrcode($data['address']);
$data['key'] = $response['data']['key'];
UserTron::create($data);
}else{
throw new \Exception('创建失败');
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑波场钱包
* @param array $params
* @return bool
* @author BD
* @date 2024/05/04 23:38
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserTron::where('id', $params['id'])->update([
'address' => $params['address'],
'key' => $params['key'],
'qrcode' => $params['qrcode'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除波场钱包
* @param array $params
* @return bool
* @author BD
* @date 2024/05/04 23:38
*/
public static function delete(array $params): bool
{
return UserTron::destroy($params['id']);
}
/**
* @notes 获取波场钱包详情
* @param $params
* @return array
* @author BD
* @date 2024/05/04 23:38
*/
public static function detail($params): array
{
return UserTron::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 更新状态
* @param array $params
* @return array
* @author BD
* @date 2024/05/04 23:38
*/
public static function updateSort(array $params)
{
return UserTron::update([
'id' => $params['id'],
'sort' => $params['sort']
]);
}
/**
* @notes 更新金额
* @param array $params
* @return array
* @author BD
* @date 2024/05/04 23:38
*/
public static function updateMoney(array $params)
{
$record = UserTron::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
//查询余额
$data = [
'action' => 'info',
'addr' => $record['address']
];
$response = UtilsService::usdt_request($data, 'POST');
$response = json_decode($response, true);
if($response['code'] == 200){
return UserTron::update([
'id' => $params['id'],
'money_trx' => $response['data']['trx'],
'money_usdt' => $response['data']['usdt'],
]);
}else{
throw new \Exception('更新失败');
}
}
/**
* @notes 转账
* @param array $params
* @return bool|string
* @author BD
* @date 2024/05/04 23:38
*/
public static function tran(array $params)
{
Db::startTrans();
try {
$userTron = UserTron::find($params['id']);
//发起转账
$data = [
'action' => 'pay',
'out_addr' => $userTron['address'],
'out_key' => $userTron['key'],
'out_money' => $params['num'],
'in_addr' => $params['in_addr'],
'type' => 'usdt',//usdt trx
];
$response = UtilsService::usdt_request($data, 'POST');
$response = json_decode($response, true);
if($response['code'] == 200){
UserTron::update([
'id' => $params['id'],
'money_usdt' => $userTron['money_usdt'] - $params['num'],
]);
$inUserTron = UserTron::where(['address' => $params['in_addr']])->findOrEmpty();
if(!$inUserTron->isEmpty()){
UserTron::update([
'id' => $inUserTron['id'],
'money_usdt' => $inUserTron['money_usdt'] + $params['num'],
]);
}
}else{
throw new \Exception('转账失败');
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 归集
* @param array $params
* @return bool|string
* @author BD
* @date 2024/05/04 23:38
*/
public static function tranAll(array $params)
{
Db::startTrans();
try {
$min_money = $params['min_money'];
$userTrons = UserTron::where("money_usdt >= $min_money")
->order(['id' => 'desc'])
->select()
->toArray();
foreach ($userTrons as &$userTron) {
$out_money = $userTron['money_usdt'] - $params['rem_money'];
if($out_money <= 0) continue;
//发起转账
$data = [
'action' => 'pay',
'out_addr' => $userTron['address'],
'out_key' => $userTron['key'],
'out_money' => $out_money,
'in_addr' => $params['in_addr'],
'type' => 'usdt',//usdt trx
];
$response = UtilsService::usdt_request($data, 'POST');
$response = json_decode($response, true);
if($response['code'] == 200){
UserTron::update([
'id' => $userTron['id'],
'money_usdt' => $params['rem_money'],
]);
$inUserTron = UserTron::where(['address' => $params['in_addr']])->findOrEmpty();
if(!$inUserTron->isEmpty()){
UserTron::update([
'id' => $inUserTron['id'],
'money_usdt' => $inUserTron['money_usdt'] + $out_money,
]);
}
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
}

View File

@@ -0,0 +1,135 @@
<?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\withdraw;
use app\common\model\withdraw\WithdrawBank;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{FileService};
use app\common\enum\YesNoEnum;
/**
* 可提现银行逻辑
* Class WithdrawBankLogic
* @package app\adminapi\logic\withdraw
*/
class WithdrawBankLogic extends BaseLogic
{
/**
* @notes 添加可提现银行
* @param array $params
* @return bool
* @author BD
* @date 2024/02/25 12:19
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WithdrawBank::create([
'lang_id' => $params['lang_id'],
'name' => $params['name'],
'code' => $params['code'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑可提现银行
* @param array $params
* @return bool
* @author BD
* @date 2024/02/25 12:19
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
WithdrawBank::where('id', $params['id'])->update([
'lang_id' => $params['lang_id'],
'name' => $params['name'],
'code' => $params['code'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除可提现银行
* @param array $params
* @return bool
* @author BD
* @date 2024/02/25 12:19
*/
public static function delete(array $params): bool
{
return WithdrawBank::destroy($params['id']);
}
/**
* @notes 获取可提现银行详情
* @param $params
* @return array
* @author BD
* @date 2024/02/25 12:19
*/
public static function detail($params): array
{
return WithdrawBank::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 提现银行数据
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/02/25 12:19
*/
public static function allByLang($params)
{
return WithdrawBank::where(['is_show' => YesNoEnum::YES,'lang_id' => $params['lang_id']])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -0,0 +1,162 @@
<?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\withdraw;
use app\common\model\withdraw\{WithdrawMethod,WithdrawWallet};
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{FileService};
use app\common\enum\YesNoEnum;
/**
* 提现方式逻辑
* Class WithdrawMethodLogic
* @package app\adminapi\logic\withdraw
*/
class WithdrawMethodLogic extends BaseLogic
{
/**
* @notes 添加提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WithdrawMethod::create([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'charge' => $params['charge'],
'is_show' => $params['is_show'],
'is_qrcode' => $params['is_qrcode'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$method = WithdrawMethod::find($params['id']);
if ($method->isEmpty()) {
throw new \Exception('提现方式不存在');
}
WithdrawWallet::where('method_id', $method['id'])->update([
'lang_id' => $params['lang_id'],
]);
WithdrawMethod::where('id', $params['id'])->update([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'charge' => $params['charge'],
'is_qrcode' => $params['is_qrcode'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function delete(array $params): bool
{
return WithdrawMethod::destroy($params['id']);
}
/**
* @notes 获取提现方式详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function detail($params): array
{
return WithdrawMethod::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:53
*/
public static function getAllData()
{
$field = 'wm.id,wm.name,wm.lang_id';
$field .= ',l.name as lang_name';
return WithdrawMethod::alias('wm')
->join('language l', 'l.id = wm.lang_id')
->field($field)
->where(['wm.is_show' => YesNoEnum::YES])
->order(['wm.sort' => 'desc', 'wm.id' => 'desc'])
->select()
->toArray();
}
}

View File

@@ -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\withdraw;
use app\common\model\withdraw\WithdrawWallet;
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{FileService};
/**
* 用户提现钱包逻辑
* Class WithdrawWalletLogic
* @package app\adminapi\logic\withdraw
*/
class WithdrawWalletLogic extends BaseLogic
{
/**
* @notes 编辑用户提现钱包
* @param array $params
* @return bool
* @author BD
* @date 2024/02/26 13:32
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
WithdrawWallet::where('id', $params['id'])->update([
'bank_id' => $params['bank_id'],
'name' => $params['name'],
'account' => $params['account'],
'img' => $params['img'] ? FileService::setFileUrl($params['img']) : '',
'is_disable' => $params['is_disable']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除用户提现钱包
* @param array $params
* @return bool
* @author BD
* @date 2024/02/26 13:32
*/
public static function delete(array $params): bool
{
return WithdrawWallet::destroy($params['id']);
}
}