初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\{cache\AdminAuthCache, service\ConfigService, service\FileService, service\TencentMapKeyService};
use WpOrg\Requests\Requests;
/**
* 配置类逻辑层
* Class ConfigLogic
* @package app\adminapi\logic
*/
class ConfigLogic
{
/**
* @notes 获取配置
* @return array
* @author 段誉
* @date 2021/12/31 11:03
*/
public static function getConfig(): array
{
$config = [
// 文件域名
'oss_domain' => request()->domain().'/',
// 网站名称
'web_name' => ConfigService::get('platform', 'platform_name',''),
// 网站图标
'web_favicon' => FileService::getFileUrl(ConfigService::get('platform', 'icon','')),
// 网站logo
'web_logo' => FileService::getFileUrl(ConfigService::get('platform', 'platform_logo','')),
// 登录页
'login_image' => FileService::getFileUrl(ConfigService::get('platform', 'poster','')),
// 版权信息
'copyright_config' => ConfigService::get('copyright', 'config', []),
//文档信息开关
'document_status' => ConfigService::get('platform', 'doc_show',1),
'tencent_map_key' => (new TencentMapKeyService())->getTencentMapKey(),
];
return $config;
}
/**
* @notes 正版检测
* @return mixed
* @author ljj
* @date 2023/5/16 11:49 上午
*/
public static function checkLegal()
{
$check_domain = config('project.check_domain');
$product_code = config('project.product_code');
$domain = $_SERVER['HTTP_HOST'];
$result = Requests::get($check_domain.'/api/version/productAuth?code='.$product_code.'&domain='.$domain);
$result = json_decode($result->body,true);
return $result['data'];
}
/**
* @notes 检测新版本
* @return mixed
* @author ljj
* @date 2023/5/25 7:02 下午
*/
public static function checkVersion()
{
$version = config('project.version');
$product_code = config('project.product_code');
$check_domain = config('project.check_domain');
$result = Requests::get($check_domain.'/api/version/hasNew?code='.$product_code.'&version='.$version);
$result = json_decode($result->body,true);
return $result['data'];
}
}

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,89 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\adminapi\service\AdminTokenService;
use app\common\service\FileService;
use think\facade\Config;
/**
* 登录逻辑
* Class LoginLogic
* @package app\adminapi\logic
*/
class LoginLogic extends BaseLogic
{
/**
* @notes 管理员账号登录
* @param $params
* @return false|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 令狐冲
* @date 2021/6/30 17:00
*/
public function login($params)
{
$time = time();
$admin = Admin::where('account', '=', $params['account'])->find();
//用户表登录信息更新
$admin->login_time = $time;
$admin->login_ip = request()->ip();
$admin->save();
//设置token
$adminInfo = AdminTokenService::setToken($admin->id, $params['terminal'], $admin->multipoint_login);
//返回登录信息
$avatar = $admin->avatar ? $admin->avatar : Config::get('project.default_image.admin_avatar');
$avatar = FileService::getFileUrl($avatar);
return [
'name' => $adminInfo['name'],
'avatar' => $avatar,
'role_name' => $adminInfo['role_name'],
'token' => $adminInfo['token'],
];
}
/**
* @notes 退出登录
* @param $adminInfo
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 令狐冲
* @date 2021/7/5 14:34
*/
public function logout($adminInfo)
{
//token不存在不注销
if (!isset($adminInfo['token'])) {
return false;
}
//设置token过期
return AdminTokenService::expireToken($adminInfo['token']);
}
}

View File

@@ -0,0 +1,279 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\IndexVisit;
use app\common\model\order\Order;
use app\common\model\user\User;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 工作台
* Class WorkbenchLogic
* @package app\adminapi\logic
*/
class WorkbenchLogic extends BaseLogic
{
/**
* @notes 工作套
* @param $adminInfo
* @return array
* @author 段誉
* @date 2021/12/29 15:58
*/
public static function index()
{
return [
// 版本信息
'version' => self::versionInfo(),
// 今日数据
'today' => self::today(),
// 常用功能
'menu' => self::menu(),
// 近15日访客数
'visitor' => self::visitor(),
// 近15日营业额
'business' => self::business15()
];
}
/**
* @notes 常用功能
* @return array[]
* @author 段誉
* @date 2021/12/29 16:40
*/
public static function menu() : array
{
return [
[
'name' => '服务列表',
'image' => FileService::getFileUrl(config('project.default_image.admin_goods_lists')),
'url' => '/service/lists'
],
[
'name' => '分类管理',
'image' => FileService::getFileUrl(config('project.default_image.admin_goods_category')),
'url' => '/service/category'
],
[
'name' => '订单列表',
'image' => FileService::getFileUrl(config('project.default_image.admin_order')),
'url' => '/order/index'
],
[
'name' => '师傅列表',
'image' => FileService::getFileUrl(config('project.default_image.admin_staff')),
'url' => '/master_worker/list'
],
[
'name' => '首页装修',
'image' => FileService::getFileUrl(config('project.default_image.admin_index_decorate')),
'url' => '/decorate/user/pages'
],
[
'name' => '消息通知',
'image' => FileService::getFileUrl(config('project.default_image.admin_news_notice')),
'url' => '/application/message/notice'
],
[
'name' => '支付配置',
'image' => FileService::getFileUrl(config('project.default_image.admin_set_payment')),
'url' => '/setting/payment/payment_config'
],
];
}
/**
* @notes 版本信息
* @return array
* @author 段誉
* @date 2021/12/29 16:08
*/
public static function versionInfo() : array
{
return [
'platform_name' => ConfigService::get('platform', 'platform_name',''),
'version' => config('project.version'),
'website' => ConfigService::get('website', 'name'),
];
}
/**
* @notes 今日数据
* @return int[]
* @author 段誉
* @date 2021/12/29 16:15
*/
public static function today() : array
{
return [
'time' => date('Y-m-d H:i:s'),
// 今日销量
'today_sales_count' => Order::where('pay_status', YesNoEnum::YES)
->whereDay('create_time')
->count(),
// 总销销量
'total_sales_count' => Order::where('pay_status', YesNoEnum::YES)
->count(),
// 今日销售额
'today_sales_amount' => Order::where('pay_status', YesNoEnum::YES)
->whereDay('create_time')
->sum('total_order_amount'),
// 总销售额
'total_sales_amount' => Order::where('pay_status', YesNoEnum::YES)
->sum('total_order_amount'),
// 今日访问量
'today_visitor' => count(array_unique(IndexVisit::whereDay('create_time')->column('ip'))),
// 总访问量
'total_visitor' => count(array_unique(IndexVisit::column('ip'))),
// 今日新增用户量
'today_new_user' => User::whereDay('create_time')->count(),
// 总用户量
'total_new_user' => User::count(),
];
}
/**
* @notes 文章阅读排名
* @return array[]
* @author 段誉
* @date 2021/12/29 16:40
*/
public static function article() : array
{
return [
['name' => '文章1', 'read' => 1000],
['name' => '文章2', 'read' => 800],
['name' => '文章3', 'read' => 600],
['name' => '文章4', 'read' => 400],
];
}
/**
* @notes 访问数
* @return array
* @author 段誉
* @date 2021/12/29 16:57
*/
public static function visitor() : array
{
$today = new \DateTime();
$todayStr = $today->format('Y-m-d') . ' 23:59:59';
$todayDec15 = $today->add(\DateInterval::createFromDateString('-14day'));
$todayDec15Str = $todayDec15->format('Y-m-d');
$field = [
"FROM_UNIXTIME(create_time,'%Y%m%d') as date",
"ip"
];
$lists = IndexVisit::field($field)
->distinct(true)
->whereTime('create_time', 'between', [$todayDec15Str,$todayStr])
->select()
->toArray();
// 集合一天的IP
$temp1 = [];
foreach ($lists as $item) {
$temp1[$item['date']][] = $item['ip'];
}
// 统计数量
$temp2 = [];
foreach ($temp1 as $k => $v) {
$temp2[$k] = count($v);
}
$userData = [];
$date = [];
for($i = 0; $i < 15; $i ++) {
$today = new \DateTime();
$targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day'));
$targetDay = $targetDay->format('Ymd');
$date[] = $targetDay;
$userData[] = $temp2[$targetDay] ?? 0;
}
return [
'date' => $date,
'list' => [
['name' => '访客数', 'data' => $userData]
]
];
}
/**
* @notes 近15天营业额
* @return array
* @author Tab
* @date 2021/9/10 18:06
*/
public static function business15()
{
$today = new \DateTime();
$todayStr = $today->format('Y-m-d') . ' 23:59:59';
$todayDec15 = $today->add(\DateInterval::createFromDateString('-14day'));
$todayDec15Str = $todayDec15->format('Y-m-d');
$field = [
"FROM_UNIXTIME(create_time,'%Y%m%d') as date",
"sum(total_order_amount) as today_amount"
];
$lists = Order::field($field)
->whereTime('create_time', 'between', [$todayDec15Str,$todayStr])
->where('pay_status', YesNoEnum::YES)
->group('date')
->select()
->toArray();
$lists = array_column($lists, 'today_amount', 'date');
$amountData = [];
$date = [];
for($i = 0; $i < 15; $i ++) {
$today = new \DateTime();
$targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day'));
$targetDay = $targetDay->format('Ymd');
$date[] = $targetDay;
$amountData[] = $lists[$targetDay] ?? 0;
}
return [
'date' => $date,
'list' => [
['name' => '营业额', 'data' => $amountData]
]
];
}
}

View File

@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\ad;
use app\common\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\ad\Ad;
class AdLogic extends BaseLogic
{
/**
* @notes 添加广告
* @param $params
* @return bool
* @author ljj
* @date 2022/2/14 7:00 下午
*/
public function add($params)
{
Ad::create([
'name' => $params['name'],
'pid' => $params['pid'],
'image' => $params['image'],
'link_type' => $params['link_type'],
'link_address' => $params['link_address'],
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
]);
return true;
}
/**
* @notes 查看广告详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/15 10:14 上午
*/
public function detail($id)
{
return Ad::where('id',$id)->findOrEmpty()->toArray();
}
/**
* @notes 编辑广告
* @param $params
* @return bool
* @author ljj
* @date 2022/2/15 10:24 上午
*/
public function edit($params)
{
Ad::update([
'name' => $params['name'],
'pid' => $params['pid'],
'image' => $params['image'],
'link_type' => $params['link_type'],
'link_address' => $params['link_address'],
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除广告
* @param $id
* @return bool
* @author ljj
* @date 2022/2/15 10:32 上午
*/
public function del($id)
{
Ad::destroy($id);
return true;
}
/**
* @notes 修改广告状态
* @param $params
* @return bool
* @author ljj
* @date 2022/2/15 10:38 上午
*/
public function status($params)
{
Ad::update([
'status' => $params['status'],
],['id'=>$params['id']]);
return true;
}
}

View File

@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\ad;
use app\common\logic\BaseLogic;
use app\common\model\ad\AdPosition;
class AdPositionLogic extends BaseLogic
{
/**
* @notes 添加广告位
* @param $params
* @return bool
* @author ljj
* @date 2022/2/14 5:04 下午
*/
public function add($params)
{
AdPosition::create([
'name' => $params['name'],
'status' => $params['status'],
]);
return true;
}
/**
* @notes 查看广告位详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/14 5:08 下午
*/
public function detail($id)
{
return AdPosition::where('id',$id)->findOrEmpty()->toArray();
}
/**
* @notes 编辑广告位
* @param $params
* @return bool
* @author ljj
* @date 2022/2/14 5:13 下午
*/
public function edit($params)
{
AdPosition::update([
'name' => $params['name'],
'status' => $params['status'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除广告位
* @param $id
* @return bool
* @author ljj
* @date 2022/2/14 5:28 下午
*/
public function del($id)
{
AdPosition::destroy($id);
return true;
}
/**
* @notes 修改广告位状态
* @param $params
* @return bool
* @author ljj
* @date 2022/2/14 5:32 下午
*/
public function status($params)
{
AdPosition::update([
'status' => $params['status'],
],['id'=>$params['id']]);
return true;
}
}

View File

@@ -0,0 +1,230 @@
<?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\AdminSession;
use app\common\cache\AdminTokenCache;
use app\common\service\FileService;
use think\facade\Config;
use think\facade\Db;
/**
* 管理员逻辑
* Class AdminLogic
* @package app\adminapi\logic\auth
*/
class AdminLogic extends BaseLogic
{
/**
* @notes 添加管理员
* @param array $params
* @author 段誉
* @date 2021/12/29 10:23
*/
public static function add(array $params)
{
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
$avatar = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : config('project.default_image.admin_avatar');
Admin::create([
'name' => $params['name'],
'account' => $params['account'],
'avatar' => $avatar,
'password' => $password,
'role_id' => $params['role_id'],
'dept_id' => $params['dept_id'] ?? 0,
'jobs_id' => $params['jobs_id'] ?? 0,
'create_time' => time(),
'disable' => $params['disable'],
'multipoint_login' => $params['multipoint_login'],
]);
}
/**
* @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'],
'role_id' => $params['role_id'],
'dept_id' => $params['dept_id'] ?? 0,
'jobs_id' => $params['jobs_id'] ?? 0,
'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过期
$role_id = Admin::where('id', $params['id'])->value('role_id');
if ($params['disable'] == 1 || $role_id != $params['role_id']) {
$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();
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();
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes
* @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', 'role_id', 'disable', 'root',
'multipoint_login', 'avatar', 'dept_id', 'jobs_id'
])->findOrEmpty($params['id'])->toArray();
if ($action == 'detail') {
return $admin;
}
$result['user'] = $admin;
// 当前管理员角色拥有的菜单
$result['menu'] = MenuLogic::getMenuByAdminId($params['id']);
// 当前管理员橘色拥有的按钮权限
$result['permissions'] = AuthLogic::getBtnAuthByRoleId($admin);
return $result;
}
/**
* @notes 编辑超级管理员
* @param $params
* @return Admin
* @author 段誉
* @date 2022/4/8 17:54
*/
public static function editSelf($params)
{
$data = [
'id' => $params['admin_id'],
'name' => $params['name'],
'avatar' => FileService::setFileUrl($params['avatar']),
];
if (!empty($params['password'])) {
$passwordSalt = Config::get('project.unique_identification');
$data['password'] = create_password($params['password'], $passwordSalt);
}
return Admin::update($data);
}
}

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\auth;
use app\common\model\auth\Admin;
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
{
$admin = Admin::with(['role_menu'])
->where(['id' => $adminId])
->findOrEmpty()->toArray();
if (empty($admin)) {
return [];
}
$menuId = array_column($admin['role_menu'], 'menu_id');
return SystemMenu::distinct(true)
->where([
['is_disable', '=', 0],
['perms', '<>', ''],
['id', 'in', $menuId],
])
->column('perms');
}
}

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

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\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,
]);
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();
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* App设置逻辑层
* Class AppSettingLogic
* @package app\adminapi\logic\settings\app
*/
class AppSettingLogic extends BaseLogic
{
/**
* @notes 获取App设置
* @return array
* @author 段誉
* @date 2022/3/29 10:25
*/
public static function getConfig()
{
$config = [
'ios_download_url' => ConfigService::get('app', 'ios_download_url', ''),
'android_download_url' => ConfigService::get('app', 'android_download_url', ''),
'download_title' => ConfigService::get('app', 'download_title', ''),
];
return $config;
}
/**
* @notes App设置
* @param $params
* @author 段誉
* @date 2022/3/29 10:26
*/
public static function setConfig($params)
{
ConfigService::set('app', 'ios_download_url', $params['ios_download_url'] ?? '');
ConfigService::set('app', 'android_download_url', $params['android_download_url'] ?? '');
ConfigService::set('app', 'download_title', $params['download_title'] ?? '');
}
}

View File

@@ -0,0 +1,88 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* H5设置逻辑层
* Class HFiveSettingLogic
* @package app\adminapi\logic\settings\h5
*/
class H5SettingLogic extends BaseLogic
{
/**
* @notes 获取H5设置
* @return array
* @author ljj
* @date 2022/9/23 9:38 上午
*/
public static function getConfig()
{
$config = [
'status' => ConfigService::get('h5', 'status',1),
'page_status' => ConfigService::get('h5', 'page_status',1),
'page_url' => ConfigService::get('h5', 'page_url',''),
];
return $config;
}
/**
* @notes H5设置
* @param $params
* @author ljj
* @date 2022/9/23 10:02 上午
*/
public static function setConfig($params)
{
$params['close_url'] = $params['close_url'] ?? '';
ConfigService::set('h5', 'status', $params['status']);
ConfigService::set('h5', 'page_status', $params['page_status'] ?? 0);
ConfigService::set('h5', 'page_url', $params['page_url'] ?? '');
// 恢复原入口
if(file_exists('./mobile/index_lock.html')) {
// 存在则原商城入口被修改过,先清除修改后的入口
unlink('./mobile/index.html');
// 恢复原入口
rename('./mobile/index_lock.html', './mobile/index.html');
}
// H5商城关闭 且 显示空白页
if($params['status'] == 0 && $params['page_status'] == 1) {
// 变更文件名
rename('./mobile/index.html', './mobile/index_lock.html');
// 创建新空白文件
$newfile = fopen('./mobile/index.html', 'w');
fclose($newfile);
}
// H5商城关闭 且 跳转指定页
if($params['status'] == 0 && $params['page_status'] == 2 && !empty($params['close_url'])) {
// 变更文件名
rename('./mobile/index.html', './mobile/index_lock.html');
// 创建重定向文件
$newfile = fopen('./mobile/index.html', 'w');
$content = '<script>window.location.href = "' . $params['close_url'] . '";</script>';
fwrite($newfile, $content);
fclose($newfile);
}
}
}

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\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 小程序设置逻辑
* Class MnpSettingsLogic
* @package app\adminapi\logic\channel
*/
class MnpSettingsLogic extends BaseLogic
{
/**
* @notes 获取小程序配置
* @return array
* @author ljj
* @date 2022/2/16 9:38 上午
*/
public function getConfig()
{
$domainName = $_SERVER['SERVER_NAME'];
$qrCode = ConfigService::get('mnp_setting', 'qr_code', '');
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
$config = [
'name' => ConfigService::get('mnp_setting', 'name', ''),
'original_id' => ConfigService::get('mnp_setting', 'original_id', ''),
'qr_code' => $qrCode,
'app_id' => ConfigService::get('mnp_setting', 'app_id', ''),
'app_secret' => ConfigService::get('mnp_setting', 'app_secret', ''),
'request_domain' => 'https://'.$domainName,
'socket_domain' => 'wss://'.$domainName,
'upload_file_domain' => 'https://'.$domainName,
'download_file_domain' => 'https://'.$domainName,
'udp_domain' => 'udp://'.$domainName,
'business_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置小程序配置
* @param $params
* @author ljj
* @date 2022/2/16 9:51 上午
*/
public function setConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('mnp_setting','name', $params['name'] ?? '');
ConfigService::set('mnp_setting','original_id',$params['original_id'] ?? '');
ConfigService::set('mnp_setting','qr_code',$qrCode);
ConfigService::set('mnp_setting','app_id',$params['app_id']);
ConfigService::set('mnp_setting','app_secret',$params['app_secret']);
}
/**
* @notes 获取小程序配置
* @return array
* @author ljj
* @date 2022/2/16 9:38 上午
*/
public function getCoachConfig()
{
$domainName = $_SERVER['SERVER_NAME'];
$qrCode = ConfigService::get('mnp_coach_setting', 'qr_code', '');
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
$config = [
'name' => ConfigService::get('mnp_coach_setting', 'name', ''),
'original_id' => ConfigService::get('mnp_coach_setting', 'original_id', ''),
'qr_code' => $qrCode,
'app_id' => ConfigService::get('mnp_coach_setting', 'app_id', ''),
'app_secret' => ConfigService::get('mnp_coach_setting', 'app_secret', ''),
'request_domain' => 'https://'.$domainName,
'socket_domain' => 'wss://'.$domainName,
'upload_file_domain' => 'https://'.$domainName,
'download_file_domain' => 'https://'.$domainName,
'udp_domain' => 'udp://'.$domainName,
'business_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置小程序配置
* @param $params
* @author ljj
* @date 2022/2/16 9:51 上午
*/
public function setCoachConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('mnp_coach_setting','name', $params['name'] ?? '');
ConfigService::set('mnp_coach_setting','original_id',$params['original_id'] ?? '');
ConfigService::set('mnp_coach_setting','qr_code',$qrCode);
ConfigService::set('mnp_coach_setting','app_id',$params['app_id']);
ConfigService::set('mnp_coach_setting','app_secret',$params['app_secret']);
}
/**
* @notes 获取小程序配置
* @return array
* @author ljj
* @date 2022/2/16 9:38 上午
*/
public function getShopConfig()
{
$domainName = $_SERVER['SERVER_NAME'];
$qrCode = ConfigService::get('mnp_shop_setting', 'qr_code', '');
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
$config = [
'name' => ConfigService::get('mnp_shop_setting', 'name', ''),
'original_id' => ConfigService::get('mnp_shop_setting', 'original_id', ''),
'qr_code' => $qrCode,
'app_id' => ConfigService::get('mnp_shop_setting', 'app_id', ''),
'app_secret' => ConfigService::get('mnp_shop_setting', 'app_secret', ''),
'request_domain' => 'https://'.$domainName,
'socket_domain' => 'wss://'.$domainName,
'upload_file_domain' => 'https://'.$domainName,
'download_file_domain' => 'https://'.$domainName,
'udp_domain' => 'udp://'.$domainName,
'business_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置小程序配置
* @param $params
* @author ljj
* @date 2022/2/16 9:51 上午
*/
public function setShopConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('mnp_shop_setting','name', $params['name'] ?? '');
ConfigService::set('mnp_shop_setting','original_id',$params['original_id'] ?? '');
ConfigService::set('mnp_shop_setting','qr_code',$qrCode);
ConfigService::set('mnp_shop_setting','app_id',$params['app_id']);
ConfigService::set('mnp_shop_setting','app_secret',$params['app_secret']);
}
}

View File

@@ -0,0 +1,228 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\enum\OfficialAccountEnum;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use EasyWeChat\Factory;
/**
* 微信公众号菜单逻辑层
* Class OfficialAccountMenuLogic
* @package app\adminapi\logic\wechat
*/
class OfficialAccountMenuLogic extends BaseLogic
{
/**
* @notes 保存
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 10:43
*/
public static function save($params)
{
try {
self::checkMenu($params);
ConfigService::set('oa_setting', 'menu', $params);
return true;
} catch (\Exception $e) {
OfficialAccountMenuLogic::setError($e->getMessage());
return false;
}
}
/**
* @notes 一级菜单校验
* @param $menu
* @throws \Exception
* @author 段誉
* @date 2022/3/29 10:55
*/
public static function checkMenu($menu)
{
if (empty($menu) || !is_array($menu)) {
throw new \Exception('请设置正确格式菜单');
}
if (count($menu) > 3) {
throw new \Exception('一级菜单超出限制(最多3个)');
}
foreach ($menu as $item) {
if (!is_array($item)) {
throw new \Exception('一级菜单项须为数组格式');
}
if (empty($item['name'])) {
throw new \Exception('请输入一级菜单名称');
}
if (false == $item['has_menu']) {
if (empty($item['type'])) {
throw new \Exception('一级菜单未选择菜单类型');
}
if (!in_array($item['type'], OfficialAccountEnum::MENU_TYPE)) {
throw new \Exception('一级菜单类型错误');
}
self::checkType($item);
}
if (true == $item['has_menu'] && empty($item['sub_button'])) {
throw new \Exception('请配置子菜单');
}
self::checkType($item);
if (!empty($item['sub_button'])) {
self::checkSubButton($item['sub_button']);
}
}
}
/**
* @notes 二级菜单校验
* @param $subButtion
* @throws \Exception
* @author 段誉
* @date 2022/3/29 10:55
*/
public static function checkSubButton($subButtion)
{
if (!is_array($subButtion)) {
throw new \Exception('二级菜单须为数组格式');
}
if (count($subButtion) > 5) {
throw new \Exception('二级菜单超出限制(最多5个)');
}
foreach ($subButtion as $subItem) {
if (!is_array($subItem)) {
throw new \Exception('二级菜单项须为数组');
}
if (empty($subItem['name'])) {
throw new \Exception('请输入二级菜单名称');
}
if (empty($subItem['type']) || !in_array($subItem['type'], OfficialAccountEnum::MENU_TYPE)) {
throw new \Exception('二级未选择菜单类型或菜单类型错误');
}
self::checkType($subItem);
}
}
/**
* @notes 菜单类型校验
* @param $item
* @throws \Exception
* @author 段誉
* @date 2022/3/29 10:55
*/
public static function checkType($item)
{
switch ($item['type']) {
// 关键字
case 'click':
if (empty($item['key'])) {
throw new \Exception('请输入关键字');
}
break;
// 跳转网页链接
case 'view':
if (empty($item['url'])) {
throw new \Exception('请输入网页链接');
}
break;
// 小程序
case 'miniprogram':
if (empty($item['url'])) {
throw new \Exception('请输入网页链接');
}
if (empty($item['appid'])) {
throw new \Exception('请输入appid');
}
if (empty($item['pagepath'])) {
throw new \Exception('请输入小程序路径');
}
break;
}
}
/**
* @notes 保存发布菜单
* @param $params
* @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
* @author 段誉
* @date 2022/3/29 10:55
*/
public static function saveAndPublish($params)
{
try {
self::checkMenu($params);
$officialAccountSetting = (new OfficialAccountSettingLogic())->getConfig();
if (empty($officialAccountSetting['app_id']) || empty($officialAccountSetting['app_secret'])) {
throw new \Exception('请先配置好微信公众号');
}
$app = Factory::officialAccount([
'app_id' => $officialAccountSetting['app_id'],
'secret' => $officialAccountSetting['app_secret'],
'response_type' => 'array',
]);
$result = $app->menu->create($params);
if ($result['errcode'] == 0) {
ConfigService::set('oa_setting', 'menu', $params);
return true;
}
self::setError('保存发布菜单失败' . json_encode($result));
return false;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 查看菜单详情
* @return array|int|mixed|string|null
* @author 段誉
* @date 2022/3/29 10:56
*/
public static function detail()
{
$data = ConfigService::get('oa_setting', 'menu', []);
if (!empty($data)) {
foreach ($data as &$item) {
$item['has_menu'] = !empty($item['has_menu']);
}
}
return $data;
}
}

View File

@@ -0,0 +1,217 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\enum\OfficialAccountEnum;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\channel\OfficialAccountReply;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Text;
/**
* 微信公众号回复逻辑层
* Class OfficialAccountReplyLogic
* @package app\adminapi\logic\channel
*/
class OfficialAccountReplyLogic extends BaseLogic
{
/**
* @notes 添加回复(关注/关键词/默认)
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 10:57
*/
public static function add($params)
{
try {
// 关键字回复排序值须大于0
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] <= 0) {
throw new \Exception('排序值须大于0');
}
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
}
OfficialAccountReply::create($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 查看回复详情
* @param $params
* @return array
* @author 段誉
* @date 2022/3/29 11:00
*/
public static function detail($params)
{
$field = 'id,name,keyword,reply_type,matching_type,content_type,content,status,sort';
$field .= ',reply_type as reply_type_desc, matching_type as matching_type_desc, content_type as content_type_desc, status as status_desc';
return OfficialAccountReply::field($field)->findOrEmpty($params['id'])->toArray();
}
/**
* @notes 编辑回复(关注/关键词/默认)
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function edit($params)
{
try {
// 关键字回复排序值须大于0
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] <= 0) {
throw new \Exception('排序值须大于0');
}
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
}
OfficialAccountReply::update($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除回复(关注/关键词/默认)
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function delete($params)
{
OfficialAccountReply::destroy($params['id']);
}
/**
* @notes 更新排序
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function sort($params)
{
$params['sort'] = $params['new_sort'];
OfficialAccountReply::update($params);
}
/**
* @notes 更新状态
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function status($params)
{
$reply = OfficialAccountReply::findOrEmpty($params['id']);
$reply->status = !$reply->status;
$reply->save();
}
/**
* @notes 微信公众号回调
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \ReflectionException
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function index()
{
// 确认此次GET请求来自微信服务器原样返回echostr参数内容接入生效成为开发者成功
if (isset($_GET['echostr'])) {
echo $_GET['echostr'];
exit;
}
$officialAccountSetting = (new OfficialAccountSettingLogic())->getConfig();
$config = [
'app_id' => $officialAccountSetting['app_id'],
'secret' => $officialAccountSetting['app_secret'],
'response_type' => 'array',
];
$app = Factory::officialAccount($config);
$app->server->push(function ($message) {
switch ($message['MsgType']) { // 消息类型
case OfficialAccountEnum::MSG_TYPE_EVENT: // 事件
switch ($message['Event']) {
case OfficialAccountEnum::EVENT_SUBSCRIBE: // 关注事件
$reply_content = OfficialAccountReply::where(['reply_type' => OfficialAccountEnum::REPLY_TYPE_FOLLOW, 'status' => YesNoEnum::YES])
->value('content');
if (empty($reply_content)) {
// 未启用关注回复 或 关注回复内容为空
$reply_content = OfficialAccountReply::where(['reply_type' => OfficialAccountEnum::REPLY_TYPE_DEFAULT, 'status' => YesNoEnum::YES])
->value('content');
}
if ($reply_content) {
$text = new Text($reply_content);
return $text;
}
break;
}
break;
case OfficialAccountEnum::MSG_TYPE_TEXT: // 文本
$reply_list = OfficialAccountReply::where(['reply_type' => OfficialAccountEnum::REPLY_TYPE_KEYWORD, 'status' => YesNoEnum::YES])
->order('sort asc')
->select();
$reply_content = '';
foreach ($reply_list as $reply) {
switch ($reply['matching_type']) {
case OfficialAccountEnum::MATCHING_TYPE_FULL:
$reply['keyword'] === $message['Content'] && $reply_content = $reply['content'];
break;
case OfficialAccountEnum::MATCHING_TYPE_FUZZY:
stripos($message['Content'], $reply['keyword']) !== false && $reply_content = $reply['content'];
break;
}
if ($reply_content) {
break; // 得到回复文本,中止循环
}
}
//消息回复为空的话,找默认回复
if (empty($reply_content)) {
$reply_content = OfficialAccountReply::where(['reply_type' => OfficialAccountEnum::REPLY_TYPE_DEFAULT, 'status' => YesNoEnum::YES])
->value('content');
}
if ($reply_content) {
$text = new Text($reply_content);
return $text;
}
break;
}
});
$response = $app->server->serve();
$response->send();
}
}

View File

@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 公众号设置逻辑
* Class OfficialAccountSettingLogic
* @package app\adminapi\logic\channel
*/
class OfficialAccountSettingLogic extends BaseLogic
{
/**
* @notes 获取公众号配置
* @return array
* @author ljj
* @date 2022/2/16 10:08 上午
*/
public function getConfig()
{
$domainName = $_SERVER['SERVER_NAME'];
$qrCode = ConfigService::get('oa_setting', 'qr_code', '');
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
$config = [
'name' => ConfigService::get('oa_setting', 'name', ''),
'original_id' => ConfigService::get('oa_setting', 'original_id', ''),
'qr_code' => $qrCode,
'app_id' => ConfigService::get('oa_setting', 'app_id', ''),
'app_secret' => ConfigService::get('oa_setting', 'app_secret', ''),
// url()方法返回Url实例通过与空字符串连接触发该实例的__toString()方法以得到路由地址
'url' => url('adminapi/channel.official_account_reply/index', [],'',true).'',
'token' => ConfigService::get('oa_setting', 'token'),
'encoding_aes_key' => ConfigService::get('oa_setting', 'encoding_aes_key', ''),
'encryption_type' => ConfigService::get('oa_setting', 'encryption_type'),
'business_domain' => $domainName,
'js_secure_domain' => $domainName,
'web_auth_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置公众号配置
* @param $params
* @author ljj
* @date 2022/2/16 10:08 上午
*/
public function setConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('oa_setting','name', $params['name'] ?? '');
ConfigService::set('oa_setting','original_id', $params['original_id'] ?? '');
ConfigService::set('oa_setting','qr_code', $qrCode);
ConfigService::set('oa_setting','app_id',$params['app_id']);
ConfigService::set('oa_setting','app_secret',$params['app_secret']);
ConfigService::set('oa_setting','token',$params['token'] ?? '');
ConfigService::set('oa_setting','encoding_aes_key',$params['encoding_aes_key'] ?? '');
ConfigService::set('oa_setting','encryption_type',$params['encryption_type']);
}
}

View File

@@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* 微信开放平台
* Class AppSettingLogic
* @package app\adminapi\logic\settings\app
*/
class OpenSettingLogic extends BaseLogic
{
/**
* @notes 获取微信开放平台设置
* @return array
* @author 段誉
* @date 2022/3/29 11:03
*/
public static function getConfig()
{
$config = [
'app_id' => ConfigService::get('open_platform', 'app_id', ''),
'app_secret' => ConfigService::get('open_platform', 'app_secret', ''),
];
return $config;
}
/**
* @notes 微信开放平台设置
* @param $params
* @author 段誉
* @date 2022/3/29 11:03
*/
public static function setConfig($params)
{
ConfigService::set('open_platform', 'app_id', $params['app_id'] ?? '');
ConfigService::set('open_platform', 'app_secret', $params['app_secret'] ?? '');
}
}

View File

@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* H5设置逻辑层
* Class HFiveSettingLogic
* @package app\adminapi\logic\settings\h5
*/
class WebPageSettingLogic extends BaseLogic
{
/**
* @notes 获取H5设置
* @return array
* @author 段誉
* @date 2022/3/29 10:34
*/
public static function getConfig()
{
$config = [
// 渠道状态 0-关闭 1-开启
'status' => ConfigService::get('web_page', 'status', 1),
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
'page_status' => ConfigService::get('web_page', 'page_status', 0),
// 自定义链接
'page_url' => ConfigService::get('web_page', 'page_url', ''),
'url' => request()->domain() . '/mobile'
];
return $config;
}
/**
* @notes H5设置
* @param $params
* @author 段誉
* @date 2022/3/29 10:34
*/
public static function setConfig($params)
{
ConfigService::set('web_page', 'status', $params['status']);
ConfigService::set('web_page', 'page_status', $params['page_status']);
ConfigService::set('web_page', 'page_url', $params['page_url']);
}
}

View File

@@ -0,0 +1,619 @@
<?php
namespace app\adminapi\logic\coach;
use app\common\enum\accountLog\CoachAccountLogEnum;
use app\common\enum\coach\CoachEnum;
use app\common\enum\DefaultEnum;
use app\common\enum\notice\NoticeEnum;
use app\common\enum\shop\ShopEnum;
use app\common\logic\CoachAccountLogLogic;
use app\common\model\coach\Coach;
use app\common\model\coach\CoachGoodsIndex;
use app\common\model\coach\CoachLifePhoto;
use app\common\model\coach\CoachUpdate;
use app\common\model\coach\CoachUser;
use app\common\model\goods\Goods;
use app\common\model\skill\Skill;
use app\common\service\ConfigService;
use app\common\service\FileService;
use think\Exception;
use think\facade\Config;
use think\facade\Db;
/**
* 技师逻辑类
* Class CoachLogic
* @package app\adminapi\logic\coach
*/
class CoachLogic
{
/**
* @notes 技师账号列表
* @return CoachUser[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/20 17:33
*/
public function coachUserLists()
{
$coachUserIds = Coach::where('audit_status','<>',CoachEnum::AUDIT_STATUS_PASS)->column('coach_user_id');
return CoachUser::where('id','not in',$coachUserIds)->field('id,sn,account')->select()->toArray();
}
/**
* @notes 技能列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/20 18:02
*/
public function skillLists($shopId = 0)
{
$whereShop = [];
if($shopId){
$whereShop[] = ['G.shop_id','in',[0,$shopId]];
}else{
$whereShop[] = ['G.shop_id','=',0];
}
$skillLists = Skill::field('name,id')->select()->toArray();
$goodsLists = Goods::alias('G')
->where(['G.status'=>1,'G.audit_status'=>1])
->where($whereShop)
->append(['category_desc','skill_desc'])
->join('goods_skill_index GSI','G.id = GSI.goods_id')
->field('G.id,G.price,G.name,G.category_id,G.image,GSI.skill_id')
->select()->toArray();
foreach ($skillLists as $key => $skill){
$skillGoodsLists = [];
foreach ($goodsLists as $goods){
if($skill['id'] == $goods['skill_id']){
$skillGoodsLists[] = $goods;
}
}
$skillLists[$key]['goods_list'] = $skillGoodsLists;
}
return $skillLists;
}
/**
* @notes 添加
* @param array $params
* @return string|true
* @throws \Exception
* @author cjhao
* @date 2024/8/21 15:49
*/
public function add(array $params)
{
try {
Db::startTrans();
$number = CoachUser::count()+1;
$sn = sprintf("%03d", $number);
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['mobile'], $passwordSalt);
$avatar = ConfigService::get('default_image', 'user_avatar');
$coachUser = CoachUser::where(['account'=>$params['mobile']])->findOrEmpty();
if(!$coachUser->isEmpty()){
throw new Exception('手机号码已重复');
}
$coachUser = CoachUpdate::where(['mobile'=>$params['mobile'],'audit_status'=>CoachEnum::AUDIT_STATUS_WAIT])->findOrEmpty();
if(!$coachUser->isEmpty()){
throw new Exception('手机号码已重复');
}
$coachUser = CoachUser::create([
'sn' => $sn,
'avatar' => $avatar,
'account' => $params['mobile'],
'password' => $password,
// 'channel' => $params['channel'],
]);
$coach = new Coach();
$coach->name = $params['name'];
$coach->sn = $coachUser->sn;
$coach->gender = $params['gender'];
$coach->age = $params['age'];
$coach->id_card = $params['id_card'];
$coach->mobile = $params['mobile'];
$coach->education = $params['education'];
$coach->nation = $params['nation'];
$coach->province_id = $params['province_id'];
$coach->city_id = $params['city_id'];
$coach->region_id = $params['region_id'];
$coach->longitude = $params['longitude'];
$coach->latitude = $params['latitude'];
$coach->address_detail = $params['address_detail'];
$coach->coach_user_id = $coachUser->id;
$coach->skill_id = $params['skill_id'];
$coach->id_card_front = $params['id_card_front'];
$coach->id_card_back = $params['id_card_back'];
$coach->portrait_shooting = $params['portrait_shooting'];
$coach->work_photo = $params['work_photo'];
$coach->certification = $params['certification'] ?? '';
$coach->health_certificate = $params['health_certificate'] ?? '';
$coach->work_status = $params['work_status'];
$coach->server_status = $params['server_status'];
$coach->longitude = $params['longitude'] ?? '';
$coach->latitude = $params['latitude'] ?? '';
$coach->audit_status = CoachEnum::AUDIT_STATUS_PASS;
$coach->save();
//生活照
$lifePhoto = $params['life_photo'] ?? [];
$lifePhotoLists = [];
foreach ($lifePhoto as $photo){
$lifePhotoLists[] = [
'uri' => $photo,
'coach_id' => $coach->id
];
}
(new CoachLifePhoto())->saveAll($lifePhotoLists);
//关联服务
$goodsIds = $params['goods_ids'] ?? [];
$goodsLists = [];
foreach ($goodsIds as $goodsId)
{
$goodsLists[] = [
'goods_id' => $goodsId,
'coach_id' => $coach->id,
];
}
(new CoachGoodsIndex())->saveAll($goodsLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 详情
* @param int $id
* @return array
* @author cjhao
* @date 2024/8/21 15:30
*/
public function detail(int $id)
{
$coach = (new Coach())
->where(['id'=>$id])
->append(['province_name','city_name','region_name','region_desc','life_photo'])
->withoutField('create_time,update_time,delete_time')
->findOrEmpty()
->toArray();
$goodsLists = Goods::alias('G')
->where(['CGI.coach_id'=>$id])
->join('coach_goods_index CGI','G.id=CGI.goods_id')
->field('G.id,G.name,G.image')
->select()->toArray();
$coach['life_photo'] = array_column($coach['life_photo']->toArray(),'uri');
$coach['goods_lists'] = $goodsLists;
$coach['goods_ids'] = array_column($goodsLists,'id');
return $coach;
}
/**
* @notes 编辑
* @param array $params
* @return string|true
* @throws \Exception
* @author cjhao
* @date 2024/8/21 15:50
*/
public function edit(array $params)
{
try {
Db::startTrans();
$coach = Coach::find($params['id']);
$coachUser = CoachUser::where('id','<>',$coach['coach_user_id'])
->where('account','=',$params['mobile'])
->findOrEmpty();
if(!$coachUser->isEmpty()){
throw new Exception('手机号码已存在');
}
$coachUser = CoachUpdate::where('mobile','=',$params['mobile'])
->where(['audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])
->where('coach_user_id','<>',$coach['coach_user_id'])
->findOrEmpty();
if(!$coachUser->isEmpty()){
throw new Exception('手机号码已存在');
}
CoachUser::update(['account'=>$params['mobile']],['id'=>$coach['coach_user_id']]);
$coach->name = $params['name'];
$coach->gender = $params['gender'];
$coach->age = $params['age'];
$coach->id_card = $params['id_card'];
$coach->mobile = $params['mobile'];
$coach->education = $params['education'];
$coach->nation = $params['nation'];
$coach->province_id = $params['province_id'];
$coach->city_id = $params['city_id'];
$coach->region_id = $params['region_id'];
$coach->longitude = $params['longitude'];
$coach->latitude = $params['latitude'];
$coach->address_detail = $params['address_detail'];
// $coach->coach_user_id = $params['coach_user_id'];
$coach->skill_id = $params['skill_id'];
$coach->id_card_front = $params['id_card_front'];
$coach->id_card_back = $params['id_card_back'];
$coach->portrait_shooting = $params['portrait_shooting'];
$coach->work_photo = $params['work_photo'];
$coach->certification = $params['certification'] ?? '';
$coach->health_certificate = $params['health_certificate'] ?? '';
$workStatus = $params['work_status'];
if( 0 == $params['server_status']){
$workStatus = 0;
}
$coach->work_status = $workStatus;
$coach->server_status = $params['server_status'];
$coach->save();
(new CoachLifePhoto())->where(['coach_id'=>$params['id']])->delete();
(new CoachGoodsIndex())->where(['coach_id'=>$params['id']])->delete();
//生活照
$lifePhoto = $params['life_photo'] ?? [];
$lifePhotoLists = [];
foreach ($lifePhoto as $photo){
$lifePhotoLists[] = [
'uri' => $photo,
'coach_id' => $coach->id
];
}
(new CoachLifePhoto())->saveAll($lifePhotoLists);
//关联服务
$goodsIds = $params['goods_ids'] ?? [];
$goodsLists = [];
foreach ($goodsIds as $goodsId)
{
$goodsLists[] = [
'goods_id' => $goodsId,
'coach_id' => $coach->id,
];
}
(new CoachGoodsIndex())->saveAll($goodsLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 其他数据
* @return array
* @author cjhao
* @date 2024/8/21 18:16
*/
public function otherLists()
{
$educationLists = DefaultEnum::getEducationLists();
$nationLists = DefaultEnum::getNationLists();
return [
'education_lists' => $educationLists,
'nation_lists' => $nationLists,
];
}
/**
* @notes 调整佣金
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/8/23 15:04
*/
public function adjustMoney(array $params)
{
try {
Db::startTrans();
$coach = Coach::where(['id'=>$params['id']])->findOrEmpty();
if($coach->isEmpty()){
return '技师不存在';
}
$action = $params['action'];
if(1 == $action){
$coach->money = $coach->money+$params['money'];
$coach->save();
CoachAccountLogLogic::add(
$coach->id,
CoachAccountLogEnum::MONEY,
CoachAccountLogEnum::ADMIN_INC_MONEY,
$action,
$params['money'],
'',
$params['admin_id']
);
}else{
if($params['money'] > $coach->money){
return '当前技师佣金仅剩:'.$coach->money;
}
$coach->money = $coach->money - $params['money'];
$coach->save();
CoachAccountLogLogic::add(
$coach->id,
CoachAccountLogEnum::MONEY,
CoachAccountLogEnum::ADMIN_DEC_MONEY,
2,
$params['money'],
'',
$params['admin_id']
);
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 调整佣金
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/8/23 15:04
*/
public function adjustDeposit(array $params)
{
try {
Db::startTrans();
$coach = Coach::where(['id'=>$params['id']])->findOrEmpty();
if($coach->isEmpty()){
return '技师不存在';
}
$action = $params['action'];
if(1 == $action){
$coach->deposit = $coach->deposit+$params['money'];
$coach->save();
CoachAccountLogLogic::add(
$coach->id,
CoachAccountLogEnum::DEPOSIT,
CoachAccountLogEnum::ADMIN_INC_DEPOSIT,
$action,
$params['money'],
'',
$params['admin_id']
);
}else{
if($params['money'] > $coach->deposit){
return '当前技师保证金仅剩:'.$coach->deposit;
}
$coach->deposit = $coach->deposit - $params['money'];
$coach->save();
CoachAccountLogLogic::add(
$coach->id,
CoachAccountLogEnum::DEPOSIT,
CoachAccountLogEnum::ADMIN_DEC_DEPOSIT,
$action,
$params['money'],
'',
$params['admin_id']
);
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/***
* @notes 技师审核
* @param $params
* @return string|true
* @author cjhao
* @date 2024/8/23 18:47
*/
public function coachAudit($params)
{
try {
// Db::startTrans();
$coach = Coach::where(['id'=>$params['id']])->findOrEmpty();
if($coach->isEmpty()){
return '技师不存在';
}
if(CoachEnum::AUDIT_STATUS_WAIT != $coach->audit_status){
return '技师的审核状态已改变,请刷新页面';
}
$status = CoachEnum::AUDIT_STATUS_PASS;
if(0 == $params['audit_status']){
$status = CoachEnum::AUDIT_STATUS_REFUSE;
}
$coach->audit_status = $status;
$coach->audit_remark = $params['audit_remark'] ?? '';
$coach->save();
if(CoachEnum::AUDIT_STATUS_PASS == $status){
//入驻申请成功通知-师傅
event('Notice', [
'scene_id' => NoticeEnum::APPLY_SUCCESS_NOTICE_STAFF,
'params' => [
'coach_id' => $coach['id'],
]
]);
}else{
//入驻申请失败通知-师傅
event('Notice', [
'scene_id' => NoticeEnum::APPLY_FAIL_NOTICE_STAFF,
'params' => [
'coach_id' => $coach['id'],
]
]);
}
return true;
}catch (Exception $e){
// Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 获取技师详情
* @param int $id
* @return array
* @author cjhao
* @date 2024/8/28 11:28
*/
public function updateDetail(int $id)
{
$updateCoach = (new CoachUpdate())
->where(['id'=>$id])
->append(['goods_lists'])
->withoutField('create_time,update_time,delete_time')
->findOrEmpty()
->toArray();
$coach = (new Coach())
->where(['id'=>$updateCoach['coach_id'],'audit_status'=>CoachEnum::AUDIT_STATUS_PASS])
->append(['life_photo','goods_ids'])
->withoutField('create_time,update_time,delete_time')
->findOrEmpty()
->toArray();
foreach ($updateCoach as $key => $update){
$cancel = ['id','goods_lists','coach_id','coach_user_id'];
if(in_array($key,$cancel)){
continue;
}
$data = $coach[$key] ?? '';
$updateCoach[$key.'_update'] = $update != $data ?: false;
if('goods_ids' == $key && $data){
$goodsIds = array_column($data->toArray(),'goods_id');
sort($goodsIds);
sort($update);
$updateCoach[$key.'_update'] = $update != $goodsIds ?: false;
}
if('life_photo' == $key && $data){
$uriLists = array_column($data->toArray(),'uri');
foreach ($uriLists as $uriKey => $uri){
$uriLists[$uriKey] = FileService::setFileUrl($uri);
}
sort($uriLists);
sort($update);
$updateCoach[$key.'_update'] = $uriLists != $update ?: false;
}
}
return $updateCoach;
}
/**
* @notes 技师资料审核
* @param $params
* @return string|true
* @throws \Exception
* @author cjhao
* @date 2024/8/28 11:31
*/
public function updateAudit($params)
{
try {
Db::startTrans();
$coachUpdate = CoachUpdate::where(['id'=>$params['id']])->findOrEmpty();
if($coachUpdate->isEmpty()){
return '申请记录不存在';
}
if(CoachEnum::AUDIT_STATUS_WAIT != $coachUpdate->audit_status){
return '申请的审核状态已改变,请刷新页面';
}
$status = CoachEnum::AUDIT_STATUS_PASS;
if(0 == $params['audit_status']){
$status = CoachEnum::AUDIT_STATUS_REFUSE;
}
$coachUpdate->audit_status = $status;
$coachUpdate->audit_remark = $params['audit_remark'] ?? '';
$coachUpdate->save();
if(0 == $params['audit_status']){
Db::commit();
return true;
}
$coach = Coach::where(['id'=>$coachUpdate->coach_id])->findOrEmpty();
$coach->name = $coachUpdate->name;
$coach->gender = $coachUpdate->gender;
$coach->age = $coachUpdate->age;
$coach->id_card = $coachUpdate->id_card;
// $coach->mobile = $coachUpdate->mobile;
$coach->education = $coachUpdate->education;
$coach->nation = $coachUpdate->nation;
$coach->province_id = $coachUpdate->province_id;
$coach->city_id = $coachUpdate->city_id;
$coach->region_id = $coachUpdate->region_id;
$coach->latitude = $coachUpdate->latitude;
$coach->longitude = $coachUpdate->longitude;
$coach->address_detail = $coachUpdate->address_detail;
$coach->coach_user_id = $coachUpdate->coach_user_id;
$coach->skill_id = $coachUpdate->skill_id;
$coach->id_card_front = $coachUpdate->id_card_front;
$coach->id_card_back = $coachUpdate->id_card_back;
$coach->portrait_shooting = $coachUpdate->portrait_shooting;
// $coach->work_photo = $coachUpdate->work_photo;
$coach->certification = $coachUpdate->certification;
$coach->health_certificate = $coachUpdate->health_certificate;
// $coach->work_status = $coachUpdate->work_status;
// $coach->server_status = $coachUpdate->server_status;
$coach->save();
(new CoachLifePhoto())->where(['coach_id'=>$coach->id])->delete();
(new CoachGoodsIndex())->where(['coach_id'=>$coach->id])->delete();
//生活照
$lifePhoto = $coachUpdate->life_photo;
$lifePhotoLists = [];
foreach ($lifePhoto as $photo){
$lifePhotoLists[] = [
'uri' => $photo,
'coach_id' => $coach->id
];
}
(new CoachLifePhoto())->saveAll($lifePhotoLists);
//关联服务
$goodsIds = $coachUpdate->goods_ids ;
$goodsLists = [];
foreach ($goodsIds as $goodsId)
{
$goodsLists[] = [
'goods_id' => $goodsId,
'coach_id' => $coach->id,
];
}
(new CoachGoodsIndex())->saveAll($goodsLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
}

View File

@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\coach;
use app\common\logic\BaseLogic;
use app\common\model\deposit\DepositPackage;
class DepositPackageLogic extends BaseLogic
{
/**
* @notes 添加
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
DepositPackage::create([
'name' => $params['name'],
'money' => $params['money'],
'order_limit' => $params['order_limit'],
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = DepositPackage::where('id',$id)->withoutField('update_time,delete_time')->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
DepositPackage::update([
'name' => $params['name'],
'money' => $params['money'],
'order_limit' => $params['order_limit'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return DepositPackage::destroy($id);
}
}

View File

@@ -0,0 +1,104 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\coach;
use app\common\logic\BaseLogic;
use app\common\model\goods\GoodsCategory;
use app\common\model\skill\Skill;
class SKillLogic extends BaseLogic
{
/**
* @notes 添加
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
Skill::create([
'name' => $params['name'],
'is_show' => $params['is_show'],
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = Skill::where('id',$id)->withoutField('update_time,delete_time')->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
Skill::update([
'name' => $params['name'],
'is_show' => $params['is_show'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return Skill::destroy($id);
}
/**
* @notes 修改状态
* @param $params
* @return bool
* @author ljj
* @date 2022/2/10 10:57 上午
*/
public function status($params)
{
Skill::update(['is_show'=>$params['is_show']],['id'=>$params['id']]);
return true;
}
}

View File

@@ -0,0 +1,172 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\crontab;
use app\common\enum\CrontabEnum;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\Crontab;
use app\common\service\ConfigService;
use app\common\service\CrontabService;
use Cron\CronExpression;
/**
* 定时任务逻辑层
* Class CrontabLogic
* @package app\adminapi\logic\crontab
*/
class CrontabLogic extends BaseLogic
{
/**
* @notes 添加定时任务
* @param $params
* @return bool
* @author Tab
* @date 2021/8/17 11:47
*/
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 Tab
* @date 2021/8/17 11:58
*/
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 Tab
* @date 2021/8/17 12:02
*/
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 Tab
* @date 2021/8/17 14:13
*/
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 Tab
* @date 2021/8/17 15:28
*/
public static function operate($params)
{
try {
$crontab = Crontab::findOrEmpty($params['id']);
if($crontab->isEmpty()) {
throw new \think\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 Tab
* @date 2021/8/17 15:42
*/
public static function expression($params)
{
try {
$cron = new \Cron\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,56 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\decorate;
use app\common\logic\BaseLogic;
use app\common\model\article\Article;
/**
* 装修页-数据
* Class DecorateDataLogic
* @package app\adminapi\logic\decorate
*/
class DecorateDataLogic extends BaseLogic
{
/**
* @notes 获取文章列表
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/22 16:49
*/
public static function getArticleLists($limit)
{
$field = 'id,title,desc,abstract,image,author,content,
click_virtual,click_actual,create_time';
return Article::where(['is_show' => 1])
->field($field)
->order(['id' => 'desc'])
->limit($limit)
->append(['click'])
->hidden(['click_virtual', 'click_actual'])
->select()->toArray();
}
}

View File

@@ -0,0 +1,82 @@
<?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\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\decorate\DecoratePage;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\staff\Staff;
/**
* 装修页面
* Class DecoratePageLogic
* @package app\adminapi\logic\theme
*/
class DecoratePageLogic extends BaseLogic
{
/**
* @notes 获取详情
* @param $id
* @return array
* @author 段誉
* @date 2022/9/14 18:41
*/
public static function getDetail($type,$source)
{
$result = DecoratePage::where(['type'=>$type,'source'=>$source])->findOrEmpty()->toArray();
if(5 == $type && 1 == $source ){
$dataLists = json_decode($result['data'],true);
foreach ($dataLists as $key => $data){
if('goods-comment' == $data['name'] && !isset($data['content']['enabled'])){
$dataLists[$key]['content']['enabled'] = 1;
}
}
$result['data'] = json_encode($dataLists);
}
return $result;
}
/**
* @notes 保存装修配置
* @param $params
* @return bool
* @author 段誉
* @date 2022/9/15 9:37
*/
public static function save($params)
{
$pageData = DecoratePage::where(['id' => $params['id']])->findOrEmpty();
if ($pageData->isEmpty()) {
self::$error = '信息不存在';
return false;
}
DecoratePage::update([
'id' => $params['id'],
// 'type' => $params['type'],
'data' => $params['data'],
'meta' => $params['meta'],
]);
return true;
}
}

View File

@@ -0,0 +1,73 @@
<?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\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\decorate\DecoratePage;
use app\common\model\decorate\DecorateStyle;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\staff\Staff;
/**
* 装修页面
* Class DecorateStyleLogic
* @package app\adminapi\logic\theme
*/
class DecorateStyleLogic extends BaseLogic
{
/**
* @notes 获取详情
* @param $id
* @return array
* @author 段誉
* @date 2022/9/14 18:41
*/
public static function getDetail($source)
{
$result = DecorateStyle::where(['source'=>$source])->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 保存装修配置
* @param $params
* @return bool
* @author 段誉
* @date 2022/9/15 9:37
*/
public static function save($params)
{
$pageData = DecorateStyle::where(['id' => $params['id']])->findOrEmpty();
if ($pageData->isEmpty()) {
self::$error = '信息不存在';
return false;
}
DecorateStyle::update([
'id' => $params['id'],
// 'type' => $params['type'],
'data' => $params['data'],
]);
return true;
}
}

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\decorate;
use app\common\logic\BaseLogic;
use app\common\model\decorate\DecorateTabbar;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 装修配置-底部导航
* Class DecorateTabbarLogic
* @package app\adminapi\logic\decorate
*/
class DecorateTabbarLogic extends BaseLogic
{
/**
* @notes 获取底部导航详情
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/7 16:58
*/
public static function detail($source): array
{
$detail = DecorateTabbar::where(['source'=>$source])->findOrEmpty()->toArray();
return $detail;
}
/**
* @notes 底部导航保存
* @param $params
* @return bool
* @throws \Exception
* @author 段誉
* @date 2022/9/7 17:19
*/
public static function save($params): bool
{
DecorateTabbar::update([
'id' => $params['id'],
'data' => $params['data'],
]);
return true;
}
}

View File

@@ -0,0 +1,179 @@
<?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\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();
}
}

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

View File

@@ -0,0 +1,88 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\finance;
use app\common\enum\accountLog\CoachAccountLogEnum;
use app\common\enum\accountLog\ShopAccountLogEnum;
use app\common\enum\OrderEnum;
use app\common\enum\OrderRefundEnum;
use app\common\enum\PayEnum;
use app\common\logic\BaseLogic;
use app\common\model\accountLog\CoachAccountLog;
use app\common\model\accountLog\ShopAccountLog;
use app\common\model\coach\Coach;
use app\common\model\order\Order;
use app\common\model\order\OrderRefund;
use app\common\model\RechargeOrder;
use app\common\model\settle\Settle;
use app\common\model\shop\Shop;
use app\common\model\user\User;
class CenterLogic extends BaseLogic
{
/**
* @notes 财务中心
* @return array
* @author ljj
* @date 2022/9/9 6:28 下午
*/
public function center()
{
$managementForms = [
//累计营业额
'total_amount' => Order::where(['pay_status'=>PayEnum::ISPAID])->sum('total_order_amount'),
//累计成交订单
'total_order' => Order::where(['pay_status'=>PayEnum::ISPAID])->count(),
//已退款金额
'total_refund_amount' => OrderRefund::where(['refund_status'=>OrderRefundEnum::STATUS_SUCCESS])->sum('refund_amount'),
//退款失败金额
'fail_refund_amount' => OrderRefund::where(['refund_status'=>OrderRefundEnum::STATUS_FAIL])->sum('refund_amount'),
];
$userRecharge = [
'total_user_recharge_money' => RechargeOrder::where(['pay_status'=>PayEnum::ISPAID])->sum('order_amount'),
'total_user_money' => User::sum('user_money'),
];
$coachInfo = [
'total_coach_commission' => Settle::sum('total_coach_commission'),
'total_withdraw_commission' => CoachAccountLog::where(['change_type'=>CoachAccountLogEnum::WITHDRAW_DEC_MONEY])->sum('change_amount'),
'total_may_withdraw_commission' => Coach::sum('money'),
'total_wait_settle_commission' => Order::where(['order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH])->sum('total_order_amount'),
];
$coachIds = Coach::where('shop_id','>',0)->field('id')->select()->toArray();
$coachIds = array_column($coachIds,'id');
$shopInfo = [
'total_shop_commission' => Settle::sum('total_shop_commission'),
'total_withdraw_commission' => ShopAccountLog::where(['change_type'=>ShopAccountLogEnum::WITHDRAW_DEC_MONEY])->sum('change_amount'),
'total_may_withdraw_commission' => Shop::sum('money'),
'total_wait_settle_commission' => Order::where(['coach_id'=>$coachIds,'order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH])->sum('total_order_amount'),
];
$depositInfo = [
'total_coach_deposit' => Coach::sum('deposit'),
'total_shop_deposit' => Shop::sum('deposit'),
];
return [
'management_forms' => $managementForms,
'user_recharge' => $userRecharge,
'coach_info' => $coachInfo,
'shop_info' => $shopInfo,
'deposit_info' => $depositInfo,
];
}
}

View File

@@ -0,0 +1,256 @@
<?php
namespace app\adminapi\logic\finance;
use app\common\enum\accountLog\CoachAccountLogEnum;
use app\common\enum\accountLog\ShopAccountLogEnum;
use app\common\logic\CoachAccountLogLogic;
use app\common\logic\ShopAccountLogLogic;
use app\common\model\coach\Coach;
use app\common\model\shop\Shop;
use app\common\model\withdraw\WithdrawApply;
use Exception;
use think\facade\Db;
class WithdrawLogic
{
/**
* @notes 详情
* @param $id
* @return WithdrawApply|array|\think\Model
* @author cjhao
* @date 2024/10/31 16:22
*/
public function detail($id)
{
$detail = WithdrawApply::where(['id'=>$id])->append(['apply_type_desc'])->findOrEmpty();
if(1 == $detail['source']){
$detail['relation_info'] = Coach::where(['id'=>$detail['relation_id']])->field('id,name,sn,work_photo as image,mobile')->findOrEmpty()->toArray();
}else {
$detail['relation_info'] = Shop::where(['id' => $detail['relation_id']])->field('id,name,sn,logo as image,mobile')->findOrEmpty()->toArray();
}
return $detail->toArray();
}
/**
* @notes 审核
* @param $params
* @return string|true
* @author cjhao
* @date 2024/10/31 17:44
*/
public function audit($params)
{
try {
Db::startTrans();
$id = $params['id'] ?? '';
$status = $params['status'] ?? '';
$remark = $params['remark'] ?? '';
if(empty($id)){
throw new Exception('请选择提现记录');
}
if('' == $status){
throw new Exception('请选择审核操作');
}
if(empty($remark) && 0 == $status){
throw new Exception('请输入备注');
}
$apply = WithdrawApply::where(['id'=>$id])->findOrEmpty();
if(1 != $apply->status){
throw new Exception('记录状态已改变');
}
$auditStatus = 2;
if(0 == $status){
$auditStatus = 3;
}
$apply->status = $auditStatus;
$apply->verify_remark = $remark;
$apply->save();
//拒绝,退回余额
if(0 == $status){
//申请类型
if(1 == $apply['apply_type']){
//类型
if( 1 == $apply['source']){
$relation = Coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
//余额
$relation->money = round($relation->money+$apply['money']);
$relation->save();
CoachAccountLogLogic::add(
$relation->id,
CoachAccountLogEnum::MONEY,
CoachAccountLogEnum::WITHDRAW_INC_MONEY,
1,
$apply['money'],
$apply['sn']
);
}else{
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
//余额
$relation->money = round($relation->money+$apply['money']);
$relation->save();
ShopAccountLogLogic::add(
$relation->id,
ShopAccountLogEnum::MONEY,
ShopAccountLogEnum::WITHDRAW_INC_MONEY,
1,
$apply['money'],
$apply['sn']
);
}
}else{
if( 1 == $apply['source']){
$relation = coach::where(['id'=> $apply['relation_id']])->findOrEmpty();
//余额
$relation->deposit = round($relation->deposit+$apply['money']);
$relation->save();
CoachAccountLogLogic::add(
$relation->id,
CoachAccountLogEnum::DEPOSIT,
CoachAccountLogEnum::WITHDRAW_INC_DEPOSIT,
1,
$apply['money'],
$apply['sn']
);
}else{
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
//余额
$relation->deposit = round($relation->deposit+$apply['money']);
$relation->save();
ShopAccountLogLogic::add(
$relation->id,
ShopAccountLogEnum::DEPOSIT,
ShopAccountLogEnum::WITHDRAW_INC_DEPOSIT,
1,
$apply['money'],
$apply['sn']
);
}
}
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 转账
* @param $params
* @return string|true
* @author cjhao
* @date 2024/10/31 18:13
*/
public function transfer($params)
{
try {
Db::startTrans();
$id = $params['id'] ?? '';
$status = $params['status'] ?? '';
$remark = $params['remark'] ?? '';
$transferProof = $params['transfer_proof'] ?? '';
if(empty($id)){
throw new Exception('请选择提现记录');
}
if('' == $status){
throw new Exception('请选择审核操作');
}
if(empty($remark) && 0 == $status){
throw new Exception('请输入备注');
}
$auditStatus = 5;
if(1 == $status){
if(empty($transferProof)){
throw new Exception('请上传转账凭证');
}
}else{
$auditStatus = 6;
}
$apply = WithdrawApply::where(['id'=>$id])->findOrEmpty();
$apply->status = $auditStatus;
$apply->verify_remark = $remark;
$apply->transfer_proof = $transferProof;
$apply->save();
//拒绝,退回余额
if(0 == $status){
//申请类型
if(1 == $apply['apply_type']){
//类型
if( 1 == $apply['source']){
$relation = Coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
//余额
$relation->money = round($relation->money+$apply['money']);
$relation->save();
CoachAccountLogLogic::add(
$relation->id,
CoachAccountLogEnum::MONEY,
CoachAccountLogEnum::WITHDRAW_INC_MONEY,
1,
$apply['money'],
);
}else{
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
//余额
$relation->money = round($relation->money+$apply['money']);
$relation->save();
ShopAccountLogLogic::add(
$relation->id,
ShopAccountLogEnum::MONEY,
ShopAccountLogEnum::WITHDRAW_INC_MONEY,
1,
$apply['money'],
);
}
}else{
if( 1 == $apply['source']){
$relation = coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
//余额
$relation->deposit = round($relation->deposit+$apply['money']);
$relation->save();
CoachAccountLogLogic::add(
$relation->id,
CoachAccountLogEnum::DEPOSIT,
CoachAccountLogEnum::WITHDRAW_INC_DEPOSIT,
1,
$apply['money'],
);
}else{
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
//余额
$relation->deposit = round($relation->deposit+$apply['money']);
$relation->save();
ShopAccountLogLogic::add(
$relation->id,
ShopAccountLogEnum::DEPOSIT,
ShopAccountLogEnum::WITHDRAW_INC_DEPOSIT,
1,
$apply['money'],
);
}
}
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
}

View File

@@ -0,0 +1,154 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\goods;
use app\common\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\goods\GoodsCategory;
class GoodsCategoryLogic extends BaseLogic
{
/**
* @notes 通用分类列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/2/8 6:09 下午
*/
public function commonLists($is_son)
{
$where = [];
if ($is_son) {
$where[] = ['level','=',2];
}
$lists = (new GoodsCategory())->field('id,name,pid,level')
->where(['is_show'=>DefaultEnum::SHOW])
->where($where)
->order(['sort'=>'desc','id'=>'asc'])
->select()
->toArray();
if (!$is_son) {
$lists = linear_to_tree($lists,'sons');
}
return $lists;
}
/**
* @notes 添加服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
$level = isset($params['pid']) ? (GoodsCategory::where('id',$params['pid'])->value('level') + 1) : 1;
$is_recommend = $params['is_recommend'] ?? 0;
if (isset($params['pid']) && $params['pid'] > 0) {
$is_recommend = GoodsCategory::where('id',$params['pid'])->value('is_recommend');
}
GoodsCategory::create([
'name' => $params['name'],
'pid' => $params['pid'] ?? 0,
'level' => $level,
'image' => $params['image'] ?? '',
'sort' => $params['sort'] ?? DefaultEnum::SORT,
'is_show' => $params['is_show'],
'is_recommend' => $is_recommend,
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = GoodsCategory::where('id',$id)->findOrEmpty()->toArray();
$result['pid'] = $result['pid'] ?: '';
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
$level = isset($params['pid']) ? (GoodsCategory::where('id',$params['pid'])->value('level') + 1) : 1;
GoodsCategory::update([
'name' => $params['name'],
'pid' => $params['pid'] ?? 0,
'level' => $level,
'image' => $params['image'] ?? '',
'sort' => $params['sort'],
'is_show' => $params['is_show'],
'is_recommend' => $params['is_recommend'] ?? 0,
],['id'=>$params['id']]);
//更新下级首页推荐
GoodsCategory::update([
'is_recommend' => $params['is_recommend'] ?? 0,
],['pid'=>$params['id']]);
return true;
}
/**
* @notes 删除服务分类
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return GoodsCategory::destroy($id);
}
/**
* @notes 修改服务分类状态
* @param $params
* @return bool
* @author ljj
* @date 2022/2/10 10:57 上午
*/
public function status($params)
{
GoodsCategory::update(['is_show'=>$params['is_show']],['id'=>$params['id']]);
return true;
}
}

View File

@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\goods;
use app\common\logic\BaseLogic;
use app\common\model\goods\GoodsComment;
class GoodsCommentLogic extends BaseLogic
{
/**
* @notes 服务评价回复
* @param $params
* @return bool
* @author ljj
* @date 2022/2/9 7:02 下午
*/
public function reply($params)
{
GoodsComment::update(['reply'=>$params['remark'] ?? '','status'=>1],['id'=>$params['id']]);
return true;
}
/**
* @notes 回复详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/10 9:40 上午
*/
public function detail($id)
{
return GoodsComment::where(['id'=>$id])->field('id,reply')->findOrEmpty()->toArray();
}
/**
* @notes 删除服务评价
* @param $id
* @return bool
* @author ljj
* @date 2022/2/10 9:41 上午
*/
public function del($id)
{
return GoodsComment::destroy($id);
}
}

View File

@@ -0,0 +1,315 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\goods;
use app\common\enum\DefaultEnum;
use app\common\enum\GoodsEnum;
use app\common\logic\BaseLogic;
use app\common\model\city\City;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\goods\GoodsCityIndex;
use app\common\model\goods\GoodsImage;
use app\common\model\goods\GoodsSkillIndex;
use app\common\model\skill\Skill;
use think\facade\Db;
class GoodsLogic extends BaseLogic
{
/**
* @notes 分类列表
* @return GoodsCategory[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 15:41
*/
public function categoryLists()
{
return GoodsCategory::where(['is_show'=>1,'level'=>1])
// ->with(['son'])
->withCount(['goods'])
->field('id,name,image,is_show')
->select()
->toArray();
}
/**
* @notes 城市列表
* @return City[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 15:55
*/
public function cityLists(){
return City::field('city_id as id,name')->select()->toArray();
}
/**
* @notes 技能列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 16:34
*/
public function skillLists()
{
return Skill::field('id,name')->select()->toArray();
}
/**
* @notes 添加服务
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/9 3:28 下午
*/
public function add($params)
{
// 启动事务
Db::startTrans();
try {
$goodsImage = $params['goods_image'];
$image = array_shift($params['goods_image']);
//添加服务信息
$goods = Goods::create([
'name' => $params['name'],
'category_id' => $params['category_id'],
'image' => $image,
'price' => $params['price'],
'duration' => $params['duration'],
'scribing_price' => $params['scribing_price'] ?? 0.00,
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
'tags' => $params['tags'] ?? '',
'content' => $params['content'] ?? '',
'overtime_price' => $params['overtime_price'] ?? '',
'overtime_duration' => $params['overtime_duration'] ?? '',
'commission_ratio' => $params['commission_ratio'] ?? '',
'shop_ratio' => $params['shop_ratio'] ?? '',
'virtual_order_num' => $params['virtual_order_num'] ?? '',
'appoint_start_time' => $params['appoint_start_time'] ?? '',
'appoint_end_time' => $params['appoint_end_time'] ?? '',
'audit_status' => GoodsEnum::AUDIT_STATUS_PASS,
'audit_remark' => '',
]);
$goodsImageLists = [];
//添加服务轮播图信息
foreach ($goodsImage as $image_uri) {
$goodsImageLists[] = [
'goods_id' => $goods->id,
'uri' => $image_uri,
];
}
(new GoodsImage())->saveAll($goodsImageLists);
$goodsCityLists = [];
$goodsSkillLists = [];
foreach ($params['skill_id'] as $skillId)
{
$goodsSkillLists[] = [
'goods_id' => $goods->id,
'skill_id' => $skillId
];
}
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
if($params['city_id']){
foreach ($params['city_id'] as $cityId){
$goodsCityLists[] = [
'goods_id' => $goods->id,
'city_id' => $cityId
];
}
}
(new GoodsCityIndex())->saveAll($goodsCityLists);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 查看服务详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/9 3:51 下午
*/
public function detail($id)
{
$result = Goods::where('id',$id)
->withoutField('order_num,update_time,delete_time')
->append(['category_desc','goods_image'])
->findOrEmpty()
->toArray();
$goods_image = [];
foreach ($result['goods_image'] as &$image) {
$goods_image[] = $image['uri'];
}
$result['goods_image'] = $goods_image;
$result['city_id'] = GoodsCityIndex::where(['goods_id'=>$id])->column('city_id');
$result['skill_id'] = GoodsSkillIndex::where(['goods_id'=>$id])->column('skill_id');
if(empty($result['city_id'])){
$result['city_id'] = null;
}
return $result;
}
/**
* @notes 编辑服务
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/9 4:06 下午
*/
public function edit($params)
{
// 启动事务
Db::startTrans();
try {
$goodsImage = $params['goods_image'];
$image = array_shift($params['goods_image']);
//更新服务信息
Goods::update([
'name' => $params['name'],
'category_id' => $params['category_id'],
'image' => $image,
'price' => $params['price'],
'duration' => $params['duration'],
'scribing_price' => $params['scribing_price'] ?? 0.00,
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
'tags' => $params['tags'] ?? '',
'content' => $params['content'] ?? '',
'overtime_price' => $params['overtime_price'] ?? '',
'overtime_duration' => $params['overtime_duration'] ?? '',
'commission_ratio' => $params['commission_ratio'] ?? '',
'shop_ratio' => $params['shop_ratio'] ?? '',
'virtual_order_num' => $params['virtual_order_num'] ?? '',
'appoint_start_time' => $params['appoint_start_time'] ?? '',
'appoint_end_time' => $params['appoint_end_time'] ?? '',
],['id'=>$params['id']]);
$goodsImageLists = [];
//删除旧的轮播图
GoodsImage::where('goods_id',$params['id'])->delete();
//添加服务轮播图信息
foreach ($goodsImage as $image_uri) {
$goodsImageLists[] = [
'goods_id' => $params['id'],
'uri' => $image_uri,
];
}
(new GoodsImage())->saveAll($goodsImageLists);
//删除管理图片,删除管理城市
GoodsSkillIndex::where('goods_id',$params['id'])->delete();
GoodsCityIndex::where('goods_id',$params['id'])->delete();
$goodsCityLists = [];
$goodsSkillLists = [];
foreach ($params['skill_id'] as $skillId)
{
$goodsSkillLists[] = [
'goods_id' => $params['id'],
'skill_id' => $skillId
];
}
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
if($params['city_id']) {
foreach ($params['city_id'] as $cityId) {
$goodsCityLists[] = [
'goods_id' => $params['id'],
'city_id' => $cityId
];
}
}
(new GoodsCityIndex())->saveAll($goodsCityLists);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 删除服务
* @param $ids
* @return bool|string
* @author ljj
* @date 2022/2/9 4:13 下午
*/
public function del($ids)
{
// 启动事务
// Db::startTrans();
try {
//删除师傅绑定的服务
// foreach ($ids as $id) {
// $staff_lists = Staff::whereRaw("FIND_IN_SET($id,goods_ids)")->select()->toArray();
// foreach ($staff_lists as $list) {
// $goods_ids = str_replace(','.$id.',',',',$list['goods_ids']);
// if ($goods_ids == ',') {
// $goods_ids = '';
// }
// Staff::update(['goods_ids'=>$goods_ids],['id'=>$list['id']]);
// }
// }
//删除服务
Goods::destroy($ids);
// 提交事务
// Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
// Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 修改服务状态
* @param $params
* @return Goods
* @author ljj
* @date 2022/2/9 4:54 下午
*/
public function status($params)
{
return Goods::update(['status'=>$params['status']],['id'=>$params['ids']]);
}
}

View File

@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\goods;
use app\common\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\goods\GoodsUnit;
class GoodsUnitLogic extends BaseLogic
{
/**
* @notes 通用单位列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/2/9 3:48 下午
*/
public function commonLists()
{
$lists = (new GoodsUnit())->field('id,name')
->order(['sort'=>'asc','id'=>'desc'])
->select()
->toArray();
return $lists;
}
/**
* @notes 添加服务单位
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 11:37 上午
*/
public function add($params)
{
GoodsUnit::create([
'name' => $params['name'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
]);
return true;
}
/**
* @notes 查看服务单位详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 11:49 上午
*/
public function detail($id)
{
return GoodsUnit::where('id',$id)->findOrEmpty()->toArray();
}
/**
* @notes 编辑服务单位
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 11:58 上午
*/
public function edit($params)
{
GoodsUnit::update([
'name' => $params['name'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务单位
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 12:09 下午
*/
public function del($id)
{
GoodsUnit::destroy($id);
return true;
}
}

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\marketing;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
class RechargeLogic extends BaseLogic
{
/**
* @notes 设置充值设置
* @param $params
* @author ljj
* @date 2022/11/17 4:43 下午
*/
public function setSettings($params)
{
ConfigService::set('recharge', 'recharge_open', $params['recharge_open']);
ConfigService::set('recharge', 'min_recharge_amount', $params['min_recharge_amount'] ?? '');
return true;
}
/**
* @notes 获取充值设置
* @return array
* @author ljj
* @date 2022/11/17 4:46 下午
*/
public function getSettings()
{
return [
'recharge_open' => ConfigService::get('recharge', 'recharge_open',1),
'min_recharge_amount' => ConfigService::get('recharge', 'min_recharge_amount'),
];
}
}

View File

@@ -0,0 +1,225 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\notice;
use app\common\enum\notice\NoticeEnum;
use app\common\logic\BaseLogic;
use app\common\model\notice\NoticeSetting;
/**
* 通知逻辑层
* Class NoticeLogic
* @package app\adminapi\logic\notice
*/
class NoticeLogic extends BaseLogic
{
/**
* @notes 查看通知设置详情
* @param $params
* @return array
* @author 段誉
* @date 2022/3/29 11:34
*/
public static function detail($params)
{
$field = 'id,type,scene_id,scene_name,scene_desc,system_notice,sms_notice,oa_notice,mnp_notice,support';
$noticeSetting = NoticeSetting::field($field)->findOrEmpty($params['id'])->toArray();
if (empty($noticeSetting)) {
return [];
}
if (empty($noticeSetting['system_notice'])) {
$noticeSetting['system_notice'] = [
'title' => '',
'content' => '',
'status' => 0,
];
}
$noticeSetting['system_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SYSTEM, $noticeSetting['scene_id']);
if (empty($noticeSetting['sms_notice'])) {
$noticeSetting['sms_notice'] = [
'template_id' => '',
'content' => '',
'status' => 0,
];
}
$noticeSetting['sms_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SMS, $noticeSetting['scene_id']);
if (empty($noticeSetting['oa_notice'])) {
$noticeSetting['oa_notice'] = [
'template_id' => '',
'template_sn' => '',
'name' => '',
'first' => '',
'remark' => '',
'tpl' => [],
'status' => 0,
];
}
$noticeSetting['oa_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
if (empty($noticeSetting['mnp_notice'])) {
$noticeSetting['mnp_notice'] = [
'template_id' => '',
'template_sn' => '',
'name' => '',
'tpl' => [],
'status' => 0,
];
}
$noticeSetting['mnp_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
$noticeSetting['system_notice']['is_show'] = in_array(NoticeEnum::SYSTEM, explode(',', $noticeSetting['support']));
$noticeSetting['sms_notice']['is_show'] = in_array(NoticeEnum::SMS, explode(',', $noticeSetting['support']));
$noticeSetting['oa_notice']['is_show'] = in_array(NoticeEnum::OA, explode(',', $noticeSetting['support']));
$noticeSetting['mnp_notice']['is_show'] = in_array(NoticeEnum::MNP, explode(',', $noticeSetting['support']));
$noticeSetting['default'] = '';
$noticeSetting['type'] = NoticeEnum::getTypeDesc($noticeSetting['type']);
return $noticeSetting;
}
/**
* @notes 通知设置
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 11:34
*/
public static function set($params)
{
try {
// 校验参数
self::checkSet($params);
// 拼装更新数据
$updateData = [];
foreach ($params['template'] as $item) {
$updateData[$item['type'] . '_notice'] = json_encode($item, JSON_UNESCAPED_UNICODE);
}
// 更新通知设置
NoticeSetting::where('id', $params['id'])->update($updateData);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 校验参数
* @param $params
* @throws \Exception
* @author 段誉
* @date 2022/3/29 11:35
*/
public static function checkSet($params)
{
$noticeSetting = NoticeSetting::findOrEmpty($params['id'] ?? 0);
if ($noticeSetting->isEmpty()) {
throw new \Exception('通知配置不存在');
}
if (!isset($params['template']) || !is_array($params['template']) || count($params['template']) == 0) {
throw new \Exception('模板配置不存在或格式错误');
}
// 通知类型
$noticeType = ['system', 'sms', 'oa', 'mnp'];
foreach ($params['template'] as $item) {
if (!is_array($item)) {
throw new \Exception('模板项格式错误');
}
if (!isset($item['type']) || !in_array($item['type'], $noticeType)) {
throw new \Exception('模板项缺少模板类型或模板类型有误');
}
switch ($item['type']) {
case "system";
self::checkSystem($item);
break;
case "sms";
self::checkSms($item);
break;
case "oa";
self::checkOa($item);
break;
case "mnp";
self::checkMnp($item);
break;
}
}
}
/**
* @notes 校验系统通知参数
* @param $item
* @throws \Exception
* @author 段誉
* @date 2022/3/29 11:35
*/
public static function checkSystem($item)
{
if (!isset($item['title']) || !isset($item['content']) || !isset($item['status'])) {
throw new \Exception('系统通知必填参数title、content、status');
}
}
/**
* @notes 校验短信通知必填参数
* @param $item
* @throws \Exception
* @author 段誉
* @date 2022/3/29 11:35
*/
public static function checkSms($item)
{
if (!isset($item['template_id']) || !isset($item['content']) || !isset($item['status'])) {
throw new \Exception('短信通知必填参数template_id、content、status');
}
}
/**
* @notes 校验微信模板消息参数
* @param $item
* @throws \Exception
* @author 段誉
* @date 2022/3/29 11:35
*/
public static function checkOa($item)
{
if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['first']) || !isset($item['remark']) || !isset($item['tpl']) || !isset($item['status'])) {
throw new \Exception('微信模板消息必填参数template_id、template_sn、name、first、remark、tpl、status');
}
}
/**
* @notes 校验微信小程序提醒必填参数
* @param $item
* @throws \Exception
* @author 段誉
* @date 2022/3/29 11:35
*/
public static function checkMnp($item)
{
if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['tpl']) || !isset($item['status'])) {
throw new \Exception('微信模板消息必填参数template_id、template_sn、name、tpl、status');
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\notice;
use app\common\enum\notice\SmsEnum;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* 短信配置逻辑层
* Class SmsConfigLogic
* @package app\adminapi\logic\notice
*/
class SmsConfigLogic extends BaseLogic
{
/**
* @notes 获取短信配置
* @return array
* @author 段誉
* @date 2022/3/29 11:37
*/
public static function getConfig()
{
$config = [
ConfigService::get('sms', 'ali', ['type' => 'ali', 'name' => '阿里云短信', 'status' => 1]),
ConfigService::get('sms', 'tencent', ['type' => 'tencent', 'name' => '腾讯云短信', 'status' => 0]),
];
return $config;
}
/**
* @notes 短信配置
* @param $params
* @return bool|void
* @author 段誉
* @date 2022/3/29 11:37
*/
public static function setConfig($params)
{
$type = $params['type'];
$params['name'] = self::getNameDesc(strtoupper($type));
ConfigService::set('sms', $type, $params);
$default = ConfigService::get('sms', 'engine', false);
if ($params['status'] == 1 && $default === false) {
// 启用当前短信配置 并 设置当前短信配置为默认
ConfigService::set('sms', 'engine', strtoupper($type));
return true;
}
if ($params['status'] == 1 && $default != strtoupper($type)) {
// 找到默认短信配置
$defaultConfig = ConfigService::get('sms', strtolower($default));
// 状态置为禁用 并 更新
$defaultConfig['status'] = 0;
ConfigService::set('sms', strtolower($default), $defaultConfig);
// 设置当前短信配置为默认
ConfigService::set('sms', 'engine', strtoupper($type));
return true;
}
}
/**
* @notes 查看短信配置详情
* @param $params
* @return array|int|mixed|string|null
* @author 段誉
* @date 2022/3/29 11:37
*/
public static function detail($params)
{
$default = [];
switch ($params['type']) {
case 'ali':
$default = [
'sign' => '',
'app_key' => '',
'secret_key' => '',
'status' => 1,
'name' => '阿里云短信',
];
break;
case 'tencent':
$default = [
'sign' => '',
'app_id' => '',
'secret_key' => '',
'status' => 0,
'secret_id' => '',
'name' => '腾讯云短信',
];
break;
}
$result = ConfigService::get('sms', $params['type'], $default);
$result['status'] = intval($result['status'] ?? 0);
return $result;
}
/**
* @notes 获取短信平台名称
* @param $value
* @return string
* @author 段誉
* @date 2022/3/29 11:37
*/
public static function getNameDesc($value)
{
$desc = [
'ALI' => '阿里云短信',
'TENCENT' => '腾讯云短信',
];
return $desc[$value] ?? '';
}
}

View File

@@ -0,0 +1,857 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\order;
use app\common\enum\notice\NoticeEnum;
use app\common\enum\OrderEnum;
use app\common\enum\OrderLogEnum;
use app\common\enum\OrderRefundEnum;
use app\common\model\coach\Coach;
use app\common\model\order\OrderAppend;
use app\common\model\order\OrderGap;
use app\common\model\order\OrderRefund;
use app\common\enum\PayEnum;
use app\common\logic\BaseLogic;
use app\common\logic\CoachLogic;
use app\common\logic\OrderLogLogic;
use app\common\logic\RefundLogic;
use app\common\model\order\Order;
use app\common\model\order\OrderLog;
use app\common\model\settle\SettleOrder;
use app\common\model\shop\Shop;
use app\common\service\FileService;
use think\Exception;
use think\facade\Db;
class OrderLogic extends BaseLogic
{
/**
* @notes 订单详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/11 3:01 下午
*/
public function detail($id)
{
$detail = Order::field('id,sn,shop_id,goods_price,total_order_amount,user_id,order_remarks,order_status,server_finish_time,is_settle,order_terminal,user_remark,pay_status,refund_amount,appoint_time,order_amount,user_remark,address_snap,pay_way,server_finish_time,pay_time,true_server_finish_time,total_amount,total_refund_amount,total_gap_amount,total_append_amount,car_amount,create_time,coach_id,order_distance')
->order('id','desc')
->append(['order_distance_desc','pay_way_desc','order_terminal_desc','appoint_time_desc','appoint_time','appoint_date','order_status_desc','take_order_btn','depart_btn','arrive_btn','server_start_btn','server_finish_btn','refund_btn','cancel_btn','order_cancel_time','dispatch_btn'])
->with(['order_goods' => function($query){
$query->field('order_id,goods_snap,duration,goods_num,goods_image,goods_name,goods_price')->hidden(['goods_snap']);
},'order_gap','order_append','order_log','user_info','coach_info'])
->where(['id'=>$id])
->findOrEmpty()
->toArray();
if(!isset($detail['address_snap']['house_number'])){
$detail['address_snap']['house_number'] = '';
}
$orderLog = OrderLog::where(['order_id'=>$id,'type'=>OrderLogEnum::TYPE_COACH])
->field('content,location,extra,create_time')
->select()->toArray();
$detail['shop_info'] = [];
if($detail['shop_id']){
$detail['shop_info'] = Shop::where(['id'=>$detail['shop_id']])->field('id,sn,legal_person,mobile,name,logo')->findOrEmpty();
}
$serverLogLists = [];
foreach ($orderLog as $key => $log){
$date = date('Y-m-d',strtotime($log['create_time']));
if($log['extra']){
foreach ($log['extra'] as $key => $extra){
$log['extra'][$key] = FileService::getFileUrl($extra);
}
}
$serverLogLists[] = $log;
}
// $serverLogLists = $orderLog;
if ($detail['order_status'] == OrderEnum::ORDER_STATUS_WAIT_RECEIVING) {
$detail['cancel_btn'] = 1;
}
$detail['server_log_lists'] = $serverLogLists;
$settleOrder = [];
if($detail['is_settle']){
$settleOrder = SettleOrder::where(['order_id'=>$detail['id']])->findOrEmpty();
}
$shopCommission = $settleOrder['shop_commission'] ?? 0;
$shopCarAmount = $settleOrder['shop_car_amount'] ?? 0;
$coachCommission = $settleOrder['coach_commission'] ?? 0;
$coachCarAmount = $settleOrder['coach_car_amount'] ?? 0;
// $totalOrderAmount = $settleOrder['order_amount'] ?? 0;
// $carAmount = $settleOrder['car_amount'] ?? 0;
$detail['settle_info'] = [
'status' => $detail['is_settle'],
'order_amount' => $detail['total_order_amount'],
'refund_amount' => $detail['total_refund_amount'],
'settle_car' => $settleOrder['car_amount'] ?? 0,
'settle_amount' => $settleOrder['order_amount'] ?? 0,
'coach_settle' => $settleOrder['coach_commission'] ?? 0,
'shop_settle' => $settleOrder['shop_commission'] ?? 0,
// 'total_settle_amount'=> round($totalOrderAmount + $carAmount ,2),
];
$refundInfo = OrderRefund::where(['order_id'=>$detail['id'],'refund_status'=>[OrderRefundEnum::STATUS_ING,OrderRefundEnum::STATUS_SUCCESS]])->field('sum(refund_amount) as total_refund_amount,sum(refund_car_amount) as total_refund_car_amount')->findOrEmpty();
$detail['refund_amount'] = round($refundInfo['total_refund_amount']- $refundInfo['total_refund_car_amount'],2);
$detail['refund_car_amount'] = $refundInfo['total_refund_car_amount'] ?: 0;
return $detail;
}
/**
* @notes 子订单列表
* @param $id
* @return array
* @author cjhao
* @date 2024/11/9 13:11
*/
public function subOrderLists($id)
{
$lists = Order::where(['id'=>$id])
->field('id,sn,order_amount,refund_amount,refund_car_amount,pay_time')
->with(['order_gap','order_append'])
->findOrEmpty();
$orderGapLists = [];
$orderAppendLists = [];
$subLists[] = [
'id' => $lists['id'],
'sn' => $lists['sn'],
'order_amount' => $lists['order_amount'],
'refund_amount' => $lists['refund_amount'],
'pay_time_timestamp' => $lists->getData('pay_time'),
'pay_time' => $lists['pay_time'],
'type' => 1,
'type_desc' => '基础',
'refund_btn' => $lists['order_amount'] > $lists['refund_amount'] ? 1 : 0,
];
foreach ($lists['order_gap'] as $key => $gap){
$gap['pay_time_timestamp'] = $gap->getData('pay_time');
$gap['type'] = 2;
$gap['type_desc'] = '补差价';
$gap['refund_btn'] = $gap['order_amount'] > $gap['refund_amount'] ? 1 : 0;
$orderGapLists[] = $gap->toArray();
}
foreach ($lists['order_append'] as $append){
$append['pay_time_timestamp'] = $append->getData('pay_time');
$append['type'] = 3;
$append['type_desc'] = '加钟';
$append['refund_btn'] = $append['order_amount'] > $append['refund_amount'] ? 1 : 0;
$orderAppendLists[] = $append->toArray();
}
$subLists = array_merge($subLists,$orderGapLists,$orderAppendLists);
usort($subLists, function ($item1, $item2) {
// 从小到大排序
return $item1['pay_time'] <=>$item2['pay_time'];
});
return $subLists;
}
/**
* @notes 取消订单
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/11 4:10 下午
*/
public function cancel($params)
{
// 启动事务
Db::startTrans();
try {
//TODO 已支付订单原路退回金额
$order = Order::where('id',$params['id'])->findOrEmpty()->toArray();
if(OrderEnum::ORDER_STATUS_WAIT_RECEIVING < $order['order_status'] && $order['order_status'] < OrderEnum::ORDER_STATUS_START_SERVER){
throw new Exception('订单状态已改变,请刷新页面');
}
if($order['pay_status'] == PayEnum::ISPAID) {
$orderAmount = round($params['order_amount'] + $params['car_amount']);
if($orderAmount > $order['order_amount']){
throw new Exception('退款金额大于订单金额,请重新输入');
}
(new RefundLogic())->refund($order,$order['total_order_amount'],0,OrderRefundEnum::TYPE_ADMIN,1,$params['admin_id']);
}
//更新订单状态
Order::update([
'order_status' => OrderEnum::ORDER_STATUS_CLOSE,
'cancel_time' => time(),
],['id'=>$params['id']]);
//添加订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_ADMIN,OrderLogEnum::SYSTEM_CANCEL_ORDER,$params['id'],$params['admin_id']);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 删除订单
* @param $params
* @author ljj
* @date 2022/2/11 4:27 下午
*/
public function del($params)
{
Order::destroy($params['id']);
return true;
}
/**
* @notes 商家备注
* @param $params
* @return bool
* @author ljj
* @date 2022/2/11 4:45 下午
*/
public function remark($params)
{
Order::update(['order_remarks'=>$params['order_remarks'] ?? ''],['id'=>$params['id']]);
return true;
}
/**
* @notes 商家备注详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/11 4:56 下午
*/
public function remarkDetail($id)
{
return Order::where('id',$id)->field('order_remarks')->findOrEmpty()->toArray();
}
/**
* @notes 核销订单
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/11 5:03 下午
*/
public function verification($params)
{
// 启动事务
Db::startTrans();
try {
//更新订单状态
Order::update([
'order_status' => OrderEnum::ORDER_STATUS_SERVER_FINISH,
'verification_status' => OrderEnum::VERIFICATION,
'finish_time' => time(),
],['id'=>$params['id']]);
//添加订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_ADMIN,OrderLogEnum::SHOP_VERIFICATION,$params['id'],$params['admin_id']);
$order = Order::where('id',$params['id'])->findOrEmpty()->toArray();
// 订单完成通知 - 通知买家
event('Notice', [
'scene_id' => NoticeEnum::ORDER_FINISH_NOTICE,
'params' => [
'user_id' => $order['user_id'],
'order_id' => $order['id']
]
]);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 接单操作
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/13 17:21
*/
public function take($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if($order->isEmpty()){
throw new Exception('订单不存在');
}
if(OrderEnum::ORDER_STATUS_WAIT_RECEIVING != $order->order_status){
throw new Exception('订单状态已改变,请刷新页面');
}
$order->order_status = OrderEnum::ORDER_STATUS_WAIT_DEPART;
$order->save();
//订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_COACH,OrderLogEnum::COACH_TAKE_ORDER,$order['id'],$params['admin_id']);
//提交事务
Db::commit();
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 出发操作
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/13 17:21
*/
public function depart($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if($order->isEmpty()){
throw new Exception('订单不存在');
}
if(OrderEnum::ORDER_STATUS_WAIT_DEPART != $order->order_status){
throw new Exception('订单状态已改变,请刷新页面');
}
$order->order_status = OrderEnum::ORDER_STATUS_DEPART;
$order->save();
//订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_COACH,OrderLogEnum::COACH_DEPART,$order['id'],$params['admin_id']);
//提交事务
Db::commit();
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 达到操作
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/13 17:21
*/
public function arrive($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if($order->isEmpty()){
throw new Exception('订单不存在');
}
if(OrderEnum::ORDER_STATUS_DEPART != $order->order_status){
throw new Exception('订单状态已改变,请刷新页面');
}
$order->order_status = OrderEnum::ORDER_STATUS_ARRIVE;
$order->save();
//订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_COACH,OrderLogEnum::COACH_ARRIVE,$order['id'],$params['admin_id'],'');
//提交事务
Db::commit();
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 服务开始操作
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/13 17:21
*/
public function startServer($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if($order->isEmpty()){
throw new Exception('订单不存在');
}
if(OrderEnum::ORDER_STATUS_ARRIVE != $order->order_status){
throw new Exception('订单状态已改变,请刷新页面');
}
$order->order_status = OrderEnum::ORDER_STATUS_START_SERVER;
$order->save();
//订单日志
(new OrderLogLogic())->record(OrderLogEnum::TYPE_COACH,OrderLogEnum::COACH_START_SERVER,$order['id'],$params['admin_id']);
//提交事务
Db::commit();
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 服务完成
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/14 14:52
*/
public function finishServer($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if($order->isEmpty()){
throw new Exception('订单不存在');
}
if(OrderEnum::ORDER_STATUS_START_SERVER != $order->order_status){
throw new Exception('订单状态已改变,请刷新页面');
}
$order->order_status = OrderEnum::ORDER_STATUS_SERVER_FINISH;
$order->true_server_finish_time = time();
$order->save();
(new OrderLogLogic())->record(OrderLogEnum::TYPE_ADMIN,OrderLogEnum::COACH_SERVER_FINISH,$order['id'],$params['admin_id'],'');
Coach::update(['order_num'=>['inc',1]],['id'=>$order['coach_id']]);
//提交事务
Db::commit();
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 订单退款
* @param $params
* @return bool
* @author cjhao
* @date 2024/9/27 23:54
*/
public function refund($params)
{
try {
$allRefund = $params['all_refund'] ?? 0;
$refundOrder = $params['refund_order'] ?? [];
if(empty($refundOrder) && empty($allRefund)){
throw new Exception('请选择退款订单');
}
$mainorder = [];
//全部退款的退款
if($allRefund){
$orderId = $params['order_id'] ?? '';
if(empty($orderId)){
throw new Exception('请选择退款订单');
}
$order = Order::where(['id'=>$orderId])
->field('id,sn,order_amount,refund_amount,pay_time')
->with(['order_gap','order_append'])
->findOrEmpty();
$mainOrder = $order;
if($order['order_amount'] > $order['refund_amount']){
$refundOrder[] = [
'order_sn' => $order['sn'],
'type' => 1,
];
}
if($order['order_gap']){
foreach ($order['order_gap'] as $orderGap) {
if ($orderGap['refund_amount'] >= $orderGap['order_amount']) {
continue;
}
$refundOrder[] = [
'order_sn' => $orderGap['sn'],
'type' => 2,
];
}
}
if($order['order_append']){
foreach ($order['order_append'] as $orderAppend) {
if ($orderAppend['refund_amount'] >= $orderAppend['order_amount']) {
continue;
}
$refundOrder[] = [
'order_sn' => $orderAppend['sn'],
'type' => 3,
];
}
}
if(empty($refundOrder)){
throw new Exception('订单已全部退款');
}
}
$refundOrderAmount = $params['refund_order_amount'] ?? 0;
$refundCarAmount = $params['refund_car_amount'] ?? 0;
$refundCarAmount = $refundCarAmount ?: 0;
$payWay = $params['pay_way'] ?? 1;
$refundCount = count($refundOrder);
$refundTotalOrderAmount = 0;
if(1 == $refundCount && (empty($refundOrderAmount)) && empty($refundCarAmount)){
throw new Exception('请输入退款金额');
}
//只退单个订单情况
if(1 == $refundCount){
Db::startTrans();
$type = $refundOrder[0]['type'] ?? '';
$orderSn = $refundOrder[0]['order_sn'] ?? '';
if(empty($type) || empty($orderSn)){
throw new Exception('订单参数错误');
}
switch ($type){
case 1:
$order = Order::where(['sn'=>$orderSn])->findOrEmpty();
$mainOrder = $order->toArray();
break;
case 2:
$order = OrderGap::where(['sn'=>$orderSn])->findOrEmpty();
$mainOrder = Order::where(['id'=>$order['order_id']])->findOrEmpty();;
break;
case 3:
$order = OrderAppend::where(['sn'=>$orderSn])->findOrEmpty();
$mainOrder = Order::where(['id'=>$order['order_id']])->findOrEmpty();;
break;
}
if($order->isEmpty()){
throw new Exception('订单不存在');
}
$surplusAmount = round($order['order_amount'] - $order['refund_amount'],2);
if($surplusAmount < $refundOrderAmount){
throw new Exception('订单可退金额仅剩:'.$surplusAmount);
}
if($refundCarAmount > 0){
$surplusCarAmount = round($order['car_amount'] - $order['refund_car_amount'],2);
if($surplusCarAmount < $refundCarAmount){
throw new Exception('订单可退车费仅剩:'.$surplusCarAmount);
}
}
if(2 == $payWay){
$order['pay_way'] = PayEnum::BALANCE_PAY;
}
(new RefundLogic())->refund($order,$refundOrderAmount,$refundCarAmount,OrderRefundEnum::TYPE_ADMIN,$type,$params['admin_id']);
if(1 == $type){
$order->total_refund_amount += round($refundOrderAmount+$refundCarAmount,2);
$order->refund_car_amount += $refundCarAmount;
$order->refund_amount += round($refundOrderAmount+$refundCarAmount,2);
$order->save();
}else{
$order->refund_amount += $refundOrderAmount;
$order->save();
$totalGapRefundAmount = OrderGap::where(['order_id'=>$order['order_id']])->sum('refund_amount');
$totalAppendRefundAmount = OrderAppend::where(['order_id'=>$order['order_id']])->sum('refund_amount');
$refundAmount = Order::where(['id'=>$order['order_id']])->value('refund_amount');
// $totalRefundCarAmount = Order::where(['id'=>$order['order_id']])->value('refund_car_amount');
Order::update(['total_refund_amount'=>round($totalGapRefundAmount+$totalAppendRefundAmount+$refundAmount,2)],['id'=>$order['order_id']]);
}
//未完成的订单,全部变为关闭
if(OrderEnum::ORDER_STATUS_SERVER_FINISH != $mainOrder['order_status']){
Order::where(['id'=>$mainOrder['id']])->update([
'order_status' => OrderEnum::ORDER_STATUS_CLOSE
]);
}
$refundTotalOrderAmount = $refundOrderAmount+$refundCarAmount;
Db::commit();
}else{
foreach ($refundOrder as $order) {
Db::startTrans();
$type = $order['type'] ?? '';
$orderSn = $order['order_sn'] ?? '';
if(empty($orderSn)){
throw new Exception('订单数据错误');
}
if(empty($type)){
throw new Exception($orderSn.',订单不存在');
}
switch ($type){
case 1:
$order = Order::where(['sn'=>$orderSn])->findOrEmpty();
$mainOrder = $order->toArray();
break;
case 2:
$order = OrderGap::where(['sn'=>$orderSn])->findOrEmpty();
break;
case 3:
$order = OrderAppend::where(['sn'=>$orderSn])->findOrEmpty();
break;
}
if($order->isEmpty()){
throw new Exception('订单不存在');
}
$refundCarAmount = 0;
if(1 == $type){
$refundCarAmount = round($order['car_amount'] - $order['refund_car_amount'],2);
$refundOrderAmount = round($order['order_amount'] - $order['refund_amount'] - $order['refund_car_amount'],2);
$order->total_refund_amount += $refundOrderAmount+$refundCarAmount;
$order->refund_car_amount += $refundCarAmount;
$order->refund_amount += round($refundOrderAmount+$refundCarAmount,2);
$order->save();
}else{
$refundOrderAmount = round($order['order_amount'] - $order['refund_amount'],2);
$order->refund_amount += $refundOrderAmount;
$order->save();
$totalGapRefundAmount = OrderGap::where('refund_amount','>',0)->where(['order_id'=>$order['order_id']])->sum('refund_amount');
$totalAppendRefundAmount = OrderAppend::where('refund_amount','>',0)->where(['order_id'=>$order['order_id']])->sum('refund_amount');
$refundAmount = Order::where(['id'=>$order['order_id']])->value('refund_amount');
// $totalRefundCarAmount = Order::where(['id'=>$order['order_id']])->value('refund_car_amount');
Order::update(['total_refund_amount'=>round($totalGapRefundAmount+$totalAppendRefundAmount+$refundAmount,2)],['id'=>$order['order_id']]);
}
if($refundOrderAmount <= 0 && $refundCarAmount <= 0){
break;
}
(new RefundLogic())->refund($order,$refundOrderAmount,$refundCarAmount,OrderRefundEnum::TYPE_ADMIN,$type,$params['admin_id']);
//未完成的订单,全部变为关闭
if(OrderEnum::ORDER_STATUS_SERVER_FINISH != $mainOrder['order_status']){
Order::where(['id'=>$mainOrder['id']])->update([
'order_status' => OrderEnum::ORDER_STATUS_CLOSE
]);
}
$refundTotalOrderAmount += $refundOrderAmount+$refundCarAmount;
Db::commit();
}
}
return true;
}catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 订单更换技师时获取技师列表
* @param $params
* @return array|string
* @author cjhao
* @date 2024/10/9 16:30
*/
public function coachLists($params)
{
try {
$order = Order::where(['id'=>$params['id']])->findOrEmpty();
if(OrderEnum::ORDER_STATUS_WAIT_PAY == $order->order_status || OrderEnum::ORDER_STATUS_DEPART < $order->order_status){
throw new Exception('当前订单不可更改技师');
}
$startTime = $order->getData('appoint_time');
$serverFinishTime = $order->getData('server_finish_time');
$coachLists = CoachLogic::getLeisureCoach($order['coach_id'],$startTime,$serverFinishTime,$order);
return $coachLists;
}catch (Exception $e){
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 获取退款信息
* @param $id
* @return array|string
* @author cjhao
* @date 2024/11/21 11:53
*/
public function getRefundInfo($params)
{
try {
$id = $params['id'] ?? 0;
if($id){
$order = Order::where(['id'=>$id])->field('is_settle,total_amount,order_amount,total_order_amount,car_amount,refund_car_amount,total_refund_amount')->findOrEmpty();
$surplusAmount = round($order['total_order_amount'] - $order['total_refund_amount'],2);
$surplusCarAmount = round($order['car_amount'] - $order['refund_car_amount'],2);
return [
'total_order_amount' => $order['total_order_amount'],
'order_amount' => round($order['total_order_amount'] - $order['car_amount'],2),
'refund_amount' => round($order['total_refund_amount'] - $order['refund_car_amount'],2),
'surplus_amount' => $surplusAmount,
'car_amount' => $order['car_amount'],
'refund_car_amount' => $order['refund_car_amount'],
'surplus_car_amount' => $surplusCarAmount,
'is_settle' => $order['is_settle'],
'type' => 0,
];
}else{
$refundOrder = $params['refund_order'] ?? [];
if(empty($refundOrder)){
throw new Exception('请选择订单');
}
$orderAmount = 0;
$refundAmount = 0;
$orderCarAmount = 0;
$surplusCarAmount = 0;
$refundCarAmount = 0;
$type = 0;
if(1 == count($refundOrder) && 1 == $refundOrder[0]['type']){
$type = 1;
}
foreach ($refundOrder as $order){
$type = $order['type'] ?? '';
$orderSn = $order['order_sn'] ?? '';
if(empty($type) || empty($orderSn)){
continue;
}
switch ($type){
case 1:
$order = Order::where(['sn'=>$orderSn])->findOrEmpty();
$isSettle = $order['is_settle'];
$orderCarAmount = $order['car_amount'];
$surplusCarAmount = round($order['car_amount'] - $order['refund_car_amount'],2);
$refundCarAmount = $order['refund_car_amount'];
$order['order_amount'] = round($order['order_amount'] - $order['car_amount']);
break;
case 2:
$order = OrderGap::where(['sn'=>$orderSn])->findOrEmpty();
break;
case 3:
$order = OrderAppend::where(['sn'=>$orderSn])->findOrEmpty();
break;
}
$orderAmount+=$order['order_amount'];
$refundAmount+=round($order['refund_amount'] - $order['refund_car_amount'],2);
}
if(!isset($isSettle)){
$isSettle = Order::where(['id'=>$order['order_id']])->value('is_settle');
}
return [
'total_order_amount' => round($orderAmount+$orderCarAmount,2),
'order_amount' => floatval($orderAmount),
'refund_amount' => $refundAmount,
'surplus_amount' => round($orderAmount - $refundAmount,2),
'car_amount' => floatval($orderCarAmount),
'surplus_car_amount' => $surplusCarAmount,
'refund_car_amount' => floatval($refundCarAmount),
'is_settle' => $isSettle,
'type' => $type,
];
}
}catch (Exception $e){
return $e->getMessage();
}
}
/**
* @notes 指派技师
* @param $params
* @return bool
* @author cjhao
* @date 2024/10/10 23:10
*/
public function dispatchCoach($params)
{
try {
Db::startTrans();
$order = Order::where(['id'=>$params['id']])
->findOrEmpty();
if(OrderEnum::ORDER_STATUS_WAIT_PAY == $order->order_status || OrderEnum::ORDER_STATUS_DEPART < $order->order_status){
throw new Exception('当前订单不可更改技师');
}
$startTime = $order->getData('appoint_time');
$serverFinishTime = $order->getData('server_finish_time');
$coachLists = CoachLogic::getLeisureCoach($order['coach_id'],$startTime,$serverFinishTime,$order);
$coachIds = array_column($coachLists,'id');
if(!in_array($params['coach_id'],$coachIds)){
throw new Exception('该技师该时间段忙');
}
//技师更换
$order->coach_id = $params['coach_id'];
$order->save();
$originalCoachId = $order['coach_id'];
$extra = [
'original_coach_id' => $originalCoachId,
'coach_id' => $params['coach_id']
];
(new OrderLogLogic())
->record(OrderLogEnum::TYPE_ADMIN,OrderLogEnum::ADMIN_CHANGE_COACH,$order['id'],$params['admin_id'],'','',$extra);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 获取订单的结算状态
* @param $params
* @return mixed
* @author cjhao
* @date 2025/4/18 16:27
*/
public function getOrderSettle($params)
{
$id = $params['id'];
$order = Order::where(['id'=>$id])->field('id,sn,is_settle')->findOrEmpty();
return [
'id' => $order['id'],
'sn' => $order['sn'],
'is_settle' => $order['is_settle']
];
}
}

View File

@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\order;
use app\common\enum\OrderRefundEnum;
use app\common\logic\BaseLogic;
use app\common\model\order\OrderRefund;
use app\common\model\order\OrderRefundLog;
use think\facade\Db;
class OrderRefundLogic extends BaseLogic
{
/**
* @notes 重新退款
* @param $params
* @return bool|string
* @author ljj
* @date 2022/9/9 6:18 下午
*/
public function reRefund($params)
{
// 启动事务
Db::startTrans();
try {
//新增退款日志
OrderRefundLog::create([
'sn' => generate_sn(new OrderRefundLog(), 'sn'),
'refund_id' => $params['id'],
'type' => OrderRefundEnum::TYPE_ADMIN,
'operator_id' => $params['admin_id'],
]);
//更新退款记录状态
OrderRefund::update(['refund_status'=>OrderRefundEnum::STATUS_ING],['id'=>$params['id']]);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
}

View File

@@ -0,0 +1,130 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\order;
use app\common\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\order\OrderTime;
use app\common\service\ConfigService;
class OrderTimeLogic extends BaseLogic
{
/**
* @notes 设置可预约天数
* @param $params
* @return bool
* @author ljj
* @date 2022/2/11 6:08 下午
*/
public function setTime($params)
{
ConfigService::set('order_time','time',$params['time'] ?? 7);
return true;
}
/**
* @notes 获取可预约天数
* @return array
* @author ljj
* @date 2022/2/11 6:13 下午
*/
public function getTime()
{
return ['time'=>ConfigService::get('order_time','time',7)];
}
/**
* @notes 添加预约时间段
* @param $params
* @return bool
* @author ljj
* @date 2022/2/11 6:25 下午
*/
public function add($params)
{
OrderTime::create([
'start_time' => $params['start_time'],
'end_time' => $params['end_time'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
]);
return true;
}
/**
* @notes 查看时间段详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/11 6:39 下午
*/
public function detail($id)
{
return OrderTime::where('id',$id)->append(['time_desc'])->findOrEmpty()->toArray();
}
/**
* @notes 编辑时间段
* @param $params
* @return bool
* @author ljj
* @date 2022/2/11 6:41 下午
*/
public function edit($params)
{
OrderTime::update([
'start_time' => $params['start_time'],
'end_time' => $params['end_time'],
'sort' => $params['sort'] ?: DefaultEnum::SORT,
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除时间段
* @param $params
* @return bool
* @author ljj
* @date 2022/2/11 6:45 下午
*/
public function del($params)
{
OrderTime::destroy($params['ids']);
return true;
}
/**
* @notes 修改排序
* @param $params
* @return bool
* @author ljj
* @date 2022/11/28 18:20
*/
public function sort($params)
{
OrderTime::update([
'sort' => $params['sort'],
],['id'=>$params['id']]);
return true;
}
}

View File

@@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use think\facade\Config;
class AdminLogic extends BaseLogic
{
/**
* @notes 获取个人资料
* @param $admin_id
* @return array
* @author ljj
* @date 2022/4/18 2:36 下午
*/
public static function getAdmin($admin_id)
{
$admin = Admin::where('id',$admin_id)->field('id,name,avatar,account')->findOrEmpty()->toArray();
return $admin;
}
/**
* @notes 设置个人资料
* @param $params
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/4/18 2:58 下午
*/
public static function setAdmin($params)
{
$admin = Admin::find($params['admin_id']);
$admin->name = $params['name'];
$admin->avatar = $params['avatar'];
$admin->account = $params['account'];
if (isset($params['password']) && $params['password'] != '') {
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['new_password'], $passwordSalt);
$admin->password = $password;
}
$admin->save();
return true;
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace app\adminapi\logic\setting;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 基础设置
* Class BaseLogic
* @package app\adminapi\logic\setting
*/
class BaseLogic {
/**
* @notes 获取获取
* @return array[]
* @author cjhao
* @date 2024/11/1 13:07
*/
public function getConfig(){
return [
// 'platform' => [
'platform_name' => ConfigService::get('platform', 'platform_name',''),
'platform_logo' => FileService::getFileUrl(ConfigService::get('platform', 'platform_logo','')),
'poster' => FileService::getFileUrl(ConfigService::get('platform', 'poster','')),
'icon' => FileService::getFileUrl(ConfigService::get('platform', 'icon','')),
'safety_login' => ConfigService::get('platform', 'safety_login',1),
'safety_limit' => ConfigService::get('platform', 'safety_limit',3),
'safety_limit_time' => ConfigService::get('platform', 'safety_limit_time',5),
'doc_show' => ConfigService::get('platform', 'doc_show',1),
'contacts' => ConfigService::get('platform', 'contacts',''),
'mobile' => ConfigService::get('platform', 'mobile',''),
'service_mobile' => ConfigService::get('platform', 'service_mobile',''),
// ],
// 'user' => [
'user_name' => ConfigService::get('user', 'user_name',''),
'short_name' => ConfigService::get('user', 'short_name',''),
'user_logo' => FileService::getFileUrl(ConfigService::get('user', 'user_logo','')),
// ],
// 'coach' => [
'coach_name' => ConfigService::get('coach', 'coach_name',''),
'coach_logo' => FileService::getFileUrl(ConfigService::get('coach', 'coach_logo','')),
// ],
// 'shop' => [
'shop_name' => ConfigService::get('shop', 'shop_name',''),
'shop_logo' => FileService::getFileUrl(ConfigService::get('shop', 'shop_logo','')),
// ],
];
}
/**
* @notes 设置基础设置
* @param $params
* @return void
* @author cjhao
* @date 2024/11/1 13:18
*/
public function setConfig($params){
ConfigService::set('platform', 'platform_name',$params['platform_name']);
ConfigService::set('platform', 'platform_logo',FileService::setFileUrl($params['platform_logo']));
ConfigService::set('platform', 'poster',FileService::setFileUrl($params['poster']));
ConfigService::set('platform', 'icon',FileService::setFileUrl($params['icon']));
ConfigService::set('platform', 'safety_login',$params['safety_login']);
ConfigService::set('platform', 'safety_limit',$params['safety_limit']);
ConfigService::set('platform', 'doc_show',$params['doc_show']);
ConfigService::set('platform', 'safety_limit',$params['safety_limit']);
ConfigService::set('platform', 'contacts',$params['contacts']);
ConfigService::set('platform', 'mobile',$params['mobile']);
ConfigService::set('platform', 'service_mobile',$params['service_mobile']);
ConfigService::set('user', 'user_name',$params['user_name']);
ConfigService::set('user', 'short_name',$params['short_name']);
ConfigService::set('user', 'user_logo',FileService::setFileUrl($params['user_logo']));
ConfigService::set('coach', 'coach_name',$params['coach_name']);
ConfigService::set('coach', 'coach_logo',$params['coach_logo']);
ConfigService::set('shop', 'shop_name',$params['shop_name']);
ConfigService::set('shop', 'shop_logo',FileService::setFileUrl($params['shop_logo']));
}
}

View File

@@ -0,0 +1,226 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\logic\BaseLogic;
use app\common\model\city\City;
use app\common\model\goods\GoodsCategory;
use app\common\model\Region;
use app\common\model\skill\Skill;
class CityLogic extends BaseLogic
{
/**
* @notes 城市列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/10/6 17:27
*/
public function getCityLists()
{
$lists = City::where(['level'=>2])->select()->toArray();
$cityLists = [];
foreach ($lists as $city){
$parent = $cityLists[$city['parent_id']] ?? [];
if($parent){
$parent['sons'][] =[
'id' => $city['city_id'],
'name' => $city['name'],
];
}else{
$parent = [
'id' => $city['parent_id'],
'name' => $city['parent_name'],
'sons' => [
[
'id' => $city['city_id'],
'name' => $city['name'],
],
],
];
}
$cityLists[$city['parent_id']] = $parent;
}
return array_values($cityLists);
}
/**
* @notes 城市列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/10/6 17:27
*/
public function getRegionLists()
{
$lists = City::where(['level'=>2])->select()->toArray();
$cityLists = [];
foreach ($lists as $city){
$parent = $cityLists[$city['parent_id']] ?? [];
if($parent){
$parent['children'][] =[
'value' => $city['city_id'],
'label' => $city['name'],
'children' => [],
];
}else{
$parent = [
'value' => $city['parent_id'],
'label' => $city['parent_name'],
'children' => [
[
'value' => $city['city_id'],
'label' => $city['name'],
'children' => [],
],
],
];
}
$cityLists[$city['parent_id']] = $parent;
}
$cityIds = array_column($lists,'city_id');
$regionLists = Region::where(['parent_id'=>$cityIds,'level'=>3])->select()->toArray();
foreach ($cityLists as $key => $city){
foreach ($city['children'] as $sonsKey => $sons){
foreach ($regionLists as $regionList){
if($regionList['parent_id'] == $sons['value']){
$sons['children'][] = [
'value' => $regionList['id'],
'label' => $regionList['name'],
];
}
}
$cityLists[$key]['children'][$sonsKey] = $sons;
}
}
return array_values($cityLists);
}
/**
* @notes 添加
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
$region = Region::where(['id'=>$params['city_id']])
->field('name,parent_id,level,gcj02_lng,gcj02_lat,db09_lng,db09_lat')
->findOrEmpty()
->toArray();
$parentName = Region::where(['id'=>$region['parent_id']])->value('name');
City::create([
'parent_id' => $region['parent_id'],
'parent_name' => $parentName,
'city_id' => $params['city_id'],
'level' => $region['level'],
'name' => $region['name'],
'taxi' => $params['taxi'],
'start_km' => $params['start_km'],
'start_price' => $params['start_price'],
'continue_price' => $params['continue_price'],
'gcj02_lng' => $region['gcj02_lng'],
'gcj02_lat' => $region['gcj02_lat'],
'db09_lng' => $region['db09_lng'],
'db09_lat' => $region['db09_lat'],
'bus' => $params['bus'],
'bus_start_time' => $params['bus_start_time'],
'bus_end_time' => $params['bus_end_time'],
'bus_fare' => $params['bus_fare'],
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = City::where('id',$id)->withoutField('update_time,delete_time')->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
$region = Region::where(['id'=>$params['city_id']])
->field('name,parent_id,level,gcj02_lng,gcj02_lat,db09_lng,db09_lat')
->findOrEmpty()->toArray();
$parentName = Region::where(['id'=>$region['parent_id']])->value('name');
City::update([
'parent_id' => $region['parent_id'],
'parent_name' => $parentName,
'level' => $region['level'],
'city_id' => $params['city_id'],
'name' => $region['name'],
'taxi' => $params['taxi'],
'start_km' => $params['start_km'],
'start_price' => $params['start_price'],
'continue_price' => $params['continue_price'],
'bus' => $params['bus'],
'gcj02_lng' => $region['gcj02_lng'],
'gcj02_lat' => $region['gcj02_lat'],
'db09_lng' => $region['db09_lng'],
'db09_lat' => $region['db09_lat'],
'bus_start_time' => $params['bus_start_time'],
'bus_end_time' => $params['bus_end_time'],
'bus_fare' => $params['bus_fare'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return City::destroy($id);
}
}

View File

@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
use Exception;
use think\facade\Db;
class CustomerServiceLogic extends BaseLogic
{
/**
* @notes 获取
* @return array
* @author ljj
* @date 2024/8/27 下午5:17
*/
public static function getConfig()
{
$defaultData = [
'way' => '1',
'name' => '',
'remarks' => '',
'phone' => '',
'service_phone' => '',
'business_time' => '',
'qr_code' => '',
'enterprise_id' => '',
'kefu_link' => ''
];
$config = [
'mnp' => ConfigService::get('kefu_config', 'mnp', $defaultData),
'oa' => ConfigService::get('kefu_config', 'oa', $defaultData),
'h5' => ConfigService::get('kefu_config', 'h5', $defaultData),
];
if (!empty($config['mnp']['qr_code'])) $config['mnp']['qr_code'] = FileService::getFileUrl($config['mnp']['qr_code']);
if (!empty($config['oa']['qr_code'])) $config['oa']['qr_code'] = FileService::getFileUrl($config['oa']['qr_code']);
if (!empty($config['h5']['qr_code'])) $config['h5']['qr_code'] = FileService::getFileUrl($config['h5']['qr_code']);
return $config;
}
/**
* @notes 设置
* @param $params
* @return string|true
* @author ljj
* @date 2024/8/27 下午5:17
*/
public static function setConfig($params)
{
Db::startTrans();
try {
foreach($params as $key => $value) {
if(!in_array($key, ['mnp','oa','h5'])) {
throw new Exception('数据异常');
}
ConfigService::set('kefu_config', $key, $value);
}
// 提交事务
Db::commit();
return true;
} catch (Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
}

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;
use app\common\logic\BaseLogic;
use app\common\model\HotSearch;
use app\common\service\ConfigService;
use app\common\service\FileService;
use think\facade\Validate;
/**
* 热门搜素逻辑
* Class HotSearchLogic
* @package app\adminapi\logic\setting
*/
class HotSearchLogic extends BaseLogic
{
/**
* @notes 获取配置
* @return array
* @author 段誉
* @date 2022/9/5 18:48
*/
public static function getConfig()
{
return [
// 功能状态 0-关闭 1-开启
'status' => ConfigService::get('hot_search', 'status', 0),
// 热门搜索数据
'data' => HotSearch::field(['name', 'sort'])->order(['sort' => 'desc', 'id' =>'desc'])->select()->toArray(),
];
}
/**
* @notes 设置热门搜搜
* @param $params
* @return bool
* @author 段誉
* @date 2022/9/5 18:58
*/
public static function setConfig($params)
{
try {
if (!empty($params['data'])) {
foreach ($params['data'] as $val) {
if (!isset($val['name']) || empty($val['name'])) {
throw new \think\Exception('关键词缺失', 10006);
}
if (!isset($val['sort']) || $val['sort'] < 0) {
throw new \think\Exception('排序值错误', 10006);
}
}
$model = (new HotSearch());
$model->where('id', '>', 0)->delete();
$model->saveAll($params['data']);
}
$status = empty($params['status']) ? 0 : $params['status'];
ConfigService::set('hot_search', 'status', $status);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}

View File

@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\enum\DefaultEnum;
use app\common\enum\MapKeyEnum;
use app\common\logic\BaseLogic;
use app\common\model\MapKey;
use think\facade\Cache;
class MapKeyLogic extends BaseLogic
{
/**
* @notes 公共列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2024/11/5 下午1:56
*/
public function commonLists()
{
$lists = (new MapKey())->order(['id'=>'desc'])->json(['error_info'],true)->select()->toArray();
return $lists;
}
/**
* @notes 新增key
* @param $params
* @return true
* @author ljj
* @date 2024/11/5 下午2:05
*/
public function add($params)
{
MapKey::create([
'key' => $params['key'],
'type' => $params['type']
]);
return true;
}
/**
* @notes 详情
* @param $id
* @return array
* @author ljj
* @date 2024/11/5 下午2:07
*/
public function detail($id)
{
$result = MapKey::where('id',$id)->json(['error_info'],true)->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑
* @param $params
* @return true
* @author ljj
* @date 2024/11/5 下午2:20
*/
public function edit($params)
{
$mapKey = MapKey::findOrEmpty($params['id']);
$mapKey->key = $params['key'];
$mapKey->type = $params['type'];
$mapKey->status = $mapKey->status == MapKeyEnum::STATUS_ABNORMAL ? MapKeyEnum::STATUS_WAIT : $mapKey->status;
$mapKey->save();
//删除缓存
Cache::delete('TENCENT_MAP_KEY');
return true;
}
/**
* @notes 删除
* @param $id
* @return bool
* @author ljj
* @date 2024/11/5 下午2:21
*/
public function del($id)
{
return MapKey::destroy($id);
}
}

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\setting;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use think\facade\Cache;
/**
* 存储设置逻辑层
* Class ShopStorageLogic
* @package app\adminapi\logic\settings\shop
*/
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' => '腾讯云OSS',
'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']);
}
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,62 @@
<?php
namespace app\adminapi\logic\setting;
use app\common\model\TextList;
class TextLogic
{
/**
* @notes 添加
* @param $params
* @return true
* @author cjhao
* @date 2024/11/1 10:14
*/
public function add($params)
{
TextList::create([
'title' => $params['title'],
'content' => $params['content'],
]);
return true;
}
/**
* @notes 编辑
* @param $params
* @return true
* @author cjhao
* @date 2024/11/1 10:15
*/
public function edit($params)
{
TextList::update([
'title' => $params['title'],
'content' => $params['content'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除
* @param $id
* @return bool
* @author cjhao
* @date 2024/11/1 10:16
*/
public function del($id)
{
$text = TextList::where(['id'=>$id])->findOrEmpty();
if($text->isEmpty()){
return '数据不存在';
}
if($text->is_default){
return '默认数据不允许删除';
}
$text->delete();
return true;
}
}

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
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),
'is_auth_dispatch' => ConfigService::get('transaction', 'is_auth_dispatch',1),
];
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']);
ConfigService::set('transaction', 'is_auth_dispatch', $params['is_auth_dispatch']);
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,88 @@
<?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\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)
{
return DictType::update([
'id' => $params['id'],
'name' => $params['name'],
'type' => $params['type'],
'status' => $params['status'],
'remark' => $params['remark'] ?? '',
]);
}
/**
* @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();
}
}

View File

@@ -0,0 +1,100 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\pay;
use app\common\enum\PayEnum;
use app\common\logic\BaseLogic;
use app\common\model\pay\PayConfig;
class PayConfigLogic extends BaseLogic
{
/**
* @notes 查看支付配置列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/2/15 6:03 下午
*/
public function lists()
{
$lists = PayConfig::field('id,name,pay_way,image,sort')
->order(['sort'=>'asc','id'=>'desc'])
->append(['pay_way_desc'])
->select()
->toArray();
return $lists;
}
/**
* @notes 编辑支付配置
* @param $params
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/2/15 6:13 下午
*/
public function edit($params)
{
$pay_config = PayConfig::find($params['id']);
$config = '';
if ($pay_config['pay_way'] == PayEnum::WECHAT_PAY) {
$config = [
'interface_version' => $params['interface_version'],
'merchant_type' => $params['merchant_type'],
'mch_id' => $params['mch_id'],
'pay_sign_key' => $params['pay_sign_key'],
'apiclient_cert' => $params['apiclient_cert'],
'apiclient_key' => $params['apiclient_key'],
];
}
if ($pay_config['pay_way'] == PayEnum::ALI_PAY) {
$config = [
'mode' => $params['mode'] ?? 'normal_mode',
'merchant_type' => $params['merchant_type'],
'app_id' => $params['app_id'],
'private_key' => $params['private_key'],
'ali_public_key' => $params['ali_public_key'],
];
}
$pay_config->name = $params['name'];
$pay_config->image = $params['image'];
$pay_config->sort = $params['sort'];
$pay_config->config = $config ? json_encode($config) : '';
return $pay_config->save();
}
/**
* @notes 支付配置详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/15 6:28 下午
*/
public function detail($id)
{
return PayConfig::where('id',$id)->json(['config'])->append(['pay_way_desc'])->findOrEmpty()->toArray();
}
}

View File

@@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\pay;
use app\common\enum\user\UserTerminalEnum;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\pay\PayWay;
class PayWayLogic extends BaseLogic
{
/**
* @notes 获取支付方式
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/2/15 6:51 下午
*/
public function getPayWay()
{
$pay_way = PayWay::select();
$pay_way = $pay_way->append(['pay_way_desc','icon'])->toArray();
if (empty($pay_way)) {
return [];
}
$lists = [];
for ($i=1;$i<=max(array_column($pay_way,'scene'));$i++) {
foreach ($pay_way as $val) {
if ($val['scene'] == $i) {
$lists[$i][] = $val;
}
}
}
return $lists;
}
/**
* @notes 设置支付方式
* @param $params
* @return bool|string
* @throws \Exception
* @author ljj
* @date 2022/2/15 7:02 下午
*/
public function setPayWay($params)
{
$pay_way = new PayWay;
$data = [];
foreach ($params as $key=>$value) {
$is_default = array_column($value,'is_default');
$is_default_num = array_count_values($is_default);
$status = array_column($value,'status');
$scene_name = UserTerminalEnum::getTermInalDesc($key);
if (!in_array(YesNoEnum::YES,$is_default)) {
return $scene_name.'支付场景缺少默认支付';
}
if ($is_default_num[YesNoEnum::YES] > 1) {
return $scene_name.'支付场景的默认值只能存在一个';
}
if (!in_array(YesNoEnum::YES,$status)) {
return $scene_name.'支付场景至少开启一个支付状态';
}
foreach ($value as $val) {
$result = PayWay::where('id',$val['id'])->findOrEmpty();
if ($result->isEmpty()) {
continue;
}
if ($val['is_default'] == YesNoEnum::YES && $val['status'] == YesNoEnum::NO) {
return $scene_name.'支付场景的默认支付未开启支付状态';
}
$data[] = [
'id' => $val['id'],
'is_default' => $val['is_default'],
'status' => $val['status'],
];
}
}
$pay_way->saveAll($data);
return true;
}
}

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,128 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\system;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
/**
* 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)comparePHP('8.0.0'), 'remark' => '']
];
$auth = [
['dir' => '/runtime', 'require' => 'runtime目录可写', 'status' => (int)checkDirWrite('runtime'), 'remark' => ''],
];
return [
'server' => $server,
'env' => $env,
'auth' => $auth,
];
}
/**
* @notes 获取通用配置
* @return array[]
* @author cjhao
* @date 2024/8/27 17:21
*/
public static function getGeneralSetting()
{
$orderSetting = [
'order_cancel_order' => ConfigService::get('order_setting', 'order_cancel_order'),
'order_cancel_time' => ConfigService::get('order_setting', 'order_cancel_time'),
'over_time_comment' => ConfigService::get('order_setting', 'over_time_comment'),
'over_time_comment_content' => ConfigService::get('order_setting', 'over_time_comment_content')
];
$settleSetting = [
//结算方式
'commission_settle' => ConfigService::get('settle_setting', 'commission_settle'),
//结算周期1-按状态2-周期
'commission_settle_cycle' => ConfigService::get('settle_setting', 'commission_settle_cycle'),
//1-每周、2-每月
'commission_settle_cycle_type' => ConfigService::get('settle_setting', 'commission_settle_cycle_type'),
//订单结束X天后结算,每周X每月X号
'commission_settle_cycle_day' => ConfigService::get('settle_setting', 'commission_settle_cycle_day'),
];
$serverSetting = [
'advance_appoint' => ConfigService::get('server_setting', 'advance_appoint'),
'coach_order_limit' => ConfigService::get('server_setting', 'coach_order_limit'),
'coach_server_scope' => ConfigService::get('server_setting', 'coach_server_scope'),
'shop_coach_limit' => ConfigService::get('server_setting', 'shop_coach_limit'),
'shop_order_limit' => ConfigService::get('server_setting', 'shop_order_limit'),
];
return [
'order_setting' => $orderSetting,
'settle_setting' => $settleSetting,
'server_setting' => $serverSetting,
];
}
/**
* @notes 设置通用设置
* @param array $params
* @return true
* @author cjhao
* @date 2024/8/27 17:11
*/
public static function setGeneralSetting(array $params)
{
ConfigService::set('order_setting', 'order_cancel_order',$params['order_setting']['order_cancel_order']);
ConfigService::set('order_setting', 'order_cancel_time',$params['order_setting']['order_cancel_time']);
ConfigService::set('order_setting', 'over_time_comment',$params['order_setting']['over_time_comment']);
ConfigService::set('order_setting', 'over_time_comment_content',$params['order_setting']['over_time_comment_content']);
ConfigService::set('settle_setting', 'commission_settle',$params['settle_setting']['commission_settle']);
ConfigService::set('settle_setting', 'commission_settle_cycle',$params['settle_setting']['commission_settle_cycle']);
ConfigService::set('settle_setting', 'commission_settle_cycle_type',$params['settle_setting']['commission_settle_cycle_type']);
ConfigService::set('settle_setting', 'commission_settle_cycle_day',$params['settle_setting']['commission_settle_cycle_day']);
ConfigService::set('server_setting', 'advance_appoint',$params['server_setting']['advance_appoint']);
ConfigService::set('server_setting', 'coach_order_limit',$params['server_setting']['coach_order_limit']);
ConfigService::set('server_setting', 'coach_server_scope',$params['server_setting']['coach_server_scope']);
ConfigService::set('server_setting', 'shop_coach_limit',$params['server_setting']['shop_coach_limit']);
ConfigService::set('server_setting', 'shop_order_limit',$params['server_setting']['shop_order_limit']);
return true;
}
}

View File

@@ -0,0 +1,493 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\system;
use app\common\logic\BaseLogic;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use WpOrg\Requests\Requests;
/**
* 升级逻辑
* Class UpgradeLogic
* @package app\adminapi\logic\settings\system
*/
class UpgradeLogic extends BaseLogic
{
const BASE_URL = 'https://server.likeshop.cn';
/**
* @notes 格式化列表数据
* @param $lists
* @return array
* @author 段誉
* @date 2021/8/14 17:18
*/
public static function formatLists($lists, $pageNo)
{
$localData = local_version();
$localVersion = $localData['version'];
foreach ($lists as $k => $item) {
//版本描述
$lists[$k]['version_str'] = '';
$lists[$k]['able_update'] = 0;
if ($localVersion == $item['version_no']) {
$lists[$k]['version_str'] = '您的系统当前处于此版本';
}
if ($localVersion < $item['version_no']) {
$lists[$k]['version_str'] = '系统可更新至此版本';
$lists[$k]['able_update'] = 1;
}
//最新的版本号标志
$lists[$k]['new_version'] = 0;
//注意,是否需要重新发布描述
$lists[$k]['notice'] = [];
if ($item['uniapp_publish'] == 1) {
$lists[$k]['notice'][] = '更新至当前版本后需重新发布前端商城';
}
if ($item['pc_admin_publish'] == 1) {
$lists[$k]['notice'][] = '更新至当前版本后需重新发布PC管理后台';
}
if ($item['pc_shop_publish'] == 1) {
$lists[$k]['notice'][] = '更新至当前版本后需重新发布PC商城端';
}
//处理更新内容信息
$contents = $item['update_content'];
$add = [];
$optimize = [];
$repair = [];
$contentDesc = [];
if (!empty($contents)) {
foreach ($contents as $content) {
if ($content['type'] == 1) {
$add[] = '新增:' . $content['update_function'];
}
if ($content['type'] == 2) {
$optimize[] = '优化:' . $content['update_function'];
}
if ($content['type'] == 3) {
$repair[] = '修复:' . $content['update_function'];
}
}
$contentDesc = array_merge($add, $optimize, $repair);
}
$lists[$k]['add'] = $add;
$lists[$k]['optimize'] = $optimize;
$lists[$k]['repair'] = $repair;
$lists[$k]['content_desc'] = $contentDesc;
unset($lists[$k]['update_content']);
}
$lists[0]['new_version'] = ($pageNo == 1) ? 1 : 0;
return $lists;
}
/**
* @notes 更新操作
* @param $params
* @return bool|string
* @author 段誉
* @date 2021/8/14 17:19
*/
public static function upgrade($params)
{
$openBasedir = ini_get('open_basedir');
if(strpos($openBasedir, "server") !== false) {
self::$error = '请临时关闭服务器本站点的跨域攻击设置,并重启 nginx、PHP具体参考相关升级文档';
return false;
}
// 授权验证
$params['link'] = "package_link";
$result = self::verify($params);
if (!$result['has_permission']) {
self::$error = !empty($result['msg']) ? $result['msg'] : '请先联系客服获取授权';
// 写日志
self::addlog($params['id'], $params['update_type'], false);
return false;
}
// 本地更新包路径
$localUpgradeDir = ROOT_PATH . '/upgrade/';
// 本地更新临时文件
$tempDir = ROOT_PATH . '/upgrade/temp/';
// 更新成功或失败的标识
$flag = true;
Db::startTrans();
try {
// 远程下载链接
$remoteUrl = $result['link'];
if (!is_dir($localUpgradeDir)) {
mkdir(iconv("UTF-8", "GBK", $localUpgradeDir), 0777, true);
}
//下载更新压缩包保存到本地
$remoteData = self::downFile($remoteUrl, $localUpgradeDir);
if (false === $remoteData) {
throw new \Exception('获取文件错误');
}
//解压缩
if (false === unzip($remoteData['save_path'], $tempDir)) {
throw new \Exception('解压文件错误');
}
//更新sql->更新数据类型
if (false === self::upgradeSql($tempDir . 'sql/data/')) {
throw new \Exception('更新数据库数据失败');
}
//更新文件
if (false === self::upgradeFile($tempDir . 'project/server/', self::getProjectPath())) {
throw new \Exception('更新文件失败');
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
//错误日志
$params['error'] = $e->getMessage();
// 标识更新失败
$flag = false;
}
if ($flag) {
try {
//更新sql->更新数据结构
if (false === self::upgradeSql($tempDir . 'sql/structure/')) {
throw new \Exception('更新数据库结构失败');
}
} catch (\Exception $e) {
self::$error = $e->getMessage();
//错误日志
$params['error'] = $e->getMessage();
// 标识更新失败
$flag = false;
}
}
//删除临时文件(压缩包不删除,删除解压的文件)
if ($flag && false === del_target_dir($tempDir, true)) {
Log::write('删除系统更新临时文件失败');
}
// 增加日志
self::addlog($params['id'], $params['update_type'], $flag);
return $flag;
}
/**
* @notes 授权验证
* @param $params
* @author Tab
* @date 2021/10/26 17:12
*/
public static function verify($params)
{
$domain = $_SERVER['SERVER_NAME'];
$remoteUrl = self::BASE_URL . "/api/version/verify?domain=".$domain."&product_id=19&type=2&version_id=".$params['id']."&link=".$params['link'];
$result = Requests::get($remoteUrl);
$result = json_decode($result->body, true);
$result = $result['data'] ?? ['has_permission' => false, 'link' => '', 'msg' => ''];
return $result;
}
/**
* @notes 获取远程版本数据
* @param null $pageNo
* @param null $pageSize
* @return array|mixed
* @author 段誉
* @date 2021/8/14 17:20
*/
public static function getRemoteVersion($pageNo = null, $pageSize = null)
{
$cacheVersion = Cache::get('version_lists' . $pageNo);
if (!empty($cacheVersion)) {
return $cacheVersion;
}
if (empty($pageNo) || empty($pageSize)) {
$remoteUrl = self::BASE_URL . "/api/version/lists?product_id=19&type=2&page=1";
} else {
$remoteUrl = self::BASE_URL . "/api/version/lists?product_id=19&type=2&page_no=$pageNo&page_size=$pageSize&page=1";
}
$result = Requests::get($remoteUrl);
$result = json_decode($result->body, true);
$result = $result['data'] ?? [];
Cache::set('version_lists' . $pageNo, $result, 1800);
return $result;
}
/**
* @notes 更新包下载链接
* @param $params
* @return array|false
* @author 段誉
* @date 2022/3/25 17:50
*/
public static function getPkgLine($params)
{
$map = [
1 => 'package_link', //一键更新类型 : 服務端更新包
2 => 'package_link', //服務端更新包
3 => 'pc_package_link', //pc端更新包
4 => 'uniapp_package_link', //uniapp更新包
5 => 'web_package_link', //后台前端更新包
6 => 'integral_package_link', //完整包
8 => 'kefu_package_link', //客服更新包
];
$params['link'] = $map[$params['update_type']] ?? '未知类型';
// 授权验证
$result = self::verify($params);
if (!$result['has_permission']) {
self::$error = !empty($result['msg']) ? $result['msg'] : '请先联系客服获取授权';
// 写日志
self::addlog($params['id'], $params['update_type'], false);
return false;
}
//增加日志记录
self::addlog($params['id'], $params['update_type']);
//更新包下载链接
return ['line' => $result['link']];
}
/**
* @notes 添加日志
* @param $versionId //版本id
* @param $updateType //更新类型
* @param bool $status //更新状态
* @return bool|\Requests_Response
* @author 段誉
* @date 2021/10/9 14:48
*/
public static function addlog($versionId, $updateType, $status = true)
{
//版本信息
$versionData = self::getVersionDataById($versionId);
$domain = $_SERVER['SERVER_NAME'];
try {
$paramsData = [
'version_id' => $versionData['id'],
'version_no' => $versionData['version_no'],
'domain' => $domain,
'type' => 2,//付费版
'product_id' => 19,//上门按摩
'update_type' => $updateType,
'status' => $status ? 1 : 0,
'error' => empty(self::$error) ? '' : self::$error,
];
$requestUrl = self::BASE_URL . '/api/version/log';
$result = Requests::post($requestUrl, [], $paramsData);
return $result;
} catch (\Exception $e) {
Log::write('更新日志:' . '更新失败' . $e->getMessage());
return false;
}
}
/**
* @notes 通过版本记录id获取版本信息
* @param $id
* @return array
* @author 段誉
* @date 2021/10/9 11:40
*/
public static function getVersionDataById($id)
{
$cacheVersion = self::getRemoteVersion()['lists'] ?? [];
if (!empty($cacheVersion)) {
$versionColumn = array_column($cacheVersion, null, 'id');
if (!empty($versionColumn[$id])) {
return $versionColumn[$id];
}
}
return [];
}
/**
* @notes 下载远程文件
* @param $url
* @param string $savePath
* @return array|false
* @author 段誉
* @date 2021/8/14 17:20
*/
public static function downFile($url, $savePath = './upgrade/')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$header = '';
$body = '';
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') {
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
}
curl_close($ch);
//文件名
$fullName = basename($url);
//文件保存完整路径
$savePath = $savePath . $fullName;
//创建目录并设置权限
$basePath = dirname($savePath);
if (!file_exists($basePath)) {
@mkdir($basePath, 0777, true);
@chmod($basePath, 0777);
}
if (file_put_contents($savePath, $body)) {
return [
'save_path' => $savePath,
'file_name' => $fullName,
];
}
return false;
}
/**
* @notes 获取项目路径
* @return string
* @author 段誉
* @date 2021/8/14 17:20
*/
public static function getProjectPath()
{
$path = dirname(ROOT_PATH);
if(substr($path, -1) != '/') {
$path = $path . '/';
}
return $path;
}
/**
* @notes 更新sql
* @param $dir
* @return bool
* @author 段誉
* @date 2021/8/14 17:20
*/
public static function upgradeSql($dir)
{
//没有sql文件时无需更新
if (!file_exists($dir)) {
return true;
}
//遍历指定目录下的指定后缀文件
$sqlFiles = get_scandir($dir, '', 'sql');
if (false === $sqlFiles) {
return false;
}
//当前数据库前缀
$sqlPrefix = config('database.connections.mysql.prefix');
foreach ($sqlFiles as $k => $item) {
if (get_extension($item) != 'sql') {
continue;
}
$sqlContent = file_get_contents($dir . $item);
if (empty($sqlContent)) {
continue;
}
$sqls = explode(';', $sqlContent);
//执行sql
foreach ($sqls as $sql) {
$sql = trim($sql);
if (!empty($sql)) {
$sql = str_replace('`ls_', '`' . $sqlPrefix, $sql) . ';';
Db::execute($sql);
}
}
}
return true;
}
/**
* @notes 更新文件
* @param $tempFile
* @param $oldFile
* @return bool
* @author 段誉
* @date 2021/8/14 17:21
*/
public static function upgradeFile($tempFile, $oldFile)
{
if (empty(trim($tempFile)) || empty(trim($oldFile))) {
return false;
}
// 目录不存在就新建
if (!is_dir($oldFile)) {
mkdir($oldFile, 0777, true);
}
foreach (glob($tempFile . '*') as $fileName) {
// 要处理的是目录时,递归处理文件目录。
if (is_dir($fileName)) {
self::upgradeFile($fileName . '/', $oldFile . basename($fileName) . '/');
}
// 要处理的是文件时,判断是否存在 或者 与原来文件不一致 则覆盖
if (is_file($fileName)) {
if (!file_exists($oldFile . basename($fileName))
|| md5(file_get_contents($fileName)) != md5(file_get_contents($oldFile . basename($fileName)))
) {
copy($fileName, $oldFile . basename($fileName));
}
}
}
return true;
}
}

View File

@@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\user;
use app\common\{service\ConfigService, service\FileService};
/**
* 设置-用户设置逻辑层
* Class UserLogic
* @package app\adminapi\logic\config
*/
class UserLogic
{
/**
* @notes 获取用户设置
* @return array
* @author cjhao
* @date 2021/7/27 17:49
*/
public static function getConfig():array
{
$config = [
//默认头像
'default_avatar' => ConfigService::get('config', 'default_avatar', FileService::getFileUrl(config('project.default_image.default_avatar'))),
'default_coach_avatar' => ConfigService::get('config', 'default_coach_avatar', FileService::getFileUrl(config('project.default_image.default_coach_avatar'))),
'default_shop_avatar' => ConfigService::get('config', 'default_shop_avatar', FileService::getFileUrl(config('project.default_image.default_shop_avatar'))),
];
return $config;
}
/**
* @notes 设置用户设置
* @param array $postData
* @return bool
* @author cjhao
* @date 2021/7/27 17:58
*/
public function setConfig(array $params):bool
{
ConfigService::set('config', 'default_avatar', $params['default_avatar']);
ConfigService::set('config', 'default_coach_avatar', $params['default_coach_avatar']);
ConfigService::set('config', 'default_shop_avatar', $params['default_shop_avatar']);
return true;
}
/**
* @notes 获取注册配置
* @return array
* @author ljj
* @date 2022/2/17 3:32 下午
*/
public function getRegisterConfig():array
{
$config = [
// 'default_avatar' => ConfigService::get('login', 'default_avatar', FileService::getFileUrl(config('project.default_image.user_avatar'))),
// 登录方式
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
// 注册强制绑定手机
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
// 政策协议
// 'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
// 第三方登录 开关
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
// 微信授权登录
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
// qq授权登录
// 'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
];
return $config;
}
/**
* @notes 设置登录注册
* @param array $params
* @return bool
* @author cjhao
* @date 2021/9/14 17:20
*/
public static function setRegisterConfig(array $params):bool
{
// 登录方式1-账号密码登录2-手机短信验证码登录
// ConfigService::set('login', 'default_avatar', $params['default_avatar']);
ConfigService::set('login', 'login_way', $params['login_way']);
// 注册强制绑定手机
ConfigService::set('login', 'coerce_mobile', $params['coerce_mobile']);
// 政策协议
// ConfigService::set('login', 'login_agreement', $params['login_agreement']);
// 第三方授权登录
ConfigService::set('login', 'third_auth', $params['third_auth']);
// 微信授权登录
ConfigService::set('login', 'wechat_auth', $params['wechat_auth']);
// qq登录
// ConfigService::set('login', 'qq_auth', $params['qq_auth']);
return true;
}
/**
* @notes 提现配置
* @return array
* @author cjhao
* @date 2024/8/27 17:54
*/
public function getWithdrawConfig()
{
$config = [
'way_list' => ConfigService::get('withdraw', 'way_list'),
'min_money' => ConfigService::get('withdraw', 'min_money'),
'max_money' => ConfigService::get('withdraw', 'max_money'),
'service_charge' => ConfigService::get('withdraw', 'service_charge'),
'withdraw_cycle_type' => ConfigService::get('withdraw', 'withdraw_cycle_type'),
'withdraw_cycle_date' => ConfigService::get('withdraw', 'withdraw_cycle_date'),
];
return $config;
}
/**
* @notes 设置提现配置
* @return void
* @author cjhao
* @date 2024/8/27 17:54
*/
public function setWithdrawConfig($params)
{
ConfigService::set('withdraw', 'way_list',$params['way_list']);
ConfigService::set('withdraw', 'min_money',$params['min_money']);
ConfigService::set('withdraw', 'max_money',$params['max_money']);
ConfigService::set('withdraw', 'service_charge',$params['service_charge']);
ConfigService::set('withdraw', 'withdraw_cycle_type',$params['withdraw_cycle_type']);
ConfigService::set('withdraw', 'withdraw_cycle_date',$params['withdraw_cycle_date']);
}
}

View File

@@ -0,0 +1,174 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting\web;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 网站设置
* Class WebSettingLogic
* @package app\adminapi\logic\setting
*/
class WebSettingLogic extends BaseLogic
{
/**
* @notes 获取网站信息
* @return array
* @author 段誉
* @date 2021/12/28 15:43
*/
public static function getWebsiteInfo(): array
{
return [
'name' => ConfigService::get('website', 'name'),
'web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'web_favicon')),
'web_logo' => FileService::getFileUrl(ConfigService::get('website', 'web_logo')),
'login_image' => FileService::getFileUrl(ConfigService::get('website', 'login_image')),
'shop_name' => ConfigService::get('website', 'shop_name'),
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
'mobile' => ConfigService::get('website', 'mobile'),
'contact' => ConfigService::get('website', 'contact'),
'document_status' => ConfigService::get('website','document_status',1),
];
}
/**
* @notes 设置网站信息
* @param array $params
* @author 段誉
* @date 2021/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']);
$shop_logo = FileService::setFileUrl($params['shop_logo']);
ConfigService::set('website', 'name', $params['name']);
ConfigService::set('website', 'web_favicon', $favicon);
ConfigService::set('website', 'web_logo', $logo);
ConfigService::set('website', 'login_image', $login);
ConfigService::set('website', 'shop_name', $params['shop_name']);
ConfigService::set('website', 'shop_logo', $shop_logo);
ConfigService::set('website', 'mobile', $params['mobile']);
ConfigService::set('website', 'contact', $params['contact']);
//文档信息开关
ConfigService::set('website','document_status', $params['document_status']);
}
/**
* @notes 获取版权备案
* @return array
* @author 段誉
* @date 2021/12/28 16:09
*/
public static function getCopyright() : array
{
return ConfigService::get('copyright', 'config', []);
}
/**
* @notes 设置版权备案
* @param array $params
* @return bool
* @author 段誉
* @date 2022/8/8 16:33
*/
public static function setCopyright(array $params)
{
try {
if (!is_array($params['config'])) {
throw new \Exception('参数异常');
}
ConfigService::set('copyright', 'config', $params['config'] ?? []);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 设置政策协议
* @param array $params
* @author ljj
* @date 2022/2/15 10:59 上午
*/
public static function setAgreement(array $params)
{
ConfigService::set('agreement', 'service_title', $params['service_title'] ?? '');
ConfigService::set('agreement', 'service_content', $params['service_content'] ?? '');
ConfigService::set('agreement', 'privacy_title', $params['privacy_title'] ?? '');
ConfigService::set('agreement', 'privacy_content', $params['privacy_content'] ?? '');
}
/**
* @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'),
];
return $config;
}
/**
* @notes 设置地图钥匙
* @param array $params
* @return bool
* @author ljj
* @date 2022/3/10 5:11 下午
*/
public static function setMapKey(array $params)
{
ConfigService::set('map', 'tencent_map_key', $params['tencent_map_key'] ?? '');
return true;
}
/**
* @notes 获取地图钥匙
* @return array
* @author ljj
* @date 2022/3/10 5:12 下午
*/
public static function getMapKey(): array
{
return [
'tencent_map_key' => ConfigService::get('map', 'tencent_map_key',''),
];
}
}

View File

@@ -0,0 +1,97 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\shop;
use app\common\logic\BaseLogic;
use app\common\model\deposit\DepositPackage;
class DepositPackageLogic extends BaseLogic
{
/**
* @notes 添加
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
DepositPackage::create([
'name' => $params['name'],
'money' => $params['money'],
'coach_num' => $params['coach_num'],
'type' => 2,
'order_limit' => $params['order_limit'],
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = DepositPackage::where('id',$id)->withoutField('update_time,delete_time')->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
DepositPackage::update([
'name' => $params['name'],
'money' => $params['money'],
'coach_num' => $params['coach_num'],
'order_limit' => $params['order_limit'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return DepositPackage::destroy($id);
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace app\adminapi\logic\shop;
use app\common\enum\GoodsEnum;
use app\common\logic\BaseLogic;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\goods\GoodsCityIndex;
use app\common\model\goods\GoodsSkillIndex;
use app\common\model\shop\Shop;
use think\Exception;
/**
* 项目服务类
* Class GoodsLogic
* @package app\adminapi\logic\shop
*/
class GoodsLogic extends BaseLogic
{
/**
* @notes 上下架
* @param $id
* @return true|void
* @author cjhao
* @date 2024/10/29 13:06
*/
public function status($id){
$goods = Goods::where(['id'=>$id])->findOrEmpty();
if($goods->isEmpty()){
return true;
}
$goods->status = $goods->status ? 0 : 1;
$goods->save();
}
/**
* @notes 服务详情
* @param $id
* @return array
* @author cjhao
* @date 2024/10/29 13:10
*/
public function detail($id)
{
$result = Goods::where('id',$id)
->withoutField('order_num,update_time,delete_time')
->append(['category_desc','goods_image'])
->findOrEmpty()
->toArray();
$goods_image = [];
foreach ($result['goods_image'] as &$image) {
$goods_image[] = $image['uri'];
}
$result['goods_image'] = $goods_image;
$result['city_id'] = GoodsCityIndex::where(['goods_id'=>$id])->column('city_id');
$result['skill_id'] = GoodsSkillIndex::where(['goods_id'=>$id])->column('skill_id');
// $result['category_name'] = GoodsCategory::where(['id'=>$result['category_id']])->column('name');
$result['shop_name'] = Shop::where(['id'=>$result['shop_id']])->value('name');
return $result;
}
/**
* @notes 审核
* @param $params
* @return bool
* @author cjhao
* @date 2024/10/29 13:29
*/
public function audit($params)
{
try {
$detail = Goods::where(['id'=>$params['id']])->findOrEmpty();
if($detail->isEmpty()){
throw new Exception('服务不存在');
}
if(0 != $detail->audit_status){
throw new Exception('审核状态已改变');
}
$status = GoodsEnum::AUDIT_STATUS_PASS;
if(0 == $params['audit_status']){
$status = GoodsEnum::AUDIT_STATUS_REFUSE;
$detail->status = GoodsEnum::UNSHELVE;
}
$detail->audit_status = $status;
$detail->audit_remark = $params['audit_remark'] ?? '';
$detail->save();
return true;
}catch (\Exception $e){
self::$error = $e->getMessage();
return false;
}
}
}

View File

@@ -0,0 +1,535 @@
<?php
namespace app\adminapi\logic\shop;
use app\common\enum\accountLog\ShopAccountLogEnum;
use app\common\enum\shop\ShopEnum;
use app\common\logic\BaseLogic;
use app\common\logic\ShopAccountLogLogic;
use app\common\model\accountLog\ShopAccountLog;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopCategoryIndex;
use app\common\model\shop\ShopGoodsIndex;
use app\common\model\shop\ShopImage;
use app\common\model\shop\ShopUpdate;
use app\common\model\shop\ShopUser;
use app\common\service\ConfigService;
use app\common\service\FileService;
use think\Exception;
use think\facade\Db;
use think\facade\Config;
/**
* 门店逻辑类
* Class ShopLogic
* @package app\adminapi\logic\shop
*/
class ShopLogic extends BaseLogic
{
/**
* @notes 添加门店
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/10/3 13:30
*/
public function add(array $params)
{
try {
Db::startTrans();
$number = ShopUser::count()+1;
$sn = sprintf("%03d", $number);
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['mobile'], $passwordSalt);
$avatar = ConfigService::get('default_image', 'user_avatar');
$shopUser = ShopUser::where('account','=',$params['mobile'])
->findOrEmpty();
if(!$shopUser->isEmpty()){
throw new Exception('手机号码已存在');
}
$shopUser = ShopUser::create([
'sn' => $sn,
'avatar' => $avatar,
'account' => $params['mobile'],
'password' => $password,
]);
$shop = Shop::create([
'name' => $params['name'],
'shop_user_id' => $shopUser['id'],
'mobile' => $params['mobile'],
'sn' => sprintf("%03d", Shop::count()+1),
'short_name' => $params['short_name'],
'business_start_time' => '10:00',
'business_end_time' => '22:00',
'type' => $params['type'],
'social_credit_ode' => $params['social_credit_ode'],
'legal_person' => $params['legal_person'],
'legal_id_card' => $params['legal_id_card'],
'province_id' => $params['province_id'],
'city_id' => $params['city_id'],
'region_id' => $params['region_id'],
'shop_address_detail' => $params['shop_address_detail'],
'longitude' => $params['longitude'],
'latitude' => $params['latitude'],
'id_card_front' => $params['id_card_front'],
'id_card_back' => $params['id_card_back'],
// 'portrait_shooting' => $params['portrait_shooting'],
'logo' => $params['logo'],
'business_license' => $params['business_license'],
'synopsis' => $params['synopsis'] ?? '',
'work_status' => $params['work_status'] ?? '',
'server_status' => $params['server_status'] ?? '',
'audit_status' => ShopEnum::AUDIT_STATUS_PASS,
]);
$categoryLists = [];
foreach ($params['category_ids'] as $categoryId){
$categoryLists[] = [
'shop_id' => $shop['id'],
'category_id' => $categoryId,
];
}
(new ShopCategoryIndex())->saveAll($categoryLists);
$goodsLists = [];
foreach ($params['goods_ids'] as $goodsId) {
$goodsLists[] = [
'shop_id' => $shop['id'],
'goods_id' => $goodsId,
];
}
(new ShopGoodsIndex())->saveAll($goodsLists);
$shopImageLists = [];
foreach ($params['shop_image'] as $image){
$shopImageLists[] = [
'shop_id' => $shop['id'],
'uri' => $image,
];
}
(new ShopImage())->saveAll($shopImageLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 编辑门店
* @param array $params
* @return string|true
* @throws \Exception
* @author cjhao
* @date 2024/10/3 15:11
*/
public function edit(array $params)
{
try {
Db::startTrans();
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
$shopUser = ShopUser::where('id','<>',$shop['shop_user_id'])
->where('account','=',$params['mobile'])
->findOrEmpty();
if(!$shopUser->isEmpty()){
throw new Exception('手机号码已存在');
}
ShopUser::where(['id'=>$shop['shop_user_id']])->update(['account'=>$params['mobile']]);
Shop::update([
'id' => $params['id'],
'name' => $params['name'],
'short_name' => $params['short_name'],
'type' => $params['type'],
'social_credit_ode' => $params['social_credit_ode'],
'mobile' => $params['mobile'],
'legal_person' => $params['legal_person'],
'legal_id_card' => $params['legal_id_card'],
'province_id' => $params['province_id'],
'city_id' => $params['city_id'],
'region_id' => $params['region_id'],
'shop_address_detail'=> $params['shop_address_detail'],
'longitude' => $params['longitude'],
'latitude' => $params['latitude'],
'id_card_front' => $params['id_card_front'],
'id_card_back' => $params['id_card_back'],
// 'portrait_shooting' => $params['portrait_shooting'],
'logo' => $params['logo'],
'business_license' => $params['business_license'],
'synopsis' => $params['synopsis'] ?? '',
'work_status' => $params['work_status'] ?? '',
'server_status' => $params['server_status'] ?? '',
]);
ShopCategoryIndex::where(['shop_id'=>$params['id']])->delete();
ShopGoodsIndex::where(['shop_id'=>$params['id']])->delete();
ShopImage::where(['shop_id'=>$params['id']])->delete();
$categoryLists = [];
foreach ($params['category_ids'] as $categoryId){
$categoryLists[] = [
'shop_id' => $params['id'],
'category_id' => $categoryId,
];
}
(new ShopCategoryIndex())->saveAll($categoryLists);
$goodsLists = [];
foreach ($params['goods_ids'] as $goodsId) {
$goodsLists[] = [
'shop_id' => $params['id'],
'goods_id' => $goodsId,
];
}
(new ShopGoodsIndex())->saveAll($goodsLists);
$shopImageLists = [];
foreach ($params['shop_image'] as $image){
$shopImageLists[] = [
'shop_id' => $params['id'],
'uri' => $image,
];
}
(new ShopImage())->saveAll($shopImageLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 店铺详情接口
* @param int $id
* @return array
* @author cjhao
* @date 2024/10/4 00:12
*/
public function detail(int $id)
{
$detail = Shop::where(['id'=>$id])
->append(['shop_image','region_desc','province_name','city_name'])
->withoutField('update_time,delete_time')
->findOrEmpty()->toArray();
$categoryLists = ShopCategoryIndex::alias('SC')
->where(['SC.shop_id'=>$id,'is_show'=>1])
->join('goods_category GC','SC.category_id = GC.id')
->field('GC.id,GC.name')
->select()->toArray();
$goodsLists = ShopGoodsIndex::alias('SG')
->where(['SG.shop_id'=>$id,'G.status'=>1])
->join('goods G','SG.goods_id = G.id')
->field('G.id,G.image,G.name')
->select()->toArray();
$detail['shop_image'] = array_column($detail['shop_image']->toArray(),'uri');
$detail['category_lists'] = $categoryLists;
$detail['category_ids'] = array_column($categoryLists,'id');
$detail['goods_lists'] = $goodsLists;
return $detail;
}
/**
* @notes 调整余额
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/10/3 16:08
*/
public function adjustMoney(array $params)
{
try {
Db::startTrans();
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
if($shop->isEmpty()){
return '店铺不存在';
}
$action = $params['action'];
if(1 == $action){
$shop->money = $shop->money+$params['money'];
$shop->save();
ShopAccountLogLogic::add(
$shop->id,
ShopAccountLogEnum::MONEY,
ShopAccountLogEnum::ADMIN_INC_MONEY,
$action,
$params['money'],
'',
$params['admin_id']
);
}else{
if($params['money'] > $shop->money){
return '当前店铺金额仅剩:'.$shop->money;
}
$shop->money = $shop->money - $params['money'];
$shop->save();
ShopAccountLogLogic::add(
$shop->id,
ShopAccountLogEnum::MONEY,
ShopAccountLogEnum::ADMIN_DEC_MONEY,
$action,
$params['money'],
'',
$params['admin_id']
);
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 调整余额
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/10/3 16:08
*/
public function adjustDeposit(array $params)
{
try {
Db::startTrans();
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
if($shop->isEmpty()){
return '店铺不存在';
}
$action = $params['action'];
if(1 == $action){
$shop->deposit = $shop->deposit + $params['money'];
$shop->save();
ShopAccountLogLogic::add(
$shop->id,
ShopAccountLogEnum::DEPOSIT,
ShopAccountLogEnum::ADMIN_INC_DEPOSIT,
$action,
$params['money'],
'',
$params['admin_id']
);
}else{
if($params['money'] > $shop->deposit){
return '当前店铺保证金仅剩:'.$shop->deposit;
}
$shop->deposit = $shop->deposit - $params['money'];
$shop->save();
ShopAccountLogLogic::add(
$shop->id,
ShopAccountLogEnum::DEPOSIT,
ShopAccountLogEnum::ADMIN_DEC_DEPOSIT,
$action,
$params['money'],
'',
$params['admin_id']
);
}
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 店铺审核
* @param array $params
* @return string|true
* @author cjhao
* @date 2024/10/7 00:44
*/
public function shopAudit(array $params)
{
try {
// Db::startTrans();
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
if($shop->isEmpty()){
throw new Exception('店铺不存在');
}
if(ShopEnum::AUDIT_STATUS_WAIT != $shop->audit_status){
throw new Exception( '店铺的审核状态已改变,请刷新页面');
}
$status = ShopEnum::AUDIT_STATUS_PASS;
$auditRemark = $params['audit_remark'] ?? '';
$auditStatus = $params['audit_status'] ?? 0;
if(0 == $auditStatus){
$status = ShopEnum::AUDIT_STATUS_REFUSE;
if(empty($auditRemark)){
throw new Exception("请输入备注");
}
}
$shop->audit_status = $status;
$shop->audit_remark = $params['audit_remark'] ?? '';
$shop->save();
return true;
}catch (Exception $e){
// Db::rollback();
return $e->getMessage();
}
}
public function updateDetail(int $id)
{
$updateShop = (new ShopUpdate())
->where(['id'=>$id])
->withoutField('create_time,update_time,delete_time')
->append(['region_name','province_name','city_name'])
->findOrEmpty()
->toArray();
$shop = (new Shop())
->where(['id'=>$updateShop['shop_id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])
->append(['category_ids','goods_ids','shop_image'])
->withoutField('create_time,update_time,delete_time')
->findOrEmpty()
->toArray();
foreach ($updateShop as $key => $update){
$cancel = ['id','shop_id','shop_user_id'];
if(in_array($key,$cancel)){
continue;
}
$data = $shop[$key] ?? '';
$updateShop[$key.'_update'] = $update == $data ? false: true;
if('goods_ids' == $key && $data){
$goodsIds = array_column($data->toArray(),'goods_id');
// foreach ($update as $goodsKey => $goodsId){
// $update[$goodsKey] = (int)$goodsId;
// }
sort($goodsIds);
sort($update);
$updateShop[$key.'_update'] = $update == $goodsIds ? false : true;
}
if('category_ids' == $key && $data){
$categoryIds = array_column($data->toArray(),'category_id');
// foreach ($update as $goodsKey => $goodsId){
// $update[$goodsKey] = (int)$goodsId;
// }
sort($categoryIds);
sort($update);
$updateShop[$key.'_update'] = $update == $categoryIds ? false : true;
}
if('shop_image' == $key && $data){
$uriLists = array_column($data->toArray(),'uri');
foreach ($uriLists as $uriKey => $uri){
$uriLists[$uriKey] = FileService::setFileUrl($uri);
}
sort($uriLists);
sort($update);
$updateShop[$key.'_update'] = $uriLists == $update ? false : true;
}
}
return $updateShop;
}
/**
* @notes 资料审核
* @param $params
* @return string|true
* @throws \Exception
* @author cjhao
* @date 2024/12/11 19:24
*/
public function updateAudit($params)
{
try {
Db::startTrans();
$shopUpdate = ShopUpdate::where(['id'=>$params['id']])->findOrEmpty();
if($shopUpdate->isEmpty()){
return '申请记录不存在';
}
if(ShopEnum::AUDIT_STATUS_WAIT != $shopUpdate->audit_status){
return '申请的审核状态已改变,请刷新页面';
}
$status = ShopEnum::AUDIT_STATUS_PASS;
if(0 == $params['audit_status']){
$status = ShopEnum::AUDIT_STATUS_REFUSE;
}
$shopUpdate->audit_status = $status;
$shopUpdate->audit_remark = $params['audit_remark'] ?? '';
$shopUpdate->save();
if(0 == $params){
Db::commit();
return true;
}
Shop::update([
'id' => $shopUpdate['shop_id'],
'name' => $shopUpdate['name'],
'short_name' => $shopUpdate['short_name'],
// 'mobile' => $shopUpdate['mobile'],
'type' => $shopUpdate['type'],
'business_start_time' => $shopUpdate['business_start_time'],
'business_end_time' => $shopUpdate['business_end_time'],
'social_credit_ode' => $shopUpdate['social_credit_ode'],
'legal_person' => $shopUpdate['legal_person'],
'legal_id_card' => $shopUpdate['legal_id_card'],
'province_id' => $shopUpdate['province_id'],
'city_id' => $shopUpdate['city_id'],
'region_id' => $shopUpdate['region_id'],
'shop_address_detail' => $shopUpdate['shop_address_detail'],
'longitude' => $shopUpdate['longitude'],
'latitude' => $shopUpdate['latitude'],
'id_card_front' => $shopUpdate['id_card_front'],
'id_card_back' => $shopUpdate['id_card_back'],
'portrait_shooting' => $shopUpdate['portrait_shooting'],
'logo' => $shopUpdate['logo'],
'business_license' => $shopUpdate['business_license'],
'synopsis' => $shopUpdate['synopsis'] ?? '',
]);
ShopCategoryIndex::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
ShopGoodsIndex::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
ShopImage::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
// ShopUser::where(['id'=>$shopUpdate['shop_user_id']])->update(['mobile'=>$shopUpdate['mobile']]);
$categoryLists = [];
foreach ($shopUpdate['category_ids'] as $categoryId){
$categoryLists[] = [
'shop_id' => $shopUpdate['shop_id'],
'category_id' => $categoryId,
];
}
(new ShopCategoryIndex())->saveAll($categoryLists);
$goodsLists = [];
foreach ($shopUpdate['goods_ids'] as $goodsId) {
$goodsLists[] = [
'shop_id' => $shopUpdate['shop_id'],
'goods_id' => $goodsId,
];
}
(new ShopGoodsIndex())->saveAll($goodsLists);
$shopImageLists = [];
foreach ($shopUpdate['shop_image'] as $image){
$shopImageLists[] = [
'shop_id' => $shopUpdate['shop_id'],
'uri' => $image,
];
}
(new ShopImage())->saveAll($shopImageLists);
Db::commit();
return true;
}catch (Exception $e){
Db::rollback();
return $e->getMessage();
}
}
}

View File

@@ -0,0 +1,398 @@
<?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();
$detail['menu']['pid'] = intval($detail['menu']['pid'] ?? 0);
$detail['menu']['type'] = intval($detail['menu']['type'] ?? 0);
$detail['menu']['name'] = !empty($detail['menu']['name'])
? $detail['menu']['name'] : $detail['table_comment'];
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 {
// 更新主表-数据表信息
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' => [
'pid' => $params['menu']['pid'] ?? 0,
'type' => $params['menu']['type'] ?? 0,
'name' => $params['menu']['name'] ?? $params['table_comment'],
]
]);
// 更新从表-数据表字段信息
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();
$generateService = app()->make(GenerateService::class);
return $generateService->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)
{
$tablePrefix = config('database.connections.mysql.prefix');
$tableName = str_replace($tablePrefix, '', $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' => 0, // 构建方式 0-手动添加 1-自动构建
'name' => $tableData['comment'], // 菜单名称
]
]);
}
/**
* @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;
}
}

View File

@@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\user;
use app\common\enum\accountLog\AccountLogEnum;
use app\common\logic\AccountLogLogic;
use app\common\logic\BaseLogic;
use app\common\model\user\User;
use think\facade\Db;
class UserLogic extends BaseLogic
{
/**
* @notes 用户详情
* @param $id
* @return array
* @author ljj
* @date 2022/4/21 2:28 下午
*/
public static function detail($id)
{
$result = User::where('id',$id)
->field('id,sn,nickname,avatar,mobile,sex,real_name,login_time,channel as register_source,create_time,account,user_money')
->append(['sex_desc','source_desc'])
->findOrEmpty()
->toArray();
if (!empty($result)) {
$result['login_time'] = $result['login_time'] ? date('Y-m-d H:i:s',$result['login_time']) : '-';
}
return $result;
}
/**
* @notes 修改用户信息
* @param $params
* @return bool
* @author ljj
* @date 2022/8/10 4:54 下午
*/
public function editInfo($params):bool
{
User::where(['id'=>$params['id']])->update([$params['field']=>$params['value']]);
return true;
}
/**
* @notes 调整余额
* @param array $params
* @return bool|string
* @author ljj
* @date 2023/4/12 11:58 上午
*/
public function adjustUserWallet(array $params)
{
Db::startTrans();
try {
$user = User::find($params['id']);
//增加
if(1 == $params['adjust_action']){
//调整可用余额
$user->user_money = $user->user_money + $params['adjust_num'];
$user->save();
//流水日志
AccountLogLogic::add($user->id,AccountLogEnum::MONEY,AccountLogEnum::ADMIN_INC_MONEY,AccountLogEnum::INC,$params['adjust_num']);
}else{
$user->user_money = $user->user_money - $params['adjust_num'];
$user->save();
//流水日志
AccountLogLogic::add($user->id,AccountLogEnum::MONEY,AccountLogEnum::ADMIN_DEC_MONEY,AccountLogEnum::DEC,$params['adjust_num']);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
}
}