Browse Source

修改忽略文件

master
王泽彦 10 months ago
parent
commit
d1dc1441ec
  1. 32
      niucloud/config/app.php
  2. 51
      niucloud/config/cache.php
  3. 39
      niucloud/config/captcha.php
  4. 24
      niucloud/config/console.php
  5. 20
      niucloud/config/cookie.php
  6. 5
      niucloud/config/cron.php
  7. 63
      niucloud/config/database.php
  8. 24
      niucloud/config/filesystem.php
  9. 45
      niucloud/config/gateway_worker.php
  10. 30
      niucloud/config/imgcaptcha.php
  11. 79
      niucloud/config/install.php
  12. 27
      niucloud/config/lang.php
  13. 45
      niucloud/config/log.php
  14. 8
      niucloud/config/middleware.php
  15. 16
      niucloud/config/niucloud.php
  16. 26
      niucloud/config/oauth.php
  17. 33
      niucloud/config/pay.php
  18. 22
      niucloud/config/poster.php
  19. 45
      niucloud/config/route.php
  20. 19
      niucloud/config/session.php
  21. 36
      niucloud/config/sms.php
  22. 44
      niucloud/config/terminal.php
  23. 10
      niucloud/config/trace.php
  24. 98
      niucloud/config/upload.php
  25. 6
      niucloud/config/version.php
  26. 31
      niucloud/config/view.php
  27. 29
      niucloud/core/core/base/BaseAdminController.php
  28. 31
      niucloud/core/core/base/BaseAdminService.php
  29. 29
      niucloud/core/core/base/BaseApiController.php
  30. 31
      niucloud/core/core/base/BaseApiService.php
  31. 96
      niucloud/core/core/base/BaseController.php
  32. 27
      niucloud/core/core/base/BaseCoreService.php
  33. 61
      niucloud/core/core/base/BaseJob.php
  34. 48
      niucloud/core/core/base/BaseModel.php
  35. 135
      niucloud/core/core/base/BaseService.php
  36. 46
      niucloud/core/core/base/BaseValidate.php
  37. 38
      niucloud/core/core/dict/AdvPosition.php
  38. 162
      niucloud/core/core/dict/BaseDict.php
  39. 41
      niucloud/core/core/dict/Config.php
  40. 45
      niucloud/core/core/dict/Console.php
  41. 41
      niucloud/core/core/dict/DictLoader.php
  42. 38
      niucloud/core/core/dict/DiyFormComponent.php
  43. 38
      niucloud/core/core/dict/DiyFormTemplate.php
  44. 38
      niucloud/core/core/dict/DiyFormType.php
  45. 42
      niucloud/core/core/dict/Event.php
  46. 45
      niucloud/core/core/dict/GrowthRule.php
  47. 50
      niucloud/core/core/dict/Icon.php
  48. 56
      niucloud/core/core/dict/Lang.php
  49. 46
      niucloud/core/core/dict/MemberAccountChangeType.php
  50. 45
      niucloud/core/core/dict/MemberBenefits.php
  51. 45
      niucloud/core/core/dict/MemberGift.php
  52. 29
      niucloud/core/core/dict/Menu.php
  53. 43
      niucloud/core/core/dict/Notice.php
  54. 1
      niucloud/core/core/dict/PackageGift.php
  55. 45
      niucloud/core/core/dict/PointRule.php
  56. 95
      niucloud/core/core/dict/Poster.php
  57. 40
      niucloud/core/core/dict/Printer.php
  58. 43
      niucloud/core/core/dict/RechargeGift.php
  59. 33
      niucloud/core/core/dict/Route.php
  60. 60
      niucloud/core/core/dict/Schedule.php
  61. 38
      niucloud/core/core/dict/UniappComponent.php
  62. 75
      niucloud/core/core/dict/UniappLink.php
  63. 52
      niucloud/core/core/dict/UniappPages.php
  64. 95
      niucloud/core/core/dict/UniappTemplate.php
  65. 75
      niucloud/core/core/dict/WebLink.php
  66. 17
      niucloud/core/core/exception/AddonException.php
  67. 17
      niucloud/core/core/exception/AdminException.php
  68. 18
      niucloud/core/core/exception/ApiException.php
  69. 18
      niucloud/core/core/exception/AuthException.php
  70. 18
      niucloud/core/core/exception/CaptchaException.php
  71. 18
      niucloud/core/core/exception/CommonException.php
  72. 18
      niucloud/core/core/exception/NiucloudException.php
  73. 18
      niucloud/core/core/exception/NoticeException.php
  74. 18
      niucloud/core/core/exception/PayException.php
  75. 18
      niucloud/core/core/exception/ServerException.php
  76. 18
      niucloud/core/core/exception/UploadFileException.php
  77. 18
      niucloud/core/core/exception/WechatException.php
  78. 57
      niucloud/core/core/job/Dispatch.php
  79. 118
      niucloud/core/core/loader/Loader.php
  80. 69
      niucloud/core/core/loader/Storage.php
  81. 42
      niucloud/core/core/oauth/BaseOauth.php
  82. 38
      niucloud/core/core/oauth/OauthLoader.php
  83. 32
      niucloud/core/core/oauth/Weapp.php
  84. 40
      niucloud/core/core/oauth/Wechat.php
  85. 389
      niucloud/core/core/pay/Alipay.php
  86. 203
      niucloud/core/core/pay/BasePay.php
  87. 42
      niucloud/core/core/pay/PayLoader.php
  88. 538
      niucloud/core/core/pay/Wechatpay.php
  89. 41
      niucloud/core/core/poster/BasePoster.php
  90. 205
      niucloud/core/core/poster/Poster.php
  91. 42
      niucloud/core/core/poster/PosterLoader.php
  92. 39
      niucloud/core/core/printer/BasePrinter.php
  93. 37
      niucloud/core/core/printer/KdniaoPrinter.php
  94. 39
      niucloud/core/core/printer/PrinterLoader.php
  95. 32
      niucloud/core/core/printer/sdk/yilianyun/Autoloader.php
  96. 36
      niucloud/core/core/printer/sdk/yilianyun/api/ExpressPrintService.php
  97. 22
      niucloud/core/core/printer/sdk/yilianyun/api/OauthService.php
  98. 22
      niucloud/core/core/printer/sdk/yilianyun/api/PicturePrintService.php
  99. 19
      niucloud/core/core/printer/sdk/yilianyun/api/PrintMenuService.php
  100. 20
      niucloud/core/core/printer/sdk/yilianyun/api/PrintService.php

32
niucloud/config/app.php

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 应用地址
'app_host' => env('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 默认应用
'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表(自动多应用模式有效)
'deny_app_list' => [],
// 异常页面的模板文件
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
];

51
niucloud/config/cache.php

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 默认缓存驱动
'default' => env('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => app()->getRuntimePath() . 'cache' . DIRECTORY_SEPARATOR,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
// 更多的缓存连接
// redis
'redis' => [
// 驱动方式
'type' => 'redis',
// 服务器地址
'host' => env('redis.redis_hostname', '127.0.0.1'),
// 端口
'port' => env('redis.port', '6379'),
// 密码
'password' => env('redis.redis_password', ''),
// 缓存有效期 0表示永久缓存
'expire' => 0 ,
// 缓存前缀
'prefix' => '',
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 数据库 0号数据库
'select' => env('redis.select', 0),
'serialize' => [],
// 服务端主动关闭
'timeout' => 0
],
],
];

39
niucloud/config/captcha.php

@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | Captcha配置文件
// +----------------------------------------------------------------------
return [
//验证码位数
'length' => 4,
// 验证码字符集合
'codeSet' => '1234567890',
// 验证码过期时间
'expire' => 1800,
// 是否使用中文验证码
'useZh' => false,
// 是否使用算术验证码
'math' => false,
// 是否使用背景图
'useImgBg' => false,
//验证码字符大小
'fontSize' => 14,
// 是否使用混淆曲线
'useCurve' => true,
//是否添加杂点
'useNoise' => true,
// 验证码字体 不设置则随机
'fontttf' => '',
//背景颜色
'bg' => [243, 251, 254],
// 验证码图片高度
'imageH' => 36,
// 验证码图片宽度
'imageW' => 100,
// 添加额外的验证码设置
// verify => [
// 'length'=>4,
// ...
//],
];

24
niucloud/config/console.php

@ -0,0 +1,24 @@
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
use core\dict\DictLoader;
$data = [
// 指令定义
'commands' => [
'addon:install' => 'app\command\Addon\Install',
'addon:uninstall' => 'app\command\Addon\Uninstall',
'menu:refresh' => 'app\command\Menu',
//消息队列 自定义命令
'queue:work' => 'app\command\queue\Queue',
'queue:restart' => 'app\command\queue\Queue',
'queue:listen' => 'app\command\queue\Queue',
//计划任务 自定义命令
'cron:schedule' => 'app\command\schedule\Schedule',
//wokrerman的启动停止和重启
'workerman' => 'app\command\workerman\Workerman',
],
];
return (new DictLoader("Console"))->load($data);

20
niucloud/config/cookie.php

@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
return [
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => false,
// 是否使用 setcookie
'setcookie' => true,
// samesite 设置,支持 'strict' 'lax'
'samesite' => '',
];

5
niucloud/config/cron.php

@ -0,0 +1,5 @@
<?php
return [
'tasks' => []
];

63
niucloud/config/database.php

@ -0,0 +1,63 @@
<?php
return [
// 默认使用的数据库连接配置
'default' => env('database.driver', 'mysql'),
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 时间字段配置 配置格式:create_time,update_time
'datetime_field' => '',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => env('database.type', 'mysql'),
// 服务器地址
'hostname' => env('database.hostname', '127.0.0.1'),
// 数据库名
'database' => env('database.database', ''),
// 用户名
'username' => env('database.username', 'root'),
// 密码
'password' => env('database.password', ''),
// 端口
'hostport' => env('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database.charset', 'utf8mb4'),
// 数据库表前缀
'prefix' => env('database.prefix', 'ns_'),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => env('app_debug', true),
// 开启字段缓存
'fields_cache' => false,
],
// 更多的数据库配置信息
],
];

24
niucloud/config/filesystem.php

@ -0,0 +1,24 @@
<?php
return [
// 默认磁盘
'default' => env('filesystem.driver', 'local'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/storage',
// 磁盘路径对应的外部URL路径
'url' => '/storage',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];

45
niucloud/config/gateway_worker.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | Workerman设置 仅对 php think worker:gateway 指令有效
// +----------------------------------------------------------------------
return [
// 扩展自身需要的配置
'protocol' => 'websocket', // 协议 支持 tcp udp unix http websocket text
'host' => '0.0.0.0', // 监听地址
'port' => 2348, // 监听端口
'socket' => '', // 完整监听地址
'context' => [], // socket 上下文选项
'register_deploy' => true, // 是否需要部署register
'businessWorker_deploy' => true, // 是否需要部署businessWorker
'gateway_deploy' => true, // 是否需要部署gateway
// Register配置
'registerAddress' => '127.0.0.1:1236',
// Gateway配置
'name' => 'thinkphp',
'count' => 1,
'lanIp' => '127.0.0.1',
'startPort' => 2000,
'daemonize' => false,
'pingInterval' => 30,
'pingNotResponseLimit' => 0,
'pingData' => '{"type":"ping"}',
// BusinsessWorker配置
'businessWorker' => [
'name' => 'BusinessWorker',
'count' => 1,
'eventHandler' => '\think\worker\Events',
],
];

30
niucloud/config/imgcaptcha.php

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* 请将该文件放置于config目录
*/
use think\facade\Cache;
return [
'font_file' => '', //自定义字体包路径, 不填使用默认值
//文字验证码
'click_world' => [
'backgrounds' => []
],
//滑动验证码
'block_puzzle' => [
'backgrounds' => [], //背景图片路径, 不填使用默认值
'templates' => [], //模板图
'offset' => 10, //容错偏移量
],
//水印
'watermark' => [
'fontsize' => 12,
'color' => '#ffffff',
'text' => ''
],
'cache' => [
'constructor' => [Cache::class, 'instance']
]
];

79
niucloud/config/install.php

@ -0,0 +1,79 @@
<?php
$addon_dir = root_path() . 'addon';
$addons = array_diff(scandir($addon_dir), ['.', '..']);
foreach ($addons as $addon) {
$install_php = $addon_dir . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR . 'install.php';
if (file_exists($install_php)) {
$addon_info = json_decode(file_get_contents($addon_dir . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR . 'info.json'), true);
if (!isset($addon_info['type']) || $addon_info['type'] != 'app') continue;
return include $install_php;
}
}
return [
'website_name' => 'NIUCLOUD-ADMIN',
// logo
'logo' => 'logo.jpg',
// 官网地址
'website_url' => 'https://www.niucloud.com',
// 论坛地址
'bbs_url' => 'http://bbs.niucloud.com',
// 编译帮助手册
'build_manual' => 'https://www.kancloud.cn/niushop/niucloud-admin-app/3199825',
// 安装协议
'agreement' => '<strong>版权所有 (c)2023,niucloud-admin保留所有权利。</strong>
<p>
感谢您选择niucloud-admin【以下简称niucloud】,niucloud-admin后台采用thinkphp6+php8+mysql,前端采用uniapp前后端分离的技术开发,全部源码开放。 <br/>
为了使您正确并合法的使用本软件,请您在使用前务必阅读清楚下面的协议条款:
</p>
<p>
<strong>一、本协议适用于niucloud-admin框架以及框架内所有应用,使用前请您务必仔细阅读本协议须知并勾选接受或者不接受,如不接受此协议,那么您无权利继续注册并使用本协议涉及的所有服务,如果您继续注册,登录,订阅等行为,则视为默认接受本协议。niucloud官方对本授权协议拥有最终解释权。</strong>
</p>
<p>
<strong>二、协议许可权利 </strong>
<ol>
<li>1、用户接受并承诺遵守本协议才可登录niucloud-admin官网订购应用,如果用户不同意,那么不允许在niucloud-admin官网注册账号并登录体验。</li>
<li>2、用户必须是具有独立民事责任行为能力的自然人、法人或其他组织个人。若用户不具备前述资格,那么该用户及其监护人应承担导致的一切后果。并且官方有权利对其账号进行冻结,对官方造成的利益损害有权进行申诉索赔。</li>
<li>3、用户可登录niucloud-admin官网下载并安装免费版应用。</li>
<li>4、若需要安装付费版应用,用户需要登录niucloud-admin官网付费并订购付费版应用后才可下载安装。</li>
<li>5、在更新niucloud-admin框架到最新版时,请务必对原整站内容进行备份,否则niucloud官方对升级过程中造成的数据丢失等问题不承担任何责任。</li>
<li>6、niucloud官方下架应用造成的无法更新,官方不承担任何责任。</li>
<li>7、niucloud官方因商业需求,暂停应用的更新,官方不承担任何责任。</li>
<li>8、niucloud官网有权根据需要不时地制订、修改本协议或各类规则,并以公示的方式进行公告,不再单独通知用户。变更后的协议和规则一经公布后,立即自动生效。如用户不同意相关变更,应当立即停止使用niucloud-admin付费应用。如果用户继续订阅、使用niucloud-admin付费应用,即表示用户接受经修订的协议。</li>
</ol>
</p>
<p>
<strong>三、协议规定的约束和限制</strong>
<ol>
<li>1、请尊重开发人员劳动成果,严禁对本框架进行转卖、销售或二次开发后转卖、销售等商业行为。</li>
<li>2、任何企业和个人不允许对程序代码以任何形式任何目的再发布。</li>
<li>3、基于niucloud-admin应用从事的任何商业行为,都与niucloud官方无关。</li>
<li>4、授权niucloud-admin付费应用时,必须要确保授权信息主体录入的准确性,否则出现的法律纠纷与niucloud官方无关,需要自行解决。</li>
<li>5、应用金额以最终结算价格为准,已售出的应用不做任何差价补偿。</li>
<li>6、如果用户利用特殊手段以低价或者免费获得付费应用,niucloud官方有权对应用进行回收。</li>
<li>7、niucloud-admin付费应用一旦完成交易下载源码,不得以任何形式和理由进行退款,请在购买前仔细阅读本协议。</li>
<li>8、基于niucloud-admin框架进行应用的开发,必须保留框架版权信息。</li>
</ol>
</p>
<p>
<strong>四、知识产权声明</strong>
<ol>
<li>1、niucloud-admin框架应用源代码所有权和著作权归niucloud官方所有,基于niucloud-admin框架开发的应用,所有权和著作权归应用开发商所有。</li>
<li>2、niucloud-admin框架所依托的代码、文字、图片等著作权、专利权及其他知识产权均归niucloud官方所有,除另外有特别声明。</li>
</ol>
</p>
<p><strong>五、有限担保和免责声明</strong></p>
<p>
本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。<br/>
用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未购买产品技术服务之前,我们不承诺对免费用户提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的相关责任。
电子文本形式的授权协议如同双方书面签署的协议一样,具有完全的和等同的法律效力。您一旦开始确认本协议并安装niucloud-admin框架,即被视为完全理解并接受本协议的各项条款,在享有上述条款授予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本授权协议并构成侵权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
</p>',
// 站点名称
'admin_site_name' => 'NIUCLOUD ADMIN',
// admin 端登录页默认图
'admin_login_bg' => 'install/img/niushop_login_index_left.jpg',
// admin 端默认logo
'admin_logo' => 'install/img/logo.jpg'
];

27
niucloud/config/lang.php

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | 多语言设置
// +----------------------------------------------------------------------
return [
// 默认语言
'default_lang' => env('lang.default_lang', 'zh-cn'),
// 允许的语言列表
'allow_lang_list' => ['zh-cn', 'en'],
// 多语言自动侦测变量名
'detect_var' => 'lang',
// 是否使用Cookie记录
'use_cookie' => false,
// 多语言cookie变量
'cookie_var' => 'lang',
// 多语言header变量
'header_var' => 'lang',
'extend_list' => [
],
// Accept-Language转义为对应语言包名称
'accept_language' => [
'zh-hans-cn' => 'zh-cn',
],
// 是否支持语言分组
'allow_group' => true,
];

45
niucloud/config/log.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => env('log.channel', 'file'),
// 日志记录级别
'level' => [],
// 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [],
// 关闭全局日志写入
'close' => false,
// 全局日志处理 支持闭包
'processor' => null,
// 日志通道列表
'channels' => [
'file' => [
// 日志记录方式
'type' => 'File',
// 日志保存目录
'path' => '',
// 单文件日志写入
'single' => false,
// 独立日志级别
'apart_level' => [],
// 最大日志文件数量
'max_files' => 0,
// 使用JSON格式记录
'json' => false,
// 日志处理
'processor' => null,
// 关闭通道日志写入
'close' => false,
// 日志输出格式化
'format' => '[%s][%s] %s',
// 是否实时写入
'realtime_write' => false,
],
// 其它日志通道配置
],
];

8
niucloud/config/middleware.php

@ -0,0 +1,8 @@
<?php
// 中间件配置
return [
// 别名或分组
'alias' => [],
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行
'priority' => [],
];

16
niucloud/config/niucloud.php

@ -0,0 +1,16 @@
<?php
return [
'auth' => [
'code' => env('niucloud.code', ''),//授权码
'secret' => env('niucloud.secret', ''),//授权秘钥
],
'http' => [
'max_retries' => 1,// 重试次数,默认 1,指定当 http 请求失败时重试的次数。
'retry_delay' => 1000,//重试延迟间隔(单位:ms),默认 500
'timeout' => 5.0,//最大运行时间(超时)
'verify' => false,//请求时验证SSL证书行为。设置成 true 启用SSL证书验证,默认使用操作系统提供的CA包。设置成 false 禁用证书验证(这是不安全的!)。设置成字符串启用验证,并使用该字符串作为自定义证书CA包的路径。
],
'response_type' => 'array',
];

26
niucloud/config/oauth.php

@ -0,0 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
return [
//默认驱动
'default' => 'wechat',
//驱动厂商列表及参数-第三方授权
'drivers' => [
//微信公众号
'wechat' => [
],
//微信小程序
'weapp' => [
]
]
];

33
niucloud/config/pay.php

@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
use core\dict\DictLoader;
$system = [
//默认驱动
'default' => 'wechatpay',
//驱动
'drivers' => [
//微信
'wechatpay' => [],
//支付宝
'alipay' => [],
//余额
'balancepay' => [
'driver' => 'app\service\core\paytype\CoreBalanceService', //反射类的名字
],
'offlinepay' => [
'driver' => 'app\service\core\paytype\CoreOfflineService'
]
]
];
return (new DictLoader("Config"))->load(['data' => $system, 'name' => 'pay']);

22
niucloud/config/poster.php

@ -0,0 +1,22 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
return [
//默认驱动
'default' => 'poster',
//驱动厂商列表及参数-海报
'drivers' => [
//牛云默认海报
'poster' => [
]
]
];

45
niucloud/config/route.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 路由设置
// +----------------------------------------------------------------------
return [
// pathinfo分隔符
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => true,
// 是否开启路由延迟解析
'url_lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
'route_complete_match' => false,
// 访问控制器层名称
'controller_layer' => 'controller',
// 空控制器名
'empty_controller' => 'Error',
// 是否使用控制器后缀
'controller_suffix' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache_key' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 操作方法后缀
'action_suffix' => '',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
];

19
niucloud/config/session.php

@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
return [
// session name
'name' => 'PHPSESSID',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// 驱动方式 支持file cache
'type' => 'file',
// 存储连接标识 当type使用cache的时候有效
'store' => null,
// 过期时间
'expire' => 1440,
// 前缀
'prefix' => '',
];

36
niucloud/config/sms.php

@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
use core\dict\DictLoader;
$system = [
//默认驱动
'default' => 'aliyun',
//驱动厂商列表及参数-短信
'drivers' => [
//阿里云
'aliyun' => [
'driver' => 'core\sms\Aliyun', //反射类的名字
'app_key' => '',
'secret_key' => '',
'sign' => '',
],
//腾讯云
'tencent' => [
'secret_id' => '',
'secret_key' => '',
'sign' => '',
'app_id' => '',
]
]
];
return (new DictLoader("Config"))->load(['data' => $system, 'name' => 'sms']);

44
niucloud/config/terminal.php

@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | Trace设置 开启调试模式后有效
// +----------------------------------------------------------------------
return [
// 命令行
'commands' => [
// 查看版本的命令
'version' => [
'npm' => 'npm -v',
'node' => 'node -v',
],
'npm-admin' => [
'cwd' => 'admin',
'command' => 'npm install',
],
'npm-web' => [
'cwd' => 'web',
'command' => 'npm install',
],
'npm-uni-app' => [
'cwd' => 'uni-app',
'command' => 'npm install',
],
'composer-install' => [
'cwd' => 'niucloud',
'command' => 'composer update',
],
// 切换到国内镜像
'set-mirror' => [
//切换到淘宝镜像
'npm' => 'npm config set registry https://registry.npmjs.org',
//切换到阿里云镜像
'composer' => 'composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/',
],
],
];

10
niucloud/config/trace.php

@ -0,0 +1,10 @@
<?php
// +----------------------------------------------------------------------
// | Trace设置 开启调试模式后有效
// +----------------------------------------------------------------------
return [
// 内置Html和Console两种方式 支持扩展
'type' => env('app_trace_type', 'Html'),
// 读取的日志通道名
'channel' => '',
];

98
niucloud/config/upload.php

@ -0,0 +1,98 @@
<?php
use core\dict\DictLoader;
$system = [
'default' => 'local',//默认驱动
'drivers' => [
//本地上传
'local' => [],
//七牛云
'qiniu' => [
'access_key' => '',
'secret_key' => '',
'bucket' => ''
],
//阿里云
'aliyun' => [
'access_key' => '',
'secret_key' => '',
'endpoint' => '',
'bucket' => ''
],
//腾讯云
'tencent' => [
'access_key' => '',
'secret_key' => '',
'region' => '',
'bucket' => ''
],
],
// 默认规则
'rules' => [
'image' => [
'ext' => ['jpg', 'jpeg', 'png', 'gif'],
'mime' => ['image/jpeg', 'image/gif', 'image/png'],
'size' => 10485760
],
'video' => [
'ext' => ['mp4'],
'mime' => ['video/mp4'],
'size' => 104857600
],
'wechat' => [
'ext' => ['pem', 'key'],
'mime' => [
'application/x-x509-ca-cert',
'application/octet-stream',
'application/x-iwork-keynote-sffkey'
],
'size' => 2097152
],
'aliyun' => [
'ext' => ['crt'],
'mime' => [
'application/x-x509-ca-cert',
'application/octet-stream'
],
'size' => 2097152
],
'applet' => [
'ext' => ['zip', 'rar'],
'mime' => [
'application/zip',
'application/vnd.rar',
'application/x-zip-compressed'
],
'size' => 2097152
],
'excel' => [
'ext' => ['xls', 'xlsx'],
'mime' => [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
'size' => 10485760
]
],
'thumb' => [
'thumb_type' => [
'big' => [
'width' => 1200,
'height' => 1200,
],
'mid' => [
'width' => 800,
'height' => 800,
],
'small' => [
'width' => 200,
'height' => 200,
],
]
]
];
return (new DictLoader("Config"))->load(['data' => $system, 'name' => 'upload']);

6
niucloud/config/version.php

@ -0,0 +1,6 @@
<?php
return [
'version' => '1.5.1',
'code' => '2025022201'
];

31
niucloud/config/view.php

@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板引擎类型使用Think
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
'tpl_cache' => false, //模板缓存,部署模式后改为true
'tpl_replace_string' => [
'INSTALL_IMG' => '/install/img',
'INSTALL_CSS' => '/install/css',
'INSTALL_JS' => '/install/js',
]
];

29
niucloud/core/core/base/BaseAdminController.php

@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace core\base;
/**
* 管理端控制器基类
* Class BaseAdminController
* @package core\base
*/
class BaseAdminController extends BaseController
{
public function initialize()
{
}
}

31
niucloud/core/core/base/BaseAdminService.php

@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
/**
* 后台基础服务层
* Class BaseAdminService
* @package app\service\admin
*/
class BaseAdminService extends BaseService
{
protected $username;
protected $uid;
public function __construct()
{
parent::__construct();
$this->username = $this->request->username();
$this->uid = $this->request->uid();
}
}

29
niucloud/core/core/base/BaseApiController.php

@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace core\base;
/**
* api基础控制器
* Class BaseApiController
* @package app\api\controller
*/
class BaseApiController extends BaseController
{
public function initialize()
{
}
}

31
niucloud/core/core/base/BaseApiService.php

@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
/**
* 手机前端基础服务层
* Class BaseApiService
* @package app\service\api
*/
class BaseApiService extends BaseService
{
protected $member_id;
protected $channel;
public function __construct()
{
parent::__construct();
$this->member_id = $this->request->memberId();
$this->channel = $this->request->getChannel();
}
}

96
niucloud/core/core/base/BaseController.php

@ -0,0 +1,96 @@
<?php
declare (strict_types=1);
namespace core\base;
use app\Request;
use think\App;
use think\exception\ValidateException;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var Request
*/
protected $request;
/**
* 应用实例
* @var App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{
}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = str_contains($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch();
}
return $v->failException()->check($data);
}
}

27
niucloud/core/core/base/BaseCoreService.php

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
/**
* 系统基础服务层
* Class BaseCoreService
* @package app\service\core
*/
class BaseCoreService extends BaseService
{
public function __construct()
{
parent::__construct();
}
}

61
niucloud/core/core/base/BaseJob.php

@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
use core\exception\CommonException;
use core\job\Dispatch;
use think\facade\Log;
use think\queue\Job;
/**
* 队列
*/
abstract class BaseJob extends Dispatch
{
/**
* 消费任务
* @param $params
*/
public function fire($params): void
{
$method = $params['method'] ?? 'doJob';//任务名
$data = $params['data'] ?? [];//数据
$this->runJob($method, $data);
}
/**
* 执行任务
* @param string $method
* @param array $data
* @param int $error_count
*/
protected function runJob(string $method, array $data)
{
try {
$method = method_exists($this, $method) ? $method : 'handle';
if (!method_exists($this, $method)) {
throw new CommonException('Job "'.static::class.'" not found!');
}
$this->{$method}(...$data);
return true;
} catch (\Throwable $e) {
Log::write('队列错误:'.static::class.$method.'_'.'_'.$e->getMessage().'_'.$e->getFile().'_'.$e->getLine());
throw new CommonException('Job "'.static::class.'" has error!');
}
}
}

48
niucloud/core/core/base/BaseModel.php

@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
use think\facade\Db;
use think\Model;
/**
* 基础模型
* Class BaseModel
* @package app\model
*/
class BaseModel extends Model
{
public function getModelColumn()
{
$table_name = $this->getTable();
$sql = 'SHOW TABLE STATUS WHERE 1=1 ';
$tablePrefix = config('database.connections.mysql.prefix');
if (!empty($table_name)) {
$sql .= "AND name='" .$table_name."'";
}
$tables = Db::query($sql);
$table_info = $tables[0] ?? [];
$table_name = preg_replace("/^{$tablePrefix}/", '', $table_info['Name'], 1);
return Db::name($table_name)->getFields();
}
/**
* 处理搜索条件特殊字符(%、_)
* @param $value
*/
public function handelSpecialCharacter($value)
{
$value = str_replace('%', '\%', str_replace('_', '\_', $value));
return $value;
}
}

135
niucloud/core/core/base/BaseService.php

@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
use app\validate\sys\Page;
use think\db\exception\DbException;
use think\Model;
/**
* 基础服务层
* Class BaseService
* @package app\service
*/
abstract class BaseService
{
/**
* Model 实例
* @var BaseModel
*/
protected $model;
protected $request;
public function __construct()
{
$this->request = request();
}
/**
* 分页列表参数(页码和每页多少条)
* @return mixed
*/
public function getPageParam()
{
$page = request()->params([
['page', 1],
['limit', 15]
]);
validate(Page::class)
->check($page);
return $page;
}
/**
* 分页列表
* @param Model $model
* @param array $where
* @param string $field
* @param string $order
* @param array $append
* @return array
* @throws DbException
*/
public function getPageList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null)
{
$page_params = $this->getPageParam();
$page = $page_params['page'];
$limit = $page_params['limit'];
$list = $model->where($where)->when($append, function ($query) use ($append) {
$query->append($append);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->order($order)->paginate([
'list_rows' => $limit,
'page' => $page,
]);
if (!empty($each)) {
$list = $list->each($each);
}
return $list->toArray();
}
/**
* 分页数据查询,传入model(查询后结果)
* @param $model BaseModel
* @return array
* @throws DbException
*/
public function pageQuery($model, $each = null)
{
$page_params = $this->getPageParam();
$page = $page_params['page'];
$limit = $page_params['limit'];
$list = $model->paginate([
'list_rows' => $limit,
'page' => $page,
]);
if (!empty($each)) {
$list = $list->each($each);
}
return $list->toArray();
}
/**
* 分页视图列表查询
* @param Model $model
* @param array $where
* @param string $field
* @param string $order
* @param array $append
* @return array
* @throws DbException
*/
public function getPageViewList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null)
{
$page_params = $this->getPageParam();
$page = $page_params['page'];
$limit = $page_params['limit'];
$list = $model->where($where)->when($append, function ($query) use ($append) {
$query->append($append);
})->when($with, function ($query) use ($with) {
$query->withJoin($with);
})->field($field)->order($order)->paginate([
'list_rows' => $limit,
'page' => $page,
]);
if (!empty($each)) {
$list = $list->each($each);
}
return $list->toArray();
}
}

46
niucloud/core/core/base/BaseValidate.php

@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace core\base;
use think\Validate;
/**
* 验证器器基类
* Class BaseValidate
* @package core\base
*/
class BaseValidate extends Validate
{
public function __construct()
{
parent::__construct();
$this->parseMsg();
}
public function parseMsg(){
if(!empty($this->message))
{
foreach ($this->message as $key => $value)
{
if(is_array($value))
{
$this->message[$key] = get_lang($value[0], $value[1]);
}
}
}
}
}

38
niucloud/core/core/dict/AdvPosition.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class AdvPosition extends BaseDict
{
/**
* 广告位加载
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$adv_position_files = [];
foreach ($addons as $v) {
$adv_position_path = $this->getAddonDictPath($v) . "web" . DIRECTORY_SEPARATOR . "adv_position.php";
if (is_file($adv_position_path)) {
$adv_position_files[] = $adv_position_path;
}
}
$adv_position_file_data = $this->loadFiles($adv_position_files);
$adv_position = $data;
foreach ($adv_position_file_data as $file_data) {
$adv_position = empty($adv_position) ? $file_data : array_merge($adv_position, $file_data);
}
return $adv_position;
}
}

162
niucloud/core/core/dict/BaseDict.php

@ -0,0 +1,162 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
use app\service\core\addon\CoreAddonBaseService;
use core\loader\Storage;
use think\facade\Cache;
use think\facade\Db;
/**
* Class BaseAddon
* @package
*/
abstract class BaseDict extends Storage
{
//插件整体缓存标识
public static $cache_tag_name = 'addon_cash';
/**
* 初始化
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
}
/**
* 获取本地插件目录(已安装)
*/
protected function getLocalAddons()
{
if (!file_exists(root_path() . "install.lock")) {
//尚未安装不加载插件
return [];
}
$addons = Cache::get("local_install_addons");
if (!is_null($addons)) return $addons;
$addons = Db::name("addon")->column("key");
Cache::tag(CoreAddonBaseService::$cache_tag_name)->set("local_install_addons", $addons);
return $addons;
}
/**
* 获取所有本地插件(包括未安装,用于系统指令执行)
* @return array|false
*/
public function getAllLocalAddons()
{
$addon_dir = root_path() . 'addon';
$addons = array_diff(scandir($addon_dir), ['.', '..']);
return $addons;
}
/**
* 获取插件目录
* @param string $addon
* @return string
*/
protected function getAddonPath(string $addon)
{
return root_path() . 'addon' . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR;
}
/**
* 获取系统整体app目录
* @return string
*/
protected function getAppPath()
{
return root_path() . "app" . DIRECTORY_SEPARATOR;
}
/**
* 获取插件对应app目录
* @param string $addon
* @return string
*/
protected function getAddonAppPath(string $addon)
{
return $this->getAddonPath($addon) . "app" . DIRECTORY_SEPARATOR;
}
/**
*获取系统dict path
*/
protected function getDictPath()
{
return root_path() . 'app' . DIRECTORY_SEPARATOR . 'dict' . DIRECTORY_SEPARATOR;
}
/**
*获取插件对应的dict目录
* @param string $addon
* @return string
*/
protected function getAddonDictPath(string $addon)
{
return $this->getAddonPath($addon) . 'app' . DIRECTORY_SEPARATOR . 'dict' . DIRECTORY_SEPARATOR;
}
/**
*获取插件对应的config目录
* @param string $addon
* @return string
*/
protected function getAddonConfigPath(string $addon)
{
return $this->getAddonPath($addon) . 'config' . DIRECTORY_SEPARATOR;
}
/**
* 加载文件数据
* @param $files
* @return array
*/
protected function loadFiles($files)
{
$default_sort = 100000;
$files_data = [];
if (!empty($files)) {
foreach ($files as $file) {
$config = include $file;
if (!empty($config)) {
if (isset($config['file_sort'])) {
$sort = $config['file_sort'];
unset($config['file_sort']);
$sort = $sort * 10;
while (array_key_exists($sort, $files_data)) {
$sort++;
}
$files_data[$sort] = $config;
} else {
$files_data[$default_sort] = $config;
$default_sort++;
}
}
}
}
ksort($files_data);
return $files_data;
}
/**
* 加载
* @return mixed
*/
abstract public function load(array $data);
}

41
niucloud/core/core/dict/Config.php

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Config extends BaseDict
{
public function load(array $data)
{
$config = $data['name'];
$system_config = $data['data'] ?? [];
$addons = $this->getAllLocalAddons();
$config_files = [];
foreach ($addons as $v) {
$config_path = $this->getAddonAppPath($v) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $config . '.php';
if (is_file($config_path)) {
$config_files[] = $config_path;
}
}
$files_data = $this->loadFiles($config_files);
foreach ($files_data as $file_data) {
if(!empty($file_data))
{
$system_config = empty($system_config) ? $file_data : array_merge2($system_config, $file_data);
}
}
return $system_config;
}
}

45
niucloud/core/core/dict/Console.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Console extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getAllLocalAddons();
$console_files = [];
foreach ($addons as $v) {
$console_path = $this->getAddonAppPath($v) . "/config/console.php";
if (is_file($console_path)) {
$console_files[] = $console_path;
}
}
$files_data = $this->loadFiles($console_files);
$console = $data;
foreach ($files_data as $file_data) {
if(!empty($file_data))
{
$console = empty($console) ? $file_data : array_merge2($console, $file_data);
}
}
return $console;
}
}

41
niucloud/core/core/dict/DictLoader.php

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
use core\loader\Loader;
/**
* @see DictLoader
* @mixin BaseDict
* @method array|null load(array $data = [])
*/
class DictLoader extends Loader
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\core\\dict\\';
protected $config_name = 'dict';
/**
* 默认驱动
* @return string
*/
protected function getDefault()
{
return "Event";
}
}

38
niucloud/core/core/dict/DiyFormComponent.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class DiyFormComponent extends BaseDict
{
/**
* 万能表单组件配置
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$components_files = [];
foreach ($addons as $v) {
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "components.php";
if (is_file($components_path)) {
$components_files[] = $components_path;
}
}
$components_files_data = $this->loadFiles($components_files);
$components = $data;
foreach ($components_files_data as $file_data) {
$components = empty($components) ? $file_data : array_merge2($components, $file_data);
}
return $components;
}
}

38
niucloud/core/core/dict/DiyFormTemplate.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class DiyFormTemplate extends BaseDict
{
/**
* 万能表单模版
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$components_files = [];
foreach ($addons as $v) {
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "template.php";
if (is_file($components_path)) {
$components_files[] = $components_path;
}
}
$components_files_data = $this->loadFiles($components_files);
$components = $data;
foreach ($components_files_data as $file_data) {
$components = empty($components) ? $file_data : array_merge2($components, $file_data);
}
return $components;
}
}

38
niucloud/core/core/dict/DiyFormType.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class DiyFormType extends BaseDict
{
/**
* 万能表单组件配置
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$components_files = [];
foreach ($addons as $v) {
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "type.php";
if (is_file($components_path)) {
$components_files[] = $components_path;
}
}
$components_files_data = $this->loadFiles($components_files);
$components = $data;
foreach ($components_files_data as $file_data) {
$components = empty($components) ? $file_data : array_merge2($components, $file_data);
}
return $components;
}
}

42
niucloud/core/core/dict/Event.php

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Event extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$event_files = [];
foreach ($addons as $v) {
$event_path = $this->getAddonAppPath($v) . "event.php";
if (is_file($event_path)) {
$event_files[] = $event_path;
}
}
$files_data = $this->loadFiles($event_files);
$files_data[1] = $data;
$events = [];
foreach ($files_data as $file_data) {
$events = empty($events) ? $file_data : array_merge2($events, $file_data);
}
return $events;
}
}

45
niucloud/core/core/dict/GrowthRule.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class GrowthRule extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
$account_change_type_files = [];
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "growth_rule.php";
if (is_file($system_change_type_file)) {
$account_change_type_files[] = $system_change_type_file;
}
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "growth_rule.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
return $account_change_type_array;
}
}

50
niucloud/core/core/dict/Icon.php

@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
/**
* 图标
* Class Icon
* @package core\dict
*/
class Icon extends BaseDict
{
/**
* @param array $data
* @return array
*/
public function load(array $data): array
{
$sys_path = dirname(app()->getRootPath()) . str_replace('/', DIRECTORY_SEPARATOR, '/admin/src/styles/icon');
$file_arr = getFileMap($sys_path);
$icon_arr = [];
if (!empty($file_arr)) {
foreach ($file_arr as $ck => $cv) {
if (str_contains($cv, '.json')) {
$json_string = file_get_contents($ck);
$icon = json_decode($json_string, true, 512, JSON_THROW_ON_ERROR);
$icon_arr[] = $icon;
}
}
}
if (count($icon_arr) > 1) {
$last_icon = array_pop($icon_arr); // 最后一个
$first_icon = array_shift($icon_arr); // 第一个
array_unshift($icon_arr, $last_icon); // 将系统图标放到第一位置
$icon_arr[] = $first_icon; // 交换位置
}
return $icon_arr;
}
}

56
niucloud/core/core/dict/Lang.php

@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Lang extends BaseDict
{
/**
* 加载事件
* @param array $data //传入语言类型
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$system_lang_path = $this->getAppPath() . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR;
$lang_files = [
$system_lang_path . "api.php",
$system_lang_path . "dict.php",
$system_lang_path . "validate.php",
];
foreach ($addons as $v) {
$lang_path = $this->getAddonAppPath($v) . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR;
$api_path = $lang_path . "api.php";
$dict_path = $lang_path . "dict.php";
$validate_path = $lang_path . "validate.php";
if (is_file($api_path)) {
$lang_files[] = $api_path;
}
if (is_file($dict_path)) {
$lang_files[] = $dict_path;
}
if (is_file($validate_path)) {
$lang_files[] = $validate_path;
}
}
$files_data = $this->loadFiles($lang_files);
$lang = [];
foreach ($files_data as $file_data) {
$lang = empty($lang) ? $file_data : array_merge2($lang, $file_data);
}
return $lang;
}
}

46
niucloud/core/core/dict/MemberAccountChangeType.php

@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class MemberAccountChangeType extends BaseDict
{
/**
* 加载账户变动方式
* @param array $data
* @return bool|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
$account_change_type_files = [];
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "account_change_type.php";
if (is_file($system_change_type_file)) {
$account_change_type_files[] = $system_change_type_file;
}
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "account_change_type.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
return $account_change_type_array;
}
}

45
niucloud/core/core/dict/MemberBenefits.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class MemberBenefits extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
$account_change_type_files = [];
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "benefits.php";
if (is_file($system_change_type_file)) {
$account_change_type_files[] = $system_change_type_file;
}
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "benefits.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
return $account_change_type_array;
}
}

45
niucloud/core/core/dict/MemberGift.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class MemberGift extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
$account_change_type_files = [];
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "gift.php";
if (is_file($system_change_type_file)) {
$account_change_type_files[] = $system_change_type_file;
}
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "gift.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
return $account_change_type_array;
}
}

29
niucloud/core/core/dict/Menu.php

@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Menu extends BaseDict
{
/**
* 加载菜单
* @param array $data //传入插件,应用类型
* @return array
*/
public function load(array $data): array
{
$menu_path = $this->getAddonDictPath($data['addon']) . "menu" . DIRECTORY_SEPARATOR . $data['app_type'] . ".php";
if (is_file($menu_path)) {
return include $menu_path;
}
return [];
}
}

43
niucloud/core/core/dict/Notice.php

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Notice extends BaseDict
{
/**
* 系统uniapp页面链接
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$template_files = [];
$system_path = $this->getDictPath() . "notice" . DIRECTORY_SEPARATOR . $data[ 'type' ] . ".php";
if (is_file($system_path)) {
$template_files[] = $system_path;
}
$addons = $this->getLocalAddons();
foreach ($addons as $v) {
$template_path = $this->getAddonDictPath($v) . "notice" . DIRECTORY_SEPARATOR . $data[ 'type' ] . ".php";
if (is_file($template_path)) {
$template_files[] = $template_path;
}
}
$template_files_data = $this->loadFiles($template_files);
$template_data_array = [];
foreach ($template_files_data as $file_data) {
$template_data_array = empty($template_data_array) ? $file_data : array_merge($template_data_array, $file_data);
}
return $template_data_array;
}
}

1
niucloud/core/core/dict/PackageGift.php

@ -0,0 +1 @@
// | 官方网址:https://www.niucloud.com

45
niucloud/core/core/dict/PointRule.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class PointRule extends BaseDict
{
/**
* 加载事件
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
$account_change_type_files = [];
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "point_rule.php";
if (is_file($system_change_type_file)) {
$account_change_type_files[] = $system_change_type_file;
}
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "point_rule.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
return $account_change_type_array;
}
}

95
niucloud/core/core/dict/Poster.php

@ -0,0 +1,95 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Poster extends BaseDict
{
/**
* 加载海报模板配置
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addon = $data[ 'addon' ] ?? '';
$type = $data[ 'type' ] ?? '';
$schedule_files = [];
if (empty($addon)) {
$system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
if (is_file($system_path)) {
$schedule_files[] = $system_path;
}
$addons = $this->getLocalAddons();
foreach ($addons as $v) {
$addon_path = $this->getAddonDictPath($v) . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
if (is_file($addon_path)) {
$schedule_files[] = $addon_path;
}
}
} else {
$schedule_files = [];
if ($addon == 'system') {
$system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
if (is_file($system_path)) {
$schedule_files[] = $system_path;
}
} else {
$addon_path = $this->getAddonDictPath($addon) . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
if (is_file($addon_path)) {
$schedule_files[] = $addon_path;
}
}
}
$schedule_files_data = $this->loadFiles($schedule_files);
$schedule_data_array = [];
foreach ($schedule_files_data as $file_data) {
$schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data);
}
if (!empty($type)) {
foreach ($schedule_data_array as $k => $v) {
if ($v[ 'type' ] != $type) {
unset($schedule_data_array[ $k ]);
}
}
$schedule_data_array = array_values($schedule_data_array);
}
return $schedule_data_array;
}
/**
* 获取海报组件
* @param array $data
* @return array|mixed
*/
public function loadComponents(array $data = [])
{
$addons = $this->getLocalAddons();
$components_files = [];
foreach ($addons as $v) {
$components_path = $this->getAddonDictPath($v) . "poster" . DIRECTORY_SEPARATOR . "components.php";
if (is_file($components_path)) {
$components_files[] = $components_path;
}
}
$components_files_data = $this->loadFiles($components_files);
$components = $data;
foreach ($components_files_data as $file_data) {
$components = empty($components) ? $file_data : array_merge2($components, $file_data);
}
return $components;
}
}

40
niucloud/core/core/dict/Printer.php

@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Printer extends BaseDict
{
/**
* 打印模板类型
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$types_files = [];
foreach ($addons as $v) {
$types_path = $this->getAddonDictPath($v) . "printer" . DIRECTORY_SEPARATOR . "type.php";
if (is_file($types_path)) {
$types_files[] = $types_path;
}
}
$types_files_data = $this->loadFiles($types_files);
$types = $data;
foreach ($types_files_data as $file_data) {
$types = empty($types) ? $file_data : array_merge2($types, $file_data);
}
return $types;
}
}

43
niucloud/core/core/dict/RechargeGift.php

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class RechargeGift extends BaseDict
{
/**
* 加载会员充值赠品组件
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addons = $this->getLocalAddons();
foreach ($addons as $v) {
$addon_change_type_file = $this->getAddonDictPath($v) . "recharge" . DIRECTORY_SEPARATOR . "package_gift.php";
if (is_file($addon_change_type_file)) {
$account_change_type_files[] = $addon_change_type_file;
}
}
$account_change_type_datas = $this->loadFiles($account_change_type_files);
$account_change_type_array = [];
foreach ($account_change_type_datas as $account_change_type_data) {
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data);
}
foreach ($account_change_type_array as $key => &$value) {
$value[ 'key' ] = $key;
}
usort($account_change_type_array, function($list_one, $list_two) {
return $list_one[ 'sort' ] <=> $list_two[ 'sort' ];
});
return $account_change_type_array;
}
}

33
niucloud/core/core/dict/Route.php

@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Route extends BaseDict
{
/**
* 加载路由
* @param array $data 传入路由端口
* @return true
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
foreach ($addons as $k => $v) {
$route_path = $this->getAddonAppPath($v) . DIRECTORY_SEPARATOR . $data['app_type'] . DIRECTORY_SEPARATOR . "route" . DIRECTORY_SEPARATOR . "route.php";
if (is_file($route_path)) {
include $route_path;
}
}
return true;
}
}

60
niucloud/core/core/dict/Schedule.php

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class Schedule extends BaseDict
{
/**
* 加载计划任务调度
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
$addon = $data['addon'] ?? '';
$schedule_files = [];
if (empty($addon)) {
$system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
if (is_file($system_path)) {
$schedule_files[] = $system_path;
}
$addons = $this->getLocalAddons();
foreach ($addons as $v) {
$addon_path = $this->getAddonDictPath($v) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
if (is_file($addon_path)) {
$schedule_files[] = $addon_path;
}
}
} else {
$schedule_files = [];
if ($addon == 'system') {
$system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
if (is_file($system_path)) {
$schedule_files[] = $system_path;
}
} else {
$addon_path = $this->getAddonDictPath($addon) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
if (is_file($addon_path)) {
$schedule_files[] = $addon_path;
}
}
}
$schedule_files_data = $this->loadFiles($schedule_files);
$schedule_data_array = [];
foreach ($schedule_files_data as $file_data) {
$schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data);
}
return $schedule_data_array;
}
}

38
niucloud/core/core/dict/UniappComponent.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class UniappComponent extends BaseDict
{
/**
* 系统uniapp组件配置
* @param array $data
* @return array|mixed
*/
public function load(array $data)
{
$addons = $this->getLocalAddons();
$components_files = [];
foreach ($addons as $v) {
$components_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "components.php";
if (is_file($components_path)) {
$components_files[] = $components_path;
}
}
$components_files_data = $this->loadFiles($components_files);
$components = $data;
foreach ($components_files_data as $file_data) {
$components = empty($components) ? $file_data : array_merge2($components, $file_data);
}
return $components;
}
}

75
niucloud/core/core/dict/UniappLink.php

@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
use app\service\admin\addon\AddonService;
class UniappLink extends BaseDict
{
/**
* 系统uniapp页面链接
* @param array $params
* @return array|false|mixed|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function load(array $params = [])
{
if (!empty($params[ 'params' ][ 'addon' ])) {
$addons = [ $params[ 'params' ][ 'addon' ] ];
} else {
$addons = $this->getLocalAddons();
}
$link_files = [];
foreach ($addons as $v) {
$link_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "links.php";
if (is_file($link_path)) {
$link_files[ $v ] = $link_path;
}
}
$addon_service = new AddonService();
$addon_info_list = $addon_service->getAddonListByKeys(array_keys($link_files));
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') {
$list_key = array_column($addon_info_list, 'key');
$addon_info_list = array_combine($list_key, $addon_info_list);
return $addon_info_list;
} else {
$links = $params[ 'data' ];
foreach ($link_files as $k => $v) {
$addon_link = include $v;
if (!empty($addon_link)) {
$addon_info = [];
foreach ($addon_info_list as $ck => $cv) {
if ($cv[ 'key' ] == $k) {
$addon_info = $cv;
break;
}
}
foreach ($addon_link as $ck => $cv) {
$addon_link[ $ck ][ 'addon_info' ] = $addon_info;
}
$links = array_merge($links, $addon_link);
}
}
return $links;
}
}
}

52
niucloud/core/core/dict/UniappPages.php

@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
class UniappPages extends BaseDict
{
/**
* 系统uniapp页面
* @param array $data
* @return array|mixed
*/
public function load(array $data = [])
{
// 筛选插件
if (!empty($data[ 'addon' ])) {
$addons = [ $data[ 'addon' ] ];
} else {
$addons = $this->getLocalAddons();
}
$page_files = [];
foreach ($addons as $v) {
$page_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "pages.php";
if (is_file($page_path)) {
$page_files[] = $page_path;
}
}
$page_files_data = $this->loadFiles($page_files);
if (!empty($data[ 'addon' ])) {
$pages = [];
} else {
$pages = $data;
}
foreach ($page_files_data as $file_data) {
if (empty($pages)) {
$pages = $file_data;
} else {
$pages = array_merge2($pages, $file_data);
}
}
return $pages;
}
}

95
niucloud/core/core/dict/UniappTemplate.php

@ -0,0 +1,95 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
use app\service\admin\addon\AddonService;
class UniappTemplate extends BaseDict
{
/**
* 系统uniapp页面模板
* @param array $params
* @return array|false|mixed|string
*/
public function load(array $params)
{
if (!empty($params[ 'params' ][ 'addon' ])) {
$addons = [ $params[ 'params' ][ 'addon' ] ];
} else {
$addons = $this->getLocalAddons();
}
$app_keys = []; // 应用插件key集合
$apps = []; // 应用插件集合
$page_files = []; // 模板页面文件集合
// 筛选插件
if (!empty($params[ 'params' ]) && !empty($params[ 'params' ][ 'addon' ])) {
$is_pass = true;
foreach ($addons as $k => $v) {
if ($params[ 'params' ][ 'addon' ] == $v) {
$addons = [ $v ];
$is_pass = false;
break;
}
}
// 如果没有匹配到,则返回系统的
if ($is_pass) {
return $params[ 'data' ];
}
}
foreach ($addons as $v) {
$page_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "template.php";
if (is_file($page_path)) {
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') {
$file = include $page_path;
if (!empty($file)) {
$app_keys[] = $v;
$apps[ $v ] = $file;
}
} else {
$page_files[] = $page_path;
}
}
}
// 查询存在模板页面的应用插件列表
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') {
$addon_service = new AddonService();
$list = $addon_service->getAddonListByKeys($app_keys);
$list_key = array_column($list, 'key');
$list = array_combine($list_key, $list);
foreach ($list as $k => $v) {
$list[ $k ][ 'list' ] = $apps[ $k ];
}
return $list;
} else {
// 查询应用插件下的模板页面数据
$page_files_data = $this->loadFiles($page_files);
if (!empty($params[ 'params' ]) && !empty($params[ 'params' ][ 'addon' ])) {
$pages = [];
} else {
$pages = $params[ 'data' ];
}
foreach ($page_files_data as $file_data) {
if (empty($pages)) {
$pages = $file_data;
} else {
$pages = array_merge($pages, $file_data);
}
}
return $pages;
}
}
}

75
niucloud/core/core/dict/WebLink.php

@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\dict;
use app\service\admin\addon\AddonService;
class WebLink extends BaseDict
{
/**
* 系统weblink页面链接
* @param array $params
* @return array|false|mixed|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function load(array $params = [])
{
if (!empty($params[ 'params' ][ 'addon' ])) {
$addons = [ $params[ 'params' ][ 'addon' ] ];
} else {
$addons = $this->getLocalAddons();
}
$link_files = [];
foreach ($addons as $v) {
$link_path = $this->getAddonDictPath($v) . "web" . DIRECTORY_SEPARATOR . "web_links.php";
if (is_file($link_path)) {
$link_files[ $v ] = $link_path;
}
}
$addon_service = new AddonService();
$addon_info_list = $addon_service->getAddonListByKeys(array_keys($link_files));
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') {
$list_key = array_column($addon_info_list, 'key');
$addon_info_list = array_combine($list_key, $addon_info_list);
return $addon_info_list;
} else {
$links = $params[ 'data' ];
foreach ($link_files as $k => $v) {
$addon_link = include $v;
if (!empty($addon_link)) {
$addon_info = [];
foreach ($addon_info_list as $ck => $cv) {
if ($cv[ 'key' ] == $k) {
$addon_info = $cv;
break;
}
}
foreach ($addon_link as $ck => $cv) {
$addon_link[ $ck ][ 'addon_info' ] = $addon_info;
}
$links = array_merge($links, $addon_link);
}
}
return $links;
}
}
}

17
niucloud/core/core/exception/AddonException.php

@ -0,0 +1,17 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 插件错误异常处理类
*/
class AddonException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

17
niucloud/core/core/exception/AdminException.php

@ -0,0 +1,17 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 平台管理端错误异常处理类
*/
class AdminException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/ApiException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 前端错误异常处理类
*/
class ApiException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/AuthException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 授权错误异常处理类
*/
class AuthException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/CaptchaException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 平台管理端错误异常处理类
*/
class CaptchaException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/CommonException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 平台管理端错误异常处理类
*/
class CommonException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/NiucloudException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 插件错误异常处理类
*/
class NiucloudException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/NoticeException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 消息错误异常处理类
*/
class NoticeException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/PayException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 支付错误异常处理类
*/
class PayException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/ServerException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 服务器异常处理类
*/
class ServerException extends RuntimeException
{
public function __construct($message = "", $code = 409, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/UploadFileException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 附件管理错误异常处理类
*/
class UploadFileException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

18
niucloud/core/core/exception/WechatException.php

@ -0,0 +1,18 @@
<?php
namespace core\exception;
use RuntimeException;
use Throwable;
/**
* 微信错误异常处理类
*/
class WechatException extends RuntimeException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

57
niucloud/core/core/job/Dispatch.php

@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\job;
use core\util\Queue;
/**
* 任务派遣队列
*/
class Dispatch
{
/**
* 加入队列
* @param $action
* @param array $data
* @param int $secs
* @param string|null $queue_name
* @param bool $is_async
* @return mixed
*/
public static function dispatch($action, array $data = [], int $secs = 0, string $queue_name = null, bool $is_async = true)
{
$class = static::class;//调用主调类
if (env('queue.state', false) && $is_async) {
$queue = Queue::instance()->job($class)->secs($secs);
if (is_array($action)) {
$queue->data(...$action);
} else if (is_string($action)) {
$queue->method($action)->data(...$data);
}
if ($queue_name) {
$queue->setQueueName($queue_name);
}
return $queue->push();
} else {
if($secs == 0){
$class_name = '\\' . $class;
$res = new $class_name();
if (is_array($action)) {
return $res->doJob(...$action);
} else {
return $res->$action(...$data);
}
}
}
}
}

118
niucloud/core/core/loader/Loader.php

@ -0,0 +1,118 @@
<?php
namespace core\loader;
use Exception;
use think\DbManager;
use think\Facade;
use think\helper\Str;
abstract class Loader extends Facade
{
protected $config_name = null;//配置文件名
protected $name = null;
protected $namespace = null;
protected $class = null;
protected $config = null;
protected $config_file = null;
/**
* @param string $name
* @param array $config
*/
public function __construct($name = '', array $config = [])
{
if (is_array($name)) {
$config = $name;
$name = null;
}
if ($name) {
$this->name = $name;
}
$this->config = $config;
}
/**
* 获取默认驱动
* @return mixed
*/
abstract protected function getDefault();
/**
* 创建实例对象
* @param string $type
* @return object|DbManager
* @throws Exception
*/
public function create(string $type)
{
$class = $this->getClass($type);
return self::createFacade($class, [
$this->name,
$this->config,
$this->config_file
], true);
}
/**
* 获取类
* @param string $type
* @return mixed|string
* @throws Exception
*/
public function getClass(string $type)
{
$class = config($this->config_name . '.drivers.' . $type . '.driver');
if (!empty($class) && class_exists($class)) {
return $class;
} else {
if ($this->namespace || str_contains($type, '\\')) {
$class = str_contains($type, '\\') ? $type : $this->namespace . $type;
if (class_exists($class)) {
return $class;
} else {
$class = str_contains($type, '\\') ? $type : $this->namespace . Str::studly($type);
if (class_exists($class)) {
return $class;
}
}
}
}
throw new Exception("Driver [$type] not supported.");
}
/**
* 通过装载器获取实例
* @return object|DbManager
* @throws Exception
*/
public function getLoader()
{
if (empty($this->class)) {
$this->name = $this->name ?: $this->getDefault();
if (!$this->name) {
throw new Exception(sprintf(
'could not find driver [%s].', static::class
));
}
$this->class = $this->create($this->name);
}
return $this->class;
}
/**
* 动态调用
* @param $method
* @param $arguments
* @return mixed
* @throws Exception
*/
public function __call($method, $arguments)
{
return $this->getLoader()->{$method}(...$arguments);
}
}

69
niucloud/core/core/loader/Storage.php

@ -0,0 +1,69 @@
<?php
namespace core\loader;
abstract class Storage
{
/**
* 驱动名称
* @var string
*/
protected $name;
/**
* 驱动配置文件名
* @var string
*/
protected $config_file;
/**
* 错误信息
* @var string
*/
protected $error;
/**
* BaseStorage constructor.
* @param string $name 驱动名
* @param array $config 其他配置
* @param string|null $config_file 驱动配置名
*/
public function __construct(string $name, array $config = [], string $config_file = null)
{
$this->name = $name;
$this->config_file = $config_file;
$this->initialize($config);
}
/**
* 设置错误信息
* @param string|null $error
* @return bool
*/
protected function setError(?string $error = null)
{
$this->error = $error;
return false;
}
/**
* 获取错误信息
* @return string
*/
public function getError()
{
$error = $this->error;
$this->error = null;
return $error;
}
/**
* 初始化
* @param array $config
* @return mixed
*/
abstract protected function initialize(array $config);
}

42
niucloud/core/core/oauth/BaseOauth.php

@ -0,0 +1,42 @@
<?php
namespace core\oauth;
use core\loader\Storage;
/**
* 第三方授权基类
* Class BaseOauth
* @package core\oauth
*/
abstract class BaseOauth extends Storage
{
protected $config;//配置
/**
* 初始化
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
}
/**
* 获取粉丝信息
* @param string|null $openid
* @return mixed
*/
abstract public function getFansInfo(string $openid = null);
/**
* 授权
* @param string|null $code
* @param array $options
* @return mixed
*/
abstract public function oauth(string $code = null, array $options = []);
}

38
niucloud/core/core/oauth/OauthLoader.php

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\oauth;
use core\loader\Loader;
/**
* @see OauthLoader
* @package think\facade
*/
class OauthLoader extends Loader
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\core\\oauth\\';
protected $config_name = 'oauth';
/**
* 默认驱动
* @return mixed
*/
protected function getDefault()
{
return config('oauth.default');
}
}

32
niucloud/core/core/oauth/Weapp.php

@ -0,0 +1,32 @@
<?php
namespace core\oauth;
/**
* 微信小程序授权
* Class Weapp
* @package core\oauth
*/
class Weapp extends BaseOauth
{
/**
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
parent::initialize($config);
}
public function getFansInfo(string $openid = null)
{
// TODO: Implement getFansInfo() method.
}
public function oauth(string $code = null, array $options = [])
{
// TODO: Implement oauth() method.
}
}

40
niucloud/core/core/oauth/Wechat.php

@ -0,0 +1,40 @@
<?php
namespace core\oauth;
use app\service\core\wechat\CoreWechatService;
/**
* 微信公众号登录
* Class Wechat
* @package core\oauth
*/
class Wechat extends BaseOauth
{
/**
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
parent::initialize($config);
}
public function getFansInfo(string $openid = null)
{
// TODO: Implement getFansInfo() method.
}
public function instance()
{
return CoreWechatService::app()->oauth;
}
public function oauth(string $code = null, array $options = [])
{
// $this->instance()->
// TODO: Implement oauth() method.
}
}

389
niucloud/core/core/pay/Alipay.php

@ -0,0 +1,389 @@
<?php
namespace core\pay;
use app\dict\pay\OnlinePayDict;
use app\dict\pay\RefundDict;
use app\dict\pay\TransferDict;
use core\exception\PayException;
use Psr\Http\Message\ResponseInterface;
use Throwable;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Exception\ServiceNotFoundException;
use Yansongda\Pay\Pay;
use Yansongda\Supports\Collection;
/**
* 文件管理驱动类
* Class FileDriver
* @package core\file
*/
class Alipay extends BasePay
{
/**
* @param array $config
* @return void
* @throws ContainerException
*/
protected function initialize(array $config = [])
{
parent::initialize($config);
$config['app_public_cert_path'] = url_to_path($config['app_public_cert_path'] ?? '');
$config['alipay_public_cert_path'] = url_to_path($config['alipay_public_cert_path'] ?? '');
$config['alipay_root_cert_path'] = url_to_path($config['alipay_root_cert_path'] ?? '');
$config['mode'] = Pay::MODE_NORMAL;
$this->config = $this->payConfig($config, 'alipay');
Pay::config($this->config);
}
public function mp(array $params)
{
}
/**
* 网页支付
* @param array $params
* @return array
*/
public function web(array $params)
{
return $this->returnFormat(Pay::alipay()->web([
'out_trade_no' => $params['out_trade_no'],
'total_amount' => $params['money'],
'subject' => $params['body'],
'_method' => 'get',
]));
}
/**
* 手机网页支付
* @param array $params
* @return array
*/
public function wap(array $params)
{
$response = Pay::alipay()->h5([
'out_trade_no' => $params['out_trade_no'],
'total_amount' => $params['money'],
'subject' => $params['body'],
'quit_url' => $params['quit_url'] ?? '',//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页
'_method' => 'get',
]);
$redirects = $response->getHeader('Location');
$effective_url = end($redirects);
return ['url' => $effective_url];
}
/**
* app支付
* @param array $params
* @return array
*/
public function app(array $params)
{
return $this->returnFormat(Pay::alipay()->app([
'out_trade_no' => $params['out_trade_no'],
'total_amount' => $params['money'],
'subject' => $params['body'],//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页
]));
}
/**
* 小程序支付
* @param array $params
* @return Collection
*/
public function mini(array $params)
{
return Pay::alipay()->mini([
'out_trade_no' => $params['out_trade_no'],
'total_amount' => $params['money'],
'subject' => $params['body'],
'buyer_id' => $params['buyer_id'],//买家支付宝用户ID 注:交易的买家与卖家不能相同。
]);
}
/**
* 付款码支付
* @param array $params
* @return Collection
*/
public function pos(array $params)
{
return Pay::alipay()->pos([
'out_trade_no' => $params['out_trade_no'],
'auth_code' => $params['auth_code'],//付授权码。 当面付场景传买家的付款码(25~30开头的长度为16~24位的数字,实际字符串长度以开发者获取的付款码长度为准)或者刷脸标识串(fp开头的35位字符串)。
'total_amount' => $params['money'],
'subject' => $params['body'],
]);
}
/**
* 扫码支付
* @param array $params
* @return Collection
*/
public function scan(array $params)
{
return Pay::alipay()->scan([
'out_trade_no' => $params['out_trade_no'],
'total_amount' => $params['money'],
'subject' => $params['body'],
]);
}
/**
* 转账
* @param array $params
* @return array
*/
public function transfer(array $params)
{
$result = $this->returnFormat(Pay::alipay()->transfer([
'out_biz_no' => $params['transfer_no'],
'trans_amount' => $params['money'],
'product_code' => $params['product_code'] ?: 'TRANS_ACCOUNT_NO_PWD',//业务产品码,单笔无密转账到支付宝账户固定为 : TRANS_ACCOUNT_NO_PWD; 收发现金红包固定为 : STD_RED_PACKET;
'biz_scene' => $params['scene'] ?: 'DIRECT_TRANSFER',//描述特定的业务场景,可传的参数如下:DIRECT_TRANSFER:单笔无密转账到支付宝,B2C现金红包;PERSONAL_COLLECTION:C2C现金红包-领红包
'payee_info' => [//收款方信息
'identity' => $params['to_no'],//参与方的唯一标识
'identity_type' => $params['to_type'] ?: 'ALIPAY_LOGON_ID',//参与方的标识类型,目前支持如下类型:1、ALIPAY_USER_ID 支付宝的会员ID2、ALIPAY_LOGON_ID:支付宝登录号,支持邮箱和手机号格式3、ALIPAY_OPEN_ID:支付宝openid
'name' => $params['to_name'],//参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填。
],
]));
if (!empty($result['msg']) && $result['msg'] != 'Success') {
throw new PayException($result['sub_msg']);
} else {
$status = $result['status'];
$status_array = [
'SUCCESS' => TransferDict::SUCCESS,
'WAIT_PAY' => TransferDict::WAIT,
'CLOSED' => TransferDict::FAIL,
'FAIL' => TransferDict::FAIL
];
$res = [
'status' => $status_array[$status],
];
if ($status == 'FAIL') {
$res['fail_reason'] = $result['fail_reason'];
}
}
return $res;
}
/**
* 支付关闭
* @param string $out_trade_no
* @return bool
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function close(string $out_trade_no)
{
$result = $this->returnFormat(Pay::alipay()->close([
'out_trade_no' => $out_trade_no,
]));
//todo 支付宝关闭异步回调
if (isset($result['sub_code']) && in_array($result['sub_code'], ['ACQ.REASON_ILLEGAL_STATUS', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.TRADE_NOT_EXIST', 'ACQ.TRADE_STATUS_ERROR'])) {
return true;
}
if (!empty($result['msg']) && $result['msg'] == 'Success') {
return true;
} else {
return false;
}
}
/**
* 退款
* @param array $params
* @return array|false
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function refund(array $params)
{
$out_trade_no = $params['out_trade_no'];
$money = $params['money'];
// $total = $params['total'];
$refund_no = $params['refund_no'];
$result = $this->returnFormat(Pay::alipay()->refund([
'out_trade_no' => $out_trade_no,
'refund_amount' => $money,
'out_request_no' => $refund_no
]));
if (!empty($result['msg']) && $result['msg'] == 'Success') {
$fund_change = $result['fund_change'];//退款是否成功可以根据同步响应的 fund_change 参数来判断,fund_change 表示本次退款是否发生了资金变化,返回 Y 表示退款成功,返回 N 则表示本次退款未发生资金变动 。
if ($fund_change == 'Y') {
$status = RefundDict::SUCCESS;
} else {
$status = RefundDict::DEALING;
}
return [
'status' => $status,
'refund_no' => $refund_no,
'out_trade_no' => $out_trade_no
];
} else {
//todo 这儿可以抛出错误
return false;
}
}
/**
* 支部异步回调
* @param string $action
* @param callable $callback
* @return ResponseInterface|string
*/
public function notify(string $action, callable $callback)
{
try {
$result = Pay::alipay()->callback();
//通过返回的值
if (!empty($result)) {//成功
if ($action == 'pay') {
//todo 这儿需要具体设计
$temp_data = array(
'mchid' => $result['seller_id'],
'trade_no' => $result['trade_no'],
'result' => $result,
'status' => OnlinePayDict::getAliPayStatus($result['trade_status'])
);
$callback_result = $callback($result['out_trade_no'], $temp_data);
if (is_bool($callback_result) && $callback_result) {
return Pay::alipay()->success();
}
}
}
return $this->fail();
} catch ( Throwable $e ) {
return $this->fail();
}
}
/**
* 查询普通支付订单
* @param array $params
* @return array
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function getOrder(array $params = [])
{
$out_trade_no = $params['out_trade_no'];
$order = [
'out_trade_no' => $out_trade_no,
];
$result = $this->returnFormat(Pay::alipay()->query($order));
if (!empty($result['msg']) && $result['msg'] == 'Success') {
return [
'status' => OnlinePayDict::getAliPayStatus($result['trade_status'])
];
} else {
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') {
throw new PayException($result['msg']);
} else {
return [];
}
}
}
/**
* 查询退款单据
* @param string $out_trade_no
* @param string|null $refund_no
* @return array
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function getRefund(string $out_trade_no, ?string $refund_no)
{
$order = [
'out_trade_no' => $out_trade_no,
'out_request_no' => $refund_no,
'_action' => 'refund', // 默认值,查询退款网页订单
];
$result = $this->returnFormat(Pay::alipay()->query($order));
if (!empty($result['msg']) && $result['msg'] == 'Success') {
$refund_status = $result['refund_status'] ?? '';
if ($refund_status == 'REFUND_SUCCESS') {
$status = RefundDict::SUCCESS;
} else {
$status = RefundDict::DEALING;
}
return [
'status' => $status,
'refund_no' => $refund_no,
'out_trade_no' => $out_trade_no
];
} else {
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') {
throw new PayException($result['msg']);
} else {
return [];
}
}
}
/**
* 获取转账订单
* @param string $transfer_no
* @return array
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function getTransfer(string $transfer_no, $out_transfer_no = '')
{
$order = [
'out_biz_no' => $transfer_no,
'_action' => 'transfer'
];
$result = $this->returnFormat(Pay::alipay()->query($order));
if (!empty($result['msg']) && $result['msg'] == 'Success') {
$status = $result['SUCCESS'] ?? '';
$status_array = array(
'SUCCESS' => TransferDict::SUCCESS,
'WAIT_PAY' => TransferDict::WAIT,
'CLOSED' => TransferDict::FAIL,
'FAIL' => TransferDict::FAIL
);
return [
'status' => $status_array[$status],
'transfer_no' => $transfer_no
];
} else {
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') {
throw new PayException($result['msg']);
} else {
return [];
}
}
}
public function fail()
{
return 'fail';
}
public function returnUrl($params)
{
return ['url' => $params->getHeader('Location')[0] ?? ''];
}
}

203
niucloud/core/core/pay/BasePay.php

@ -0,0 +1,203 @@
<?php
namespace core\pay;
use core\loader\Storage;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\MessageInterface;
use Yansongda\Supports\Collection;
/**
* 文件管理驱动类
* Class BasePay
*/
abstract class BasePay extends Storage
{
protected $config;//配置
/**
* 初始化
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
}
/**
* 网页支付
* @param array $params
* @return mixed
*/
abstract protected function web(array $params);
/**
* 手机网站支付
* @param array $params
* @return mixed
*/
abstract protected function wap(array $params);
/**
* app支付
* @param array $params
* @return mixed
*/
abstract protected function app(array $params);
/**
* 小程序支付
* @param array $params
* @return mixed
*/
abstract protected function mini(array $params);
/**
* 付款码支付
* @param array $params
* @return mixed
*/
abstract protected function pos(array $params);
/**
* 扫码支付
* @param array $params
* @return mixed
*/
abstract protected function scan(array $params);
/**
* 转账
* @param array $params
* @return mixed
*/
abstract protected function transfer(array $params);
/**
* 公众号支付
* @param array $params
* @return mixed
*/
abstract protected function mp(array $params);
/**
* 支付关闭
* @param string $out_trade_no
* @return mixed
*/
abstract protected function close(string $out_trade_no);
/**
* 退款
* @param array $params
* @return mixed
*/
abstract protected function refund(array $params);
/**
* 支付通知
* @param string $action
* @param callable $callback
* @return mixed
*/
abstract protected function notify(string $action, callable $callback);
/**
* 查询支付订单
* @param array $params
* @return mixed
*/
abstract protected function getOrder(array $params);
/**
* 查询退款订单
* @param string $out_trade_no
* @param string|null $refund_no
* @return mixed
*/
abstract protected function getRefund(string $out_trade_no, ?string $refund_no);
/**
* 查询转账订单
* @param string $transfer_no
* @return mixed
*/
abstract protected function getTransfer(string $transfer_no, $out_transfer_no = '');
/**
* 初始化
* @param array $config
* @param string $type
* @return mixed
*/
protected function payConfig(array $config, string $type)
{
return array_merge(
[
'logger' => [
'enable' => true,
'file' => root_path('runtime') . 'paylog' . DIRECTORY_SEPARATOR . date('Ym') . DIRECTORY_SEPARATOR . date('d') . '.log',
'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug
'type' => 'single', // optional, 可选 daily.
'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
],
'http' => [ // optional
'timeout' => 5.0,
]
],
[
$type => [
'default' => $config
]
],
['_force' => true]
);
}
public function returnFormat($param)
{
if ($param instanceof MessageInterface || $param instanceof Response) {
$return_value = $param->getBody()->getContents();
} else if ($param instanceof Collection) {
$return_value = $param->toArray();
} else {
$return_value = $param;
}
return $return_value;
}
/**
* 解析退款返回数据并解析
* @param $our_trade_no
* @param $refund_no
* @param $status
* @param int $success_time
* @param string $reason
* @return array
*/
public function getRefundData($our_trade_no, $refund_no, $status, $success_time = 0, $reason = '')
{
return [
'our_trade_no' => $our_trade_no,
'refund_no' => $refund_no,
'status' => $status,
'success_time' => $success_time,
'reason' => $reason
];
}
/**
* 获取转账数据并解析
* @param $transfer_no
* @param $status
* @param $reason
* @return void
*/
public function getTransferData($transfer_no, $status, $reason)
{
}
}

42
niucloud/core/core/pay/PayLoader.php

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\pay;
use core\loader\Loader;
/**
* @see PayLoader
* @package think\facade
* @mixin Wechatpay
* @method string|null upload(string $dir) 附件上传
* @method array fetch(string $url, ?string $key) 抓取远程附件
* @method mixed delete(string $file_name) 附件删除
*/
class PayLoader extends Loader
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\core\\pay\\';
protected $config_name = 'pay';
/**
* 默认驱动
* @return mixed
*/
protected function getDefault()
{
return config('pay.default');
}
}

538
niucloud/core/core/pay/Wechatpay.php

@ -0,0 +1,538 @@
<?php
namespace core\pay;
use app\dict\common\ChannelDict;
use app\dict\pay\OnlinePayDict;
use app\dict\pay\RefundDict;
use app\dict\pay\TransferDict;
use core\exception\PayException;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ResponseInterface;
use think\Response;
use Throwable;
use Yansongda\Artful\Exception\InvalidResponseException;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Exception\ServiceNotFoundException;
use Yansongda\Pay\Pay;
use Yansongda\Supports\Collection;
/**
* 微信支付管理驱动类 todo 注意:暂时不考虑合单类业务
* Class FileDriver
* @package core\file
*/
class Wechatpay extends BasePay
{
/**
* @param array $config
* @return void
* @throws ContainerException
*/
protected function initialize(array $config = [])
{
$this->config = $config;
$config['mch_secret_cert'] = url_to_path($config['mch_secret_cert'] ?? '');
$config['mch_public_cert_path'] = url_to_path($config['mch_public_cert_path'] ?? '');
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE
$config['mode'] = Pay::MODE_NORMAL;
if (!empty($config['wechat_public_cert_path']) && !empty($config['wechat_public_cert_id'])) {
$config['wechat_public_cert_path'] = [
$config['wechat_public_cert_id'] => url_to_path($config['wechat_public_cert_path'])
];
} else {
unset($config['wechat_public_cert_path']);
unset($config['wechat_public_cert_id']);
}
Pay::config($this->payConfig($config, 'wechat'));
}
/**
* 公众号支付
* @param array $params
* @return mixed|Collection
*/
public function mp(array $params)
{
try {
$result = $this->returnFormat(Pay::wechat()->mp([
'out_trade_no' => $params['out_trade_no'],
'description' => $params['body'],
'amount' => [
'total' => $params['money'],
],
'payer' => [
'openid' => $params['openid'],
],
]));
$code = $result['code'] ?? 0;
if ($code == 0) return $result;
//支付错误抛出
throw new PayException($result['message']);
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 手机网页支付
* @param array $params
* @return mixed
*/
public function wap(array $params)
{
try {
$order = [
'out_trade_no' => $params['out_trade_no'],
'description' => $params['body'],
'amount' => [
'total' => $params['money'],
],
'scene_info' => [
'payer_client_ip' => request()->ip(),
'h5_info' => [
'type' => 'Wap',
]
],
];
//这儿有些特殊, 默认情况下,H5 支付所使用的 appid 是微信公众号的 appid,即配置文件中的 mp_app_id 参数,如果想使用关联的小程序的 appid,则只需要在调用参数中增加 ['_type' => 'mini'] 即可
if (!empty($order['type'])) {
$order['_type'] = 'mini'; // 注意这一行
}
return $this->returnFormat(Pay::wechat()->h5($order));
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
public function web(array $params)
{
}
/**
* app支付
* @param array $params
* @return mixed|ResponseInterface
*/
public function app(array $params)
{
try {
return $this->returnFormat(Pay::wechat()->app([
'out_trade_no' => $params['out_trade_no'],
'description' => $params['body'],
'amount' => [
'total' => $params['money'],
],
]));
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 小程序支付
* @param array $params
* @return mixed|ResponseInterface
*/
public function mini(array $params)
{
try {
return $this->returnFormat(Pay::wechat()->mini([
'out_trade_no' => $params['out_trade_no'],
'description' => $params['body'],
'amount' => [
'total' => $params['money'],
'currency' => 'CNY',//一般是人民币
],
'payer' => [
'openid' => $params['openid'],
]
]));
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 付款码支付
* @param array $params
* @return mixed|Collection
*/
public function pos(array $params)
{
try {
$order = [
'out_trade_no' => $params['out_trade_no'],
'body' => $params['body'],
'total_fee' => $params['money'],
'spbill_create_ip' => request()->ip(),
'auth_code' => $params["auth_code"],
];
$result = Pay::wechat()->pos($order);
return $this->returnFormat($result);
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 扫码支付
* @param array $params
* @return mixed|Collection
*/
public function scan(array $params)
{
try {
return $this->returnFormat(Pay::wechat()->scan([
'out_trade_no' => $params['out_trade_no'],
'description' => $params['body'],
'amount' => [
'total' => $params['money'],
],
]));
} catch (\Exception $e) {
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 转账(微信的转账是很多笔的)
* @param array $params
* @return array
*/
public function transfer(array $params)
{
$to_data = $params['to_no'];//收款人数据
$channel = $to_data['channel'] ?? '';//渠道
$open_id = $to_data['open_id'] ?? '';//openid
if(empty($this->config['mch_id']) || empty($this->config['mch_secret_key']) || empty($this->config['mch_secret_cert']) || empty($this->config['mch_public_cert_path'])){
throw new PayException('WECHAT_TRANSFER_CONFIG_NOT_EXIST');
}
//这儿的批次信息可能是这儿生成的,但依然需要记录
$order = [
'out_batch_no' => ($to_data['out_batch_no'] ?? '') . '',//
'batch_name' => $params['remark'] ?? '',
'batch_remark' => $params['remark'] ?? '',
];
if($channel == ChannelDict::WEAPP){
$order['_type'] = 'mini';
}
$transfer_list = $params['transfer_list'];
//单笔转账
if (empty($transfer_list)) {
$transfer_list = [
[
'transfer_no' => $params['transfer_no'],
'money' => (int)$params['money'],
'remark' => $params['remark'],
'openid' => $open_id
]
];
}
$total_amount = 0;
$total_num = 0;
foreach ($transfer_list as $k => $v) {
$item_transfer = [
'out_detail_no' => $params['transfer_no'],
'transfer_amount' => (int)$v['money'],
'transfer_remark' => $v['remark'],
'openid' => $v['openid'],
];
$total_amount += (int)$v['money'];
$total_num++;
if (!empty($v['user_name'])) {
$item_transfer['user_name'] = $v['user_name'];// 明文传参即可,sdk 会自动加密
}
$order['transfer_detail_list'][] = $item_transfer;
}
$order['total_amount'] = $total_amount;
$order['total_num'] = $total_num;
$tran_status_list = [
'PROCESSING' => TransferDict::DEALING,
'ACCEPTED' => TransferDict::DEALING,
'CLOSED' => TransferDict::FAIL,
'FINISHED' => TransferDict::SUCCESS,
];
try {
$result = $this->returnFormat(Pay::wechat()->transfer($order));
if (!empty($result['code'])) {
// if($result['code'] == 'PARAM_ERROR'){
// throw new PayException();
// }else if($result['code'] == 'INVALID_REQUEST'){
// throw new PayException();
// }
if ($result['code'] == 'INVALID_REQUEST') {
throw new PayException(700010);
}
throw new PayException($result['message']);
}
return ['batch_id' => $result['batch_id'], 'out_batch_no' => $result['out_batch_no'], 'status' => $tran_status_list[$result['batch_status']]];
} catch (\Exception $e) {
if($e->getCode() == 9402){
return ['batch_id' => '', 'out_batch_no' => $order['out_batch_no'], 'status' => TransferDict::DEALING];
}
if ($e instanceof InvalidResponseException) {
throw new PayException($e->response->all()['message'] ?? '');
}
throw new PayException($e->getMessage());
}
}
/**
* 支付关闭
* @param string $out_trade_no
* @return void
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function close(string $out_trade_no)
{
try {
$result = Pay::wechat()->close([
'out_trade_no' => $out_trade_no,
]);
return $this->returnFormat($result);
}catch(Throwable $e){
return false;
}
return true;
}
/**
* 退款
* @param array $params
* @return array
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function refund(array $params)
{
$out_trade_no = $params['out_trade_no'];
$money = $params['money'];
$total = $params['total'];
$refund_no = $params['refund_no'];
$result = Pay::wechat()->refund([
'out_trade_no' => $out_trade_no,
'out_refund_no' => $refund_no,
'amount' => [
'refund' => $money,
'total' => $total,
'currency' => 'CNY',
],
]);
$result = $this->returnFormat($result);
$refund_status_array = [
'SUCCESS' => RefundDict::SUCCESS,
'CLOSED' => RefundDict::FAIL,
'PROCESSING' => RefundDict::DEALING,
'ABNORMAL' => RefundDict::FAIL,
];
return [
'status' => $refund_status_array[$result['status']],
'refund_no' => $refund_no,
'out_trade_no' => $out_trade_no,
'pay_refund_no' => $result['refund_id']
];
}
/**
* 异步回调
* @param string $action
* @param callable $callback
* @return ResponseInterface|Response
*/
public function notify(string $action, callable $callback)
{
try {
$result = $this->returnFormat(Pay::wechat()->callback());
if ($action == 'pay') {//支付
if ($result['event_type'] == 'TRANSACTION.SUCCESS') {
$pay_trade_data = $result['resource']['ciphertext'];
$temp_params = [
'trade_no' => $pay_trade_data['transaction_id'],
'mch_id' => $pay_trade_data['mchid'],
'status' => OnlinePayDict::getWechatPayStatus($pay_trade_data['trade_state'])
];
$callback_result = $callback($pay_trade_data['out_trade_no'], $temp_params);
if (is_bool($callback_result) && $callback_result) {
return Pay::wechat()->success();
}
}
} else if ($action == 'refund') {//退款
if ($result['event_type'] == 'REFUND.SUCCESS') {
$refund_trade_data = $result['resource']['ciphertext'];
$refund_status_array = [
'SUCCESS' => RefundDict::SUCCESS,
'CLOSED' => RefundDict::FAIL,
'PROCESSING' => RefundDict::DEALING,
'ABNORMAL' => RefundDict::FAIL,
];
$temp_params = [
'trade_no' => $refund_trade_data['transaction_id'],
'mch_id' => $refund_trade_data['mchid'],
'refund_no' => $refund_trade_data['out_refund_no'],
'status' => $refund_status_array[$refund_trade_data['refund_status']],
];
$callback_result = $callback($refund_trade_data['out_trade_no'], $temp_params);
if (is_bool($callback_result) && $callback_result) {
return Pay::wechat()->success();
}
}
}
return $this->fail();
} catch ( Throwable $e ) {
// throw new PayException($e->getMessage());
return $this->fail($e->getMessage());
}
}
/**
* 查询普通支付订单
* @param array $params
* @return array|MessageInterface|Collection|null
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function getOrder(array $params = [])
{
$out_trade_no = $params['out_trade_no'];
$transaction_id = $params['transaction_id'] ?? '';
$order = [
];
if (!empty($out_trade_no)) {
$order['out_trade_no'] = $out_trade_no;
}
if (!empty($transaction_id)) {
$order['transaction_id'] = $transaction_id;
}
$result = Pay::wechat()->query($order);
if (empty($result))
return $result;
$result = $this->returnFormat($result);
return [
'status' => OnlinePayDict::getWechatPayStatus($result['trade_state']),
];
}
/**
* 查询退款单据
* @param string|null $out_trade_no
* @param string|null $refund_no
* @return array|Collection|MessageInterface|null
* @throws ContainerException
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function getRefund(?string $out_trade_no, ?string $refund_no = '')
{
$order = [
'_action' => 'refund',
'transaction_id' => $out_trade_no,
'out_refund_no' => $refund_no,
''
];
$result = Pay::wechat()->query($order);
if (empty($result))
return $result;
$result = $this->returnFormat($result);
$refund_status_array = [
'SUCCESS' => RefundDict::SUCCESS,
'CLOSED' => RefundDict::FAIL,
'PROCESSING' => RefundDict::DEALING,
'ABNORMAL' => RefundDict::FAIL,
];
return [
'status' => $refund_status_array[$result['status']],
'refund_no' => $refund_no,
'out_trade_no' => $out_trade_no
];
}
/**
* 获取转账订单(todo 切勿调用)
* @param string $transfer_no
* @return array
* @throws ContainerException
* @throws InvalidParamsException
*/
public function getTransfer(string $transfer_no, $out_batch_no = '')
{
$order = [
'out_batch_no' => $out_batch_no,
'out_detail_no' => $transfer_no,
'_action' => 'transfer',
];
try {
$result = Pay::wechat()->query($order);
$result = $this->returnFormat($result);
//微信转账状态
$transfer_status_array = [
'INIT' => TransferDict::DEALING,//初始态。 系统转账校验中
'WAIT_PAY' => TransferDict::DEALING,
'PROCESSING' => TransferDict::DEALING,
'FAIL' => TransferDict::FAIL,
'SUCCESS' => TransferDict::SUCCESS,
];
return [
'status' => $transfer_status_array[$result['detail_status']],
'transfer_no' => $transfer_no
];
}catch(Throwable $e){
return [
'status' => TransferDict::DEALING,
'transfer_no' => $transfer_no
];
}
}
public function fail($message = '')
{
$response = [
'code' => 'FAIL',
'message' => $message ?: '失败',
];
return response($response, 400, [], 'json');
}
}

41
niucloud/core/core/poster/BasePoster.php

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\poster;
use core\loader\Storage;
/**
* Class BasePoster
* @package
*/
abstract class BasePoster extends Storage
{
/**
* 初始化
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
}
/**
* 创建海报
* @param array $poster
* @param string $dir
* @param string $file_path
* @return mixed
*/
abstract public function createPoster(array $poster, string $dir, string $file_path);
}

205
niucloud/core/core/poster/Poster.php

@ -0,0 +1,205 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\poster;
use Kkokk\Poster\Facades\Poster as PosterInstance;
class Poster extends BasePoster
{
/**
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
parent::initialize($config);
}
/**
* 创建海报
* @param array $poster_data
* @param string $dir
* @param string $file_path
* @return mixed|string
* @throws \Exception
*/
public function createPoster(array $poster_data, string $dir, string $file_path)
{
$bg_type = $poster_data[ 'global' ][ 'bgType' ];
$instance = PosterInstance::extension('gd')->config([ 'path' => realpath($dir) . DIRECTORY_SEPARATOR . $file_path ]);
$bg_width = $poster_data[ 'global' ][ 'width' ];
$bg_height = $poster_data[ 'global' ][ 'height' ];
if ($bg_type == 'url' && !empty($poster_data[ 'global' ][ 'bgUrl' ]) && is_file($poster_data[ 'global' ][ 'bgUrl' ])) {
$im = $instance->buildIm($bg_width, $bg_height)->buildImage([
'src' => $poster_data[ 'global' ][ 'bgUrl' ],
// 'angle' => 80
], 0, 0, 0, 0, $bg_width, $bg_height);
} else {
$im = $instance->buildIm($bg_width, $bg_height, $this->getRgbColor($poster_data[ 'global' ][ 'bgColor' ]));
}
$align_array = [
'center', 'left', 'right', 'top', 'bottom'
];
foreach ($poster_data[ 'value' ] as $k => $v) {
$type = $v[ 'type' ];
switch ($type) {
case 'text':
$font_size = ceil($v[ 'fontSize' ]);
$default_font = 'static' . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . 'SourceHanSansCN-Regular.ttf';
$font = $v[ 'fontFamily' ] ? : $default_font;
$content_list = $this->getText($v[ 'value' ], $font_size, $font, $v[ 'space' ] ?? 0, $v[ 'width' ], $v[ 'height' ], $v[ 'lineHeight' ] + $font_size);
$base_y = $this->getX($v[ 'y' ]);
if (is_array($base_y)) {
$diff_height = count($content_list) * ( $v[ 'lineHeight' ] + $font_size );
$again_y = $base_y[ 0 ];
if ($again_y == 'center') {
$base_y_num = ( $bg_height - $diff_height ) > 0 ? ( $bg_height - $diff_height ) / 2 : 0;
} else if ($again_y == 'top') {
$base_y_num = 0;
} else {
$base_y_num = $bg_height - $v[ 'height' ];
}
} else {
$base_y_num = $base_y;
}
// if(in_array($base_y, $align_array)){
// $diff_height = count($content_list)*($v[ 'lineHeight' ]+$font_size);
// $base_y_num = ($bg_height-$diff_height) > 0 ? ($bg_height-$diff_height)/2 : 0;
// }else{
// $base_y_num = $base_y[0];
// }
foreach ($content_list as $ck => $content) {
if ($ck == 0) {
if ($v[ 'lineHeight' ] > 0) {
$item_line = $v[ 'lineHeight' ] / 2;
} else {
$item_line = 0;
}
} else {
$item_line = $v[ 'lineHeight' ] + $font_size;
}
$base_y_num += $item_line;
//计算文本框宽度
$im = $im->buildText($content, $this->getX($v[ 'x' ]), $base_y_num, $font_size, $this->getRgbColor($v[ 'fontColor' ]), $v[ 'width' ], $font, $v[ 'weight' ] ? 10 : null); # 合成文字
}
break;
case 'image':
if (is_file($v[ 'value' ])) {
$im = $im->buildImage($v[ 'value' ], $this->getX($v[ 'x' ]), $this->getY($v[ 'y' ]), 0, 0, $v[ 'width' ], $v[ 'height' ], false, $v[ 'shape' ] ?? 'normal'); # 合成图片
}
break;
case 'draw':
if (!empty($v[ 'draw_type' ]) && $v[ 'draw_type' ] == 'Polygon') {
$points = $v[ 'points' ];
$im = $im->buildLine($points[ 0 ][ 0 ], $points[ 0 ][ 1 ], $points[ 2 ][ 0 ], $points[ 2 ][ 1 ], $this->getRgbColor($v[ 'bgColor' ]), 'filled_rectangle');
}
break;
}
}
$path = $im->getPoster();
return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(realpath(''), '', $path[ 'url' ]));
}
public function getX($dst_x)
{
if (is_int($dst_x)) {
return $dst_x;
} else {
return [ $dst_x, 0 ];
}
}
public function getY($dst_y)
{
if (is_int($dst_y)) {
return $dst_y;
} else {
return [ $dst_y, 0 ];
}
}
public function getRgbColor($color)
{
$color = $color ? : '#FFFFFF';
if (!str_contains($color, '#')) {
$color = str_replace('rgba(', '', $color);
$color = str_replace(')', '', $color);
list($r, $g, $b) = explode(',', $color);
list($r, $g, $b) = array_map(function($v) { return (int) $v; }, [ $r, $g, $b ]);
} else {
list($r, $g, $b) = sscanf($color, "#%02x%02x%02x");
}
return [ $r, $g, $b, 1 ];
}
/**
* 获取高度限制过后的文本
* @param $content
* @param $fontSize
* @param $font
* @param $space
* @param $max_ws
* @param $max_hs
* @param $line_height
* @return mixed
*/
public function getText($content, $fontSize, $font, $space, $max_ws, $max_hs, $line_height)
{
$calcSpace = $space > $fontSize ? ( $space - $fontSize ) : 0; // 获取间距计算值
$fontSize = ( $fontSize * 3 ) / 4; // px 转化为 pt
mb_internal_encoding('UTF-8'); // 设置编码
// 这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度
$contents = '';
$contentsArr = [];
$letter = [];
$line = 1;
$calcSpaceRes = 0;
// 将字符串拆分成一个个单字 保存到数组 letter 中
for ($i = 0; $i < mb_strlen($content); $i++) {
$letter[] = mb_substr($content, $i, 1);
}
$textWidthArr = [];
$contentStr = '';
$line_num = 1;
$total_width = 0;
$content_list = [];
foreach ($letter as $l) {
$textStr = $contentStr . $l;
$fontBox = imagettfbbox($fontSize, 0, $font, $textStr);
$textWidth = abs($fontBox[ 2 ]) + $calcSpaceRes;
$textWidthArr[ $line ] = $textWidth;
// 判断拼接后的字符串是否超过预设的宽度
if (( $textWidth > $max_ws ) && ( $contents !== '' )) {
$line_num++;
if (( $line_num * $line_height ) > $max_hs) {
break;
}
$contents .= "\n";
$contentStr = "";
$line++;
}
if (empty($content_list[ $line_num - 1 ])) $content_list[ $line_num - 1 ] = '';
$content_list[ $line_num - 1 ] .= $l;
$contents .= $l;
$contentStr .= $l;
$line === 1 && $calcSpaceRes += $calcSpace;
$text_width = max(array_values($textWidthArr));
}
return $content_list;
}
}

42
niucloud/core/core/poster/PosterLoader.php

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\poster;
use core\loader\Loader;
/**
* @see PosterLoader
* @package think\facade
* @mixin BasePoster
* @method string|null createPoster( array $poster, string $dir, string $file_path ) 创建海报
*/
class PosterLoader extends Loader
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\core\\poster\\';
protected $config_name = 'poster';
/**
* 默认驱动
* @return mixed
*/
protected function getDefault()
{
return config('poster.default');
}
}

39
niucloud/core/core/printer/BasePrinter.php

@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\printer;
use core\loader\Storage;
/**
* Class BasePrinter
* @package core\printer
*/
abstract class BasePrinter extends Storage
{
/**
* 初始化
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
}
/**
* 打印小票
* @param array $data
* @return mixed
*/
abstract protected function printTicket(array $data);
}

37
niucloud/core/core/printer/KdniaoPrinter.php

@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\printer;
class KdniaoPrinter extends BasePrinter
{
protected $config;
/**
* @param array $config
* @return void
*/
protected function initialize(array $config = [])
{
parent::initialize($config);
$this->config = $config;
}
/**
* 打印小票
* @param array $data
* @return mixed|void
*/
public function printTicket(array $data)
{
}
}

39
niucloud/core/core/printer/PrinterLoader.php

@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\printer;
use core\loader\Loader;
/**
* Class PrinterLoader
* @package core\printer
*/
class PrinterLoader extends Loader
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\core\\printer\\';
protected $config_name = 'printer';
/**
* 默认驱动
* @return mixed
*/
protected function getDefault()
{
return 'kdbird';
}
}

32
niucloud/core/core/printer/sdk/yilianyun/Autoloader.php

@ -0,0 +1,32 @@
<?php
namespace core\printer\sdk\yilianyun;
class Autoloader{
public static function loadByNamespace($name)
{
$class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name);
if (strpos($name, 'App\\') === 0) {
$class_file = __DIR__ . substr($class_path, strlen('App')) . '.php';
}elseif(empty($class_file) || !is_file($class_file)){
$class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $class_path . ".php";
}
if (is_file($class_file)) {
require_once ($class_file);
if (class_exists($name, false)) {
return true;
}
}
return false;
}
}
spl_autoload_register('\core\printer\sdk\yilianyun\Autoloader::loadByNamespace');

36
niucloud/core/core/printer/sdk/yilianyun/api/ExpressPrintService.php

@ -0,0 +1,36 @@
<?php
namespace core\printer\sdk\yilianyun\api;
class ExpressPrintService extends RpcService{
/**
*面单打印接口
*不支持机型: k4-wh, k4-wa, m1 (k4系列机型不建议使用不干胶热敏纸)
*
* @param $machineCode
* @param $content
* @param $originId
* @param int $sandbox
* @return mixed
* @throws \Exception
*/
public function index($machineCode, $content, $originId, $sandbox = 0)
{
return $this->client->call('expressprint/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId, 'sandbox' => $sandbox));
}
/**
* 面单取消接口
*
* @param $machineCode
* @param $content
* @return mixed
* @throws \Exception
*/
public function cancel($machineCode, $content)
{
return $this->client->call('expressprint/cancel', array('machine_code' => $machineCode, 'content' => $content));
}
}

22
niucloud/core/core/printer/sdk/yilianyun/api/OauthService.php

@ -0,0 +1,22 @@
<?php
namespace core\printer\sdk\yilianyun\api;
class OauthService extends RpcService{
/**
* 设置推送URL接口
*
* @param $cmd string 推送队列键
* @param $url string 推送地址
* @param $status string 推送开关
* @return mixed
*/
public function setPushUrl($cmd, $url, $status = 'open')
{
return $this->client->call('oauth/setpushurl', array('cmd' => $cmd, 'url' => $url, 'status' => $status));
}
}

22
niucloud/core/core/printer/sdk/yilianyun/api/PicturePrintService.php

@ -0,0 +1,22 @@
<?php
namespace core\printer\sdk\yilianyun\api;
class PicturePrintService extends RpcService{
/**
* 图形打印接口
* 不支持机型: k4-wh, k4-wa, m1
*
* @param $machineCode string 机器码
* @param $pictureUrl string 图片链接地址
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母
* @param $idempotence int 幂等处理
* @return mixed
*/
public function index($machineCode, $pictureUrl, $originId, $idempotence = 0)
{
return $this->client->call('pictureprint/index', array('machine_code' => $machineCode, 'picture_url' => $pictureUrl, 'origin_id' => $originId, $idempotence => $idempotence));
}
}

19
niucloud/core/core/printer/sdk/yilianyun/api/PrintMenuService.php

@ -0,0 +1,19 @@
<?php
namespace core\printer\sdk\yilianyun\api;
class PrintMenuService extends RpcService{
/**
* 添加应用菜单接口
*
* @param $machineCode string 机器码
* @param $content string 菜单详情(json)
* @return mixed
*/
public function addPrintMenu($machineCode, $content)
{
return $this->client->call('printmenu/addprintmenu', array('machine_code' => $machineCode, 'content' => $content));
}
}

20
niucloud/core/core/printer/sdk/yilianyun/api/PrintService.php

@ -0,0 +1,20 @@
<?php
namespace core\printer\sdk\yilianyun\api;
class PrintService extends RpcService{
/**
* 打印接口
*
* @param $machineCode string 机器码
* @param $content string 打印内容
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母
* @param $idempotence int 幂等处理
* @return mixed
*/
public function index($machineCode, $content, $originId, $idempotence = 0)
{
return $this->client->call('print/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId, 'idempotence' => $idempotence));
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save