初始化仓库

This commit is contained in:
wangxiaowei
2025-04-22 14:09:52 +08:00
commit 8b100110bb
5155 changed files with 664201 additions and 0 deletions

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\setting\app
*/
class AppSettingLogic extends BaseLogic
{
/**
* @notes 获取App设置
* @return array
* @author 段誉
* @date 2022/3/29 10:25
*/
public static function getConfig()
{
$config = [
'ios_download_url' => ConfigService::get('app', 'ios_download_url', ''),
'android_download_url' => ConfigService::get('app', 'android_download_url', ''),
'download_title' => ConfigService::get('app', 'download_title', ''),
];
return $config;
}
/**
* @notes App设置
* @param $params
* @author 段誉
* @date 2022/3/29 10:26
*/
public static function setConfig($params)
{
ConfigService::set('app', 'ios_download_url', $params['ios_download_url'] ?? '');
ConfigService::set('app', 'android_download_url', $params['android_download_url'] ?? '');
ConfigService::set('app', 'download_title', $params['download_title'] ?? '');
}
}

View File

@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
/**
* 小程序设置逻辑
* Class MnpSettingsLogic
* @package app\adminapi\logic\channel
*/
class MnpSettingsLogic extends BaseLogic
{
/**
* @notes 获取小程序配置
* @return array
* @author ljj
* @date 2022/2/16 9:38 上午
*/
public function getConfig()
{
$domainName = $_SERVER['SERVER_NAME'];
$qrCode = ConfigService::get('mnp_setting', 'qr_code', '');
$qrCode = empty($qrCode) ? $qrCode : FileService::getFileUrl($qrCode);
$config = [
'name' => ConfigService::get('mnp_setting', 'name', ''),
'original_id' => ConfigService::get('mnp_setting', 'original_id', ''),
'qr_code' => $qrCode,
'app_id' => ConfigService::get('mnp_setting', 'app_id', ''),
'app_secret' => ConfigService::get('mnp_setting', 'app_secret', ''),
'request_domain' => 'https://'.$domainName,
'socket_domain' => 'wss://'.$domainName,
'upload_file_domain' => 'https://'.$domainName,
'download_file_domain' => 'https://'.$domainName,
'udp_domain' => 'udp://'.$domainName,
'business_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置小程序配置
* @param $params
* @author ljj
* @date 2022/2/16 9:51 上午
*/
public function setConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('mnp_setting','name', $params['name'] ?? '');
ConfigService::set('mnp_setting','original_id',$params['original_id'] ?? '');
ConfigService::set('mnp_setting','qr_code',$qrCode);
ConfigService::set('mnp_setting','app_id',$params['app_id']);
ConfigService::set('mnp_setting','app_secret',$params['app_secret']);
}
}

View File

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

View File

@ -0,0 +1,224 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\channel;
use app\common\enum\OfficialAccountEnum;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\channel\OfficialAccountReply;
use app\common\service\wechat\WeChatConfigService;
use app\common\service\wechat\WeChatOaService;
/**
* 微信公众号回复逻辑层
* Class OfficialAccountReplyLogic
* @package app\adminapi\logic\channel
*/
class OfficialAccountReplyLogic extends BaseLogic
{
/**
* @notes 添加回复(关注/关键词/默认)
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 10:57
*/
public static function add($params)
{
try {
// 关键字回复排序值须大于0
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] < 0) {
throw new \Exception('排序值须大于或等于0');
}
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
}
OfficialAccountReply::create($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 查看回复详情
* @param $params
* @return array
* @author 段誉
* @date 2022/3/29 11:00
*/
public static function detail($params)
{
$field = 'id,name,keyword,reply_type,matching_type,content_type,content,status,sort';
$field .= ',reply_type as reply_type_desc, matching_type as matching_type_desc, content_type as content_type_desc, status as status_desc';
return OfficialAccountReply::field($field)->findOrEmpty($params['id'])->toArray();
}
/**
* @notes 编辑回复(关注/关键词/默认)
* @param $params
* @return bool
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function edit($params)
{
try {
// 关键字回复排序值须大于0
if ($params['reply_type'] == OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['sort'] < 0) {
throw new \Exception('排序值须大于或等于0');
}
if ($params['reply_type'] != OfficialAccountEnum::REPLY_TYPE_KEYWORD && $params['status']) {
// 非关键词回复只能有一条记录处于启用状态,所以将该回复类型下的已有记录置为禁用状态
OfficialAccountReply::where(['reply_type' => $params['reply_type']])->update(['status' => YesNoEnum::NO]);
}
OfficialAccountReply::update($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除回复(关注/关键词/默认)
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function delete($params)
{
OfficialAccountReply::destroy($params['id']);
}
/**
* @notes 更新排序
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function sort($params)
{
$params['sort'] = $params['new_sort'];
OfficialAccountReply::update($params);
}
/**
* @notes 更新状态
* @param $params
* @author 段誉
* @date 2022/3/29 11:01
*/
public static function status($params)
{
$reply = OfficialAccountReply::findOrEmpty($params['id']);
$reply->status = !$reply->status;
$reply->save();
}
/**
* @notes 微信公众号回调
* @return \Psr\Http\Message\ResponseInterface|void
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
* @throws \ReflectionException
* @throws \Throwable
* @author 段誉
* @date 2023/2/27 14:38\
*/
public static function index()
{
$server = (new WeChatOaService())->getServer();
// 事件
$server->addMessageListener(OfficialAccountEnum::MSG_TYPE_EVENT, function ($message, \Closure $next) {
switch ($message['Event']) {
case OfficialAccountEnum::EVENT_SUBSCRIBE: // 关注事件
$replyContent = OfficialAccountReply::where([
'reply_type' => OfficialAccountEnum::REPLY_TYPE_FOLLOW,
'status' => YesNoEnum::YES
])
->value('content');
if ($replyContent) {
return $replyContent;
}
break;
}
return $next($message);
});
// 文本
$server->addMessageListener(OfficialAccountEnum::MSG_TYPE_TEXT, function ($message, \Closure $next) {
$replyList = OfficialAccountReply::where([
'reply_type' => OfficialAccountEnum::REPLY_TYPE_KEYWORD,
'status' => YesNoEnum::YES
])
->order('sort asc')
->select();
$replyContent = '';
foreach ($replyList as $reply) {
switch ($reply['matching_type']) {
case OfficialAccountEnum::MATCHING_TYPE_FULL:
$reply['keyword'] === $message['Content'] && $replyContent = $reply['content'];
break;
case OfficialAccountEnum::MATCHING_TYPE_FUZZY:
stripos($message['Content'], $reply['keyword']) !== false && $replyContent = $reply['content'];
break;
}
if ($replyContent) {
break; // 得到回复文本,中止循环
}
}
//消息回复为空的话,找默认回复
if (empty($replyContent)) {
$replyContent = static::getDefaultReply();
}
if ($replyContent) {
return $replyContent;
}
return $next($message);
});
return $server->serve();
}
/**
* @notes 默认回复信息
* @return mixed
* @author 段誉
* @date 2023/2/27 14:36
*/
public static function getDefaultReply()
{
return OfficialAccountReply::where([
'reply_type' => OfficialAccountEnum::REPLY_TYPE_DEFAULT,
'status' => YesNoEnum::YES
])
->value('content');
}
}

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', 1),
'business_domain' => $domainName,
'js_secure_domain' => $domainName,
'web_auth_domain' => $domainName,
];
return $config;
}
/**
* @notes 设置公众号配置
* @param $params
* @author ljj
* @date 2022/2/16 10:08 上午
*/
public function setConfig($params)
{
$qrCode = isset($params['qr_code']) ? FileService::setFileUrl($params['qr_code']) : '';
ConfigService::set('oa_setting','name', $params['name'] ?? '');
ConfigService::set('oa_setting','original_id', $params['original_id'] ?? '');
ConfigService::set('oa_setting','qr_code', $qrCode);
ConfigService::set('oa_setting','app_id',$params['app_id']);
ConfigService::set('oa_setting','app_secret',$params['app_secret']);
ConfigService::set('oa_setting','token',$params['token'] ?? '');
ConfigService::set('oa_setting','encoding_aes_key',$params['encoding_aes_key'] ?? '');
ConfigService::set('oa_setting','encryption_type',$params['encryption_type']);
}
}

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\setting\app
*/
class OpenSettingLogic extends BaseLogic
{
/**
* @notes 获取微信开放平台设置
* @return array
* @author 段誉
* @date 2022/3/29 11:03
*/
public static function getConfig()
{
$config = [
'app_id' => ConfigService::get('open_platform', 'app_id', ''),
'app_secret' => ConfigService::get('open_platform', 'app_secret', ''),
];
return $config;
}
/**
* @notes 微信开放平台设置
* @param $params
* @author 段誉
* @date 2022/3/29 11:03
*/
public static function setConfig($params)
{
ConfigService::set('open_platform', 'app_id', $params['app_id'] ?? '');
ConfigService::set('open_platform', 'app_secret', $params['app_secret'] ?? '');
}
}

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\setting\h5
*/
class WebPageSettingLogic extends BaseLogic
{
/**
* @notes 获取H5设置
* @return array
* @author 段誉
* @date 2022/3/29 10:34
*/
public static function getConfig()
{
$config = [
// 渠道状态 0-关闭 1-开启
'status' => ConfigService::get('web_page', 'status', 1),
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
'page_status' => ConfigService::get('web_page', 'page_status', 0),
// 自定义链接
'page_url' => ConfigService::get('web_page', 'page_url', ''),
'url' => request()->domain() . '/mobile'
];
return $config;
}
/**
* @notes H5设置
* @param $params
* @author 段誉
* @date 2022/3/29 10:34
*/
public static function setConfig($params)
{
ConfigService::set('web_page', 'status', $params['status']);
ConfigService::set('web_page', 'page_status', $params['page_status']);
ConfigService::set('web_page', 'page_url', $params['page_url']);
}
}