作者 燕梦迪

1111

正在显示 46 个修改的文件 包含 4763 行增加0 行删除

要显示太多修改。

为保证性能只显示 46 of 46+ 个文件。

APP_DEBUG = false
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = test
PASSWORD = test
HOSTPORT = 3306
CHARSET = utf8mb4
DEBUG = true
[LANG]
default_lang = zh-cn
\ No newline at end of file
... ...
/.idea
/.vscode
*.log
/public/storage
/.DS_Store
\ No newline at end of file
... ...
sudo: false
language: php
branches:
only:
- stable
cache:
directories:
- $HOME/.composer/cache
before_install:
- composer self-update
install:
- composer install --no-dev --no-interaction --ignore-platform-reqs
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
script:
- php think unit
deploy:
provider: releases
api_key:
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
file:
- ThinkPHP_Core.zip
- ThinkPHP_Full.zip
skip_cleanup: true
on:
tags: true
... ...
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
... ...
![介绍](https://kt8logo.oss-cn-beijing.aliyuncs.com/ktadminbg.jpg)
[官网](http://www.ktadmin.cn) | [GPT开发教程](https://www.showdoc.com.cn/gpt1) | [安装教程](https://www.showdoc.com.cn/ktadmin/9320271198492681) | [开发文档](https://www.showdoc.com.cn/ktadmin/) | [应用开发](https://www.showdoc.com.cn/ktadmin/9324421497854622) | [GPTCMS](https://gitee.com/kt8cn/gptcms) | [API文档](https://www.showdoc.com.cn/2032412156402378/9297860525650426/) | [使用手册](https://kqv9wk0r7t.feishu.cn/wiki/I93BwE1raisNfqkekf0ctS98nhc)
#### :star: KtAdmin无偿供大家使用,您的 :star: star是我们前进的动力
### **开发者交流QQ群:670057597 (群内会提供技术指导)**
# 系统推荐:GPTCMS-ChatGPT(5分钟搭建GPT智能聊天SAAS系统)
直达链接: https://gitee.com/kt8cn/gptcms
### **KtAdmin用户(开发者)交流群 **
![输入图片说明](https://kt8logo.oss-cn-beijing.aliyuncs.com/gptcms-free.png)
### **系统介绍**
[狂团(kt8.cn)](http://www.kt8.cn)旗下[ KtAdmin ]是为独立版SAAS系统而生的快速开发框架!
KtAdmin 基于当前流行的ThinkPHP6.x+Vue3+Elementui++Vite 开发 , 是一款免费开源的多用户,多应用的独立版SAAS系统开发框架。
[KtAdmin]遵循较为宽松的Apache2.0开源协议,支持免费商用。
### **重磅公告一(密码为kt8.cn)!!**
狂团KtAdmin底层已封装ChatGPT、gpt-3.5、gpt-4、文心一言、百度文本审核、文字转语音、语音转文字等人工智能API,支持快速调用。开发好的成品应用可上架至狂团软件商城[www.kt8.cn](http://www.kt8.cn)获取丰厚收入!
使用api调用方式,只需配置key与api域名即可快速调用,秒级响应,支持流输出、连续对话,文本审核等强大功能!
**GPT使用教程:** http://x.kt8.cn/question/33.html
### **重磅公告二!!**
基于KtAdmin框架的免费GPT极速版应用已上线,框架已默认集成,部署框架即可使用( **如果需要访问密码,默认为 kt8.cn 也可以自行修改** )。
部署完成后,登录admin后台,配置key和接口地址即可使用,配置后应用访问路径为: 域名/chat
![输入图片说明](https://xcx-diy.oss-cn-beijing.aliyuncs.com/chatnew.png)
### **应用市场-商业变现**
狂团平台拥有数量庞大的商业用户群体,基于KtAdmin开发的系统可以上架至平台,快速变现,优质应用平台可协助推广分发!访问[狂团](http://www.kt8.cn)首页,第一个新独立版类目即为KtAdmin应用市场,可在线安装免费和付费应用。
### 微信与抖音及其他生态插件
KtAdmin目前已通过免费应用形式提供了企业微信底层(服务商代自建应用模式)、微信小程序在线提审发布底层、微信开放平台底层,可直接在KtAdmin应用市场在线免费安装,并长期免费更新。后续还将视情况免费提供抖音底层、快手底层、B站底层、阿里云剪辑底层、TikTok底层、字节巨量广告底层等各种必要的生态底层应用(大部分已完成开发),帮助各位开发者提升研发效率,避免重复造轮子。
### 代理商功能
代理商OEM系统将以插件的形式对外提供,内含多项核心技术,敬请期待(已完成开发)!
### 主要特性
1.为独立版SAAS系统而生的快速开发框架,可大量节省SAAS系统开发周期,快速完成交付。
2.天然saas底层,支持无限账号,无需重复部署安装,高效管理多个用户,多个应用。
3.天然支持多应用,多插件,一个域名即可统一化管理多套系统,多个插件,同时支持共享一套账户余额套餐系统。
4.秉承“每个系统都是一个生态“的开放共赢理念,帮助每一套建立合作的独立系统构建自己的插件生态,共生共荣。
5.后端使用tp6原生底层,无改动,无额外学习成本,易开发,易上手,效率极高。
6.前端无限制,可按喜好使用VUE2,VUE3,JQ等。
7.自带用户管理,应用市场,阿里云oss,腾讯云cos,七牛云存储,阿里云短信,等诸多实用功能,开箱即用,无需重复开发。
8.KtAdmin搭载狂团成熟的在线更新解决方案,可统一化管理主系统及各种插件的在线安装,在线更新。
9.支持开发者生态,并为开发者提供成熟的主系统在线更新,插件在线安装,在线更新等基础设施服务,同时以狂团平台及数万精准源码用户为依托,为开发者提供精准的系统分发及流量支持。
### **系统下载**
:point_right: 本仓库是面向技术开发者群体的开发版
:point_right: 如果您是非技术用户或者需要稳定的标准版,可直接下载[https://www.kt8.cn/item/view1520.html](https://www.kt8.cn/item/view1520.html)
(我们面向非技术群体提供标准版安装包,直接上传到服务器,按安装教程安装即可,并免费提供在线一键更新系统)
### .env
根目录会自带一个.example.env文件,你可以直接更名为.env文件并根据你的要求进行修改
### 软件架构
1.后端目录结构和thinkphp6常用结构一致
2.框架前端代码放在VUE目录下,user是用户后台项目(打包后上传至public/app/base目录下),admin是管理后台项目(打包后上传至public/app/base/admin目录下
### 应用开发
KtAdmin的应用开发简单到不用去熟悉框架。简单来说就是根据tp6的多应用模式在 app 目录下新建一个应用, 然后按标准把应用封装成一个插件包。这个插件包是完全独立的,以至于我们一直在说前端可以按需使用JQ,VUE等,而并不是非得跟框架一样使用VUE3。我们一直建议,尽量不用动框架里面base应用的代码,甚至都不用去看他,只需要简单看下应用开发流程文档(和TP6官方的多应用模式文档),就可以开始开发应用。
### 开发者交流群(联系客服拉群)
![联系客服](https://www.kt8.cn/config/ueditor/php/upload/image/20211020/1634724501157966.png)
### 在线演示
**用户后台** http://demo.kt8.cn 账号123456 密码123456
**管理后台** http://demo.kt8.cn/app/base/admin
账号admin 密码123456
### 功能截图
![管理后台](https://kt8logo.oss-cn-beijing.aliyuncs.com/ktadmin.png)
![用户后台](https://kt8logo.oss-cn-beijing.aliyuncs.com/kt1.png)
### 插件下载
后续免费/付费插件均发布至[狂团软件商城 www.kt8.cn](http://www.kt8.cn),可自行下载
### 关于我们
我们在SAAS系统行业深耕了八年,曾研发出了多套在行业内有一定知名度的系统,也帮助不少客户实现了千万级收入。我们非常了解这个行业,了解行业痛点,了解客户需求。如今,希望KtAdmin这套凝聚了我们八年SAAS行业研发经验的系统能帮到更多有需要的人。
### 版权信息
KtAdmin遵循Apache2.0开源协议发布,并提供免费使用。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2022 by KtAdmin (http://www.ktadmin.cn)
All rights reserved。
### 允许行为
1.允许商用
2.允许基于框架开发应用并作为独立系统出售
3.允许修改代码以满足自身需求
### 禁止行为
1.禁止修改框架代码并再次发布框架衍生版等与Ktadmin产生恶意竞争或对抗的行为
2.禁止任意删除修改代码注释版权或页面版权等任何违反Apache2.0开源协议及《中华人民共和国著作权法》的行为
\ No newline at end of file
... ...
deny from all
\ No newline at end of file
... ...
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}
... ...
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\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 = false !== strpos($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(true);
}
return $v->failException(true)->check($data);
}
}
... ...
<?php
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}
... ...
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
/**
* 这是管理后台的菜单文件
*/
return [
//系统
[
"path" => "/system/site",
"redirect" => "/system/site",
"meta" => ['title'=>'系统设置', 'icon'=>'Setting'],
"component" => "MyLayout",
"children" => [
[
"path" => "/system/site",
"name" => "system",
"meta" => ['title'=>'系统设置', 'icon'=>'Setting', 'alwaysShow'=>true],
"redirect" => "/system/site",
"component" => "RouterView",
"children" => [
[
"path" => "/system/site",
"name" => "systemsite",
"meta" => ['title'=>'站点设置'],
"component" => "() => import('@/pages/admin/system/site.vue')",
],
[
"path" => "/system/loginsetup",
"name" => "systemloginsetup",
"meta" => ['title'=>'登录设置'],
"component" => "() => import('@/pages/admin/system/login.vue')",
],
[
"path" => "/system/oss",
"name" => "systemoss",
"meta" => ['title'=>'存储设置'],
"component" => "() => import('@/pages/admin/system/oss.vue')",
],
[
"path" => "/system/sms",
"name" => "systemsms",
"meta" => ['title'=>'短信设置'],
"component" => "() => import('@/pages/admin/system/sms.vue')",
],
[
"path" => "/wxpay/config",
"name" => "wxpayconfig",
"meta" => ['title'=>'支付配置'],
"component" => "() => import('@/pages/admin/wxpay/wxpayconfig.vue')",
],
[
"path" => "/system/aiconfig",
"name" => "systemaiconfig",
"meta" => ['title'=>'AI接口设置'],
"component" => "() => import('@/pages/admin/system/aiconfig.vue')",
],
[
"path" => "/system/gptconfig",
"name" => "systemgptconfig",
"meta" => ['title'=>'GPT接口设置'],
"component" => "() => import('@/pages/admin/system/gptconfig.vue')",
],
[
"path" => "/system/cs",
"name" => "systemcs",
"meta" => ['title'=>'内容安全'],
"component" => "() => import('@/pages/admin/system/contentsecurity.vue')",
],
]
],
[
"path" => "/kt/config",
"name" => "kt",
"meta" => ['title'=>'狂团对接', 'icon'=>'HelpFilled', 'alwaysShow'=>true],
"redirect" => "/kt/config",
"component" => "RouterView",
"children" => [
[
"path" => "/kt/config",
"name" => "ktconfig",
"meta" => ['title'=>'在线更新'],
"component" => "() => import('@/pages/admin/kt/ktconfig.vue')",
],
[
"path" => "/kt/app",
"name" => "ktapp",
"meta" => ['title'=>'应用列表'],
"component" => "() => import('@/pages/admin/kt/ktapp.vue')",
],
[
"path" => "/kt/appstore",
"name" => "appstore",
"meta" => ['title'=>'应用商店'],
"component" => "() => import('@/pages/admin/kt/appstore.vue')",
],
[
"path" => "/kt/dockset",
"name" => "ktdockset",
"meta" => ['title'=>'对接设置'],
"component" => "() => import('@/pages/admin/kt/dockset.vue')",
],
]
],
]
],
//用户
[
"path" => "/user/list",
"redirect" => "/user/list",
"meta" => ['title'=>'用户管理', 'icon'=>'User'],
"component" => "MyLayout",
"children" => [
[
"path" => "/user/list",
"name" => "user",
"meta" => ['title'=>'用户管理', 'icon'=>'User', 'alwaysShow'=>true],
"redirect" => "/user/list",
"component" => "RouterView",
"children" => [
[
"path" => "/user/list",
"name" => "userlist",
"meta" => ['title'=>'用户列表'],
"component" => "() => import('@/pages/admin/user/list.vue')",
],
[
"path" => "/user/add",
"name" => "useradd",
"meta" => ['title'=>'新增用户'],
"component" => "() => import('@/pages/admin/user/add.vue')",
],
[
"path" => "/user/edit",
"name" => "useredit",
"meta" => ['title'=>'编辑用户', 'hiddenInSideMenu'=>true],
"component" => "() => import('@/pages/admin/user/edit.vue')",
],
]
]
]
],
//应用套餐
[
"path" => "/package/list",
"redirect" => "/package/list",
"meta" => ['title'=>'套餐管理', 'icon'=>'Coin'],
"component" => "MyLayout",
"children" => [
[
"path" => "/package/list",
"name" => "package",
"meta" => ['title'=>'应用套餐', 'icon'=>'Coin', 'alwaysShow'=>true],
"redirect" => "/package/list",
"component" => "RouterView",
"children" => [
[
"path" => "/package/list",
"name" => "paskagelist",
"meta" => ['title'=>'套餐列表'],
"component" => "() => import('@/pages/admin/package/list.vue')",
],
[
"path" => "/package/add",
"name" => "paskageadd",
"meta" => ['title'=>'新增套餐'],
"component" => "() => import('@/pages/admin/package/add.vue')",
]
]
],
]
],
//应用
[
"path" => "/app/mainapp",
"redirect" => "/app/mainapp",
"meta" => ['title'=>'应用设置', 'icon'=>'Menu'],
"component" => "MyLayout",
"children" => [
[
"path" => "/app/mainapp",
"name" => "apps",
"meta" => ['title'=>'应用管理', 'icon'=>'Menu', 'alwaysShow'=>true],
"redirect" => "/app/mainapp",
"component" => "RouterView",
"children" => [
[
"path" => "/app/mainapp",
"name" => "appmainapp",
"meta" => ['title'=>'应用设置'],
"component" => "() => import('@/pages/admin/app/mainapp.vue')"
],
[
"path" => "/app/plugin",
"name" => "appplugin",
"meta" => ['title'=>'插件设置'],
"component" => "() => import('@/pages/admin/app/plugin.vue')"
],
[
"path" => "/app/tools",
"name" => "apptools",
"meta" => ['title'=>'工具应用'],
"component" => "() => import('@/pages/admin/app/tools.vue')"
],
[
"path" => "/app/template",
"name" => "apptemplate",
"meta" => ['title'=>'模板应用'],
"component" => "() => import('@/pages/admin/app/template.vue')"
],
]
],
]
],
//市场
[
"path" => "/market/index",
"redirect" => "/market/index",
"meta" => ['title'=>'自营市场', 'icon'=>'Goods'],
"component" => "MyLayout",
"children" => [
[
"path" => "/market/index",
"name" => "market",
"meta" => ['title'=>'应用市场', 'icon'=>'Goods', 'alwaysShow'=>true],
"redirect" => "/market/index",
"component" => "RouterView",
"children" => [
[
"path" => "/market/index",
"name" => "marketindex",
"meta" => ['title'=>'应用管理'],
"component" => "() => import('@/pages/admin/market/index.vue')"
],
[
"path" => "/market/edit",
"name" => "marketedit",
"meta" => ['title'=>'市场编辑', 'hiddenInSideMenu'=>true],
"component" => "() => import('@/pages/admin/market/edit.vue')"
],
[
"path" => "/market/classification",
"name" => "marketclassification",
"meta" => ['title'=>'分类管理'],
"component" => "() => import('@/pages/admin/market/classification.vue')"
],
]
],
[
"path" => "/market/openuse",
"name" => "marketopenuse",
"meta" => ['title'=>'已购应用', 'icon'=>'Present', 'alwaysShow'=>true],
"redirect" => "/market/openuse",
"component" => "RouterView",
"children" => [
[
"path" => "/market/openuse",
"name" => "marketopenuse",
"meta" => ['title'=>'应用管理'],
"component" => "() => import('@/pages/admin/market/openuse.vue')"
],
]
],
// [
// "path" => "/market/order",
// "name" => "marketorder",
// "meta" => ['title'=>'市场订单', 'icon'=>'Tickets', 'alwaysShow'=>true],
// "redirect" => "/market/order",
// "component" => "RouterView",
// "children" => [
// [
// "path" => "/market/order",
// "name" => "marketorder",
// "meta" => ['title'=>'订单列表'],
// "component" => "() => import('@/pages/admin/market/order.vue')"
// ],
// ]
// ],
]
],
];
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// 这是系统自动生成的公共文件
/**
* 执行sql 保证sql执行完
* @param $content
* @return array
* @throws \Exception
*/
function updateRunSql($content){
// error_reporting(0);
//遍历执行sql语句
//去除空行和注释
$content=removeBom($content);//自动去除bom头
// $content = preg_replace("/[\/\*][\s\S\r\n]*[\*\/]/", '', $content);
// $content = preg_replace("/[--]+(.+)(\r\n)+/", '', $content);
$content = preg_replace("/\/\*[\s\S\r\n]*\*\//", '', $content);
$content = preg_replace("/--+(.+)(\r\n)+/", '', $content);
$sqlArr = preg_split("/;[\r\n]*/", $content);
$error_message = '';
foreach ($sqlArr as $v) {
$v = str_replace( "\r\n",' ',$v);
if (empty($v)) continue;
try {
think\facade\Db::execute($v);
} catch (\Exception $e) {
// $error_message .= $e->getMessage() . ' ';
// \Log::error('sql执行错误:' . $e->getMessage());
$error_message = $v;
}
}
if ($error_message) {
return ['status'=>'error','msg'=> $error_message];
} else {
return ['status'=>'success','msg'=>'执行成功'];
}
}
/**
* 自动找到内容bom头并去除
* @param $content
* @return bool|string
*/
function removeBom($content){
$contents=$content;
$charset[1]=substr($contents,0,1);
$charset[2]=substr($contents,1,1);
$charset[3]=substr($contents,2,1);
if(ord($charset[1])==239 && ord($charset[2])==187 && ord($charset[3])==191){
$content=substr($content,3);
}
return $content;
}
/**
*
* 清空文件夹
* @param $dirName
* @param $oldtime 小于的时间
* @param $newtime 大于的时间
*/
function clear_dir($dirName){
if(is_dir($dirName)){//如果传入的参数不是目录,则为文件,应将其删除
//如果传入的参数是目录
$handle = @opendir($dirName);
while(($file = @readdir($handle)) !== false){
if($file!='.'&&$file!='..'){
$dir = $dirName . '/' . $file; //当前文件$dir为文件目录+文件
remove_dir($dir);
}
}
remove_dir($dirName);
}
}
/**
*
* 清空并删除文件夹
* @param $dirName
* @param $oldtime 小于的时间
* @param $newtime 大于的时间
*/
function remove_dir($dirName,$oldtime=null,$newtime=null){
if(!is_dir($dirName)){//如果传入的参数不是目录,则为文件,应将其删除
$mtime = filectime($dirName);
if($oldtime===null&&$newtime===null){
@unlink($dirName);
}else{
if(isset($oldtime)){
if($mtime<$oldtime){
@unlink($dirName);
}
}
if(isset($newtime)){
if($mtime>$newtime){
@unlink($dirName);
}
}
}
return false;
}
//如果传入的参数是目录
$handle = @opendir($dirName);
while(($file = @readdir($handle)) !== false){
if($file!='.'&&$file!='..'){
$dir = $dirName . '/' . $file; //当前文件$dir为文件目录+文件
remove_dir($dir,$oldtime,$newtime);
}
}
closedir($handle);
return @rmdir($dirName) ;
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
return [
// 默认磁盘
'default' => env('filesystem.driver', 'public'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/storage',
// 磁盘路径对应的外部URL路径
'url' => '/storage',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 路由设置
// +----------------------------------------------------------------------
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',
// 'middleware' => [
// // app\base\middleware\check::class,
// ],
];
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller;
use app\BaseController;
use think\facade\Db;
use think\Request;
use think\facade\Session;
use app\base\model\admin\system\SmsModel;
use app\kt_agent\model\admin\agent\ManageModel;
use app\base\model\BaseModel;
use think\facade\Cache;
use think\facade\Log;
class BaseAdmin extends BaseController
{
protected $req;
protected $admin;
protected $uid;
protected $token;
protected $host;
protected $appName;
protected $Jssdk;
public function __construct(Request $request){
// $url = strtolower($request->controller().'/'.$request->action());
if(Session::has('uid')) Session::delete('uid');
$this->req = $request;
$this->host = $request->host();
$this->token = $this->req->header('UserToken');
$this->admin = Db::table('kt_base_agent')->where([['agency_token', '=', $this->token], ['expire_time', '>',time()]])->find();
// var_dump(time());
// var_dump($this->admin);die;
if($this->admin){
$this->uid = $this->admin['id'];
Session::set('uid',$this->admin['id']);
}
// var_dump(request()->file()); die; // $this->Jssdk = \Wechat\Loader::get('Script',config('app.webchat'));
}
/**
* 发送短信验证码
* @return \think\Response
*/
public function sendCode()
{
$phone = $this->req->post('phone');
if(!preg_match("/^1[3456789]\d{9}$/", $phone)) return error('手机号格式不正确');
$data = [
'phone' => $phone,
'bh' => '001', //验证码模板
'param' => ['code'=>SmsModel::getCode()]
];
$uid = SmsModel::getAdminId();
$res = SmsModel::sendSms($data,$uid);
if($res != 'ok') return error('发送失败');
return success('发送成功');
}
/**
* 获取前端路由配置
*/
public function getAdminRoutes(){
$adminRoutes = include app_path()."adminroutes.php";
$show = $this->req->param('show',0);
$agent = $this->admin;
if($agent['isadmin'] || $show==1){
return success('OK',$adminRoutes);
}
$auths = ManageModel::authInfo($agent['level'])['auths']??[];//获取代理权限
$noAuths = ['/market/index','/market/edit','/market/classification','/kt/config'];//代理不能有的权限
$auths = array_diff($auths,$noAuths);
$newRoutes = [];
foreach ($adminRoutes as $value) {
if($value['path'] == '/index'){
$newRoutes[] = $value;
continue;
}
$children1 = [];
if($value['children']){
foreach ($value['children'] as $cValue1) {
$children2 = [];
if($cValue1['children']){
foreach ($cValue1['children'] as $cValue2) {
if(in_array($cValue2['path'], $auths)){
$children2[] = $cValue2;
}
}
}
if($children2){
$cValue1['path'] = reset($children2)['path'];
$cValue1['children'] = $children2;
$children1[] = $cValue1;
}
}
}
if($children1){
$value['path'] = reset($children1)['path'];
$value['children'] = $children1;
$newRoutes[] = $value;
}
}
return success('OK',$newRoutes);
}
/**
* 清理缓存
* @return \think\Response
*/
public function clearCache()
{
$isadmin = BaseModel::isAdmin($this->uid);
if(!$isadmin) return error('该账户不是管理员');
Log::clear();
$this->logClear();
Cache::clear();
return success('清理成功');
}
/**
* 删除日志
* @return \think\Response
*/
private function logClear(){
$white = [".","..","storage"];
$runtimeDir = root_path().'runtime';
$dirs = scandir($runtimeDir);
foreach ($dirs as $dir) {
if(in_array($dir, $white) || !is_dir(root_path().'runtime/'.$dir)) continue;
$this->delDir(root_path().'runtime/'.$dir);
}
return 'ok';
}
/**
*递归删除文件夹
* @return \think\Response
*/
private function delDir($path){
if (!is_dir($path)) {
return false;
}
$content = scandir($path);
foreach ($content as $v) {
if ('.' == $v || '..' == $v) {
continue;
}
$item = $path . '/' . $v;
if (is_file($item)) {
unlink($item);
continue;
}
$this->delDir($item);
}
return rmdir($path);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller;
use app\BaseController;
use think\facade\Db;
use think\Request;
use app\base\model\BaseModel;
use think\facade\Session;
class BaseUser extends BaseController
{
protected $req;
protected $user;
protected $wid;
protected $token;
public function __construct(Request $request){
// $url = strtolower($request->controller().'/'.$request->action());
$this->req = $request;
$this->host = $request->host();
$url = $request->url();
$this->token = $this->req->header('UserToken');
$this->user = Db::table('kt_base_user')->where([['token', '=', $this->token], ['expire_time', '>',time()]])->find();
// var_dump($this->user);
if($this->user){
$this->wid = $this->user['id'];
Session::set('wid',$this->user['id']);
Session::set('uid',$this->user['agid']);
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\base\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
$domain = request()->domain();
return redirect($domain.'/app/base');
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin;
use think\facade\Db;
use think\facade\Session;
use app\BaseController;
use app\base\model\admin\system\KtModel;
use PclZip;
use think\facade\Log;
/**
* 插件安装更新
*/
class AppInstall extends BaseController
{
public function index()
{
$orderbh = request()->get('orderbh');
$operation = request()->get('operation');
$uid = KtModel::getAdminId();
$config = Db::table('kt_base_ktconfig')->where('uid',$uid)->find();
if(!$config){
echo '配置错误';
exit;
}
$params = [
'key' => $config['key'],
'secret' => $config['secret'],
'orderbh' => $orderbh,
];
$detail = KtModel::getModuleDetailApi($params);
if(!$detail || !isset($detail['status'])){
echo '未知错误';
exit;
}
if($detail['status'] != 'success'){
echo $detail['msg'];
exit;
}
$pulgin = $detail['data'];
$module = Db::table('kt_base_market_app')->where('code',$pulgin['name'])->find();
if($module && $operation == "uninstall"){
$res = Db::table('kt_base_market_app')->where('code',$pulgin['name'])->delete();
echo 'success';
exit;
}
$data = [];
if(!$module){
$data['create_time'] = date("Y-m-d H:i:s");
$operation = 'install';
}else{
$data['id'] = $module['id'];
if(!$module['version']){
$operation = 'install';
}
if($operation == 'upgrade' && $module['version'] == $pulgin['version']){
echo '已更新到最新版本';
exit;
}
}
$data['version'] = $pulgin['version'];
$data['orderbh'] = $orderbh;
$data['has_applets'] = $pulgin['has_applets'];
$data['expire_date'] = $pulgin['expire_date'];
$params = [
'key' => $config['key'],
'secret' => $config['secret'],
'orderbh' => $orderbh,
];
$downPlugin = KtModel::downModuleApi($params);
if($downPlugin['status'] != 'success'){
echo $downPlugin['msg'];
exit;
}
//资源文件名
$file_name = $downPlugin['data']['filename'];
$resource = $downPlugin['data']['resource'];
$path = root_path().'public/static/temp/module/';
is_dir($path) or mkdir($path, 0777, true);
$file_path = $path.'/'.$file_name;
$res = file_put_contents($file_path, base64_decode($resource));
$zipName = $file_name;
if(!file_exists($file_path)) exit('写入失败');
$zipArc = new PclZip($file_path);
//插件目录
// $nameIndex = $zipArc->getNameIndex(0);
// $zipArc->close();
// $nameIndexArr = explode('/', $nameIndex);
// $name = $nameIndexArr[0];
$nameIndex = $zipArc->listContent();
$nameIndexArr = explode('/', $nameIndex[0]['filename']);
$name = $nameIndexArr[0];
try {
$re = $zipArc->extract(PCLZIP_OPT_PATH, root_path().'app', PCLZIP_OPT_REPLACE_NEWER);
if (!$re){echo '解压失败';exit;}
} catch (\Exception $e) {
echo '解压失败';exit;
}
//public目录移动
$appPublicPath = root_path().'app'.'/'.$name.'/public';
if(file_exists($appPublicPath)){
if(file_exists($appPublicPath.'/static/'.$name)){
if(file_exists(root_path().'public/static/'.$name)){
clear_dir(root_path().'public/static/'.$name);
}
if(file_exists(root_path().'public/static/'.$name)){
echo '请检查前端目录 public/static权限';exit;
}
rename($appPublicPath.'/static/'.$name,root_path().'public/static/'.$name);
}
if($name == 'gptcms'){
if(file_exists($appPublicPath.'/app/kt_ai')){
if(file_exists(root_path().'public/app/kt_ai')){
clear_dir(root_path().'public/app/kt_ai');
}
if(file_exists(root_path().'public/app/kt_ai')){
echo '请检查前端文件public/app权限';exit;
}
rename($appPublicPath.'/app/kt_ai',root_path().'public/app/kt_ai');
}
}else{
if(file_exists($appPublicPath.'/app/'.$name)){
if(file_exists(root_path().'public/app/'.$name)){
clear_dir(root_path().'public/app/'.$name);
}
if(file_exists(root_path().'public/app/'.$name)){
echo '请检查前端文件public/app权限';exit;
}
rename($appPublicPath.'/app/'.$name,root_path().'public/app/'.$name);
}
}
}
$xmlfilepath = root_path().'app/'.$name.'/mainfest.xml';
if(!file_exists($xmlfilepath)) $xmlfilepath = root_path().'app/'.$name.'/manifest.xml';
$xml = simplexml_load_file($xmlfilepath,'SimpleXMLElement', LIBXML_NOCDATA);
$xml_arr = json_decode(json_encode($xml), 1);
$data['user_link'] = $xml_arr['application']['userindex'] ?? '';
$data['admin_link'] = $xml_arr['application']['adminindex'] ?? '';
$data['target'] = $xml_arr['application']['target'] ?? 2;
$data['describe'] = $xml_arr['application']['describe'] ?? '';
$data['app_type'] = $xml_arr['application']['type'] ?? 1;
$data['author'] = $xml_arr['application']['author'] ?? '';
if($data['app_type'] == 2){
$nameArr = explode('_', $xmlArr['application']['code']);
if($data['app_type']=2 && in_array('plugin', $nameArr)){
$key = array_keys($nameArr,'plugin');
$panmeArr = array_slice($nameArr, 0,$key);
$pname = implode('_', $panmeArr);
$data['pid'] = Db::table("kt_base_market_app")->where(["code"=>$pname])->value('id') ?: 0;
}
}
$sqla = '';
$upgradePath = root_path().'/app/'.$name.'/upgrade';
if($operation == 'install'){
$data['code'] = $xml_arr['application']['code'];
$data['name'] = $xml_arr['application']['name'];
$data['logo'] = $xml_arr['application']['logo'];
if(is_dir($upgradePath)){
$versionDirs = scandir($upgradePath);
sort($versionDirs);
if($versionDirs){
foreach ($versionDirs as $versionDir) {
if($versionDir == "." || $versionDir == ".." ) continue;
if(!is_dir($upgradePath.'/'.$versionDir)) continue;
$sqla = '';
if(file_exists($upgradePath.'/'.$versionDir.'/up.sql')){
$sqla = file_get_contents($upgradePath.'/'.$versionDir.'/up.sql');
// $sqlArr = include($upgradePath.'/'.$versionDir.'/up.sql');
// foreach ((array)$sqlArr as $val) {
// $sqla .= $val;
// }
}
if($sqla){
try{
$resRunSql = $this->updateRunSql($sqla);
if($resRunSql) {
// echo "版本:".$versionDir." sql:".$resRunSql['msg'];
// exit;
}else{
Log::error($resRunSql);
}
}catch(Exception $r){
Log::error($r);
// \Log::error('sql执行错误:' . $resRunSql['msg']);
// echo "版本:".$versionDir." sql:".$resRunSql['msg'];
// exit;
}
}
$data['version'] = $versionDir;
}
}
}
}else if($operation == 'upgrade'){
if(is_dir($upgradePath)){
$versionDirs = scandir($upgradePath);
foreach ($versionDirs as $key => $value) {
if($value == "." || $value == ".." ) unset($versionDirs[$key]);
}
sort($versionDirs);
if($versionDirs){
// arsort($versionDirs);
$versionDirKey = array_keys($versionDirs,$module['version'])[0];
for ($i=$versionDirKey + 1; $i < count($versionDirs); $i++) {
if(!is_dir($upgradePath.'/'.$versionDirs[$i])) continue;
$sqla = '';
if(file_exists($upgradePath.'/'.$versionDirs[$i].'/up.sql')){
$sqla = file_get_contents($upgradePath.'/'.$versionDirs[$i].'/up.sql');
// $sqlArr = include($upgradePath.'/'.$versionDirs[$i].'/up.sql');
// foreach ((array)$sqlArr as $k => $val) {
// $sqla .= $val;
// }
}
if($sqla){
try{
$resRunSql = $this->updateRunSql($sqla);
if($resRunSql) {
// echo "版本:".$versionDirs[$i]." sql:".$resRunSql['msg'];
// exit;
}else{
Log::error($resRunSql);
}
}catch(Exception $r){
Log::error($resRunSql);
// echo "版本:".$versionDirs[$i]." sql:".$resRunSql['msg'];
// exit;
}
}
$data['version'] = $versionDirs[$i];
}
}
}
}
$data['install_type'] = 2;
$data['uid'] = KtModel::getAdminId();
// $data['can_update'] = 0;
Db::table('kt_base_market_app')->save($data);
unlink($file_path);
echo 'success';
exit;
}
private function updateRunSql($content){
// error_reporting(0);
//遍历执行sql语句
//去除空行和注释
$content=removeBom($content);//自动去除bom头
// $content = preg_replace("/[\/\*][\s\S\r\n]*[\*\/]/", '', $content);
// $content = preg_replace("/[--]+(.+)(\r\n)+/", '', $content);
$content = preg_replace("/\/\*[\s\S\r\n]*\*\//", '', $content);
$content = preg_replace("/--+(.+)(\r\n)+/", '', $content);
$sqlArr = preg_split("/;[\r\n]*/", $content);
$error_message = '';
foreach ($sqlArr as $v) {
$v = str_replace( "\r\n",' ',$v);
if (empty($v)) continue;
try {
Db::execute($v);
} catch (\Exception $e) {
// $error_message .= $e->getMessage() . ' ';
// \Log::error('sql执行错误:' . $e->getMessage());
$error_message = $v;
}
}
// if ($error_message) {
// return ['status'=>'error','msg'=> $error_message];
// } else {
// return ['status'=>'success','msg'=>'执行成功'];
// }
return $error_message;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin;
use think\facade\Db;
use think\facade\Session;
use app\BaseController;
use app\base\model\admin\system\KtModel;
use PclZip;
/**
* 系统更新
*/
class BaseInstall extends BaseController
{
private $param=[];
public function index()
{
$u = $_SERVER['HTTP_HOST'];
$a = 'download';
$b = "all"; //每次请求安装全部版本,参数填 all, 每次安装一个版本 one
//下载当前已安装的下一版本
$param = [
'a' => $a,
'u' => $u,
];
//获取key
$uid = KtModel::getAdminId();
$config = Db::table('kt_base_ktconfig')->where('uid',$uid)->find();
if(!$config || !$config['key'] || !$config['secret']) exit('config error');
$param['webkey'] = $config['key'];
$param['sign'] = KtModel::makeSignApi($param,$config['secret']);
$this->param = $param;
$url = 'https://www.kt8.cn/cloud/apiauthsys/index?'.http_build_query($param);
if($b == 'one'){
$res = $this->insta($url,$param);
exit($res);
}else if($b == 'all'){
$msg = '';
while (1) {
$res = $this->insta($url);
if($res!="success"){
$msg = $res;
break;
}
}
if($msg=="newest"){
exit('success');
}else{
exit($msg);
}
}
}
private function insta($url)
{
//如果存在sql文件,则删除
$sqlPath = root_path() . 'update.sql';
if (file_exists($sqlPath)){
unlink($sqlPath);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output,1);
if($res && $res['status'] == 'success'){
$resource = $res['data']['resource'];
$file_name = $res['data']['filename'];
$path = root_path().'public/temp/module/';
is_dir($path) or mkdir($path, 0777, true);
$file_path = $path.'/'.$file_name;
file_put_contents($file_path, base64_decode($resource));
KtModel::makelog($this->param,$file_name);
// $zipArc = new \ZipArchive();
$zipArc = new PclZip($file_path);
// if (!$zipArc->open($file_path)) exit('更新失败');
// if (!$zipArc->extractTo(root_path())) {
// $zipArc->close();
// exit('更新失败');
// }
try {
$re = $zipArc->extract(PCLZIP_OPT_PATH, root_path(), PCLZIP_OPT_REPLACE_NEWER);
// if (!$re) return $zipArc->error_string;
if (!$re) return '解压失败';
} catch (\Exception $e) {
// \Log::error('插件解压失败,错误信息:' . $e->getMessage());
return '解压失败';
}
unlink($file_path);
//去项目根目录找update.sql文件,执行sql
if (file_exists($sqlPath)) {
$sqlContent = file_get_contents($sqlPath);
$sqlArr=preg_split("/;[\r\n]+/", $sqlContent);
foreach($sqlArr as $v){
Db::execute($v);
}
unlink($sqlPath);
}
return 'success';
}
return $res['msg'];
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin;
use think\facade\Db;
use app\base\controller\BaseAdmin;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
class Login extends BaseAdmin
{
/*
* 登录
*/
public function index()
{
$username = $this->req->param('username');
$password = $this->req->param('password');
if(!$username) return error('缺少参数username');
if(!$password) return error('缺少参数password');
$where = [
['un', '=', $username],
['telephone', '=', $username]
];
$userAgency = Db::table('kt_base_agent')->whereOr($where)->find();
if(!$userAgency) return error('账户不存在');
if($userAgency['pwd'] != md5($password) && $userAgency['pwd'] != ktEncrypt($password)) return error('帐号或密码错误');
if($userAgency['isstop'] != 1 ) return error('账户已经被停用或作废');
$token = $userAgency['agency_token'] && $userAgency['expire_time'] > time() ? $userAgency['agency_token'] : Uuid::uuid1();
Db::table('kt_base_agent')->where('id',$userAgency['id'])->update(['agency_token'=>"{$token}",'expire_time'=> time() + (7*24*3600),'lasttime'=>date("Y-m-d H:i:s") ]);
Db::table('kt_base_loginlog')->insert([
'admin' => 1,
'wid' => $userAgency['id'],
'uip' => $this->req->ip(),
'create_time' => date("Y-m-d H:i:s")
]);
return success('登录成功',['token'=>$token]);
}
/*
* 修改密码
*/
public function forgotPassword()
{
$uid = Session::get('uid');
$agent = Db::table('kt_base_agent')->find($uid);
$password = $this->req->post('password');
if($agent['pwd'] != md5($password) && $agent['pwd'] != ktEncrypt($password)) return error('当前密码错误');
$new_password = $this->req->post('new_password');
$confirm_password = $this->req->post('confirm_password');
if(!$new_password || !$confirm_password) return error('请输入新密码');
if($new_password != $confirm_password) return error('两次输入的新密码不一致');
if($agent['pwd'] == ktEncrypt($new_password)) return error('新旧密码一致');
$res = Db::table('kt_base_agent')->where('id',$uid)->update([
"pwd" => ktEncrypt($new_password),
]);
if($res) return success('修改成功');
return error('修改失败');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin;
use think\facade\Db;
use think\facade\Session;
use app\BaseController;
use think\facade\Queue;
/**
* 统一定时任务类
*/
class Task extends BaseController
{
/*
*入口
*/
public function index()
{
$tasks = Db::table('kt_base_timed_task')->where('status',1)->select();
if($tasks->isEmpty()) return 'ok';
foreach ($tasks as $task) {
if($task['last_time'] + $task['interval_time'] > time()){
$jobHandlerClassName = $task['class_ame'];
$isPushed = Queue::push($jobHandlerClassName, array('time'=>time()), 'timed_task');
Db::table('kt_base_timed_task')->where('id',$task['id']->update([
'last_time' => time(),
]);
}
}
return success('执行成功');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\app;
use think\facade\Db;
use think\facade\Session;
use app\base\controller\BaseAdmin;
use app\base\model\admin\app\AppManageModel;
class AppManage extends BaseAdmin
{
/**
* 主应用
*/
public function mainapp()
{
$uid = Session::get('uid');
// return error(base_path());
$res = AppManageModel::mainapp($this->req);
return success('应用列表',$res);
}
/**
* 子应用(主应用插件)
*/
public function plugin()
{
$uid = Session::get('uid');
// return error(base_path());
$res = AppManageModel::plugin($this->req);
return success('应用列表',$res);
}
/**
* 工具应用
*/
public function tools()
{
$uid = Session::get('uid');
// return error(base_path());
$res = AppManageModel::tools($this->req);
return success('应用列表',$res);
}
/**
* 模板应用
*/
public function template()
{
$uid = Session::get('uid');
// return error(base_path());
$res = AppManageModel::template($this->req);
return success('模板应用',$res);
}
/**
* 使用模板
*/
public function useTemplate()
{
$code = $this->req->param("code");
if(!$code) return error("应用编码不可为空");
$res = AppManageModel::useTemplate($code);
return success('设置成功',$res);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\market;
use think\facade\Db;
use think\facade\Session;
use app\base\controller\BaseAdmin;
use app\base\model\admin\market\AppManageModel;
class AppManage extends BaseAdmin
{
public function index()
{
$uid = Session::get('uid');
// return error(base_path());
$res = AppManageModel::list($this->req);
return success('应用列表',$res);
}
/**
* 删除
*/
public function delete()
{
$uid = Session::get('uid');
// return error(base_path());
return AppManageModel::delete($this->req);
}
/**
* 应用信息
*/
public function appInfo()
{
$code = $this->req->param("code");
if(!$code) return error("应用编码不可为空");
$info = AppManageModel::appInfo($code);
return success("操作成功",$info);
}
/**
* 设置应用信息
*/
public function setApp()
{
$data = [];
$data['code'] = $this->req->param("code");
$data['name'] = $this->req->param("name");
$data['logo'] = $this->req->param("logo");
$data['sort'] = $this->req->param("sort",0);
$data['try_days'] = $this->req->param("try_days",7);
$data['scene'] = $this->req->param("scene");
$data['type'] = $this->req->param("type");
$data['describe'] = $this->req->param("describe");
$data['shelves'] = $this->req->param("shelves",0);
$data['label'] = $this->req->param("label",[]);
$data['specs'] = $this->req->param("specs",[]);
if(!$data['code']) return error("应用编码不可为空");
if(!$data['name']) return error("应用名称不可为空");
if(!$data['type']) return error("类别不可为空");
if(!$data['specs']) return error("规格不可为空");
$label = $data['label'];
if(count($label)>3) return error('最多三个标签');
foreach ($label as $l) {
if(mb_strlen($l) > 4) return error('标签不合法,最多4个字');
}
AppManageModel::setApp($data);
return success("修改成功");
}
/**
* 分类列表
*/
public function types()
{
$page = $this->req->param('page',1);
$size = $this->req->param('size',10);
$types = AppManageModel::types($page,$size);
return success('操作成功',$types);
}
/**
* 分类信息
*/
public function typeInfo(){
$id = $this->req->param("id");
if(!$id) return error("分类id不可为空");
$info = AppManageModel::typeInfo($id);
return success("操作成功",$info);
}
/**
* 添加分类
*/
public function addType()
{
$data = [];
$data['name'] = $this->req->param("name");
$data['sort'] = $this->req->param("sort",0);
$data['level'] = $this->req->param("level",1);
$data['pid'] = $this->req->param("pid",0);
if(!$data['name']) return error("分类名称不可为空");
$res = AppManageModel::addType($data);
if($res != 'ok') return error($res);
return success('操作成功');
}
/**
* 编辑分类
*/
public function editType()
{
$data = [];
$id = $this->req->param("id");
$data['name'] = $this->req->param("name");
$data['sort'] = $this->req->param("sort",0);
$data['level'] = $this->req->param("level",1);
$data['pid'] = $this->req->param("pid",0);
if(!$id) return error("分类id不可为空");
if(!$data['name']) return error("分类名称不可为空");
AppManageModel::editType($id,$data);
return success('操作成功');
}
/**
* 删除分类
*/
public function delType()
{
$id = $this->req->param("id");
if(!$id) return error("分类id不可为空");
$res = AppManageModel::delType($id);
if($res['status'] == 'error') return error($res['msg']);
return success('操作成功');
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\market;
use think\facade\Db;
use think\facade\Session;
use app\base\controller\BaseAdmin;
use app\base\model\admin\market\OpenuseModel;
class Openuse extends BaseAdmin
{
/*
* 已购应用列表
*/
public function allApp()
{
return OpenuseModel::allApp($this->req);
}
/*
* 已购应用列表
*/
public function list()
{
return OpenuseModel::list($this->req);
}
/*
* 已购应用列表
*/
public function updateStatus()
{
return OpenuseModel::updateStatus($this->req);
}
/*
* 获取代理折扣
*/
public function discount()
{
return OpenuseModel::discount();
}
/*
* 续费和购买
*/
public function buy()
{
return OpenuseModel::buy($this->req);
}
/*
* 用户订单列表(用户在用户后台购买)
*/
public function userOrder()
{
return OpenuseModel::userOrderList($this->req);
}
/*
* 套餐的开通与购买
*/
public function setmealBuy()
{
return OpenuseModel::setmealBuy($this->req);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use think\facade\Session;
use app\base\controller\BaseAdmin;
use app\base\model\admin\system\KtModel;
class Kt extends BaseAdmin
{
/**
* 狂团配置
*/
public function ktconfig()
{
return KtModel::getKtconfig($this->req);
}
/**
* 应用列表
*/
public function ktapp()
{
return KtModel::ktapp($this->req);
}
/**
* 删除应用
*/
public function delete()
{
return KtModel::delete($this->req);
}
/**
* 应用列表
*/
public function sync()
{
return KtModel::sync();
}
/**
* 狂团配置
*/
public function updateKtconfig()
{
return KtModel::updateKtconfig($this->req);
}
/**
* 狂团配置
*/
public function ktinfo()
{
return KtModel::ktinfo();
}
/**
* 应用商店
*/
public function appStore()
{
$page = $this->req->param('page',1);
$size = $this->req->param('size',10);
return KtModel::appStore($page,$size);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use Ramsey\Uuid\Uuid;
use OSS\OssClient;
use OSS\Core\OssException;
use think\facade\Filesystem;
use think\facade\Session;
use app\base\model\BaseModel;
use app\base\controller\BaseAdmin;
use Qcloud\Cos\Client;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
/**
* 媒体类
**/
class Media extends BaseAdmin
{
/**
* oss数据
* @return \think\Response
*/
public function info()
{
$uid = Session::get('uid');
$res = BaseModel::storageInfo();
return success('云存储配置',$res);
}
/**
* 云存储服务器配置保存
* @return \think\Response
*/
public function save()
{
$uid = Session::get('uid');
$data = [];
$data = $this->req->post();
if($data['type'] == 2 && (!$data['oss_id'] || !$data['oss_secret'] || !$data['oss_endpoint'] || !$data['oss_bucket'])) return error('参数错误');
if($data['type'] == 3 && (!$data['cos_secretId'] || !$data['cos_secretKey'] || !$data['cos_bucket'] || !$data['cos_endpoint'])) return error('参数错误');
if($data['type'] == 4 && (!$data['kodo_key'] || !$data['kodo_secret'] || !$data['kodo_domain'] || !$data['kodo_bucket'])) return error('参数错误');
$res = BaseModel::storageUpdate($data);
if($res != 'ok') return error($res);
return success('更新成功');
}
/**
* 上传文件
* @return \think\Response
*/
public function upload()
{
$uid = Session::get("uid");
// 获取表单上传文件
$file = request()->file('file');
if(!$file) return error('未检测到上传资源');
$res = [];
$storage = BaseModel::getStorageInfo();
$type = $storage['type'] ?? 1;
switch ($type) {
case 1: //本地
$res = $this->uploadLocal($file);
break;
case 2: //阿里云
$res = $this->uploadOss($storage,$file);
break;
case 3: //腾讯云
$res = $this->uploadCos($storage,$file);
break;
case 4: //七牛
$res = $this->uploadKodo($storage,$file);
break;
}
if($res == 'error') return error('上传失败');
return success('上传成功',$res);
}
/**
* 上传到Oss
* @return \think\Response
*/
public function uploadLocal($file)
{
$domain = $this->req->domain();
// $imgTruePath = $file->getPathname(); //获取临时地址
$ext = $file->extension(); //获取后缀
$minType = $file->getMime(); //获取文件类型
$fileName = $file->getOriginalName(); //获取上传名
$time = date('Y-m-d');
$res = Filesystem::putFile( 'upload/base/'.$time, $file, 'uniqid');
return $domain.'/storage/'.$res;
}
/**
* 上传到Oss
* @return \think\Response
*/
public function uploadOss($storage,$file)
{
$accessKeyId = $storage['oss_id'];
$accessKeySecret = $storage['oss_secret'];
$endpoint = $storage['oss_endpoint'];
$bucket = $storage['oss_bucket'];
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
// 设置Socket层传输数据的超时时间
$ossClient->setTimeout(3600);
// 设置建立连接的超时时间,单位秒,默认10秒。
$ossClient->setConnectTimeout(10);
// $bucketExist = $ossClient->doesBucketExist($bucket); //判断bucket是否存在
// if (!$bucketExist) {
// $ossClient->createBucket($bucketName, \OSS\OssClient::OSS_ACL_TYPE_PUBLIC_READ);
// }
$imgTruePath = $file->getPathname(); //获取临时地址
$ext = $file->extension(); //获取后缀
$minType = $file->getMime(); //获取文件类型
$fileName = $file->getOriginalName();
$filePath = 'base/'.uniqid('base_').'.'.$ext;
$uploadOssRes = $ossClient->uploadFile($bucket, $filePath, $imgTruePath);
$url = $uploadOssRes['info']['url'];
return $url;
} catch (OssException $e) {
print $e->getDetails(); //调试时,打开,输出错误信息
return 'error';
}
}
/**
* 上传到Cos
* @return \think\Response
*/
public function uploadCos($storage,$file)
{
$secretId = $storage['cos_secretId'];
$secretKey = $storage['cos_secretKey'];
$endpoint = $storage['cos_endpoint'];
$bucket = $storage['cos_bucket'];
$regionArr = explode('.', $endpoint);
$region = $regionArr[2];
$cosClient = new Client(
array(
'region' => $region,
'schema' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
$imgTruePath = $file->getPathname(); //获取临时地址
$ext = $file->extension(); //获取后缀
$minType = $file->getMime(); //获取文件类型
$fileName = $file->getOriginalName();
$filePath = 'base/'.uniqid('base_').'.'.$ext;
try {
$result = $cosClient->putObject(
array(
'Bucket' => $bucket,
'Key' => $filePath,
'Body' => fopen($imgTruePath, 'rb')
)
);
$url = "https://".$result['Location'];
return $url;
}catch (\Exception $e) {
return 'error';
}
}
/**
* 上传到kodo 七牛云
* @return \think\Response
*/
public function uploadKodo($storage,$file)
{
$accessKey = $storage['kodo_key'];
$secretKey = $storage['kodo_secret'];
$bucket = $storage['kodo_bucket'];
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($bucket);
$imgTruePath = $file->getPathname(); //获取临时地址
$ext = $file->extension(); //获取后缀
$minType = $file->getMime(); //获取文件类型
$fileName = $file->getOriginalName();
$filePath = 'base/'.uniqid('base_').'.'.$ext;
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $filePath, $imgTruePath);
if ($err !== null) {
return 'error';
} else {
return 'http://' . $storage['kodo_domain'] . '/' . $ret['key'];
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use think\facade\Session;
use app\base\controller\BaseAdmin;
use app\base\model\admin\system\SetModel;
/**
* 接口配置
*/
class Set extends BaseAdmin
{
/**
* Baidu AI配置 获取
*/
public function BaiduAi()
{
return SetModel::BaiduAi();
}
/**
* Baidu AI配置 保存
*/
public function BaiduAiSet()
{
return SetModel::BaiduAiSet($this->req);
}
/**
* Aliyun 语音合成配置 获取
*/
public function Aliyun()
{
return SetModel::Aliyun();
}
/**
* Aliyun 语音合成配置 保存
*/
public function AliyunSet()
{
return SetModel::AliyunSet($this->req);
}
/**
* 腾讯云 语音转合字幕配置 获取
*/
public function Tencent()
{
return SetModel::Tencent();
}
/**
* 腾讯云 语音转合字幕配置 保存
*/
public function TencentSet()
{
return SetModel::TencentSet($this->req);
}
/**
* GPT配置 获取
*/
public function Gpt()
{
return SetModel::Gpt();
}
/**
* GPT配置 保存
*/
public function GptSet()
{
return SetModel::GptSet($this->req);
}
/**
* 内容审核 获取
*/
public function review()
{
return SetModel::review();
}
/**
* 提问审核 设置
*/
public function questionSet()
{
return SetModel::questionSet($this->req);
}
/**
* 回复审核 设置
*/
public function replySet()
{
return SetModel::replySet($this->req);
}
/**
* 敏感词库获取
*/
public function sensitiveLexicon()
{
return SetModel::sensitiveLexicon();
}
/**
* 敏感词库保存
*/
public function sensitiveLexiconSave()
{
return SetModel::sensitiveLexiconSave($this->req);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use app\base\controller\BaseAdmin;
use app\base\model\admin\system\BasicModel;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
/**
* 基础配置控制器 Site
*/
class Site extends BaseAdmin
{
/*
* 基本设置 拉取数据 初始化
*/
public function index(){
$res = BasicModel::getSite();
return success("获取成功",$res);
}
/*
* 修改基础配置
*/
public function setSite(){
$domain = $this->req->param("domain");
if(!$domain) return error("站点域名不可为空");
$webname = $this->req->param("webname");
if(!$webname) return error("站点名称不可为空");
$webtitle = $this->req->param("webtitle");
$copyright = $this->req->param("copyright");
$register_check = $this->req->param("registerCheck");
$registration_audit = $this->req->param("registrationAudit");
$pc_official = $this->req->param("pcOfficial");
$debug = $this->req->param("debug",0);
$addSite = BasicModel::setSite($domain,$webname,$webtitle,$copyright,$register_check,$registration_audit,$pc_official,$debug);
return success("修改成功",$addSite);
}
/*
* 修改logo信息
*/
public function setLogo(){
$user_logo = $this->req->param("userLogo");
$login_logo = $this->req->param("loginLogo");
$pc_logo = $this->req->param("pcLogo");
$setLogo = BasicModel::setLogo($user_logo,$login_logo,$pc_logo);
return success("修改成功",$setLogo);
}
/*
* 修改登录背景
*/
public function setBackground(){
$login_background_status = $this->req->param("loginBackgroundStatus");
$login_background = $this->req->param("loginBackground");
$setBackground = BasicModel::setBackground($login_background,$login_background_status);
return success("修改成功",$setBackground);
}
/*
* 修改其他信息
*/
public function setAdditional(){
$kf_code = $this->req->param("kfCode");
$gzh_code = $this->req->param("gzhCode");
$company_name = $this->req->param("companyName");
$company_address = $this->req->param("companyAddress");
$telephone = $this->req->param("telephone");
$qq = $this->req->param("qq");
$record_number = $this->req->param("recordNumber");
$key_word = $this->req->param("keyWord");
$describe = $this->req->param("describe");
$setAdditional = BasicModel::setAdditional($kf_code,$gzh_code,$company_name,$company_address,$telephone,$qq,$record_number,$key_word,$describe);
return success("修改成功",$setAdditional);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
use app\base\model\admin\system\SmsModel;
use app\base\controller\BaseAdmin;
/**
* 短信
**/
class Sms extends BaseAdmin
{
/**
* 短信配置
* @return \think\Response
*/
public function index()
{
$res = SmsModel::SmsInfo();
return success('短信配置',$res);
}
/**
* 短信配置保存
* @return \think\Response
*/
public function save()
{
$data = [];
$data = $this->req->post();
$res = SmsModel::smsUpdate($data);
if($res != 'ok') return error($res);
return success('更新成功');
}
/**
* 短信验证码模板配置
* @return \think\Response
*/
public function codeTemplateSave()
{
$data = [];
$data = $this->req->post();
$data['bh'] = '001';
$res = SmsModel::templateSave($data);
if($res != 'ok') return error($res);
return success('更新成功');
}
/**
* 获取短信验证码模板配置
* @return \think\Response
*/
public function getCodeTemplate()
{
$where = [];
$where['bh'] = '001';
$where['uid'] = Session::get('uid');
$res = SmsModel::getTemplate($where);
return success('短信模板配置',$res);
}
/**
* 发送短信验证码
* @return \think\Response
*/
public function sendCode()
{
$phone = $this->req->post('phone');
if(!preg_match("/^1[3456789]\d{9}$/", $phone)) return error('手机号格式不正确');
$data = [
'phone' => $phone,
'bh' => '001', //验证码模板
'param' => ['code'=>SmsModel::getCode()]
];
$res = SmsModel::sendSms($data);
if($res != 'ok') return error('发送失败');
return success('发送成功');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use app\base\controller\BaseAdmin;
use app\base\model\admin\system\WxpayConfingModel;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
/**
* 微信配置
*/
class WxpayConfing extends BaseAdmin{
/*
* 配置拉取数据
*/
public function index(){
$res = WxpayConfingModel::info();
$data =[
'appid' => isset($res[0]) ? $res[0] : null,
'mch_id' => isset($res[1]) ? $res[1] : null,
'key' => isset($res[2]) ? $res[2] : null,
'appsecret' => isset($res[3]) ? $res[3] : null,
];
return success("获取成功",$data);
}
/*
* 添加修改配置
*/
public function upd(){
$appid = $this->req->param("appid");
$mch_id = $this->req->param("mch_id");
$key = $this->req->param("key");
$appsecret = $this->req->param("appsecret");
if(!$appid || !$mch_id || !$key || !$appsecret)return error("缺少参数");
$res = WxpayConfingModel::upd(["config"=>$appid.",".$mch_id.",".$key.",".$appsecret]);
return success("修改成功",$res);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\user;
use think\facade\Db;
use app\base\controller\BaseAdmin;
use app\base\model\admin\user\AppPackageModel;
use think\facade\Session;
class AppPackage extends BaseAdmin
{
/**
* 套餐列表
*/
public function packageList()
{
$uid = Session::get('uid');
$res = AppPackageModel::packageList();
return success('套餐列表',$res);
}
/**
* 套餐详情
*/
public function packageInfo()
{
$id = $this->req->param("id");
if(!$id) return error("套餐id不可为空");
$info = AppPackageModel::packageInfo($id);
return success("操作成功",$info);
}
/**
* 新增套餐
*/
public function addPackage()
{
$data = [];
$data['name'] = $this->req->param("name");
$data['specs'] = $this->req->param("specs",[]);
$data['apps'] = $this->req->param("apps",[]);
$data['sort'] = $this->req->param("sort",0);
if(!$data['name']) return error("套餐名称不可为空");
if(!$data['specs']) return error("套餐规格不可为空");
if(!$data['apps']) return error("包含应用不可为空");
$res = AppPackageModel::addPackage($data);
if($res != 'ok') return error($res);
return success("添加成功");
}
/**
* 编辑套餐
*/
public function editPackage()
{
$data = [];
$id = $this->req->param("id");
$data['name'] = $this->req->param("name");
$data['specs'] = $this->req->param("specs",[]);
$data['apps'] = $this->req->param("apps",[]);
$data['sort'] = $this->req->param("sort",0);
if(!$id) return error("套餐id不可为空");
if(!$data['name']) return error("套餐名称不可为空");
if(!$data['specs']) return error("套餐规格不可为空");
if(!$data['apps']) return error("包含应用不可为空");
$res = AppPackageModel::editPackage($id,$data);
if($res != 'ok') return error($res);
return success("修改成功");
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\user;
use think\facade\Db;
use app\base\controller\BaseAdmin;
use app\base\model\admin\system\BasicModel;
use app\base\model\admin\user\UserModel;
use app\base\model\admin\plug\AppManageModel;
use app\base\model\BaseModel;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
class Manage extends BaseAdmin
{
/**
* 我的客户管理
*/
public function index()
{
$page = $this->req->param('page')?:1;
$status = $this->req->param('status');
$un = $this->req->param('un');
$size = $this->req->param("size")?:10;
$agname = $this->req->param("agname");
$data = UserModel::info($page,$un,$status,$size,$agname);
return success('获取成功',$data);
}
/**
* 获取代理列表
*/
public function getAgents()
{
$data = UserModel::getAgents();
return success('获取成功',$data);
}
/*
* 启用停用作废 1为启用,0为禁用,2为作废
*/
public function switch()
{
$id = $this->req->param('id');
if(!$id) return error("请选择账户");
$status = $this->req->param('status');
$data = UserModel::switch($id,$status);
return success('更新成功',$data);
}
/**
* username 账号
* password 密码
* telephone 手机号
* contacts 联系人
* remark 备注
* agid 上级代理id
* id 用户id
*/
public function addUser()
{
$id = $this->req->param('id');
$username = $this->req->param('username');
if(!$username) return error("账号不可为空");
$password = $this->req->param('password');
if(!$password && !$id) return error("密码不可为空");
$telephone = $this->req->param('telephone');
// if(!$telephone) return error("手机号不可为空");
$contacts = $this->req->param('contacts');
// if(!$contacts) return error("联系人不可为空");
$remark = $this->req->param('remark');
$agid = $this->req->param('agid');
$set = UserModel::setUser($username,$id);
if($set) return error("用户名重复");
if($id) $user = UserModel::user($id);
if($password) $password = ktEncrypt($password);
if(!$password && $id) $password = $user["pwd"]?:ktEncrypt("123456");
$add = UserModel::addUser($username,$password,$telephone,$contacts,$remark,$agid,$id);
return success('修改成功',$add);
}
/**
* 编辑拉取数据
*/
public function getUser()
{
$id = $this->req->param('id');
if(!$id) return error("参数错误");
$data = UserModel::getUser($id);
return success('获取成功',$data);
}
/*
* 充值
* 先获取客户余额
*/
public function recharge()
{
$id = $this->req->param("id");
$type = $this->req->param("type");
if(!$id) return error("参数错误");
$money = $this->req->param("money");
$remark = $this->req->param("remark");
if($money <= 0) return error("充值金额不可小于1");
$user = UserModel::getUser($id);
$agent = UserModel::getAgent();
if($type == 1){
if($agent["balance"] < $money)return error("管理员余额不足,请重新选择");
$agent_balance = $agent["balance"] - $money;
$user_balance = $user["balance"] + $money;
}
if($type == 2){
if($user["balance"] < $money)return error("客户余额不足,请重新选择");
$agent_balance = $agent["balance"] + $money;
$user_balance = $user["balance"] - $money;
}
UserModel::updAgent($agent_balance);
UserModel::updUser($id,$user_balance);
$out_trade_no = date('YmdHis', time()) . time() . rand(10000, 99999);
$add = UserModel::addRecord($money,$out_trade_no,$type,$id,$remark);
return success('充值成功',$add);
}
/*
* 获取员工已开套餐及已购买应用
*/
public function auth()
{
$id = $this->req->param("id");
if(!$id) return error("参数错误,id不可为空");
$auth = UserModel::auth($id);
$data["appauth"] = $auth;
return success('获取成功',$auth);
}
// 引擎列表
public function engine()
{
$res = UserModel::list();
$agent = UserModel::getAgent();
$data["setmeal"] = $res;
$data["balance"] = $agent["balance"];
return success('获取成功',$data);
}
//选择引擎拿到引擎对应的套餐
public function getMeal()
{
$name = $this->req->param("name");
$id = $this->req->param("id");
if(!$id) return error("参数错误");
if(!$name) return error("参数错误");
$user = UserModel::getUser($id);
$set_meal = UserModel::getSetmeal($user["agid"],$name);
$price = json_decode($set_meal["price"],1);
$set_meal = UserModel::setMeal($price,$name);
$appauth = UserModel::appauth($id,$name);
$res["setMealList"] = $set_meal;
$res["setMeal"]["set_meal"] = NULL;
$res["setMeal"]["mend_time"] = time();
if($appauth) $res["setMeal"] = $appauth;
if($appauth) $res["setMeal"]["mend_time"] = strtotime($appauth["mend_time"]);
return success('获取成功',$res);
}
/**
* 升级续费时的价格
*/
public function prices()
{
$prices = 0;
$price_difference = 0;
$name = $this->req->param("name");
$id = $this->req->param("id");
$mend_time = $this->req->param("mendTime");
$title = $this->req->param("title");
$code = $this->req->param("code");
$setmeal_id = $this->req->param("setmealId");
if(!$id || !$mend_time || !$setmeal_id || !$name) return error("参数错误");
$user = UserModel::getUser($id);
$appauth = UserModel::appauth($id,$name);
//获取已配置套餐的代理
$set_meal = UserModel::getSetmeal($user["agid"],$name);
//选择套餐的价格
$price = json_decode($set_meal["price"],1)[$setmeal_id];
//当前套餐的价格
$user_price = 0;
if($appauth) $user_price = json_decode($set_meal["price"],1)[$appauth["set_meal"]];
if($appauth && $price != $user_price && strtotime($appauth["mend_time"]) >= time()){
//当前套餐剩日价格
$day_price = $user_price/365;//当前会员日价格
//当前套餐剩余天数
$day_time = floor((strtotime($appauth["mend_time"])-time())/86400);//当前会员剩余天数(省略小数)
//当前套餐剩余金额
$return_price = floor($day_time * $day_price);//当前会员折扣金钱数 套餐剩余金额
//新套餐日价格
$day_price_new = $price/365;//新会员日价格
//新套餐所需的金额
$return_price_new = floor($day_price_new * $day_price);//新会员折扣金钱数
//差价
$price_difference = $return_price_new - $return_price; //需要的差价
}
//获取到指定的时间有多少年多少天
$mend_times = self::getDateGap($appauth["mend_time"]??date("Y-m-d",time()),$mend_time);
//年价格
if($mend_times["year"]) $prices = $prices+$mend_times["year"]*$price;
//日价格 套餐所需金额,到指定日期的金额 prices
if($mend_times["day"]) $prices = $prices+floor($mend_times["day"]*($price/365));
return success('所需费用',$prices);
}
/*
* 升级续费
* "kt_".$name."_type" 套餐名称表
* "kt_".$name."_setmeal" 套餐设置表
* "kt_".$name."_setmeal_record" 记录表
*/
public function upgrade()
{
$prices = 0;
$price_difference = 0;
$name = $this->req->param("name");
$id = $this->req->param("id");
$mend_time = $this->req->param("mendTime");
$title = $this->req->param("title");
$code = $this->req->param("code");
$setmeal_id = $this->req->param("setmealId");
if(!$id || !$mend_time || !$setmeal_id || !$name || !$title || !$code) return error("参数错误");
$user = UserModel::getUser($id);
// var_dump($id);die;
$appauth = UserModel::appauth($id,$name);
//获取已配置套餐的代理
$set_meal = UserModel::getSetmeal($user["agid"],$name);
//选择套餐的价格
$price = json_decode($set_meal["price"],1)[$setmeal_id];
//当前套餐的价格
$user_price = 0;
if($appauth) $user_price = json_decode($set_meal["price"],1)[$appauth["set_meal"]];
if($appauth && $price != $user_price && strtotime($appauth["mend_time"]) >= time()){
//当前套餐剩日价格
$day_price = $user_price/365;//当前会员日价格
//当前套餐剩余天数
$day_time = floor((strtotime($appauth["mend_time"])-time())/86400);//当前会员剩余天数(省略小数)
//当前套餐剩余金额
$return_price = floor($day_time * $day_price);//当前会员折扣金钱数 套餐剩余金额
//新套餐日价格
$day_price_new = $price/365;//新会员日价格
//新套餐所需的金额
$return_price_new = floor($day_price_new * $day_price);//新会员折扣金钱数
//差价
$price_difference = $return_price_new - $return_price; //需要的差价
}
//获取到指定的时间有多少年多少天
$mend_times = self::getDateGap($appauth["mend_time"]??date("Y-m-d",time()),$mend_time);
//年价格
if($mend_times["year"]) $prices = $prices+$mend_times["year"]*$price;
//日价格 套餐所需金额,到指定日期的金额 prices
if($mend_times["day"]) $prices = $prices+floor($mend_times["day"]*($price/365));
$money = $prices;
//套餐差价如果大于0的情况下补齐差价,如果小于0的情况下舍弃不要
if($prices && $price_difference > 0) $prices += $price_difference;
$agent = UserModel::getAgent();
if($agent["balance"] < $prices) return error("余额不足");
if($agent["isadmin"] != 1){
$agent_level = UserModel::getAgentLevel($agent["level"]);
if($agent_level) $prices = floor($prices*($agent_level["discount"]/10));
}
$add = UserModel::addSetmealRecord($id,$setmeal_id,$price_difference,$prices,$money,$mend_time,$mend_times["year"],$mend_times["day"],$name);
UserModel::updAppauth($id,$code,$title,$name,$mend_time,$setmeal_id);
if(!$add) return error("入库失败");
$balance = $agent["balance"] - $prices;
UserModel::updAgent($balance);
UserModel::updUsers($id,$setmeal_id,$mend_time);
return success('续费成功,已扣除',$prices);
}
public function getDateGap($mendtime,$end)
{
$start = strtotime($mendtime);
$end = strtotime($end);
list($sy,$sm,$sd) = explode("-", date("Y-m-d", $start));
list($ey,$em,$ed) = explode("-", date("Y-m-d", $end));
$y = $ey - $sy;
$m = $em - $sm;
$w = date('W', $end) - date('W', $start);
$d = $ed - $sd;
if ($y > 0) { // 表示跨了年
$m += 12 * $y;
$startYear = date('Y', $start);
$endYear = date('Y', $end);
for ($i = $startYear; $i < $endYear; $i++) {
for ($j = 31;$j > 24;$j--) {
$tmpWeek = date('W', strtotime(sprintf("%s-12-%s", $i, $j)));
if (intval($tmpWeek) != 1) { // 不是第一周,则是当年的最后一周
$w += $tmpWeek; // 加上当年的周数量
break;
}
}
}
}
if ($m > 0) { // 表示跨了月
for($i = 1; $i <= $m; $i++) {
$d += date('t', strtotime("+{$i} month", $start)); // 跨了月
}
}
$years = floor($d/365);
$tian = $years * 365;
$days = $d-$tian;
return ["year"=>$years,"day"=>$days];
}
/*
* 越权登录获取token
*/
public function getToken(){
$id = $this->req->param('id');
if(!$id) return error("参数错误");
$res = UserModel::getToken($id);
return success('获取成功',["token"=>$res["token"]]);
}
/*
* 拉取所属代理
*/
public function getAdents(){
$uid = Session::get("uid");
$ids = BaseModel::getAdentIds($uid);
$data = UserModel::getAdents($ids);
return success("获取成功",$data);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\user;
use think\facade\Db;
use think\facade\Cache;
use app\base\controller\BaseUser;
use think\facade\Session;
use app\base\model\BaseModel;
use app\base\model\user\AppModel;
class App extends BaseUser
{
/**
*获取 已购买应用
**/
public function openAppList()
{
$page = $this->req->get('page',1);
$size = $this->req->get('size',10);
$title = $this->req->get('title','');
$pid = $this->req->get('pid',0);
$where = [];
$where[] = ['pid','=',$pid];
if($title) $where[] = ['name','like',"%{$title}%"];
$res = AppModel::openAppList($where,$page,$size);
return success("已拥有引擎",$res);
}
/**
*获取 已购买应用
**/
public function updateOpenApp()
{
$data = [];
$data['id'] = $this->req->post('id');
$data['sequence'] = $this->req->post('sequence');
$data['self_title'] = $this->req->post('self_title');
if(!$data['id'] || !$data['sequence'] || !$data['self_title']) return error('参数错误');
$res = AppModel::save($data);
return success("更新成功");
}
/**
*获取 全部应用
**/
public function appList()
{
$page = $this->req->get('page',1);
$size = $this->req->get('size',10);
$type = $this->req->get('type',0);
$title = $this->req->get('title','');
$where = [];
if($type) $where[] = ['type','=',$type];
if($title) $where[] = ['name','like',"%{$title}%"];
$res = AppModel::appList($where,$page,$size);
return success("全部引擎",$res);
}
/**
*获取详情
**/
public function appDetail()
{
$id = $this->req->get('id');
$res = AppModel::appDetail($id);
return success("引擎详情",$res);
}
/**
*获取 应用分类
**/
public function appType()
{
$res = AppModel::appType();
return success("引擎分类",$res);
}
/**
*试用
**/
public function tryout()
{
$id = $this->req->get('id');
if(!$id) return error('参数错误');
return AppModel::tryout($id);
}
/**
*立即使用
**/
public function openappUse()
{
return AppModel::openappUse($this->req);
}
/**
*购买
**/
public function buy()
{
// [{ "id":1,"duration": 1, "duration_type": 1, "old_price": 0.02, "price": 0.01 }]
$id = $this->req->post('id');
if(!$id) return error('请选择引擎');
$specsid = $this->req->post('specsid');
if(!$specsid) return error('请选择规格');
return AppModel::buy($id,$specsid);
}
/**
*购买结果
**/
public function getPayResult()
{
return AppModel::getPayResult($this->req);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\user;
use think\facade\Db;
use think\facade\Log;
use app\BaseController;
use paySDK\NewPay;
/**
* 外部联系人回调
*/
class CallbackWxPay extends BaseController
{
public function webchat(){
$post= file_get_contents("php://input");
if (!$post) $post = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
if (!$post) exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>');
libxml_disable_entity_loader(true);
$xml = simplexml_load_string($post,'SimpleXMLElement',LIBXML_NOCDATA);
$data = (array)$xml;
$out_trade_no = isset($data['out_trade_no']) && !empty($data['out_trade_no']) ? $data['out_trade_no'] : 0;
$order = Db::table('kt_base_recharge')->where('bh',$out_trade_no)->where('ifok',0)->find();
if($order){
$user = Db::table('kt_base_user')->where('id',$order['wid'])->find();
$config = Db::table('kt_base_pay_config')->where(['uid'=>$user['agid'],'type'=>'wx'])->find();
$wxKey = explode(',',$config['config'])[2] ?? null;
// $oldSign = $data['sign'];
// $signA = "appid=".$data['appid']."&bank_type=".$data['bank_type']."&cash_fee=".$data['cash_fee']."&fee_type=".$data
// ['fee_type']."&is_subscribe=".$data['is_subscribe']."&mch_id=".$data['mch_id']."&nonce_str=".$data['nonce_str']."&openid=".
// $data['openid']."&out_trade_no=".$data['out_trade_no']."&result_code=".$data['result_code']."&return_code=".$data
// ['return_code']."&time_end=".$data['time_end']."&total_fee=".$data['total_fee']."&trade_type=".$data
// ['trade_type']."&transaction_id=".$data['transaction_id']."&key=".$wxKey;
// $newSign = strtoupper(MD5($signA));
if($this->confirm_sign($data,$wxKey)){
Db::table('kt_base_user')->where('id',$user['id'])->update(['balance'=>$user['balance'] + $data['total_fee']/100 ]);
Db::table('kt_base_recharge')->where('bh',$out_trade_no)->update([
'update_time'=> date('Y-m-d H:i:s'),
'uip'=> request()->ip(),
'status' => '交易成功',
'ifok'=> 1,
'jyh' => $data['transaction_id']
]);
$this->buy($out_trade_no);
}
}
echo 'SUCCESS';
exit;
}
public function confirm_sign($data,$key,$sign_key='sign'){
if (key_exists($sign_key, $data)) {
$sign = $data[$sign_key];
}
if (!$sign){
return false;
}
$data2=$data;
unset($data2['sign']);
ksort($data2);
$string = $this->array_to_string($data2);
$string = $string . "&key=" . $key;
$string = md5($string);
$sign2 = strtoupper($string);
return $sign==$sign2;
}
public function array_to_string($params){
$string = '';
if (!empty($params)) {
$array = [];
foreach ($params as $key => $value) {
$array[] = $key . '=' . $value;
}
$string = implode("&", $array);
}
return $string;
}
public function buy($bh)
{
$order = Db::table('kt_base_user_order')->where('bh',$bh)->find();
$app = Db::table("kt_base_market_app")->json(['specs'])->find($order['app_id']);
$specs = [];
foreach ($app['specs'] as $v) {
if($v['id'] == $order['specs_id']){
$specs = $v;
break;
}
}
$wid = $order['wid'];
$user = Db::table("kt_base_user")->find($wid);
$data = [
'wid' => $wid,
'name' => $app['name'],
'code' => $app['code'],
'logo' => $app['logo'],
'version' => $app['version'],
// 'mend_time' => date("Y-m-d H:i:s",strtotime("+".$app['try_days']." day")),
'update_time' => date("Y-m-d H:i:s"),
'app_id' => $order['app_id'],
];
$has = Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$order['app_id'])->find();
if($has){
$data['id'] = $has['id'];
if(strtotime($has['mend_time'] < time())){
$date = date("Y-m-d H:i:s");
}else{
$date = $has['mend_time'];
}
}else{
$date = date("Y-m-d H:i:s");
$data['create_time'] = date("Y-m-d H:i:s");
}
// [{ "id":1,"duration": 1, "duration_type": 1, "old_price": 0.02, "price": 0.01 }]
$content = '';
$day = 0;
switch ($specs['duration_type']) {
case 2:
$content = '用户购买规格时长'.$specs['duration'].'月的套餐';
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." month",strtotime($date)));
break;
case 3:
$content = '用户购买规格时长'.$specs['duration'].'年的套餐';
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." year",strtotime($date)));
break;
}
$pid = 0;
if ($app['pid'] != 0) {
$pApp = Db::table("kt_base_market_app")->find($app['pid']);
$pOpenapp = Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$pApp['id'])->find();
$pid = $pOpenapp['id'];
}
$data['pid'] = $pid;
$res = Db::table("kt_base_user_openapp")->save($data);
if($res){
Db::table("kt_base_user")->where('id',$wid)->update([
'balance' => Db::raw('balance-'.$order['price']),
'update_time'=>date("Y-m-d H:i:s"),
]);
Db::table("kt_base_user_order")->where('id',$order['id'])->update([
'status' => 2,
'content' => $content
]);
return 'ok';
}
return 'error';
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\user;
use think\facade\Db;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
use app\base\model\BaseModel;
use app\base\controller\BaseUser;
class Login extends BaseUser
{
public function index()
{
if(!$this->req->isPost()) return error('请使用POST请求');
$username = $this->req->param('username');
$password = $this->req->param('password');
if(!$username) return error('缺少参数username');
if(!$password) return error('缺少参数password');
$where = [
['un', '=', $username],
['telephone', '=', $username],
['email','=',$username]
];
$user = Db::table('kt_base_user')->whereOr($where)->find();
if(!$user) return error('用户不存在');
if($user['pwd'] != md5($password) && $user['pwd'] != ktEncrypt($password)) return error('帐号或密码错误');
if($user['isstop'] != 1 ) return error('账号审核中或已停用');
// if(strtotime($user['mendtime']) <= time()) return error('账号已到期');
$token = $user['token'] && $user['expire_time'] > time() ? $user['token'] : Uuid::uuid1();
Db::table('kt_base_user')->where('id',$user['id'])->inc('logtimes')->update(['token'=>"{$token}",'expire_time'=> time() + (7*24*3600),'lasttime'=>date("Y-m-d H:i:s")]);
Db::table('kt_base_loginlog')->insert([
'admin' => 2 ,
'wid' => $user['id'],
'uip' => $this->req->ip(),
'create_time' => date("Y-m-d H:i:s")
]);
return success('登录成功',['token'=>$token]);
}
/**
*获取登录页相关信息
**/
public function getLoginInfo(){
$res = BaseModel::getLoginInfo($this->host);
return success("登陆前相关信息",$res);
}
/*
* 修改密码
*/
public function updatePwd()
{
$wid = Session::get('wid');
$user = Db::table('kt_base_user')->find($wid);
$password = $this->req->post('password');
if($user['pwd'] != md5($password) && $user['pwd'] != ktEncrypt($password)) return error('当前密码错误');
$new_password = $this->req->post('new_password');
$confirm_password = $this->req->post('confirm_password');
if(!$new_password || !$confirm_password) return error('请输入新密码');
if($new_password != $confirm_password) return error('两次输入的新密码不一致');
if($user['pwd'] == ktEncrypt($new_password)) return error('新旧密码一致');
$res = Db::table('kt_base_user')->where('id',$wid)->update([
"pwd" => ktEncrypt($new_password),
]);
if($res) return success('修改成功');
return error('修改失败');
}
/**
*忘记密码
**/
public function fogretpwd(){
$phone = $this->req->post('phone');
if(!preg_match("/^1[3456789]\d{9}$/", $phone)) return error('手机号格式不正确');
$user = Db::table('kt_base_user')->where('telephone',$phone)->find();
if(!$user) return error('账号不存在');
$code = $this->req->post('code');
$key = 'sms_'.$phone;
$cacheCode = Cache::get($key);
if(!$code || $code!=$cacheCode) return error('验证码不正确');
$password = trim($this->req->post('password'));
if(!$password) return error('请填写新密码');
Db::table('kt_base_user')->where('id',$user['id'])->update(['pwd'=>ktEncrypt($password)]);
Cache::delete($key);
return success('修改成功');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\user;
use think\facade\Db;
use app\base\controller\BaseUser;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
use app\base\model\BaseModel;
class Register extends BaseUser
{
public function index()
{
$username = $this->req->param("username");
$password = $this->req->param("password");
$phone = $this->req->param("phone");
if(!$username) return error('缺少参数username');
if(!$password) return error('缺少参数password');
if(!$phone) return error('缺少参数phone');
if(!preg_match("/^1[23456789]\d{9}$/", $phone)) return error("手机号格式错误,请重新输入");
$where = [
['un', '=', $username],
['telephone', '=', $phone]
];
$user = Db::table('kt_base_user')->whereOr($where)->find();
if($user) return error("账户已存在,请重新注册");
$res = BaseModel::getLoginInfo($this->host);
Db::table('kt_base_user')->insert([
'un' => $username ,
'pwd' => ktEncrypt($password),
'telephone' => $phone,
'agid' => $res["id"],
'mendtime' => date('Y-m-d', strtotime('-7 days')),
'create_time' => date("Y-m-d H:i:s",time())
]);
return success("注册成功");
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// 这是系统自动生成的event定义文件
return [
];
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// 这是系统自动生成的middleware定义文件
return [
app\base\middleware\admincheck::class,
];
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\base\middleware;
use think\Response;
/**
* 全局跨域请求处理
* Class CrossDomain
* @package app\middleware
*/
class CrossDomain
{
public function handle($request, \Closure $next)
{
//header('Access-Control-Allow-Origin: *');
header('Access-Control-Max-Age: 1800');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers: usertoken, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, Token, token, wid');
if (strtoupper($request->method()) == "OPTIONS") {
return Response::create()->send();
}
return $next($request);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\base\middleware;
use think\facade\Db;
use think\facade\Request;
class admincheck
{
protected $whiteList = [
'/',
'/base/adminuser/login',
'/base/admin/login',
'/base/baseadmin/sendcode',
'/base/admin/appinstall',
'/base/admin/baseinstall',
];
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$token = $request->header('UserToken');
// echo app('http')->getName(); //获取应用名
$url = strtolower($request->baseUrl()); //获取url地址, 不带域名,然后小写,
// die();
if(in_array($url,$this->whiteList) || preg_match("/^\/base\/user/", $url)) return $next($request);
if(!$token) return error('缺少参数UserToken');
$admin = Db::table('kt_base_agent')->where([['agency_token', '=', $token],['expire_time','>',time()]])->find();
if(!$admin) return error('无效的UserToken');
Db::table('kt_base_agent')->where('id',$admin['id'])->update(['expire_time'=> time() + (7*24*3600)]);
return $next($request);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\base\middleware;
use think\facade\Db;
use think\facade\Request;
class check
{
protected $whiteList = [
'/',
'/base/user/login',
'/base/user/logout',
'/base/user/register',
'/base/user/getlogininfo',
'/base/baseadmin/sendcode',
'/base/user/fogretpwd',
'/base/user/callbackwxpay',
];
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$token = $request->header('UserToken');
// echo app('http')->getName(); //获取应用名
$url = strtolower($request->baseUrl()); //获取url地址, 不带域名,然后小写,
if(in_array($url,$this->whiteList)) return $next($request);
if(!$token) return error('缺少参数UserToken');
$user = Db::table('kt_base_user')->where([['token', '=', $token],['expire_time','>',time()]])->find();
if(!$user) return error('无效的UserToken');
Db::table('kt_base_user')->where('id',$user['id'])->update(['expire_time'=> time() + (7*24*3600) ]);
return $next($request);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model;
use think\facade\Db;
use think\facade\Session;
/*
* 基础功能model
*/
class BaseModel
{
static protected $uid;
/**
* 获取应用下xml配置信息
* @param $app 应用目录
* @return
*/
static public function getMainfest($app){
$path = base_path().'/'.$app.'/mainfest.xml';
if(!file_exists($path)) $path = base_path().'/'.$app.'/manifest.xml';
$xml = [];
if(is_file($path)) $xml = json_decode(json_encode(simplexml_load_file($path,'SimpleXMLElement', LIBXML_NOCDATA)), 1);
return $xml;
}
/**
* 获取 随机数
* @param leg 长度
* @return
*/
static public function getCode(){
return rand(100000,999999);
}
/**
* 获取
* @param $host 域名,不带协议
* @return
*/
static public function getLoginInfo($host){
$admin = Db::table('kt_base_agent')->field('id,key_word,describe,record_number,user_logo,login_logo,domain,webname,webtitle,login_background,register_check,registration_audit,company_name')->where('domain',$host)->find();
if(!$admin) $admin = Db::table('kt_base_agent')->field('id,key_word,record_number,describe,user_logo,login_logo,domain,webname,webtitle,login_background,register_check,registration_audit,company_name')->where('isadmin',1)->find();
$gptcms_path = root_path().'/public/static/gptcms/hot/verify.txt';
$admin['gptcms_c_s'] = 0;
if(file_exists($gptcms_path) && filesize($gptcms_path) !== 0){
$admin['gptcms_c_s'] = 1;
}
return $admin;
}
/**
* 判断当前代理是否是 管理员
*
* @return
*/
static public function isAdmin($uid){
$res = Db::table('kt_base_agent')->where('id',$uid)->value('isadmin') ?: 0;
return $res;
}
/**
* 获取当前uid
*
* @return
*/
static public function getUid(){
$uid = Session::get('uid');
if(!$uid) $uid = Db::table('kt_base_agent')->where('isadmin',1)->value('id');
return $uid;
}
/**
* 获取管理员id
*
* @return
*/
static public function getAdminId(){
$res = Db::table('kt_base_agent')->where('isadmin',1)->value('id');
return $res;
}
/**
* 根据文件夹获取配置信息
* @return
*/
static public function getMainfestByName($code){
$res = [];
$base = base_path();
$filePath = $base."/".$code."/mainfest.xml";
if(!file_exists($filePath)) $filePath = $base."/".$code."/manifest.xml";
if(is_file($filePath)){
$xml=simplexml_load_file($filePath,'SimpleXMLElement', LIBXML_NOCDATA);
$xmlArr = json_decode(json_encode($xml), 1);
if(isset($xmlArr['application'])) $res = $xmlArr['application'];
}
return $res;
}
/**
* 获取当前代理下所有代理id,包括下级的下级代理id
*
* @return $ids 代理id array()
*/
static public function getAdentIds($uid){
$ids = [];
$ids[] = $uid;
self::getAdentId($uid,$ids);
return $ids;
}
static public function getAdentId($uid,&$ids){
$res = Db::table('kt_base_agent')->where('pid',$uid)->column('id');
if(count($res)>0){
foreach ($res as $id) {
$ids[] = $id;
self::getAdentId($id,$ids);
}
}
return $ids;
}
/**
* 获取 云存储配置, 当前代理未设置自动获取上级代理配置
* @param $uid 账户id
* @return
*/
static public function getStorageInfo($uid=''){
$uid = $uid ?: Session::get('uid');
$res = Db::table('kt_base_storage_config')->field('uid,type,oss_id,oss_secret,oss_endpoint,oss_bucket,cos_secretId,cos_secretKey,cos_bucket,cos_endpoint,kodo_key,kodo_secret,kodo_domain,kodo_bucket')->where('uid',$uid)->find();
if(!$res){
$user = Db::table('kt_base_agent')->find($uid);
if($user['isadmin'] == 1) return $res;
$res = self::getStorageInfo($user['pid']);
}
return $res;
}
/**
* 获取 当前用户云存储配置
* @param $uid 账户id
* @return
*/
static public function storageInfo(){
$uid = Session::get('uid');
$res = Db::table('kt_base_storage_config')->field('uid,type,oss_id,oss_secret,oss_endpoint,oss_bucket,cos_secretId,cos_secretKey,cos_bucket,cos_endpoint,kodo_key,kodo_secret,kodo_domain,kodo_bucket')->where('uid',$uid)->find();
return $res;
}
/**
* 保存 云存储配置
* @param $data 更新数据 array
* @return
*/
static public function storageUpdate($data){
$uid = Session::get('uid');
$config = Db::table('kt_base_storage_config')->where('uid',$uid)->find();
$param = [];
if($config) $param['id'] = $config['id'];
$param['uid'] = $uid;
$param['type'] = $data['type'];
switch ($data['type']) {
case '2':
$param['oss_id'] = $data['oss_id'];
$param['oss_secret'] = $data['oss_secret'];
$param['oss_endpoint'] = $data['oss_endpoint'];
$param['oss_bucket'] = $data['oss_bucket'];
break;
case '3':
$param['cos_secretId'] = $data['cos_secretId'];
$param['cos_secretKey'] = $data['cos_secretKey'];
$param['cos_bucket'] = $data['cos_bucket'];
$param['cos_endpoint'] = $data['cos_endpoint'];
break;
case '4':
$param['kodo_key'] = $data['kodo_key'];
$param['kodo_secret'] = $data['kodo_secret'];
$param['kodo_domain'] = $data['kodo_domain'];
$param['kodo_bucket'] = $data['kodo_bucket'];
break;
}
$res = Db::table('kt_base_storage_config')->save($param);
return 'ok';
}
/**
* 初始化云存储数据
* @return
*/
static private function inisetStorage(){
$uid = Session::get('uid');
$config = Db::table('kt_base_storage_config')->where('wid',$wid)->find();
if(!$config){
Db::table('kt_base_storage_config')->insert(
[
'uid' => $uid,
'type' => 1,
'create_time'=>date("Y-m-d H:i:s"),
'update_time'=>date("Y-m-d H:i:s"),
]
);
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model\admin\app;
use think\facade\Db;
use think\facade\Session;
use app\base\model\BaseModel;
use think\facade\Cache;
/*
* 应用管理
*/
class AppManageModel extends BaseModel
{
/**
* 获取 主应用列表
* @return
*/
public static function mainapp($req)
{
$data = [];
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,admin_link,install_type,author,target,version,c_time')->where('admin_link','<>','')->where('app_type',1);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->select();
$res = $res->select()->toArray();
foreach ($res as $key=>$value) {
$res[$key]['admin_link'] = $req->domain().$value['admin_link'];
}
return $res;
}
/**
* 获取 子应用(主应用插件)
* @return
*/
public static function plugin($req)
{
$data = [];
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,admin_link,install_type,author,target,version,c_time')->where('admin_link','<>','')->where('app_type',2);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->select();
$res = $res->select()->toArray();
foreach ($res as $key=>$value) {
$res[$key]['admin_link'] = $req->domain().$value['admin_link'];
}
return $res;
}
/**
* 获取 工具应用
* @return
*/
public static function tools($req)
{
$data = [];
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,admin_link,install_type,author,target,version,c_time')->where('admin_link','<>','')->where('app_type',3);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->select();
$res = $res->select()->toArray();
foreach ($res as $key=>$value) {
$res[$key]['admin_link'] = $req->domain().$value['admin_link'];
}
return $res;
}
/**
* 获取 模板应用
* @return
*/
public static function template($req)
{
$uid = Session::get('uid');
$data = [];
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,admin_link,install_type,author,target,version,c_time')->where('admin_link','<>','')->where('app_type',4);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->select();
$res = $res->select()->toArray();
foreach ($res as $key=>$value) {
$res[$key]['admin_link'] = $req->domain().$value['admin_link'];
$isuse = Db::table('kt_base_user_template')->where(['uid'=>$uid,'code'=>$value['code']])->field('id')->find();
$res[$key]['isuse'] = $isuse?1:0;
}
return $res;
}
/**
* 使用模板
* @return
*/
public static function useTemplate($code)
{
$uid = Session::get('uid');
$template = Db::table('kt_base_user_template')->where(['uid'=>$uid])->find();
$data = [];
$data['uid'] = $uid;
$data['code'] = $code;
if(isset($template['id'])){
$data['utime'] = date('Y-m-d H:i:s');
$res = Db::table('kt_base_user_template')->where(['uid'=>$uid])->update($data);
}else{
$data['ctime'] = date('Y-m-d H:i:s');
$res = Db::table('kt_base_user_template')->insert($data);
}
return $res;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model\admin\market;
use think\facade\Db;
use think\facade\Session;
use app\base\model\BaseModel;
use think\facade\Cache;
/*
* 应用管理
*/
class AppManageModel extends BaseModel
{
/**
* 获取 应用列表
* @return
*/
public static function list($req)
{
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$appType = $req->post('app_type');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($appType) $where[] = ['app_type','=',$appType];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,install_type,author,version,c_time')->where('app_type','<',3);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->page($page,$size)->select();
return $res->select();
}
/**
* 删除 应用
* @return
*/
public static function delete($req)
{
$id = $req->post('id');
$app = Db::table('kt_base_market_app')->find($id);
if(!$app) return error('应用不存在');
$res = Db::table('kt_base_market_app')->delete($id);
if($res) return success('删除成功');
return error('删除失败');
}
/**
* 应用信息
*/
public static function appInfo($code)
{
$uid = Session::get("uid");
$info = Db::table("kt_base_market_app")->where(["code"=>$code,'uid'=>$uid])->json(['specs',"label"])->find();
//初始化数据
if(!$info){
$app = self::getMainfestByName($code);
if(!$app) return null;
$data = [
'uid' => $uid,
'code' => $code,
'name' => $app['name'],
'logo' => $app['logo'],
'sort' => 0,
'recom' => 0,
'try_days' => 7,
'scene' => $app['description'] ?? '',
'version' => $app['version'] ?? '',
'user_link' => $app['userindex'] ?? '',
'admin_link' => $app['adminindex'] ?? '',
'describe' => $app['description'] ?? '',
'c_time' => date('Y-m-d H:i:s'),
];
$nameArr = explode('_', $code);
if($app['type'] == 2 && in_array('plugin', $nameArr)){
$key = array_keys($nameArr,'plugin');
$panmeArr = array_slice($nameArr, 0,$key);
$pname = implode('_', $panmeArr);
$data['pid'] = Db::table("kt_base_market_app")->where(["code"=>$pname,'uid'=>$uid])->value('id') ?: 0;
}
$id = Db::table("kt_base_market_app")->insertGetId($data);
$info = Db::table("kt_base_market_app")->find($id);
}
if(isset($info['specs'])){
foreach ($info["specs"] as $key=>$value){
if(is_int($info["specs"][$key]["duration_type"]))$info["specs"][$key]["duration_type"] = (string)$info["specs"][$key]["duration_type"];
}
}
return $info;
}
/**
* 设置应用信息
*/
public static function setApp($args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$info = Db::table("kt_base_market_app")->where(["code"=>$args['code'],'uid'=>$uid])->find();
if($info){
$args['u_time'] = date('Y-m-d H:i:s');
$res = Db::table("kt_base_market_app")->where(["code"=>$args['code'],'uid'=>$uid])->json(['specs',"label"])->update($args);
}else{
$args['c_time'] = date('Y-m-d H:i:s');
$res = Db::table("kt_base_market_app")->json(['specs',"label"])->insert($args);
}
return $res;
}
/**
* 分类列表
*/
public static function types($page=1,$size=10)
{
$uid = Session::get("uid");
$res = Db::table('kt_base_market_type')->where(['uid'=>$uid]);
$data['count'] = $res->count();
$data['item'] = $res->page($page,$size)->select();
$data['page'] = $page;
$data['size'] = $size;
return $data;
}
/**
* 分类信息
*/
public static function typeInfo($id)
{
$uid = Session::get("uid");
$info = Db::table("kt_base_market_type")->where(['id'=>$id])->find();
return $info;
}
/**
* 添加分类
*/
public static function addType($args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$args['c_time'] = date('Y-m-d H:i:s');
$info = Db::table("kt_base_market_type")->where(['name'=>$args['name'],'level'=>1])->find();
if($info) return '分类名称已存在';
$res = Db::table("kt_base_market_type")->insert($args);
return 'ok';
}
/**
* 修改分类
*/
public static function editType($id,$args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$args['u_time'] = date('Y-m-d H:i:s');
$info = Db::table("kt_base_market_type")->find($id);
if($info['name'] != $args['name']){
$checkname = Db::table("kt_base_market_type")->where(['name'=>$args['name'],'level'=>1])->find();
if($checkname) return ['status'=>'error','msg'=>'分类名称已存在'];
}
$res = Db::table("kt_base_market_type")->where(['id'=>$id])->update($args);
return $res;
}
/**
* 删除分类
*/
public static function delType($id)
{
$app = Db::table("kt_base_market_app")->where(["type"=>$id])->find();
if($app) return ['status'=>'error','msg'=>'删除失败'];
$res = Db::table("kt_base_market_type")->where(['id'=>$id])->delete();
return $res;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model\admin\market;
use think\facade\Db;
use think\facade\Session;
use app\base\model\BaseModel;
use app\kt_agent\model\admin\agent\ManageModel;
use think\facade\Cache;
/*
* 应用管理
*/
class OpenuseModel extends BaseModel
{
/*
* 获取所有应用列表
*/
static public function allApp($req)
{
$keyword = $req->post('keyword');
$res = Db::table("kt_base_market_app")->where('shelves',1);
if($keyword) $res->where('name',"like","%{$keyword}%");
$res = $res->json(['specs'])->select();
return success('所用应用列表',$res);
}
/*
* 已购应用列表
*/
static public function list($req)
{
$data = [];
$uid = Session::get('uid');
$ids = Db::table('kt_base_user')->where('agid',$uid)->column('id');
$page = $req->post('page',1);
$size = $req->post('size',10);
$keyword = $req->post('keyword');
$expired_type = $req->post('expired_type');
$res = Db::table("kt_base_user_openapp")
->field('id,wid,name,self_title,app_id,code,mend_time,sequence,logo,version,status,create_time')
->where('wid','in',$ids);
if($keyword) $res->where('name','like',"%{$keyword}%");
if($expired_type) {
switch ($expired_type) {
case '1':
$res->whereTime('mend_time','<=',date("Y-m-d H:i:s"));
break;
case '2':
$res->whereBetweenTime('mend_time',date("Y-m-d H:i:s"),date("Y-m-d H:i:s",strtotime("+7 day")));
break;
case '3':
$res->whereBetweenTime('mend_time',date("Y-m-d H:i:s"),date("Y-m-d H:i:s",strtotime("+30 day")));
break;
case '4':
$res->whereBetweenTime('mend_time',date("Y-m-d H:i:s"),date("Y-m-d H:i:s",strtotime("+90 day")));
break;
}
}
$data['count'] = $res->count();
$data['item'] = $res->order('create_time','desc')
->page($page,$size)
->filter(function($r){
if(!$r['self_title']) $r['self_title']=$r['name'].$r['wid'];
$r['username'] = Db::table('kt_base_user')->where('id',$r['wid'])->value('un');
$specs = Db::table('kt_base_market_app')->where('id',$r['app_id'])->json(['specs'])->find();
$r['specs'] = $specs ? $specs ['specs']: [];
$market_app = Db::table("kt_base_market_app")->where('id',$r['app_id'])->find();
$r['name'] = isset($market_app['name'])?$market_app['name']:$r['name'];
$r['logo'] = isset($market_app['logo'])?$market_app['logo']:$r['logo'];
return $r;
})
->select();
$data['page'] = $page;
$data['size'] = $size;
return success('已购应用列表',$data);
}
/*
* 开启停止
*/
static public function updateStatus($req)
{
$uid = Session::get('uid');
$status = $req->post('status');
$id = $req->post('id');
if(!$id) return error('参数错误');
$res = Db::table("kt_base_user_openapp")->where('id',$id)->update([
'status' => $status,
'update_time' => date("Y-m-d H:i:s")
]);
return success('修改成功');
}
/*
* 获取代理折扣
*/
static public function discount()
{
$uid = Session::get('uid');
$discount = 10;
if(class_exists("app\kt_agent\model\admin\agent\ManageModel")){
$discount = ManageModel::discount($uid) ?: 10;
}
return success('代理折扣',$discount);
}
/*
* 续费和购买
*/
static public function buy($req)
{
$uid = Session::get('uid');
$specsid = $req->post('specsid');
if(!$specsid) return error('缺少参数specsid');
$wid = $req->post('wid');
if(!$wid) return error('缺少参数wid');
$id = $req->post('app_id');//app_id
$app = Db::table("kt_base_market_app")->json(['specs'])->find($id);
if(!$app) return error('无此应用');
$pid = 0;
if($app['pid'] != 0){
$pApp = Db::table("kt_base_market_app")->find($app['pid']);
$pOpenapp = Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$pApp['id'])->find();
if(!$pOpenapp) return error('请先购买主应用');
$pid = $pOpenapp['id'];
}
$specs = [];
foreach ($app['specs'] as $v) {
if($v['id'] == $specsid){
$specs = $v;
break;
}
}
if(!$specs) return error('此应用无此规格');
$agent = Db::table("kt_base_agent")->find($uid);
$bh = date('YmdHis').rand(1000,9999).'|'.$wid;
$discounty = 10;
if(class_exists("app\kt_agent\model\admin\agent\ManageModel")){
$discounty = ManageModel::discount($uid) ?: 10;
}
$discount = $discounty/10;
$discount_price = sprintf("%.2f",$specs['price']*$discount);
if($agent['balance'] < $discount_price) return error('余额不足');
$orderId = Db::table("kt_base_agent_apporder")->insertGetId([
'uid' => $uid,
'wid' => $wid,
'app_id' => $id,
'bh' => $bh,
'specs_id' => $specs['id'],
'specs_content' => json_encode($specs,320),
// 'content' => $content,
// 'openapp_id' => Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$id)->value('id'),
'price' => $specs['price'],
'discount_price' => $discount_price,
'create_time'=>date("Y-m-d H:i:s"),
]);
if(!$orderId) return error('开通失败');
Db::table("kt_base_agent")->where('id',$uid)->update([
'balance' => Db::raw('balance-'.$discount_price),
'update_time'=>date("Y-m-d H:i:s"),
]);
$data = [
'wid' => $wid,
'name' => $app['name'],
'code' => $app['code'],
'logo' => $app['logo'],
'version' => $app['version'],
// 'mend_time' => date("Y-m-d H:i:s",strtotime("+".$app['try_days']." day")),
'update_time' => date("Y-m-d H:i:s"),
'app_id' => $id,
'pid' => $pid,
];
$has = Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$id)->find();
if($has){
$data['id'] = $has['id'];
if(strtotime($has['mend_time'] < time())){
$date = time();
}else{
$date = strtotime($has['mend_time']);
}
}else{
$date = time();
$data['create_time'] = date("Y-m-d H:i:s");
}
$content = '';
switch ($specs['duration_type']) {
case 2:
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." month",$date));
break;
case 3:
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." year",$date));
break;
}
$res = Db::table("kt_base_user_openapp")->save($data);
if(!$res){
Db::table("kt_base_user")->where('id',$wid)->update([
'balance' => Db::raw('balance+'.$discount_price)
]);
return error('购买失败');
}
return success('购买成功');
}
/*
* 用户订单列表(用户在用户后台购买)
*/
static public function userOrderList($req)
{
$uid = Session::get('uid');
$ids = Db::table('kt_base_user')->where('agid',$uid)->column('id');
$page = $req->post('page',1);
$size = $req->post('size',10);
$keyword = $req->post('keyword');
$res = Db::table("kt_base_user_order")
->alias('o')
->field('o.id,o.wid,o.content,o.app_id,o.price,o.create_time,o.openapp_id,o.status,o.balance_pay,o.specs_id,o.bh,o.specs_content,a.name')
->leftJoin("kt_base_market_app a","o.app_id=a.id")
->json(['o.pecs_content'])
->where('o.wid','in',$ids);
if($keyword) $res->where("a.name",'like',"%{$keyword}%");
$data['count'] = $res->count();
$data['item'] = $res->order('o.create_time','desc')
->page($page,$size)
->select();
$data['page'] = $page;
$data['size'] = $size;
return success('用户订单列表',$data);
}
/*
* 开通套餐
*/
static public function setmealBuy($req)
{
$uid = Session::get('uid');
$specsid = $req->post('specsid');
$packageid = $req->post('packageid');
if(!$packageid) return error('缺少参数packageid');
if(!$specsid) return error('缺少参数specsid');
$wid = $req->post('wid');
if(!$wid) return error('缺少参数wid');
$package = Db::table('kt_base_app_package')->json(['specs','apps'])->find($packageid);
if(!$package) return error("参数错误");
$specs = [];
foreach ($package['specs'] as $v) {
if($v['id'] == $specsid){
$specs = $v;
break;
}
}
if(!$specs) return error('不存在规格');
$agent = Db::table("kt_base_agent")->find($uid);
$bh = date('YmdHis').rand(1000,9999).'|'.$wid;
$discounty = 10;
if(class_exists("app\kt_agent\model\admin\agent\ManageModel")){
$discounty = ManageModel::discount($uid) ?: 10;
}
$discount = $discounty/10;
$discount_price = sprintf("%.2f",$specs['price']*$discount);
if($agent['balance'] < $discount_price) return error('余额不足');
$orderData = [];
foreach ($package['apps'] as $code) {
$app = Db::table("kt_base_market_app")->where('code',$code)->find();
$orderData[] = [
'uid' => $uid,
'wid' => $wid,
'app_id' => $app['id'],
'bh' => $bh,
'specs_id' => $specs['id'],
'specs_content' => json_encode($specs,320),
// 'content' => $content,
// 'openapp_id' => Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$id)->value('id'),
'price' => $specs['price'],
'discount_price' => $discount_price,
'create_time'=>date("Y-m-d H:i:s"),
'setmeal_type' => 2,
];
}
$orderRes = Db::table("kt_base_agent_apporder")->insertAll($orderData);
if(!$orderRes) return error('开通失败');
//套餐开通记录
Db::table("kt_base_user_package_recode")->insert([
"uid" => $uid,
"wid" => $wid,
"package_id" => $packageid,
"specs_id" => $specsid,
"app"=>json_encode($package['apps']),
"specs_content"=>json_encode($specs,320),
"create_time" => date("Y-m-d H:i:s"),
]);
//扣款
Db::table("kt_base_agent")->where('id',$uid)->update([
'balance' => Db::raw('balance-'.$discount_price),
'update_time'=>date("Y-m-d H:i:s"),
]);
foreach ($package['apps'] as $code) {
$app = Db::table("kt_base_market_app")->where('code',$code)->find();
$data = [
'wid' => $wid,
'name' => $app['name'],
'code' => $app['code'],
'logo' => $app['logo'],
'version' => $app['version'],
// 'mend_time' => date("Y-m-d H:i:s",strtotime("+".$app['try_days']." day")),
'update_time' => date("Y-m-d H:i:s"),
'app_id' => $app['id'],
];
$has = Db::table("kt_base_user_openapp")->where('wid',$wid)->where('app_id',$app['id'])->find();
if($has){
$data['id'] = $has['id'];
if(strtotime($has['mend_time'] < time())){
$date = time();
}else{
$date = strtotime($has['mend_time']);
}
}else{
$date = time();
$data['create_time'] = date("Y-m-d H:i:s");
}
$content = '';
switch ($specs['duration_type']) {
case 2:
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." month",$date));
break;
case 3:
$data['mend_time'] = date("Y-m-d H:i:s",strtotime("+".$specs['duration']." year",$date));
break;
}
$res = Db::table("kt_base_user_openapp")->save($data);
}
return success('开通成功');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model\admin\system;
use think\facade\Db;
use think\facade\Session;
use app\base\model\BaseModel;
use think\facade\Env;
/*
* 基础功能model
*/
class BasicModel extends BaseModel
{
/*
* 获取基本配置信息
* uid 登录时存储的uid 唯一
*/
static public function getSite(){
$uid = Session::get("uid");
$res = Db::table("kt_base_agent")->where(["id"=>$uid])->find();
$res['isadmin'] = self::isAdmin($uid) ? true : false;
$res['debug'] = Env::get('APP_DEBUG') ? 1 : 0;
return $res;
}
/*
* 修改基本配置信息
* domain 站点域名
* webname 站点名称
* webtitle 站点标题
* copyright 版权设置
* register_check 注册验证码(开启,关闭)
* registration_audit 注册审核(开启,关闭)----目前不确定代理商是否可以设置此项
* pc_official PC官网(开启,关闭)
*/
static public function setSite($domain,$webname,$webtitle,$copyright,$register_check,$registration_audit,$pc_official,$debug){
$uid = Session::get("uid");
$data["domain"] = $domain;
$data["webname"] = $webname;
$data["webtitle"] = $webtitle;
$data["copyright"] = $copyright;
$data["register_check"] = $register_check;
$data["registration_audit"] = $registration_audit;
$data["pc_official"] = (int)$pc_official?:2;
$res = Db::table("kt_base_agent")->where(["id"=>$uid])->save($data);
if(self::isAdmin($uid)){
$debugt = $debug ? 'true' : 'false';
self::setDebug($debugt);
}
return $res;
}
static public function setDebug($debugt){
$env = file_get_contents(root_path().'.env');
$envArr = explode("\n", $env);
foreach ($envArr as &$v) {
$vArr = explode('=', $v);
if(count($vArr)>0){
if(trim($vArr[0]) == "APP_DEBUG"){
$v = "APP_DEBUG = ".$debugt;
break;
}
}
}
$str = implode("\n", $envArr);
file_put_contents(root_path().'.env',$str);
return "ok";
}
/**
* logo设置
* user_logo 用户后台LOGO
* login_logo 登录页LOGO
* pc_logo PC官网LOGO
*/
static public function setLogo($user_logo=NULL,$login_logo=NULL,$pc_logo=NULL){
$uid = Session::get("uid");
$data["user_logo"] = $user_logo;
$data["login_logo"] = $login_logo;
$data["pc_logo"] = $pc_logo;
$res = Db::table("kt_base_agent")->where(["id"=>$uid])->save($data);
return $res;
}
/**
* login_background 背景图设置
*/
static public function setBackground($login_background=NULL,$login_background_status){
$uid = Session::get("uid");
$data["login_background_status"] = $login_background_status;
$data["login_background"] = $login_background;
$res = Db::table("kt_base_agent")->where(["id"=>$uid])->save($data);
return $res;
}
/**
* 设置其他设置
* kf_code 客服二维码(上传图片)
* gzh_code 公众号二维码 (上传图片)
* company_name 公司名称
* company_address 公司地址
* telephone 联系电话
* qq 联系QQ
* record_number 备案号
* key_word seo关键词
* describe seo描述
*/
static public function setAdditional($kf_code=NULL,$gzh_code=NULL,$company_name=NULL,$company_address=NULL,$telephone=NULL,$qq=NULL,$record_number=NULL,$key_word=NULL,$describe=NULL){
$uid = Session::get("uid");
$data["kf_code"] = $kf_code;
$data["gzh_code"] = $gzh_code;
$data["company_name"] = $company_name;
$data["company_address"] = $company_address;
$data["telephone"] = $telephone;
$data["qq"] = $qq;
$data["record_number"] = $record_number;
$data["key_word"] = $key_word;
$data["describe"] = $describe;
$res = Db::table("kt_base_agent")->where(["id"=>$uid])->save($data);
return $res;
}
}
\ No newline at end of file
... ...