Files
juipphp/app/tencent/controller/Index.php

105 lines
3.2 KiB
PHP
Raw Normal View History

2024-02-29 15:13:44 +08:00
<?php
namespace app\tencent\controller;
use fastphp\base\Controller;
use app\tencent\model\Agreement as AgreementModel;
2024-04-16 16:01:09 +08:00
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
2024-02-29 15:13:44 +08:00
class Index extends Controller
{
2024-04-16 16:01:09 +08:00
private $accessKey = 'AfRhvJoAKL24ftGcHMor1WwSpVdular7L7X97JNY';
private $secretKey = 'OyyU-6M45oDZAlVsf8fH0RFALGxTNHAT-yR6cmtU';
private $bucket = 'zip9';
2024-02-29 15:13:44 +08:00
public function upload()
{
$username = $this->userinfo['LoginName'];
$userid = $this->userinfo['UserId'];
$data = $_POST;
2024-04-16 16:01:09 +08:00
$xieyi = $_FILES['xieyi'];
$size_limit = 30 * 1024 * 1024;
if ($xieyi['size']>$size_limit) {
echo json_encode(['code' => -1,'msg'=>'文件过大仅限30M']);
die;
}
2024-02-29 15:13:44 +08:00
$agreement_data = [
'user_id' => $userid,
'username' => $username,
2024-04-16 14:05:31 +08:00
'status' => 1,
2024-02-29 15:13:44 +08:00
'describe' => $data['describe'],
];
2024-04-16 14:05:31 +08:00
if(!$data['status']) {
echo json_encode(['code' => -1,'msg'=>'失败']);die;
2024-02-29 15:13:44 +08:00
}
2024-04-16 16:01:09 +08:00
$auth = new Auth($this->accessKey, $this->secretKey);
// 初始化 UploadManager 对象并进行文件的上传。
$uploadMgr = new UploadManager();
// 需要填写你的 Access Key 和 Secret Key
// 构建鉴权对象
// 生成上传 Token
$token = $auth->uploadToken($this->bucket);
// 要上传文件的本地路径
$xieyi_filePath = $xieyi['tmp_name'];
// 上传到存储后保存的文件名
$xieyi_key = $username.'-'.time().'.png';
2024-04-16 14:05:31 +08:00
2024-04-16 16:01:09 +08:00
// 调用 UploadManager 的 putFile 方法进行文件的上传。
list($ret, $err) = $uploadMgr->putFile($token, $xieyi_key, $xieyi_filePath, null, 'application/octet-stream', true, null, 'v2');
$agreement_data['xieyi'] = 'http://zip.juip.com/'.$xieyi_key;
2024-02-29 15:13:44 +08:00
2024-04-16 14:05:31 +08:00
$agreement_model = new AgreementModel;
$status = $agreement_model->add($agreement_data);
2024-02-29 15:13:44 +08:00
2024-04-16 14:05:31 +08:00
if ($status) {
echo json_encode(['code' => 1,'msg'=>'成功']);
2024-02-29 15:13:44 +08:00
} else {
2024-04-16 14:05:31 +08:00
echo json_encode(['code' => -1,'msg'=>'失败']);
2024-02-29 15:13:44 +08:00
}
}
2024-02-29 17:35:18 +08:00
public function get_list() {
$get_data = json_decode(file_get_contents("php://input"), true);
$agreement_model = new AgreementModel;
$where = [];
$page = 0;
if (!empty($get_data['username'])) {
$where['username'] = $get_data['username'];
}
if (isset($get_data['PageIndex'])) {
$page = ($get_data['PageIndex'] - 1) * 50;
}
$list = $agreement_model->getListPage($where, '*', 'id desc', "$page,50");
$data = [
'Code' => 30000,
'Data' => $list,
'Message' => '',
'TotalCount' => (int)$agreement_model->getCount($where)['count'],
];
echo json_encode($data);
}
2024-02-29 18:47:00 +08:00
public function get_is_upload() {
$agreement_model = new AgreementModel;
$data = $agreement_model->getOne(['user_id' => $this->userinfo['UserId']]);
if (empty($data)) {
echo json_encode(['code'=>-1]);
} else {
echo json_encode(['code'=>1]);
}
}
2024-02-29 15:13:44 +08:00
}