mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 10:32:48 +08:00
项目完成服务器信息和配置文件;
This commit is contained in:
1
app/.htaccess
Normal file
1
app/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
150
app/BaseController.php
Normal file
150
app/BaseController.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use think\facade\View;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
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, '.')) {
|
||||
// 支持场景
|
||||
list($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);
|
||||
}
|
||||
|
||||
public function success($msg = '操作成功',$jump_to_url = null,$code = 200,$params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
$jump_to_url = url($jump_to_url);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
throw new HttpResponseException(json_message($data,0,$msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/success'),$code));
|
||||
}
|
||||
public function error($msg = '操作失败',$jump_to_url = null,$code = 200,$params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
$jump_to_url = url($jump_to_url);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
throw new HttpResponseException(json_message($data,0,$msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/error'),$code));
|
||||
}
|
||||
|
||||
}
|
||||
68
app/ExceptionHandle.php
Normal file
68
app/ExceptionHandle.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
17
app/Request.php
Normal file
17
app/Request.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
|
||||
}
|
||||
226
app/admin/controller/App.php
Normal file
226
app/admin/controller/App.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use app\model\App as ModelApp;
|
||||
use app\model\UploadFiles;
|
||||
|
||||
class App extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$app_list = ModelApp::paginate(10);
|
||||
|
||||
View::assign('app_list',$app_list);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
$installed_app_list = ModelApp::column('mark_id');
|
||||
|
||||
$app_list = get_app_info();
|
||||
|
||||
View::assign('app_list',$app_list);
|
||||
View::assign('installed_app_list',$installed_app_list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_app = ModelApp::where('mark_id',$post_data['mark_id'])->find();
|
||||
|
||||
if(!empty($model_app)){
|
||||
return json_message('应用已存在,不能重复创建');
|
||||
}
|
||||
|
||||
$model_app = new ModelApp();
|
||||
|
||||
if(!empty($post_data['poster'])){
|
||||
UploadFiles::update(['userd_time'=>time()],['save_name'=>$post_data['poster']]);
|
||||
}
|
||||
|
||||
if(!empty($post_data['detail'])){
|
||||
|
||||
foreach ($post_data['detail'] as $key => $value) {
|
||||
if(isset($value['insert'])){
|
||||
if(isset($value['insert']['image'])){
|
||||
$full_save_name = $value['insert']['image'];
|
||||
$save_name = de_source_link($full_save_name);
|
||||
if($save_name){
|
||||
UploadFiles::update(['used_time'=>time()],['save_name'=>$save_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$model_app->data($post_data,true);
|
||||
|
||||
$model_app->save();
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
$model_app = ModelApp::find($id);
|
||||
$app_list = get_app_info();
|
||||
|
||||
View::assign('app_list',$app_list);
|
||||
View::assign('app',$model_app);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_app = ModelApp::where('id',$id)->find();
|
||||
|
||||
if(empty($model_app)){
|
||||
return json_message('应用不存在');
|
||||
}
|
||||
|
||||
if(!empty($post_data['poster'])){
|
||||
if($post_data['poster'] != $model_app->getData('poster')){
|
||||
UploadFiles::destroy(['save_name'=>$model_app->getData('poster')]);
|
||||
UploadFiles::update(['userd_time'=>time()],['save_name'=>$post_data['poster']]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($post_data['detail'])){
|
||||
$image_list = [];
|
||||
$new_image_list = [];
|
||||
foreach ($model_app->detail as $key => $value) {
|
||||
if(isset($value['insert'])){
|
||||
if(isset($value['insert']['image'])){
|
||||
$full_save_name = $value['insert']['image'];
|
||||
$save_name = de_source_link($full_save_name);
|
||||
if($save_name){
|
||||
$image_list[] = $save_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($post_data['detail'] as $key => $value) {
|
||||
if(isset($value['insert'])){
|
||||
if(isset($value['insert']['image'])){
|
||||
$full_save_name = $value['insert']['image'];
|
||||
$save_name = de_source_link($full_save_name);
|
||||
if($save_name){
|
||||
$new_image_list[] = $save_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$del_image_list = array_diff($image_list,$new_image_list);
|
||||
|
||||
foreach ($del_image_list as $key => $value) {
|
||||
UploadFiles::destroy(['save_name'=>$value]);
|
||||
}
|
||||
|
||||
$add_image_list = array_diff($new_image_list,$image_list);
|
||||
|
||||
foreach ($add_image_list as $key => $value) {
|
||||
UploadFiles::update(['used_time'=>time()],['save_name'=>$value]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$model_app->data($post_data,true);
|
||||
|
||||
$model_app->save();
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
$model_app = ModelApp::find($id);
|
||||
|
||||
if(!empty($model_app->getData('poster'))){
|
||||
UploadFiles::udpate(['delete_time'=>time()],['save_name'=>$model_app->getData('poster')]);
|
||||
}
|
||||
|
||||
if(!empty($model_app->getData('detail'))){
|
||||
foreach ($model_app->detail as $key => $value) {
|
||||
if(isset($value['insert'])){
|
||||
if(isset($value['insert']['image'])){
|
||||
$full_save_name = $value['insert']['image'];
|
||||
$save_name = de_source_link($full_save_name);
|
||||
if($save_name){
|
||||
UploadFiles::update(['delete_time'=>time()],['save_name'=>$save_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$model_app->delete();
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
34
app/admin/controller/Common.php
Normal file
34
app/admin/controller/Common.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Session;
|
||||
use app\model\Admin;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
class Common extends BaseController{
|
||||
|
||||
public $adminInfo = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
|
||||
$admin_id = Session::get('admin_id');
|
||||
|
||||
if($this->request->controller() !== 'Login'){
|
||||
|
||||
if(empty($admin_id)){
|
||||
return $this->error('请登录','admin/Login/index');
|
||||
}
|
||||
|
||||
$this->adminInfo = Admin::find(Session::get('admin_id'));
|
||||
|
||||
if(empty($this->adminInfo)){
|
||||
if($this->request->controller() !== 'Login'){
|
||||
throw new HttpResponseException(redirect('admin/Login/index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
94
app/admin/controller/Index.php
Normal file
94
app/admin/controller/Index.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Session;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends Common
|
||||
{
|
||||
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
51
app/admin/controller/Login.php
Normal file
51
app/admin/controller/Login.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use think\facade\Validate;
|
||||
use think\validate\ValidateRule as Rule;
|
||||
use app\model\Admin;
|
||||
use think\facade\Session;
|
||||
|
||||
class Login extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
|
||||
public function auth()
|
||||
{
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$validate = Validate::rule('account',Rule::isRequire())
|
||||
->rule('password',Rule::isRequire());
|
||||
|
||||
if(!$validate->check($post_data)){
|
||||
return json_message($validate->getError());
|
||||
}
|
||||
|
||||
$model_admin = Admin::where('account',$post_data['account'])->find();
|
||||
|
||||
if(empty($model_admin)){
|
||||
return json_message('帐号不存在');
|
||||
}
|
||||
|
||||
if($model_admin->getData('password') !== md5($post_data['password'].$model_admin->getData('salt'))){
|
||||
return json_message('密码错误');
|
||||
}
|
||||
|
||||
Session::set('admin_id',$model_admin->id);
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
84
app/admin/controller/Member.php
Normal file
84
app/admin/controller/Member.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
|
||||
class Member extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
67
app/admin/controller/System.php
Normal file
67
app/admin/controller/System.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
use app\model\UploadFiles;
|
||||
use EasyWeChat\Factory;
|
||||
use think\facade\Config;
|
||||
use app\model\WxPublicAccount;
|
||||
|
||||
class System extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
public function others()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
$upload_files_config = [
|
||||
'site_logo'
|
||||
];
|
||||
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$list = SystemConfig::column('value','name');
|
||||
|
||||
foreach ($post_data as $key => $value) {
|
||||
if(\in_array($key,$upload_files_config)){
|
||||
$old_save_name = get_system_config($key);
|
||||
UploadFiles::update(['used_time'=>time()],['save_name'=>$value]);
|
||||
if($old_save_name != $value){
|
||||
UploadFiles::destroy(['save_name'=>$old_save_name]);
|
||||
}
|
||||
}
|
||||
if(isset($list[$key])){
|
||||
SystemConfig::where('name',$key)->update(['value'=>$value]);
|
||||
}else{
|
||||
$model_sysconfig = new SystemConfig();
|
||||
$model_sysconfig->name = $key;
|
||||
$model_sysconfig->value = $value;
|
||||
$model_sysconfig->save();
|
||||
}
|
||||
|
||||
$list[$key] = $value;
|
||||
}
|
||||
|
||||
Cache::set('system_config',$list);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
106
app/api/controller/Files.php
Normal file
106
app/api/controller/Files.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Config;
|
||||
use app\model\UploadFiles;
|
||||
use app\BaseController;
|
||||
|
||||
class Files extends BaseController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$type = $request->param('type');
|
||||
if(empty($type)){
|
||||
return json_message('缺少类型参数');
|
||||
}
|
||||
|
||||
$file = request()->file('file');
|
||||
|
||||
if(empty($file)){
|
||||
return json_message('上传失败');
|
||||
}
|
||||
|
||||
$dir_name = $request->param('dir','data');
|
||||
$model_file = new UploadFiles();
|
||||
$model_file->file_name = $file->getOriginalName();
|
||||
$model_file->mime_type = $file->getOriginalMime();
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
try {
|
||||
$model_file->save_name = Filesystem::putFile('upload/'.$dir_name,$file,'uniqid');
|
||||
$model_file->save();
|
||||
return json_message($model_file->append(['src'])->toArray());
|
||||
} catch (\Throwable $th) {
|
||||
return json_message($th->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
126
app/api/controller/WxOpen.php
Normal file
126
app/api/controller/WxOpen.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Config;
|
||||
use EasyWeChat\Factory;
|
||||
use app\model\WxPublicAccount;
|
||||
use app\model\UploadFiles;
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
|
||||
class WxOpen extends BaseController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
|
||||
$server = $openPlatform->server;
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
public function appAuthCallback()
|
||||
{
|
||||
$auth_code = $this->request->param('auth_code');
|
||||
|
||||
if (empty($auth_code)) {
|
||||
return $this->error('缺少参数','admin/System/others');
|
||||
}
|
||||
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
|
||||
$auth_info = $openPlatform->handleAuthorize($auth_code);
|
||||
|
||||
$model_auth_account = WxPublicAccount::where('authorizer_appid',$auth_info['authorization_info']['authorizer_appid'])->find();
|
||||
|
||||
if(!empty($model_auth_account)){
|
||||
if($model_auth_account->getData('deauth_time') === 0){
|
||||
return $this->error('不能重复授权','admin/System/others');
|
||||
}else{
|
||||
$model_auth_account->deauth_time = 0;
|
||||
}
|
||||
}else{
|
||||
$model_auth_account = new WxPublicAccount();
|
||||
$model_auth_account->authorizer_appid = $auth_info['authorization_info']['authorizer_appid'];
|
||||
// $model_auth_account->authorizer_access_token = $auth_info['authorization_info']['authorizer_access_token'];
|
||||
$model_auth_account->authorizer_refresh_token = $auth_info['authorization_info']['authorizer_refresh_token'];
|
||||
$model_auth_account->create_time = time();
|
||||
}
|
||||
|
||||
$wx_public_account_info = $openPlatform->getAuthorizer($model_auth_account->authorizer_appid);
|
||||
|
||||
|
||||
$model_auth_account->nick_name = $wx_public_account_info['authorizer_info']['nick_name'];
|
||||
|
||||
|
||||
if(!empty($model_auth_account->getData('head_img'))){
|
||||
UploadFiles::destroy(['save_name'=>$model_auth_account->getData('head_img')]);
|
||||
}
|
||||
|
||||
$model_auth_account->head_img = \save_url_file($wx_public_account_info['authorizer_info']['head_img'],3);
|
||||
UploadFiles::update(['used_time'=>time()],['save_name'=>$model_auth_account->getData('head_img')]);
|
||||
$model_auth_account->service_type_info = $wx_public_account_info['authorizer_info']['service_type_info']['id'];
|
||||
$model_auth_account->verify_type_info = $wx_public_account_info['authorizer_info']['verify_type_info']['id'];
|
||||
$model_auth_account->user_name = $wx_public_account_info['authorizer_info']['user_name'];
|
||||
$model_auth_account->alias = $wx_public_account_info['authorizer_info']['alias'];
|
||||
|
||||
if(!empty($model_auth_account->getData('qrcode_url'))){
|
||||
UploadFiles::destroy(['save_name'=>$model_auth_account->getData('qrcode_url')]);
|
||||
}
|
||||
$model_auth_account->qrcode_url = save_url_file($wx_public_account_info['authorizer_info']['qrcode_url'],2);
|
||||
UploadFiles::update(['used_time'=>time()],['save_name'=>$model_auth_account->getData('qrcode_url')]);
|
||||
$model_auth_account->business_info = json_encode($wx_public_account_info['authorizer_info']['business_info']);
|
||||
$model_auth_account->principal_name = $wx_public_account_info['authorizer_info']['principal_name'];
|
||||
$model_auth_account->signature = $wx_public_account_info['authorizer_info']['signature'];
|
||||
|
||||
$func_info = '';
|
||||
|
||||
foreach ($wx_public_account_info['authorization_info']['func_info'] as $key => $value) {
|
||||
$func_info .= $value['funcscope_category']['id'];
|
||||
}
|
||||
|
||||
$model_auth_account->func_info = $func_info;
|
||||
|
||||
$model_auth_account->save();
|
||||
$auth_type = $this->request->param('auth_type');
|
||||
|
||||
switch ($auth_type) {
|
||||
case 'system':
|
||||
$default_wx_public_account_id = get_system_config('default_wx_public_account_id');
|
||||
|
||||
if(empty($default_wx_public_account_id)){
|
||||
SystemConfig::create(['name'=>'default_wx_public_account_id','value'=>$model_auth_account->id]);
|
||||
}else{
|
||||
SystemConfig::update(['value'=>$model_auth_account->id],['name'=>get_system_config('default_wx_public_account_id')]);
|
||||
}
|
||||
|
||||
$list = SystemConfig::column('value','name');
|
||||
Cache::set('system_config',$list);
|
||||
|
||||
if($model_auth_account->getData('verify_type_info') !== 0){
|
||||
return $this->error('授权成功,但不能使用,公众号未认证','admin/System/others');
|
||||
}
|
||||
|
||||
return $this->success('授权成功','admin/System/others');
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
$info = $openPlatform->getAuthorizer('wx3280c83a307cbe7c');
|
||||
|
||||
dump($info);
|
||||
}
|
||||
}
|
||||
136
app/common.php
Normal file
136
app/common.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
use League\Flysystem\Util\MimeType;
|
||||
use think\File;
|
||||
use think\facade\Filesystem;
|
||||
use app\model\UploadFiles;
|
||||
|
||||
function json_message($data = [],$code = 0,$msg = '')
|
||||
{
|
||||
if(is_string($data)){
|
||||
|
||||
$code = $code === 0 ? 500 : $code;
|
||||
$msg = $data;
|
||||
$data = [];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code'=>$code,
|
||||
'msg'=>$msg,
|
||||
'data'=>$data
|
||||
]);
|
||||
}
|
||||
|
||||
function get_system_config($name,$default = '')
|
||||
{
|
||||
|
||||
$list = Cache::get('system_config');
|
||||
|
||||
if(empty($list)){
|
||||
$list = SystemConfig::column('value','name');
|
||||
}
|
||||
|
||||
if(isset($list[$name])){
|
||||
return $list[$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
function get_source_link($url)
|
||||
{
|
||||
if(strpos($url,'/') === 0){
|
||||
return $url;
|
||||
}if(strpos($url,'http') === 0){
|
||||
return $url;
|
||||
}else{
|
||||
$resource_domain = get_system_config('resource_domain');
|
||||
|
||||
if(empty($resource_domain)){
|
||||
request()->host();
|
||||
}
|
||||
return 'http://'.$resource_domain.'/'.$url;
|
||||
}
|
||||
}
|
||||
|
||||
function de_source_link($url)
|
||||
{
|
||||
$domain = 'http://'.get_system_config('resource_domain').'/';
|
||||
if(strpos($url,$domain) === 0){
|
||||
return str_replace($domain,'',$url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function save_url_file($url,$type)
|
||||
{
|
||||
|
||||
$file_data = geturl($url);
|
||||
|
||||
$mime_type = MimeType::detectByContent($file_data);
|
||||
|
||||
$ext_name = array_search($mime_type,MimeType::getExtensionToMimeTypeMap());
|
||||
$temp_file = tempnam(app()->getRuntimePath(),'url_save_').'.'.$ext_name;
|
||||
file_put_contents($temp_file,$file_data);
|
||||
$file = new File($temp_file);
|
||||
|
||||
$save_name = Filesystem::putFile('wx_public_account/qrcode_url',$file,'unique');
|
||||
|
||||
$model_file = new UploadFiles();
|
||||
$model_file->file_name = $file->getFilename();
|
||||
$model_file->mime_type = $mime_type;
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
|
||||
$model_file->save_name = $save_name;
|
||||
$model_file->save();
|
||||
|
||||
return $save_name;
|
||||
}
|
||||
|
||||
function geturl($url){
|
||||
$headerArray =array();
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function posturl($url,$data){
|
||||
$data = json_encode($data);
|
||||
$headerArray =array();
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
27
app/event.php
Normal file
27
app/event.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
'AppInit' => [],
|
||||
'HttpRun' => [],
|
||||
'HttpEnd' => [],
|
||||
'LogLevel' => [],
|
||||
'LogWrite' => [],
|
||||
],
|
||||
|
||||
'subscribe' => [
|
||||
],
|
||||
];
|
||||
86
app/index/controller/Index.php
Normal file
86
app/index/controller/Index.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class Index
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
14
app/middleware.php
Normal file
14
app/middleware.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// 全局请求缓存
|
||||
// \think\middleware\CheckRequestCache::class,
|
||||
// 多语言加载
|
||||
// \think\middleware\LoadLangPack::class,
|
||||
// Session初始化
|
||||
\think\middleware\SessionInit::class,
|
||||
// 页面Trace调试
|
||||
// \think\middleware\TraceDebug::class,
|
||||
|
||||
'\\app\\middleware\ConfigInit'
|
||||
];
|
||||
36
app/middleware/ConfigInit.php
Normal file
36
app/middleware/ConfigInit.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
use think\helper\Arr;
|
||||
|
||||
class ConfigInit
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
|
||||
$tables = @Db::query("show tables");
|
||||
if(!empty($tables)){
|
||||
|
||||
//设置存储
|
||||
$filesystem_config = Config::get('filesystem');
|
||||
Arr::set($filesystem_config,'default','public');
|
||||
|
||||
Config::set($filesystem_config, 'filesystem');
|
||||
|
||||
// 社微信开放平台
|
||||
|
||||
$wx_open_app = [];
|
||||
$wx_open_app = Arr::add($wx_open_app,'app_id',get_system_config('wx_open_app_id'));
|
||||
$wx_open_app = Arr::add($wx_open_app,'secret',get_system_config('wx_open_app_secret'));
|
||||
$wx_open_app = Arr::add($wx_open_app,'token',get_system_config('wx_open_app_token'));
|
||||
$wx_open_app = Arr::add($wx_open_app,'aes_key',get_system_config('wx_open_app_aes_key'));
|
||||
|
||||
Config::set($wx_open_app,'wx_open_app');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
13
app/model/Admin.php
Normal file
13
app/model/Admin.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Admin extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
14
app/model/SystemConfig.php
Normal file
14
app/model/SystemConfig.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class SystemConfig extends Model
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
22
app/model/UploadFiles.php
Normal file
22
app/model/UploadFiles.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class UploadFiles extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function getSrcAttr()
|
||||
{
|
||||
return \get_source_link($this->getData('save_name'));
|
||||
}
|
||||
}
|
||||
23
app/model/WxPublicAccount.php
Normal file
23
app/model/WxPublicAccount.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class WxPublicAccount extends Model
|
||||
{
|
||||
//
|
||||
public function getHeadImgAttr($value)
|
||||
{
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function getQrcodeUrlAttr($value)
|
||||
{
|
||||
return \get_source_link($value);
|
||||
}
|
||||
}
|
||||
19
app/provider.php
Normal file
19
app/provider.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use app\ExceptionHandle;
|
||||
use app\Request;
|
||||
|
||||
// 容器Provider定义文件
|
||||
return [
|
||||
'think\Request' => Request::class,
|
||||
'think\exception\Handle' => ExceptionHandle::class,
|
||||
];
|
||||
Reference in New Issue
Block a user