初始化
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\FileManage;
|
||||
use app\common\model\Folders;
|
||||
use app\common\model\Policys;
|
||||
use app\common\model\Shares;
|
||||
use app\common\model\Stores;
|
||||
use think\Exception;
|
||||
use think\response\Download;
|
||||
|
||||
class File extends Home
|
||||
{
|
||||
|
||||
public function list(){
|
||||
$folder_id = input('get.folder_id',0);
|
||||
$search = input('get.search','');
|
||||
|
||||
$page = input('get.page',1);
|
||||
$limit = input('get.rows',20);
|
||||
|
||||
$file_list = FileManage::ListFile($folder_id,$search,$this->userInfo['id'],$page,$limit);
|
||||
|
||||
return json($file_list);
|
||||
}
|
||||
|
||||
public function mkdir(){
|
||||
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'folder_id' => 'require|number',
|
||||
'folder_name' => 'require|chsDash|max:255',
|
||||
'folder_miaoshu' => 'max:255'
|
||||
],[
|
||||
'folder_name.chsDash' => '文件名只能是汉字、字母、数字和下划线_及破折号-'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['status' => 0,'msg' => $result]);
|
||||
|
||||
try {
|
||||
$dir_id = FileManage::createFolder($data['folder_id'],$data['folder_name'],$data['folder_miaoshu'],$this->userInfo['id']);
|
||||
|
||||
return json(['status' => 1,'msg' => '新建文件夹成功~','data' => $dir_id]);
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function rename(){
|
||||
$id = input('get.id');
|
||||
$file_name = input('get.file_name');
|
||||
$is_folder = input('get.is_folder');
|
||||
|
||||
$is_folder = intval($is_folder);
|
||||
|
||||
try {
|
||||
if($is_folder){
|
||||
$result = $this->validate(['file_name' => $file_name],[
|
||||
'file_name' => 'require|chsDash|max:255',
|
||||
],[
|
||||
'file_name.chsDash' => '文件(夹)名只能是汉字、字母、数字和下划线_及破折号-'
|
||||
]);
|
||||
|
||||
$info = Folders::where('id',$id)->where('uid',$this->userInfo['id'])->find();
|
||||
if(empty($info)){
|
||||
throw new Exception('文件数据不存在');
|
||||
}
|
||||
$info['folder_name'] = $file_name;
|
||||
$info->save();
|
||||
}else{
|
||||
$result = $this->validate(['file_name' => $file_name],['file_name' => 'require|max:255',]);
|
||||
|
||||
$info = Stores::where('id',$id)->where('uid',$this->userInfo['id'])->find();
|
||||
if(empty($info)){
|
||||
throw new Exception('文件数据不存在');
|
||||
}
|
||||
$info['origin_name'] = $file_name;
|
||||
$info->save();
|
||||
}
|
||||
|
||||
if($result !== true){
|
||||
throw new Exception($result);
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '重命名成功']);
|
||||
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(){
|
||||
$id = input('get.id');
|
||||
$is_folder = input('get.is_folder');
|
||||
$uid = $this->userInfo['id'];
|
||||
|
||||
if(empty($id)){
|
||||
return json(['status' => 0,'msg' => '删除错误,参数缺失']);
|
||||
}
|
||||
|
||||
//删除目录
|
||||
if(boolval($is_folder)){
|
||||
|
||||
$pid = Folders::where('id',$id)->value('parent_folder');
|
||||
|
||||
if($pid == 0){
|
||||
return json(['status' => 0,'msg' => '删除失败,您不能删除根目录']);
|
||||
}
|
||||
|
||||
$child_object = getFolderChildFiles($uid,$pid);
|
||||
|
||||
if(!empty($child_object['file'])){
|
||||
Stores::destroy($child_object['file']);
|
||||
}
|
||||
|
||||
if(!empty($child_object['folder'])){
|
||||
Folders::destroy($child_object['folder']);
|
||||
}
|
||||
|
||||
}else{
|
||||
Stores::destroy(function($query) use($id,$uid){
|
||||
$query->where('id','=',$id)->where('uid','=',$uid);
|
||||
});
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '删除成功']);
|
||||
}
|
||||
|
||||
public function edit_folder(){
|
||||
$id = input('get.id');
|
||||
$info = Folders::get($id);
|
||||
|
||||
if(empty($info)){
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
|
||||
if($this->request->isPost()){
|
||||
$folder_name = input('post.folder_name');
|
||||
$folder_miaoshu = input('post.folder_miaoshu');
|
||||
$shouyi = input('post.shouyi');
|
||||
|
||||
Folders::where('id',$id)->update([
|
||||
'folder_name' => $folder_name,
|
||||
'desc' => $folder_miaoshu,
|
||||
'size' => $shouyi
|
||||
]);
|
||||
|
||||
return json(['status' => 1,'msg' => '修改文件夹信息成功']);
|
||||
}
|
||||
|
||||
$this->assign('info',$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function edit_file(){
|
||||
$id = input('get.id');
|
||||
$info = Stores::get($id);
|
||||
|
||||
if(empty($info)){
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
|
||||
if($this->request->isPost()){
|
||||
$file_name = input('post.file_name');
|
||||
$file_miaoshu = input('post.file_miaoshu');
|
||||
|
||||
Stores::where('id',$id)->update([
|
||||
'origin_name' => $file_name,
|
||||
'desc' => $file_miaoshu
|
||||
]);
|
||||
|
||||
return json(['status' => 1,'msg' => '修改文件信息成功']);
|
||||
}
|
||||
|
||||
$this->assign('info',$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function delete_all(){
|
||||
$ids = input('get.ids');
|
||||
$idFs = input('get.idFs');
|
||||
|
||||
$uid = $this->userInfo['id'];
|
||||
$success_ids = [];
|
||||
|
||||
if(empty($ids) && empty($idFs)){
|
||||
return json(['status' => 0,'msg' => '请选择需要删除的文件(夹)~']);
|
||||
}
|
||||
|
||||
if(!empty($ids)){
|
||||
$ids_list = explode(',',$ids);
|
||||
try {
|
||||
foreach ($ids_list as $file){
|
||||
//删除
|
||||
Stores::destroy(function($query) use($file,$uid){
|
||||
$query->where('id','=',$file)->where('uid','=',$uid);
|
||||
});
|
||||
$success_ids[] = $file;
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($idFs)){
|
||||
$idFs_list = explode(',',$idFs);
|
||||
try {
|
||||
foreach ($idFs_list as $dir){
|
||||
$pid = Folders::where('id',$dir)->value('parent_folder');
|
||||
if($pid == 0){
|
||||
return json(['status' => 0,'msg' => '删除失败,目录操作异常']);
|
||||
}
|
||||
|
||||
//删除
|
||||
$child_object = getFolderChildFiles($uid,$pid);
|
||||
|
||||
if(!empty($child_object['file'])){
|
||||
Stores::destroy($child_object['file']);
|
||||
}
|
||||
|
||||
if(!empty($child_object['folder'])){
|
||||
Folders::destroy($child_object['folder']);
|
||||
}
|
||||
|
||||
$success_ids[] = $dir;
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '成功删除 '.count($success_ids).' 个文件(夹)~','data' => $success_ids]);
|
||||
}
|
||||
|
||||
public function move_files(){
|
||||
$ids = input('get.ids');
|
||||
$idFs = input('get.idFs');
|
||||
|
||||
$this->assign('ids',$ids);
|
||||
$this->assign('idFs',$idFs);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function folder_list(){
|
||||
$folder_id = input('post.folder_id',0);
|
||||
$folder = FileManage::FolderList($folder_id,$this->userInfo['id']);
|
||||
return json(['status' => 1,'msg' => 'ok','data' => $folder]);
|
||||
}
|
||||
|
||||
public function move_to_file(){
|
||||
$folder_id = input('post.folder_id',0);
|
||||
$ids = input('post.ids');
|
||||
$idFs = input('post.idFs');
|
||||
|
||||
$uid = $this->userInfo['id'];
|
||||
|
||||
if(empty($ids) && empty($idFs)){
|
||||
return json(['status' => 0,'msg' => '请选择需要移动的文件或者文件夹']);
|
||||
}
|
||||
|
||||
$folder_id = FileManage::getFolderPid($folder_id,$uid);
|
||||
|
||||
$root_folder = FileManage::getFolderPid(0,$uid);
|
||||
|
||||
$ids_list = array_filter(explode(',',trim($ids)));
|
||||
$idFs_list = array_filter(explode(',',trim($idFs)));
|
||||
|
||||
$success = [];
|
||||
|
||||
//移动目录
|
||||
if(!empty($idFs_list)){
|
||||
foreach ($idFs_list as $dir){
|
||||
if($dir != $root_folder && $dir != $folder_id && !empty($dir)){
|
||||
Folders::where('id',$dir)->where('uid',$uid)->update(['parent_folder' => $folder_id]);
|
||||
$success[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//移动文件
|
||||
if(!empty($ids_list)){
|
||||
foreach ($ids_list as $file){
|
||||
if(!empty($file)){
|
||||
Stores::where('id',$file)->where('uid',$uid)->update(['parent_folder' => $folder_id]);
|
||||
$success[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '成功移动 '.count($success).' 个文件(夹)~','data' => $success]);
|
||||
}
|
||||
|
||||
public function set_share_pass(){
|
||||
$id = input('get.id');
|
||||
$pass = input('get.pass');
|
||||
$is_folder = input('get.is_folder');
|
||||
$pass_status = input('get.pass_status');
|
||||
|
||||
$is_folder = intval($is_folder);
|
||||
$pass_status = intval($pass_status);
|
||||
|
||||
$uid = $this->userInfo['id'];
|
||||
|
||||
if($is_folder){
|
||||
$info = Folders::where('id',$id)->where('uid',$uid)->find();
|
||||
}else{
|
||||
$info = Stores::where('id',$id)->where('uid',$uid)->find();
|
||||
}
|
||||
|
||||
if(empty($info)){
|
||||
return json(['status' => 0,'msg' => '文件数据不存在']);
|
||||
}
|
||||
|
||||
$result = $this->validate(['pass' => $pass],['pass|提取码' => 'require|alphaNum|length:4,6'],[
|
||||
'pass.require' => '提取码必须填写',
|
||||
'pass.alphaNum' => '提取码只能为字母或者数字',
|
||||
'pass.length' => '提取码长度只能为 4 ~ 6 位字母或者数字'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['status' => 0,'msg' => $result]);
|
||||
|
||||
Shares::updateShare($info['shares_id'],[
|
||||
'pwd' => $pass,
|
||||
'pwd_status' => $pass_status
|
||||
]);
|
||||
|
||||
return json(['status' => 1,'msg' => '设置提取码成功']);
|
||||
|
||||
}
|
||||
|
||||
public function user_download(){
|
||||
$id = input('get.id',0);
|
||||
$info = Stores::where('id',$id)->where('uid',$this->userInfo['id'])->find();
|
||||
|
||||
if(empty($info)){
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
|
||||
$share = Shares::where('id',$info['shares_id'])->find();
|
||||
|
||||
$share_url = getShareUrl($share['code']);
|
||||
|
||||
$this->redirect($share_url);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
<?php
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\driver\AliyunOss;
|
||||
use app\common\model\driver\Local;
|
||||
use app\common\model\driver\TxyunOss;
|
||||
use app\common\model\FileManage;
|
||||
use app\common\model\Folders;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\Profit;
|
||||
use app\common\model\Record;
|
||||
use app\common\model\Reports;
|
||||
use app\common\model\Shares;
|
||||
use app\common\model\Stores;
|
||||
use app\common\model\Users;
|
||||
use Qrcode\Qrcode;
|
||||
use think\Exception;
|
||||
use think\facade\Cookie;
|
||||
use think\response\Download;
|
||||
|
||||
class Index extends Home
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch('index_'.config('basic.index_theme'));
|
||||
}
|
||||
|
||||
public function share(){
|
||||
|
||||
$code = $this->request->param('code');
|
||||
//分享信息
|
||||
$info = Shares::where('code',$code)->find();
|
||||
|
||||
//分享信息不存在
|
||||
if(empty($info)){
|
||||
return $this->fetch('404');
|
||||
}
|
||||
|
||||
// 判断类型
|
||||
if($info['type']){
|
||||
$storeInfo = Folders::where('uid',$info['uid'])
|
||||
->where('id',$info['source_id'])
|
||||
->find();
|
||||
}else{
|
||||
$storeInfo = Stores::where('uid',$info['uid'])
|
||||
->where('id',$info['source_id'])
|
||||
->find();
|
||||
}
|
||||
|
||||
// 存储文件/夹不存在
|
||||
if(empty($storeInfo)){
|
||||
return $this->fetch('404');
|
||||
}
|
||||
|
||||
// 获取文件所有者信息
|
||||
$user = Users::where('id',$storeInfo['uid'])->field('id,nickname,avatar,status,group,desc')->find();
|
||||
|
||||
if(empty($user) || $user['status'] == 0){
|
||||
return $this->fetch('404');
|
||||
}
|
||||
|
||||
$this->assign('share_id',$info['id']);
|
||||
$this->assign('is_login',$this->is_login);
|
||||
$this->assign('url',getShareUrl($code));
|
||||
|
||||
$share_pwd = Cookie::get('share_key_'.$code);
|
||||
|
||||
// 需要密码
|
||||
if($info['pwd_status'] == 1 && !empty($info['pwd']) && $share_pwd != $info['pwd']){
|
||||
// VIP用户组
|
||||
$vip_group = config('vip.vip_group');
|
||||
|
||||
$is_vip = $user['group'] == $vip_group ? 1 : 0;
|
||||
|
||||
$desc = empty(trim($user['desc'])) ? '暂无签名' : $user['desc'];
|
||||
|
||||
$this->assign('desc',$desc);
|
||||
$this->assign('userinfo',$user);
|
||||
$this->assign('is_vip',$is_vip);
|
||||
return $this->fetch('pwd');
|
||||
}
|
||||
|
||||
// 显示界面
|
||||
if($info['type']){
|
||||
|
||||
// 目录显示
|
||||
$base_info = [
|
||||
'id' => $storeInfo['id'],
|
||||
'username' => getSafeNickname($user['nickname']),
|
||||
'folder_name' => $storeInfo['folder_name'],
|
||||
'desc' => $storeInfo['desc'],
|
||||
'is_desc' => empty(trim($storeInfo['desc'])) ? 0 : 1,
|
||||
'create_time' => $storeInfo->getData('create_time')
|
||||
];
|
||||
|
||||
Folders::where('id',$storeInfo['id'])->where('uid',$storeInfo['uid'])->setInc('count_open',1);
|
||||
|
||||
// 获取当前文件夹下所有文件
|
||||
$share_list = FileManage::ShareListFile($storeInfo['id'],$user['id']);
|
||||
|
||||
$this->assign('share_list',$share_list);
|
||||
$this->assign('info',$base_info);
|
||||
|
||||
if($this->request->isMobile()){
|
||||
return $this->fetch('folder_wap');
|
||||
}
|
||||
return $this->fetch('folder');
|
||||
}else{
|
||||
|
||||
// 统计数据
|
||||
Profit::record($storeInfo['uid'],$storeInfo['id'],'view');
|
||||
|
||||
// 文件显示
|
||||
$file_info = [
|
||||
'username' => getSafeNickname($user['nickname']),
|
||||
'file_name' => $storeInfo['origin_name'],
|
||||
'size' => countSize($storeInfo['size']),
|
||||
'create_time' => friendDate($storeInfo->getData('create_time'))
|
||||
];
|
||||
|
||||
// 获取VIP价格
|
||||
$vip_rule = getVipRule();
|
||||
|
||||
// 获取最高价格
|
||||
$vip_max = end($vip_rule)['id'];
|
||||
|
||||
$download = getFileDownloadUrl($storeInfo['shares_id'],$storeInfo['id']);
|
||||
|
||||
$this->assign('vip_max',$vip_max);
|
||||
$this->assign('vip_rule',$vip_rule);
|
||||
$this->assign('download',$download);
|
||||
$this->assign('user',$this->userInfo);
|
||||
$this->assign('info',$file_info);
|
||||
return $this->fetch('file');
|
||||
}
|
||||
}
|
||||
|
||||
public function report(){
|
||||
$share_id = input('get.share_id');
|
||||
|
||||
$share = Shares::where('id',$share_id)->find();
|
||||
|
||||
if(empty($share)){
|
||||
return $this->fetch('user/err',['msg' => '传递参数不正确']);
|
||||
}
|
||||
|
||||
// 获取文件信息
|
||||
if($share['type'] == 1){
|
||||
$files = Folders::where('id',$share['source_id'])->find();
|
||||
}else{
|
||||
$files = Stores::where('id',$share['source_id'])->find();
|
||||
}
|
||||
|
||||
// 文件信息获取失败
|
||||
if(empty($files)){
|
||||
return $this->fetch('user/err',['msg' => '文件信息获取失败']);
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
$share_user = Users::where('id',$share['uid'])->find();
|
||||
|
||||
if(empty($share_user)){
|
||||
return $this->fetch('user/err',['msg' => '举报用户不存在']);
|
||||
}
|
||||
|
||||
// 分享信息
|
||||
$report = [
|
||||
'share_id' => $share['id'],
|
||||
'source_name' => $share['type'] ? $files['folder_name'] : $files['origin_name'],
|
||||
'source_url' => getShareUrl($share['code']),
|
||||
'source_uid' => $share['uid'],
|
||||
'source_username' => $share_user['username'],
|
||||
'source_type' => $share['type'],
|
||||
'create_time' => time(),
|
||||
'real_ip' => request()->ip()
|
||||
];
|
||||
|
||||
if($this->request->isPost()){
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'contact|联系方式' => 'require',
|
||||
'content|详细描述' => 'require',
|
||||
'type|危害类别' => 'require'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
|
||||
$report_key = 'report_'.$share_id;
|
||||
|
||||
if(!empty(Cookie::get($report_key))){
|
||||
return json(['code' => 0,'msg' => '您已经举报过了,请勿重复举报']);
|
||||
}
|
||||
|
||||
$report = array_merge($report,$data);
|
||||
|
||||
Cookie::set('report_'.$share_id,'1');
|
||||
|
||||
Reports::create($report);
|
||||
|
||||
return json(['code' => 1,'msg' => '举报反馈成功']);
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function qrcode(){
|
||||
$url = input('get.url');
|
||||
if(!empty($url)){
|
||||
Qrcode::createQrcode($url);
|
||||
}
|
||||
}
|
||||
|
||||
public function share_pass(){
|
||||
$id = input('post.id');
|
||||
$pass = input('post.pass');
|
||||
|
||||
$id = intval($id);
|
||||
|
||||
$info = Shares::where('id',$id)->find();
|
||||
|
||||
if(empty($info)){
|
||||
return json(['status' => 0,'msg' => '分享数据不存在']);
|
||||
}
|
||||
|
||||
if($pass != $info['pwd']){
|
||||
return json(['status' => 0,'msg' => '提取码不正确']);
|
||||
}
|
||||
|
||||
Cookie::set('share_key_'.$info['code'],$info['pwd'],3600);
|
||||
|
||||
return json(['status' => 1,'msg' => '提取码正确']);
|
||||
}
|
||||
|
||||
public function download(){
|
||||
$file = input('get.file');
|
||||
$shares_id = input('get.shares');
|
||||
$timestamp = input('get.timestamp');
|
||||
$sign = input('get.sign');
|
||||
$is_count = input('get.is_count');
|
||||
|
||||
// 数据签名校验
|
||||
if(!getDownloadFileSignVerify([
|
||||
'file' => $file,
|
||||
'shares' => $shares_id,
|
||||
'timestamp' => $timestamp
|
||||
],$sign)){
|
||||
return $this->fetch('user/err',['msg' => '数据sign签名校验失败']);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// 获取存储数据
|
||||
$stores = Stores::get($file);
|
||||
|
||||
if(empty($stores)){
|
||||
throw new Exception('文件数据不存在');
|
||||
}
|
||||
|
||||
if($is_count){
|
||||
// 统计数据
|
||||
Profit::record($stores['uid'],$stores['id'],'down',1);
|
||||
$download_url = getFileDownloadUrl($stores['shares_id'],$stores['id'],0);
|
||||
return redirect($download_url);
|
||||
}
|
||||
|
||||
// 获取存储策略
|
||||
$policy = $stores->getPolicy();
|
||||
|
||||
if(empty($policy)){
|
||||
throw new Exception('文件数据存储策略不存在');
|
||||
}
|
||||
|
||||
// 禁止下载
|
||||
if($this->groupData['speed'] === 0){
|
||||
throw new Exception('您当前的用户组禁止下载文件');
|
||||
}
|
||||
|
||||
// 远程文件下载
|
||||
if($policy->type == 'remote'){
|
||||
$down_url = getDownloadRemote($stores['file_name'],$stores['origin_name'],$policy->config['server_uri'],$this->groupData['speed'],$policy->config['access_token']);
|
||||
$this->redirect($down_url);
|
||||
}
|
||||
|
||||
// 存储驱动下载
|
||||
switch ($policy->type){
|
||||
case 'aliyunoss':
|
||||
$driver = new AliyunOss(0,0,0);
|
||||
break;
|
||||
case 'txyunoss':
|
||||
$driver = new TxyunOss(0,0,0);
|
||||
break;
|
||||
default:
|
||||
$driver = new Local(0,0,0);
|
||||
break;
|
||||
}
|
||||
|
||||
// 下载
|
||||
return $driver->download($stores,$this->groupData['speed'],$policy);
|
||||
|
||||
}catch (Exception $e){
|
||||
return $this->fetch('user/err',['msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function return_callback(){
|
||||
$param = input('get.');
|
||||
$sign = input('get.sign');
|
||||
|
||||
if($sign != $this->sign_param($param)){
|
||||
$this->error('签名校验失败');
|
||||
}
|
||||
|
||||
$order = Order::where('trade_no',$param['out_trade_no'])->find();
|
||||
|
||||
if(empty($order)){
|
||||
$this->error('订单数据不存在');
|
||||
}
|
||||
|
||||
if($order['status'] != 1){
|
||||
$this->error('订单未支付成功');
|
||||
}
|
||||
|
||||
$this->success('VIP开通/续费成功','none','请刷新当前页面,然后重新点击下载');
|
||||
}
|
||||
|
||||
public function return_notify(){
|
||||
$param = input('get.');
|
||||
$sign = input('get.sign');
|
||||
|
||||
if($sign != $this->sign_param($param)){
|
||||
exit('Fail is sign verify.');
|
||||
}
|
||||
|
||||
if($param['trade_status'] != 'TRADE_SUCCESS'){
|
||||
exit('Fail is trade status.');
|
||||
}
|
||||
|
||||
// 查找订单
|
||||
$order = Order::where('trade_no',$param['out_trade_no'])->find();
|
||||
|
||||
if(empty($order)){
|
||||
exit('Fail order is not found.');
|
||||
}
|
||||
|
||||
// 查找用户
|
||||
$user = Users::where('id',$order['uid'])->find();
|
||||
|
||||
if(empty($user)){
|
||||
exit('Fail order user is not found.');
|
||||
}
|
||||
|
||||
// VIP用户组
|
||||
$vip_group = config('vip.vip_group');
|
||||
// 开通/续费时长
|
||||
$vip_expire = $order['vip_day'] * 86400;
|
||||
// 开通/续费VIP
|
||||
if($user['group'] == $vip_group){
|
||||
// 续费VIP
|
||||
$user['group_expire'] = $user['group_expire'] + $vip_expire;
|
||||
}else{
|
||||
// 开通VIP
|
||||
$user['group'] = $vip_group;
|
||||
$user['group_expire'] = time() + $vip_expire;
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
$user->save();
|
||||
|
||||
// 完成订单
|
||||
$order['status'] = 1;
|
||||
$order['out_trade_no'] = $param['trade_no'];
|
||||
$order['pay_time'] = time();
|
||||
|
||||
// 保存订单
|
||||
$order->save();
|
||||
|
||||
// 查询分成用户
|
||||
$share = Shares::where('id',$order['profit_id'])->find();
|
||||
// 参与分成
|
||||
if(!empty($share)){
|
||||
// 用户分成奖励比例
|
||||
$vip_profit = config('vip.vip_profit');
|
||||
// 计算用户分成奖励
|
||||
$user_profit = ($order['money'] / 100) * $vip_profit;
|
||||
// 通用户不奖励
|
||||
if($order['uid'] != $share['uid']){
|
||||
// 奖励
|
||||
Record::addRecord($share['uid'],0,'VIP分成',$user_profit,'用户'.getSafeNickname($user['nickname']).'开通VIP奖励');
|
||||
// 记录
|
||||
Profit::record($share['uid'],$share['source_id'],'count_order',1);
|
||||
Profit::record($share['uid'],$share['source_id'],'count_order_yes',1);
|
||||
Profit::record($share['uid'],$share['source_id'],'count_money',$order['money']);
|
||||
Profit::record($share['uid'],$share['source_id'],'count_profit',$user_profit);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理完成
|
||||
exit('SUCCESS');
|
||||
}
|
||||
|
||||
protected function sign_param($param): string
|
||||
{
|
||||
unset($param['sign']);
|
||||
unset($param['sign_type']);
|
||||
ksort($param);
|
||||
reset($param);
|
||||
return md5(urldecode(http_build_query($param)) . config('pay.api_key'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\FileManage;
|
||||
use app\common\model\Folders;
|
||||
use app\common\model\Profit;
|
||||
use app\common\model\Shares;
|
||||
use app\common\model\Stores;
|
||||
|
||||
class Recycle extends Home
|
||||
{
|
||||
|
||||
public function index(){
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
public function list(){
|
||||
|
||||
$limit = input('get.rows',20);
|
||||
$page = input('get.page',1);
|
||||
$search = input('get.search','');
|
||||
|
||||
$file_list = FileManage::RecycleFile($search,$this->userInfo['id'],$page,$limit);
|
||||
return json($file_list);
|
||||
}
|
||||
|
||||
|
||||
public function clear(){
|
||||
// 清空回收站
|
||||
$uid = $this->userInfo['id'];
|
||||
|
||||
$success_ids = [];
|
||||
|
||||
try {
|
||||
$stores = Stores::onlyTrashed()->where('uid',$uid)->select();
|
||||
foreach ($stores as $file){
|
||||
// 删除文件
|
||||
$file->delete(true);
|
||||
// 删除分享信息
|
||||
Profit::where('file_id',$file['id'])
|
||||
->where('uid',$uid)
|
||||
->delete();
|
||||
|
||||
$success_ids[] = $file['id'];
|
||||
}
|
||||
|
||||
$folders = Folders::onlyTrashed()->where('uid',$uid)->select();
|
||||
foreach ($folders as $dir){
|
||||
// 删除文件
|
||||
$dir->delete(true);
|
||||
// 获取子文件夹
|
||||
$folder_object = getFolderChildFiles($uid,$dir['id']);
|
||||
|
||||
// 子文件夹
|
||||
if(!empty($folder_object['folder'])){
|
||||
Folders::where('id','in',$folder_object['folder'])->delete(true);
|
||||
}
|
||||
|
||||
// 子文件
|
||||
if(!empty($folder_object['file'])){
|
||||
// 删除文件
|
||||
Stores::where('id','in',$folder_object['file'])->delete(true);
|
||||
// 删除分享信息
|
||||
Profit::where('file_id','in',$folder_object['file'])
|
||||
->where('uid',$uid)
|
||||
->delete();
|
||||
}
|
||||
|
||||
$success_ids[] = $dir['id'];
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '成功清空回收站,共删除 '.count($success_ids).' 个文件(夹)~']);
|
||||
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function restore(){
|
||||
$ids = input('get.ids');
|
||||
$idFs = input('get.idFs');
|
||||
|
||||
$uid = $this->userInfo['id'];
|
||||
|
||||
$success_ids = [];
|
||||
|
||||
if(empty($ids) && empty($idFs)){
|
||||
return json(['status' => 0,'msg' => '请选择需要还原的文件(夹)~']);
|
||||
}
|
||||
|
||||
if(!empty($ids)){
|
||||
try {
|
||||
$stores = Stores::onlyTrashed()->where('id','in',$ids)->where('uid',$uid)->select();
|
||||
foreach ($stores as $file){
|
||||
//还原文件
|
||||
$file->restore();
|
||||
$success_ids[] = $file['id'];
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($idFs)){
|
||||
try {
|
||||
$folders = Folders::onlyTrashed()->where('id','in',$idFs)->where('uid',$uid)->select();
|
||||
foreach ($folders as $dir){
|
||||
//还原文件
|
||||
$dir->restore();
|
||||
$success_ids[] = $dir['id'];
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '成功还原 '.count($success_ids).' 个文件(夹)~','data' => $success_ids]);
|
||||
}
|
||||
|
||||
|
||||
public function delete(){
|
||||
$ids = input('get.ids');
|
||||
$idFs = input('get.idFs');
|
||||
|
||||
$uid = $this->userInfo['id'];
|
||||
$success_ids = [];
|
||||
|
||||
if(empty($ids) && empty($idFs)){
|
||||
return json(['status' => 0,'msg' => '请选择需要删除的文件(夹)~']);
|
||||
}
|
||||
|
||||
if(!empty($ids)){
|
||||
try {
|
||||
$stores = Stores::onlyTrashed()->where('id','in',$ids)->where('uid',$uid)->select();
|
||||
foreach ($stores as $file){
|
||||
// 删除文件
|
||||
$file->delete(true);
|
||||
|
||||
// 删除分享信息
|
||||
Profit::where('file_id',$file['id'])
|
||||
->where('uid',$uid)
|
||||
->delete();
|
||||
|
||||
$success_ids[] = $file['id'];
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($idFs)){
|
||||
try {
|
||||
$folders = Folders::onlyTrashed()->where('id','in',$idFs)->where('uid',$uid)->select();
|
||||
foreach ($folders as $dir){
|
||||
// 删除文件
|
||||
$dir->delete(true);
|
||||
|
||||
// 获取子文件夹
|
||||
$folder_object = getFolderChildFiles($uid,$dir['id']);
|
||||
|
||||
// 子文件夹
|
||||
if(!empty($folder_object['folder'])){
|
||||
Folders::where('id','in',$folder_object['folder'])->delete(true);
|
||||
}
|
||||
|
||||
// 子文件
|
||||
if(!empty($folder_object['file'])){
|
||||
// 删除文件
|
||||
Stores::where('id','in',$folder_object['file'])->delete(true);
|
||||
// 删除分享信息
|
||||
Profit::where('file_id','in',$folder_object['file'])
|
||||
->where('uid',$uid)
|
||||
->delete();
|
||||
}
|
||||
|
||||
$success_ids[] = $dir['id'];
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return json(['status' => 1,'msg' => '成功彻底删除 '.count($success_ids).' 个文件(夹)~','data' => $success_ids]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\Profit;
|
||||
use app\common\model\Record;
|
||||
use app\common\model\Withdraw;
|
||||
|
||||
class Share extends Home
|
||||
{
|
||||
|
||||
public function index(){
|
||||
$time = input('get.time');
|
||||
$query = [];
|
||||
if(!empty($time)){
|
||||
$query = ['time' => $time];
|
||||
}else{
|
||||
$time = date('Y-m-d');
|
||||
}
|
||||
|
||||
$list = Profit::where('uid',$this->userInfo['id'])
|
||||
->whereBetweenTime('create_time',$time)
|
||||
->order([
|
||||
'count_money' => 'desc',
|
||||
'id' => 'desc'
|
||||
])
|
||||
->paginate(15,false,[
|
||||
'query' => $query
|
||||
]);
|
||||
|
||||
$this->assign('time',$time);
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function record(){
|
||||
|
||||
$list = Record::where('uid',$this->userInfo['id'])->order('create_time desc')->paginate(15);
|
||||
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function withdraw(){
|
||||
|
||||
$list = Withdraw::where('uid',$this->userInfo['id'])->order('create_time desc')->paginate(15);
|
||||
$money = Withdraw::where('uid',$this->userInfo['id'])->where('status',1)->sum('money');
|
||||
|
||||
$this->assign('money',$money);
|
||||
$this->assign('list',$list);
|
||||
$this->assign('amount',$this->userInfo['amount']);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function echarts(){
|
||||
$id = input('get.id');
|
||||
|
||||
// 获取当月所有时间
|
||||
$month_time = [];
|
||||
$time_type = [];
|
||||
|
||||
for ($i = 0;$i < 30;$i++){
|
||||
$month_time[] = strtotime('-'.$i.' day');
|
||||
$time_type[] = "'".date('m-d',strtotime('-'.$i.' day'))."'";
|
||||
}
|
||||
|
||||
$time_type = array_reverse($time_type);
|
||||
$time_type = implode(',',$time_type);
|
||||
|
||||
// 获取当月间隔时间
|
||||
$start_time = strtotime(date('Y-m-d',strtotime('-29 day')));
|
||||
$end_time = strtotime('now');
|
||||
|
||||
// 获取30天的统计记录
|
||||
$profit = Profit::where('file_id',$id)
|
||||
->where('uid',$this->userInfo['id'])
|
||||
->whereTime('create_time','>=',$start_time)
|
||||
->whereTime('create_time','<=',$end_time)
|
||||
->order('create_time desc')
|
||||
->select();
|
||||
|
||||
|
||||
// 图表统计
|
||||
$series_reg = str_split(str_repeat('0',30),1);
|
||||
$series_order = str_split(str_repeat('0',30),1);
|
||||
$series_money = str_split(str_repeat('0',30),1);
|
||||
|
||||
foreach ($month_time as $key => $item){
|
||||
$item_time = date('Y-m-d',$item);
|
||||
foreach ($profit as $profit_item){
|
||||
$profit_time = date('Y-m-d',$profit_item['create_time']);
|
||||
if($item_time == $profit_time){
|
||||
$series_reg[$key] = $profit_item['count_reg'];
|
||||
$series_order[$key] = $profit_item['count_order_yes'];
|
||||
$series_money[$key] = $profit_item['count_money'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$series_reg = array_reverse($series_reg);
|
||||
$series_reg = implode(',',$series_reg);
|
||||
|
||||
$series_order = array_reverse($series_order);
|
||||
$series_order = implode(',',$series_order);
|
||||
|
||||
$series_money = array_reverse($series_money);
|
||||
$series_money = implode(',',$series_money);
|
||||
|
||||
$this->assign('profit',$profit);
|
||||
|
||||
$this->assign('series_reg',$series_reg);
|
||||
$this->assign('series_order',$series_order);
|
||||
$this->assign('series_money',$series_money);
|
||||
$this->assign('time_type',$time_type);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\FileManage;
|
||||
use app\common\model\FileUpload;
|
||||
use app\common\model\Groups;
|
||||
use app\common\model\Policys;
|
||||
use app\common\model\Shares;
|
||||
use app\common\model\Stores;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Upload extends Home
|
||||
{
|
||||
|
||||
public function index(){
|
||||
|
||||
// 上传策略
|
||||
$policy = $this->getPolicy();
|
||||
|
||||
// 上传文件数量限制
|
||||
$upload_limit = 20;
|
||||
|
||||
// 上传限制
|
||||
$upload_rule = [
|
||||
'upsize_byte' => $this->groupData['max_storage'],
|
||||
'upsize' => countSize($this->groupData['max_storage']),
|
||||
'fsize_byte' => $this->groupData['max_storage'] * $upload_limit,
|
||||
'fsize' => countSize($this->groupData['max_storage'] * $upload_limit),
|
||||
];
|
||||
|
||||
$folder_id = FileManage::getFolderAllowPid(0,$this->userInfo['id']);
|
||||
|
||||
$upload_api = $this->getPolicyUrl($policy,[
|
||||
'md' => 'upload',
|
||||
'size' => $this->groupData['max_storage'],
|
||||
'notify' => url('upload/notify','',false,true),
|
||||
'root_folder_id' => $folder_id
|
||||
]);
|
||||
|
||||
$this->assign('upload_api',$upload_api);
|
||||
|
||||
$this->assign('upload_limit',$upload_limit);
|
||||
$this->assign('upload_rule',$upload_rule);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function notify(){
|
||||
$data = input('get.');
|
||||
$policy_id = input('get.policy_id');
|
||||
$sign = input('get.sign');
|
||||
|
||||
$policy = Policys::where('id',$policy_id)->find();
|
||||
|
||||
if(empty($policy)){
|
||||
exit('Fail policy not found.');
|
||||
}
|
||||
|
||||
if(empty($sign)){
|
||||
exit('Fail is no params a sign.');
|
||||
}
|
||||
|
||||
$remote_sign = $this->remote_sign_params($data,$policy['config']['access_token']);
|
||||
|
||||
if($remote_sign != $sign){
|
||||
exit('Fail is sign verify.');
|
||||
}
|
||||
|
||||
// 加入数据库
|
||||
$data = [
|
||||
'uid' => $data['uid'],
|
||||
'origin_name' => $data['name'],
|
||||
'file_name' => $data['path'],
|
||||
'size' => $data['size'],
|
||||
'meta' => '',
|
||||
'mime_type' => $data['mime'],
|
||||
'ext' => $data['ext'],
|
||||
'parent_folder' => $data['folder_id'],
|
||||
'policy_id' => $policy['id'],
|
||||
'dir' => '',
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$file_id = (new Stores)->insertGetId($data);
|
||||
|
||||
$share_id = Shares::addShare($data['uid'],$file_id,0);
|
||||
|
||||
Stores::where('id',$file_id)->update(['shares_id' => $share_id]);
|
||||
|
||||
exit('UPLOAD_SUCCESS');
|
||||
}
|
||||
|
||||
public function file(){
|
||||
|
||||
// 存储策略
|
||||
$policy = $this->getPolicy();
|
||||
|
||||
try {
|
||||
// 上传文件
|
||||
$result = (new FileUpload())
|
||||
->source($this->userInfo['id'],$policy,$this->groupData['max_storage'])
|
||||
->upload();
|
||||
|
||||
return json($result);
|
||||
|
||||
}catch (Exception $e){
|
||||
return json(['code' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Home;
|
||||
use app\common\model\Certify;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\Profit;
|
||||
use app\common\model\Record;
|
||||
use app\common\model\Shares;
|
||||
use app\common\model\Users;
|
||||
use app\common\model\Withdraw;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use function MongoDB\BSON\toRelaxedExtendedJSON;
|
||||
|
||||
class User extends Home
|
||||
{
|
||||
|
||||
public function index(){
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function login(){
|
||||
$layer = input('get.layer',0);
|
||||
$share_id = input('get.share_id',0);
|
||||
|
||||
if(empty($layer)) $layer = 0;
|
||||
|
||||
if((new Users)->login_auth('default')){
|
||||
return redirect('user/index');
|
||||
}
|
||||
|
||||
if($this->request->isPost()){
|
||||
$username = input('post.username');
|
||||
$password = input('post.password');
|
||||
|
||||
try {
|
||||
(new Users)->login($username,$password,'default');
|
||||
|
||||
return json(['status' => 1,'msg' => '登录成功']);
|
||||
}catch (\Throwable $e){
|
||||
return json(['status' => 0,'msg' => '登录失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('share_id',$share_id);
|
||||
$this->assign('layer',$layer);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function register(){
|
||||
$data = input('post.');
|
||||
$share_id = input('get.share_id');
|
||||
|
||||
if(config('register.allow_register') != 1){
|
||||
return json(['code' => 0,'msg' => '管理员已关闭用户注册功能']);
|
||||
}
|
||||
|
||||
$result = $this->validate($data,[
|
||||
'nickname|昵称' => 'require|chsAlphaNum|length:2,18',
|
||||
'username|用户帐号' => 'require|alphaNum|length:6,26',
|
||||
'password|登录密码' => 'require|alphaNum|length:6,18',
|
||||
'email|安全邮箱' => 'require|email'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
|
||||
$default_group = config('register.default_group');
|
||||
|
||||
// 获取注册来源
|
||||
$share_info = Shares::where('id',$share_id)->find();
|
||||
|
||||
try {
|
||||
(new Users)->register(
|
||||
$data['username'],
|
||||
$data['email'],
|
||||
$data['password'],
|
||||
$default_group,
|
||||
['nickname' => $data['nickname']]
|
||||
);
|
||||
|
||||
// 统计数据
|
||||
if(!empty($share_info)){
|
||||
Profit::record($share_info['uid'],$share_info['source_id'],'reg',1);
|
||||
}
|
||||
|
||||
return json(['code' => 1,'msg' => '注册帐号成功']);
|
||||
}catch (Exception $e){
|
||||
return json(['code' => 0,'msg' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function logout(){
|
||||
(new Users)->logout('default');
|
||||
$this->success('退出登录成功','index/index');
|
||||
}
|
||||
|
||||
public function vip(){
|
||||
$share_id = input('get.share_id',0);
|
||||
$is_layer = input('get.layer',0);
|
||||
|
||||
$rule = getVipRule();
|
||||
|
||||
$this->assign('rule',$rule);
|
||||
$this->assign('share_id',$share_id);
|
||||
$this->assign('is_layer',$is_layer);
|
||||
|
||||
if($this->request->isMobile()){
|
||||
return $this->fetch('vip_wap');
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function payment(){
|
||||
$vip_type = input('get.vip',0);
|
||||
$share_id = input('get.share_id',0);
|
||||
$pay_type = input('get.pay_type',0);
|
||||
|
||||
if($pay_type != 'alipay' && $pay_type != 'wxpay'){
|
||||
$this->error('支付方式错误');
|
||||
}
|
||||
|
||||
// 获取VIP规则
|
||||
$rule = getVipRule();
|
||||
|
||||
// 判断VIP类型是否正确
|
||||
if(!isset($rule[$vip_type])){
|
||||
$this->error('VIP类型不存在');
|
||||
}
|
||||
|
||||
// 获取VIP价格
|
||||
$vip_config = $rule[$vip_type];
|
||||
|
||||
// 获取支付配置信息
|
||||
$config = config('pay.');
|
||||
|
||||
// 本地创建订单号
|
||||
$trade_no = strtoupper('VIP_'.date('YmdHis').substr(md5(uniqid()),0,10));
|
||||
|
||||
// 订单数据
|
||||
$order = [
|
||||
'uid' => $this->userInfo['id'],
|
||||
'trade_no' => $trade_no,
|
||||
'type' => $pay_type,
|
||||
'profit_id' => $share_id,
|
||||
'money' => $vip_config['money'],
|
||||
'vip_day' => $vip_config['day'],
|
||||
'create_time' => time(),
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
Order::create($order);
|
||||
|
||||
// 获取支付参数
|
||||
$pay_params = [
|
||||
'pid' => $config['api_pid'],
|
||||
'type' => $pay_type,
|
||||
'out_trade_no' => $trade_no,
|
||||
'notify_url' => url('index/return_notify','',false,true),
|
||||
'return_url' => url('index/return_callback','',false,true),
|
||||
'name' => 'VIP会员',
|
||||
'money' => $vip_config['money']
|
||||
];
|
||||
|
||||
ksort($pay_params);
|
||||
reset($pay_params);
|
||||
|
||||
$pay_params['sign'] = md5(urldecode(http_build_query($pay_params)) . $config['api_key']);
|
||||
$pay_params['sign_type'] = strtoupper('MD5');
|
||||
|
||||
|
||||
$pay_html = '<html><head><title>正在跳转支付</title><meta name="viewport" content="width=device-width, initial-scale=1.0">';
|
||||
$pay_html .= '<style>body{background-color: #e6e6e6;}.pay_btn{border: 0;display: block;width: 100%;font-size: 22px;font-weight: bold;outline: none;height: 250px;color: #989898;line-height: 250px;background-color: transparent;}</style>';
|
||||
$pay_html .= '</head><body>';
|
||||
// 拼接支付表单
|
||||
$pay_html .= '<form id="alipaysubmit" name="alipaysubmit" action="'.$config['api_gateway'].'" method="POST">';
|
||||
foreach ($pay_params as $key => $val) {
|
||||
$pay_html .= '<input type="hidden" name="'.$key.'" value="'.$val.'" />';
|
||||
}
|
||||
$pay_html .= '<input class="pay_btn" type="submit" value="订单创建中..."></form>';
|
||||
$pay_html .= "<script>document.forms['alipaysubmit'].submit();</script>";
|
||||
$pay_html .= '</body></html>';
|
||||
|
||||
exit($pay_html);
|
||||
}
|
||||
|
||||
public function vip_close(){
|
||||
$lock_time = time() - 7200;
|
||||
Order::where('status',0)
|
||||
->limit(50)
|
||||
->whereTime('create_time','<=',$lock_time)
|
||||
->update(['status' => 2]);
|
||||
|
||||
return json(['code' => 1,'msg' => '关闭订单成功']);
|
||||
}
|
||||
|
||||
public function forget(){
|
||||
if($this->request->isPost()){
|
||||
$email = input('post.email');
|
||||
$result = $this->validate(['email' => $email],['email|安全邮箱' => 'require|email']);
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
$info = Users::where('email',$email)->find();
|
||||
if(empty($info)){
|
||||
return json(['code' => 0,'msg' => '该邮箱未绑定帐号']);
|
||||
}
|
||||
|
||||
// 获取key
|
||||
$forget_key = 'forget_'.str_replace(['@','.'],['_','_'],$info['email']);
|
||||
|
||||
// 邮件发送记录
|
||||
$forget_info = Cache::get($forget_key);
|
||||
|
||||
if(!empty($forget_info)){
|
||||
if($forget_info['time'] >= time()){
|
||||
return json(['code' => 0,'msg' => '发送频繁,请等待'.($forget_info['time'] - time()) . ' 秒后重新发送']);
|
||||
}
|
||||
}
|
||||
|
||||
$hash_key = bin2hex($forget_key);
|
||||
$sign = md5($forget_key . time());
|
||||
// 设置找回密码key
|
||||
Cache::set($forget_key,[
|
||||
'uid' => $info['id'],
|
||||
'email' => $info['email'],
|
||||
'sign' => $sign,
|
||||
'time' => time() + 60
|
||||
],600);
|
||||
|
||||
// 找回密码链接
|
||||
$forget_url = url('user/reset','',false,true)."?key={$hash_key}&sign={$sign}";
|
||||
|
||||
// 发送邮件
|
||||
if(!sendEmail($info['username'],$forget_url)){
|
||||
return json(['code' => 0,'msg' => '找回密码邮件发送失败,请联系管理员处理']);
|
||||
}
|
||||
|
||||
return json(['code' => 1,'msg' => '找回密码邮件发送成功']);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function reset(){
|
||||
$key = input('get.key');
|
||||
$sign = input('get.sign');
|
||||
|
||||
if(empty($key) || empty($sign)){
|
||||
return $this->fetch('err',['msg' => '参数缺失']);
|
||||
}
|
||||
|
||||
$forget_key = @hex2bin($key);
|
||||
|
||||
if(empty($forget_key)){
|
||||
return $this->fetch('err',['msg' => '参数验证失败']);
|
||||
}
|
||||
|
||||
$forget_info = Cache::get($forget_key);
|
||||
|
||||
if(empty($forget_info)){
|
||||
return $this->fetch('err',['msg' => '访问错误,无效链接']);
|
||||
}
|
||||
|
||||
if($sign != $forget_info['sign']){
|
||||
return $this->fetch('err',['msg' => '访问错误,数据签名校验失败']);
|
||||
}
|
||||
|
||||
if($this->request->isPost()){
|
||||
$pwd = input('post.pwd');
|
||||
$result = $this->validate(['pwd' => $pwd],['pwd|密码' => 'require|alphaNum|length:6,18']);
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
|
||||
$password = md5($pwd . config('app.pass_salt'));
|
||||
|
||||
Users::where('id',$forget_info['uid'])->update(['password' => $password]);
|
||||
|
||||
return json(['code' => 1,'msg' => '密码修改成功']);
|
||||
}
|
||||
|
||||
$this->assign('key',$key);
|
||||
$this->assign('sign',$sign);
|
||||
return $this->fetch('reset');
|
||||
}
|
||||
|
||||
public function auth(){
|
||||
if($this->request->isPost()){
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'name|姓名' => 'require|chs|length:2,20',
|
||||
'idcard|身份证号码' => 'require|idCard'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
|
||||
if($this->userInfo['is_auth']){
|
||||
return json(['code' => 0,'msg' => '您已完成实名认证,请勿重复提交']);
|
||||
}
|
||||
|
||||
if(Certify::where('uid',$this->userInfo['id'])->where('status',0)->count() > 0){
|
||||
return json(['code' => 0,'msg' => '您提交的实名资料正在审核中,请勿重复提交']);
|
||||
}
|
||||
|
||||
Certify::create([
|
||||
'uid' => $this->userInfo['id'],
|
||||
'name' => $data['name'],
|
||||
'idcard' => $data['idcard'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
return json(['code' => 1,'msg' => '实名资料已提交,请耐心等待审核']);
|
||||
}
|
||||
|
||||
$this->assign('info',$this->userInfo->getCertify());
|
||||
$this->assign('is_auth',$this->userInfo['is_auth']);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function withdraw(){
|
||||
if($this->request->isPost()){
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'tx_money|提现金额' => 'require|float',
|
||||
'alipay_account|支付宝帐号' => 'require|max:255',
|
||||
'alipay_name|支付宝姓名' => 'require|chs|max:60'
|
||||
]);
|
||||
|
||||
if($result !== true) return json(['code' => 0,'msg' => $result]);
|
||||
|
||||
$withdraw_count = Withdraw::where('uid',$this->userInfo['id'])
|
||||
->where('status',0)
|
||||
->whereTime('create_time','d')
|
||||
->count();
|
||||
|
||||
if($withdraw_count > 0){
|
||||
return json(['code' => 0,'msg' => '您有一条提现申请还在审核中,请勿重复提交']);
|
||||
}
|
||||
|
||||
if(floatval($this->userInfo['amount']) - floatval($data['tx_money']) < 0){
|
||||
return json(['code' => 0,'msg' => '您的账户余额不足']);
|
||||
}
|
||||
|
||||
// 扣钱
|
||||
Record::addRecord($this->userInfo['id'],1,'用户提现',$data['tx_money'],'余额提现'.$data['tx_money'].'元至支付宝');
|
||||
|
||||
// 添加记录
|
||||
Withdraw::create([
|
||||
'uid' => $this->userInfo['id'],
|
||||
'money' => $data['tx_money'],
|
||||
'alipay_account' => $data['alipay_account'],
|
||||
'alipay_name' => $data['alipay_name'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
return json(['code' => 1,'msg' => '申请成功,请等待处理']);
|
||||
}
|
||||
$this->assign('amount',$this->userInfo['amount']);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function info(){
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function change_pass(){
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'old_password|原密码' => 'require|alphaNum|length:6,18',
|
||||
'password|新密码' => 'require|alphaNum|length:6,18'
|
||||
]);
|
||||
|
||||
if($result !== true){
|
||||
return json(['code' => 0,'msg' => $result]);
|
||||
}
|
||||
|
||||
|
||||
$en_password = md5($data['old_password'] . config('app.pass_salt'));
|
||||
|
||||
if($en_password != $this->userInfo['password']){
|
||||
return json(['code' => 0,'msg' => '修改失败,原密码不正确']);
|
||||
}
|
||||
|
||||
$en_new_password = md5($data['password'] . config('app.pass_salt'));
|
||||
|
||||
Users::where('id',$this->userInfo['id'])->update([
|
||||
'password' => $en_new_password
|
||||
]);
|
||||
|
||||
return json(['code' => 1,'msg' => '密码修改成功,请重新登录']);
|
||||
}
|
||||
|
||||
public function set_userinfo(){
|
||||
$data = input('post.');
|
||||
$result = $this->validate($data,[
|
||||
'nickname|昵称' => 'require|max:30|min:1',
|
||||
'desc|个性签名' => 'max:255'
|
||||
]);
|
||||
|
||||
if($result !== true){
|
||||
return json(['code' => 0,'msg' => $result]);
|
||||
}
|
||||
|
||||
Users::where('id',$this->userInfo['id'])->update([
|
||||
'nickname' => $data['nickname'],
|
||||
'desc' => $data['desc']
|
||||
]);
|
||||
|
||||
return json(['code' => 1,'msg' => '更新用户资料成功']);
|
||||
}
|
||||
|
||||
public function upload_avatar(){
|
||||
$file = request()->file('file');
|
||||
|
||||
if(!$file){
|
||||
return json(['code' => 0,'msg' => '请选择上传的文件','data' => []]);
|
||||
}
|
||||
|
||||
// 根目录
|
||||
$root_path = getSafeDirSeparator(realpath(env('root_path') . './public').'/avatar');
|
||||
|
||||
$info = $file->validate(['size'=> 2097152,'ext'=>'jpg,png,gif'])->move($root_path);
|
||||
if($info){
|
||||
$avatar = '/avatar/'.str_replace('\\','/',$info->getSaveName());
|
||||
Users::where('id',$this->userInfo['id'])->update([
|
||||
'avatar' => $avatar
|
||||
]);
|
||||
return json(['code' => 1,'msg' => '头像上传成功','data' => []]);
|
||||
}else{
|
||||
// 上传失败获取错误信息
|
||||
return json(['code' => 0,'msg' => $file->getError(),'data' => []]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user