初始化代码
This commit is contained in:
10
application/version/model/Capital.php
Normal file
10
application/version/model/Capital.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\version\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Capital extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
63
application/version/model/SystemMenu.php
Normal file
63
application/version/model/SystemMenu.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\version\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class SystemMenu extends Model
|
||||
{
|
||||
|
||||
// 获取初始化数据
|
||||
public function getSystemInit($aid = 0)
|
||||
{
|
||||
$homeInfo = [
|
||||
'title' => '首页',
|
||||
'href' => '',
|
||||
];
|
||||
$logoInfo = [
|
||||
'title' => '系统 管理',
|
||||
'image' => 'images/logo.png',
|
||||
];
|
||||
$menuInfo = $this->getMenuList($aid);
|
||||
$systemInit = [
|
||||
'homeInfo' => $homeInfo,
|
||||
'logoInfo' => $logoInfo,
|
||||
'menuInfo' => $menuInfo,
|
||||
];
|
||||
return $systemInit;
|
||||
}
|
||||
|
||||
// 获取菜单列表
|
||||
private function getMenuList($aid)
|
||||
{
|
||||
$menuList = Db::name('system_menu_version')
|
||||
->field('id,pid,title,icon,href,target')
|
||||
->where('status', 1)
|
||||
->where('type', 'in', [1, 2])
|
||||
->order('sort', 'desc')
|
||||
->select();
|
||||
|
||||
$menuList = $this->buildMenuChild(0, $menuList);
|
||||
return $menuList;
|
||||
}
|
||||
|
||||
//递归获取子菜单
|
||||
private function buildMenuChild($pid, $menuList)
|
||||
{
|
||||
$treeList = [];
|
||||
foreach ($menuList as &$v) {
|
||||
|
||||
if ($pid == $v['pid']) {
|
||||
$node = $v;
|
||||
$child = $this->buildMenuChild($v['id'], $menuList);
|
||||
if (!empty($child)) {
|
||||
$node['child'] = $child;
|
||||
}
|
||||
// todo 后续此处加上用户的权限判断
|
||||
$treeList[] = $node;
|
||||
}
|
||||
}
|
||||
return $treeList;
|
||||
}
|
||||
}
|
||||
214
application/version/model/Upload.php
Normal file
214
application/version/model/Upload.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\version\model;
|
||||
|
||||
use think\Model;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
use Qiniu\Auth;
|
||||
use think\facade\Env;
|
||||
use Qcloud\Cos\Client;
|
||||
|
||||
class Upload extends Model
|
||||
{
|
||||
//单文件上传
|
||||
public function single_file_upload($file, $file_category_name = 'all')
|
||||
{
|
||||
//判断上传方式
|
||||
$config = get_system_config();
|
||||
$reslut = ['code' => 201, 'msg' => '非法上传存储类型', 'data' => null];
|
||||
if ($config['file_upload_type'] == 1) {
|
||||
$reslut = $this->local_upload($file, $file_category_name);
|
||||
} elseif ($config['file_upload_type'] == 2) {
|
||||
$reslut = $this->qiniu_upload($file, $file_category_name);
|
||||
}elseif ($config['file_upload_type'] == 3) {
|
||||
$reslut = $this->tencent_upload($file, $file_category_name);
|
||||
}
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
public function server_local_upload($filePath){
|
||||
|
||||
$config = get_system_config();
|
||||
$accessKey = $config['qiniu_access_key'];
|
||||
$secretKey = $config['qiniu_secret_key'];
|
||||
$bucket = $config['qiniu_bucket_name'];
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
// 生成上传 Token
|
||||
$token = $auth->uploadToken($bucket);
|
||||
// 初始化 UploadManager 对象并进行文件的上传。
|
||||
$uploadMgr = new UploadManager();
|
||||
// 调用 UploadManager 的 putFile 方法进行文件的上传。
|
||||
$local_filePath= Env::get('root_path')."/public/".$filePath;
|
||||
list($ret, $err) = $uploadMgr->putFile($token, $filePath, $local_filePath);
|
||||
if ($err !== null) {
|
||||
return ['code' => 201, 'msg' => "上传失败", 'data' => null];
|
||||
} else {
|
||||
$data = [];
|
||||
$data['image_path'] = $ret['key'];
|
||||
$data['size'] = 0;
|
||||
$data['http_image_path'] = localpath_to_netpath($ret['key']);
|
||||
|
||||
return ['code' => 200, 'msg' => "上传成功", 'data' => $data];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function local_upload($file, $file_category_name = 'all')
|
||||
{
|
||||
// // 获取表单上传文件 例如上传了001.jpg
|
||||
|
||||
// 移动到框架应用根目录/uploads/ 目录下
|
||||
$root_path = 'public/uploads/' . $file_category_name;
|
||||
mkdirs($root_path); //创建文件
|
||||
$info = $file->validate(['ext' => 'jpeg,jpg,png,gif,mp4,mp3,wgt,svga'])->move('./uploads/' . $file_category_name);
|
||||
if ($info) {
|
||||
$file_info = $info->getInfo();
|
||||
// 成功上传后 获取上传信息
|
||||
// 输出 jpg
|
||||
// echo $info->getExtension();
|
||||
// // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
|
||||
// echo $info->getSaveName();
|
||||
// // 输出 42a79759f284b767dfcb2a0197904287.jpg
|
||||
// echo $info->getFilename();
|
||||
$image_path = '/uploads/' . $file_category_name . '/' . $info->getSaveName(); //返回的地址
|
||||
$image_path = str_replace("\\", "/", $image_path);
|
||||
$img['image_path'] = $image_path;
|
||||
$img['size'] = $file_info['size'];
|
||||
$img['http_image_path'] = localpath_to_netpath($image_path);
|
||||
return ['code' => 200, 'msg' => '上传成功', 'data' => $img];
|
||||
} else {
|
||||
|
||||
return ['code' => 201, 'msg' => '上传失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
public function qiniu_upload($file, $file_category_name = 'all')
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
ini_set('upload_max_filesize', '200M');
|
||||
ini_set('post_max_size', '200M');
|
||||
|
||||
$config = get_system_config();
|
||||
$accessKey = $config['qiniu_access_key'];
|
||||
$secretKey = $config['qiniu_secret_key'];
|
||||
$bucket = $config['qiniu_bucket_name'];
|
||||
|
||||
if (empty($file)) {
|
||||
return ['code' => 201, 'msg' => '请上传文件', 'data' => null];
|
||||
}
|
||||
$validate_reslut = $file->validate(['ext' => 'jpeg,jpg,png,gif,mp4,mp3,wgt,svga,apk'])->check();
|
||||
if (!$validate_reslut) {
|
||||
return ['code' => 201, 'msg' => '非法上传存储类型', 'data' => null];
|
||||
}
|
||||
$extension = strtolower(pathinfo($file->getInfo('name'), PATHINFO_EXTENSION));
|
||||
$file_info = $file->getInfo();
|
||||
|
||||
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
// 生成上传 Token
|
||||
$token = $auth->uploadToken($bucket);
|
||||
// 要上传文件的本地路径
|
||||
$filePath = $file_info['tmp_name'];
|
||||
// 上传到存储后保存的文件名
|
||||
$savename = date('Ymd') . '/' . md5(microtime(true)) . ".$extension";
|
||||
$key = $file_category_name . '/' . $savename;
|
||||
// 初始化 UploadManager 对象并进行文件的上传。
|
||||
$uploadMgr = new UploadManager();
|
||||
// 调用 UploadManager 的 putFile 方法进行文件的上传。
|
||||
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
|
||||
if ($err !== null) {
|
||||
return ['code' => 201, 'msg' => "上传失败", 'data' => null];
|
||||
} else {
|
||||
$data = [];
|
||||
$data['image_path'] = $ret['key'];
|
||||
$data['size'] = $file_info['size'];
|
||||
$data['http_image_path'] = localpath_to_netpath($ret['key']);
|
||||
$data['suffix'] = $extension;
|
||||
// $data_json = json_encode($data);
|
||||
// error_log($data_json, 3, 'upload.txt');
|
||||
return ['code' => 200, 'msg' => "上传成功", 'data' => $data];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_qiniu_upload_token()
|
||||
{
|
||||
$config = get_system_config();
|
||||
$accessKey = $config['qiniu_access_key'];
|
||||
$secretKey = $config['qiniu_secret_key'];
|
||||
$bucket = $config['qiniu_bucket_name'];
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$token = $auth->uploadToken($bucket);
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => ['token' => $token]];
|
||||
}
|
||||
|
||||
public function tencent_upload($file, $file_category_name = 'all')
|
||||
{
|
||||
$config = get_system_config();
|
||||
$secretId = $config['tencent_secret_id'];
|
||||
// $secretId = 111111;
|
||||
$secretKey = $config['tencent_secret_key'];
|
||||
$region = $config['tencent_territory'];
|
||||
$bucket = $config['tencent_bucket_name'];
|
||||
|
||||
if (empty($file)) {
|
||||
return ['code' => 201, 'msg' => '请上传文件', 'data' => null];
|
||||
}
|
||||
// dump($file);exit;
|
||||
|
||||
$validate_reslut = $file->validate(['ext' => 'jpeg,jpg,png,gif,mp4,mp3,wgt,svga,apk'])->check();
|
||||
// dump($file);exit;
|
||||
if (!$validate_reslut) {
|
||||
return ['code' => 201, 'msg' => '非法上传存储类型', 'data' => null];
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($file->getInfo('name'), PATHINFO_EXTENSION));
|
||||
$file_info = $file->getInfo();
|
||||
|
||||
|
||||
// 构建鉴权对象
|
||||
$cosClient = new Client(
|
||||
array(
|
||||
'region' => $region,
|
||||
'schema' => 'https', //协议头部,默认为http
|
||||
'credentials'=> array(
|
||||
'secretId' => $secretId ,
|
||||
'secretKey' => $secretKey
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// 要上传文件的本地路径
|
||||
$filePath = $file_info['tmp_name'];
|
||||
// 上传到存储后保存的文件名
|
||||
$savename = date('Ymd') . '/' . md5(microtime(true)) . ".$extension";
|
||||
$key = $file_category_name . '/' . $savename;
|
||||
// 初始化 UploadManager 对象并进行文件的上传。
|
||||
$file = fopen($filePath, "rb");
|
||||
|
||||
if ($file) {
|
||||
$result = $cosClient->putObject(array(
|
||||
'Bucket' => $bucket,
|
||||
'Key' => $key,
|
||||
'Body' => $file)
|
||||
);
|
||||
|
||||
$data = [];
|
||||
$data['image_path'] = $result['Key'];
|
||||
$data['size'] = $file_info['size'];
|
||||
$data['http_image_path'] = localpath_to_netpath($result['Key']);
|
||||
$data['mp4_task_id'] = '';
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => "上传成功", 'data' => $data];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => "上传失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
24
application/version/model/User.php
Normal file
24
application/version/model/User.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\version\model;
|
||||
|
||||
use think\Model;
|
||||
use think\DB;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
public function check_login_token($login_token)
|
||||
{
|
||||
if (empty($login_token)) {
|
||||
return ['code' => 201, 'msg' => '登录失效', 'data' => ''];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['login_token', '=', $login_token];
|
||||
$user_info = db::name('user')->where($map)->find();
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '登录失效', 'data' => ''];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '登录成功', 'data' => $user_info['uid']];
|
||||
}
|
||||
}
|
||||
}
|
||||
93
application/version/model/Version.php
Normal file
93
application/version/model/Version.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\version\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class Version extends Model
|
||||
{
|
||||
public function get_version_list($page, $limit)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['type', 'in', [1,2]];
|
||||
$list = db::name('version')->where($map)->order('vid desc')->page($page, $limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
|
||||
}
|
||||
$data = [];
|
||||
$data['count'] = db::name('version')->where($map)->count();
|
||||
$data['list'] = $list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit_version($data)
|
||||
{
|
||||
if (empty($data)) {
|
||||
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
||||
}
|
||||
$version_info = db::name('version')->find($data['vid']);
|
||||
if (empty($version_info)) {
|
||||
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
||||
}
|
||||
|
||||
$update_data = [];
|
||||
$update_data['type'] = $data['type'];
|
||||
$update_data['version'] = $data['version'];
|
||||
$update_data['down_url'] = $data['down_url'];
|
||||
$update_data['note'] = $data['note'];
|
||||
$update_data['is_force_update'] = $data['is_force_update'];
|
||||
$update_data['update_time'] = time();
|
||||
$reslut = db::name('version')->where(['vid' => $data['vid']])->update($update_data);
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//添加
|
||||
public function add_version($data)
|
||||
{
|
||||
|
||||
$add_data = [];
|
||||
$add_data['type'] = $data['type'];
|
||||
$add_data['version'] = $data['version'];
|
||||
$add_data['down_url'] = $data['down_url'];
|
||||
$add_data['note'] = $data['note'];
|
||||
$add_data['is_force_update'] = $data['is_force_update'];
|
||||
$add_data['add_time'] = time();
|
||||
$reslut = db::name('version')->insert($add_data);
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取信息
|
||||
public function get_version_info($vid)
|
||||
{
|
||||
if (empty($vid)) {
|
||||
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
||||
}
|
||||
$version_info = db::name('version')->where(['vid' => $vid])->find();
|
||||
$version_info['http_base_image'] = localpath_to_netpath($version_info['down_url']);
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $version_info];
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del_version($vid)
|
||||
{
|
||||
if (empty($vid)) {
|
||||
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('version')->where(['vid' => $vid])->delete();
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user