154 lines
5.1 KiB
PHP
154 lines
5.1 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\home\controller;
|
|
use api\Httpcurl;
|
|
use app\service\SwooleService;
|
|
use think\facade\Db;
|
|
use think\facade\Request;
|
|
use think\facade\View;
|
|
|
|
class Upload extends Base
|
|
{
|
|
public function index()
|
|
{
|
|
$order_sn = Request::instance()->param('id');
|
|
!empty($order_sn) or $this->error('参数错误');
|
|
//获取数据
|
|
$response = Httpcurl::request(config('app.get_evus_detail_url'), 'post', ['order_sn' => $order_sn, 'model' => MODEL]);
|
|
if ($response[3]) {
|
|
return $this->error("订单不存在,请重新提交", url('detail/index'));
|
|
}
|
|
$pay_result = json_decode($response[0], true);
|
|
if (empty($pay_result)) {
|
|
return $this->error("订单不存在,请重新提交", url('detail/index'));
|
|
}
|
|
if (!$pay_result['code']) {
|
|
return $this->error($pay_result['msg'], url('detail/index'));
|
|
}
|
|
|
|
Db::name('images_log')->where(['order_sn' => $order_sn, 'type' => 'evus登记信息(护照、签证)有误'])->update([
|
|
'is_read' => 1
|
|
]);
|
|
View::assign('data', $pay_result['data']);
|
|
return View::fetch();
|
|
|
|
}
|
|
public function upload_file()
|
|
{
|
|
// 获取上传的文件
|
|
$file = request()->file('file');
|
|
|
|
if (!$file) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '请选择上传文件',
|
|
]);
|
|
}
|
|
$imgdata = file_get_contents($file->getPathname());
|
|
/*同时上传护照文件*/
|
|
$fileName = date('YmdHis') . uniqid() . '.' . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
|
try {
|
|
$client = SwooleService::getInstance();
|
|
|
|
$client->sendTask([
|
|
'type' => 'upload_ali',
|
|
'data' => [
|
|
'Bucket' => BUCKET,
|
|
'Key' => $fileName, //重命名的文件名
|
|
'file_content' => base64_encode($imgdata),
|
|
]
|
|
]);
|
|
$client->close();
|
|
return json([
|
|
'code' => 1,
|
|
'msg' => '上传成功',
|
|
'path' => OSS_URL . $fileName,
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '上传失败',
|
|
'path' => ''
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function file_upload()
|
|
{
|
|
// 获取上传的文件
|
|
$file = request()->file('file');
|
|
|
|
if (!$file) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '请选择上传文件',
|
|
]);
|
|
}
|
|
$imgdata = file_get_contents($file->getPathname());
|
|
$fileName = date('YmdHis') . uniqid() . '.' . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
|
try {
|
|
$client = SwooleService::getInstance();
|
|
$client->sendTask([
|
|
'type' => 'upload_ali',
|
|
'data' => [
|
|
'Bucket' => BUCKET,
|
|
'Key' => $fileName, //重命名的文件名
|
|
'file_content' => base64_encode($imgdata),
|
|
]
|
|
]);
|
|
$client->close();
|
|
return json([
|
|
'code' => 1,
|
|
'msg' => '上传成功',
|
|
'path' => OSS_URL . $fileName,
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '上传失败',
|
|
'path' => '',
|
|
]);
|
|
}
|
|
}
|
|
public function doapply()
|
|
{
|
|
$params = Request::instance()->param();
|
|
!empty($params['order_sn']) or $this->error('参数错误');
|
|
$imgs = array_filter($params['imgs']);
|
|
if (empty($imgs)) {
|
|
return $this->error('请上传照片');
|
|
}
|
|
$order = Db::name('msg')->where(['order_sn' => $params['order_sn']])->find();
|
|
if (empty($order)) {
|
|
return $this->error('数据错误,请联系管理员');
|
|
}
|
|
$data = [];
|
|
foreach ($imgs as $ig) {
|
|
$data[] = [
|
|
'order_id' => $order['id'],
|
|
'order_sn' => $order['order_sn'],
|
|
'last_name' => $order['last_name'],
|
|
'first_name' => $order['first_name'],
|
|
'passport_number' => $order['passport_number'],
|
|
'visa_foil_number' => $order['visa_foil_number'],
|
|
'img' => $ig
|
|
];
|
|
}
|
|
$res = Db::name('images')->insertAll($data);
|
|
if ($res > 0) {
|
|
//推送发票
|
|
$url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4c22d454-4abf-48bb-8512-fb591a3ac545';
|
|
$data = array('msgtype' => 'text', 'text' => [
|
|
'content' => "订单号{$order['order_sn']}已成功更新护照信息,请及时处理",
|
|
]);
|
|
Httpcurl::request($url, 'post', json_encode($data), [
|
|
'Content-Type: application/json'
|
|
]);
|
|
return $this->success('上传成功', url('home/index/index'));
|
|
} else {
|
|
return $this->error('数据错误,请联系管理员');
|
|
}
|
|
}
|
|
}
|