From e58a2b6ca49a3d56eab615e55643d29b4cde2673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwanyongkang=E2=80=9D?= <“937888580@qq.com”> Date: Wed, 17 Apr 2024 16:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=A7=A3=E9=99=A4=E5=B1=8F?= =?UTF-8?q?=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/agent/controller/Index.php | 79 ++++++++++++++++++++++++++++++++ app/tencent/controller/Index.php | 9 +++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/app/agent/controller/Index.php b/app/agent/controller/Index.php index 8ed402d..c2ec6bb 100644 --- a/app/agent/controller/Index.php +++ b/app/agent/controller/Index.php @@ -8,10 +8,18 @@ use app\agent\model\User as UserModel; use alipay\AliverifyPublic as Aliverify; use extend\alisms\Sms; use extend\redis\Redisop; +use app\tencent\model\Agreement as AgreementModel; +use Qiniu\Auth; +use Qiniu\Storage\UploadManager; class Index { + private $accessKey = 'AfRhvJoAKL24ftGcHMor1WwSpVdular7L7X97JNY'; + private $secretKey = 'OyyU-6M45oDZAlVsf8fH0RFALGxTNHAT-yR6cmtU'; + private $bucket = 'zip9'; + + //代理登录 public function login() { @@ -287,4 +295,75 @@ class Index echo json_encode($userinfo); } + public function upload() + { + + $user_model = new UserModel; + + $data = $_POST; + + $username = $data['username']; + + $userinfo = $user_model->getOne(['LoginCode' => $username]); + + if (empty($userinfo)) { + echo json_encode(['code' => -1,'msg'=>'手机号不存在!']);die; + } + + $userid = $userinfo['Id']; + + $agreement_model = new AgreementModel; + + $is_ipload = $agreement_model->getOne(['user_id' => $userid]); + + if (!empty($is_ipload)) { + echo json_encode(['code' => -1,'msg'=>'已经上传过!']);die; + } + + + + $xieyi = $_FILES['xieyi']; + + $size_limit = 30 * 1024 * 1024; + if ($xieyi['size']>$size_limit) { + echo json_encode(['code' => -1,'msg'=>'文件过大,仅限30M']); + die; + } + + $agreement_data = [ + 'user_id' => $userid, + 'username' => $username, + 'status' => 1, + 'describe' => $data['describe'], + ]; + if(!$data['status']) { + echo json_encode(['code' => -1,'msg'=>'失败']);die; + } + + $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'; + + // 调用 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; + + $status = $agreement_model->add($agreement_data); + + if ($status) { + echo json_encode(['code' => 1,'msg'=>'成功']); + } else { + echo json_encode(['code' => -1,'msg'=>'失败']); + } + } + + } \ No newline at end of file diff --git a/app/tencent/controller/Index.php b/app/tencent/controller/Index.php index 7dc785a..981ec14 100644 --- a/app/tencent/controller/Index.php +++ b/app/tencent/controller/Index.php @@ -20,6 +20,14 @@ class Index extends Controller $userid = $this->userinfo['UserId']; $data = $_POST; + $agreement_model = new AgreementModel; + + $is_ipload = $agreement_model->getOne(['user_id' => $userid]); + + if (!empty($is_ipload)) { + echo json_encode(['code' => -1,'msg'=>'已经上传过!']);die; + } + $xieyi = $_FILES['xieyi']; @@ -56,7 +64,6 @@ class Index extends Controller 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; - $agreement_model = new AgreementModel; $status = $agreement_model->add($agreement_data); if ($status) {