...
|
...
|
@@ -3,13 +3,12 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\exception\UploadException;
|
|
|
use app\common\library\Upload;
|
|
|
use app\common\model\Area;
|
|
|
use app\common\model\Version;
|
|
|
use fast\Random;
|
|
|
use Qiniu\Auth;
|
|
|
use think\Config;
|
|
|
use think\Hook;
|
|
|
use EasyWeChat\Factory;
|
|
|
use think\Db;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -63,70 +62,122 @@ class Common extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传文件
|
|
|
* @ApiMethod (POST)
|
|
|
* @param File $file 文件流
|
|
|
* 上传文件-七牛
|
|
|
*
|
|
|
* @ApiTitle (上传文件-七牛)
|
|
|
* @ApiSummary (测试描述信息)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiParams (name="file", type="file", required=true, description="用户名")
|
|
|
*/
|
|
|
public function upload()
|
|
|
public function uploadQiniu()
|
|
|
{
|
|
|
Config::set('default_return_type', 'json');
|
|
|
//必须设定cdnurl为空,否则cdnurl函数计算错误
|
|
|
Config::set('upload.cdnurl', '');
|
|
|
$chunkid = $this->request->post("chunkid");
|
|
|
if ($chunkid) {
|
|
|
if (!Config::get('upload.chunking')) {
|
|
|
$this->error(__('Chunk file disabled'));
|
|
|
}
|
|
|
$action = $this->request->post("action");
|
|
|
$chunkindex = $this->request->post("chunkindex/d");
|
|
|
$chunkcount = $this->request->post("chunkcount/d");
|
|
|
$filename = $this->request->post("filename");
|
|
|
$method = $this->request->method(true);
|
|
|
if ($action == 'merge') {
|
|
|
$attachment = null;
|
|
|
//合并分片文件
|
|
|
try {
|
|
|
$upload = new Upload();
|
|
|
$attachment = $upload->merge($chunkid, $chunkcount, $filename);
|
|
|
} catch (UploadException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
|
|
} elseif ($method == 'clean') {
|
|
|
//删除冗余的分片文件
|
|
|
try {
|
|
|
$upload = new Upload();
|
|
|
$upload->clean($chunkid);
|
|
|
} catch (UploadException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success();
|
|
|
} else {
|
|
|
//上传分片文件
|
|
|
//默认普通上传文件
|
|
|
$file = $this->request->file('file');
|
|
|
try {
|
|
|
$upload = new Upload($file);
|
|
|
$upload->chunk($chunkid, $chunkindex, $chunkcount);
|
|
|
} catch (UploadException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success();
|
|
|
$config = get_addon_config('qiniu');
|
|
|
$file = $this->request->file('file');
|
|
|
if (!$file || !$file->isValid()) {
|
|
|
$this->error("请上传有效的文件");
|
|
|
}
|
|
|
$fileInfo = $file->getInfo();
|
|
|
$filePath = $file->getRealPath() ?: $file->getPathname();
|
|
|
preg_match('/(\d+)(\w+)/', $config['maxsize'], $matches);
|
|
|
$type = strtolower($matches[2]);
|
|
|
$typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3];
|
|
|
$size = (int)$config['maxsize'] * pow(1024000, isset($typeDict[$type]) ? $typeDict[$type] : 0);
|
|
|
|
|
|
$suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
|
|
|
$suffix = $suffix ? $suffix : 'file';
|
|
|
|
|
|
$md5 = md5_file($filePath);
|
|
|
$search = ['$(year)', '$(mon)', '$(day)', '$(etag)', '$(ext)'];
|
|
|
$replace = [date("Y"), date("m"), date("d"), $md5, '.' . $suffix];
|
|
|
$object = ltrim(str_replace($search, $replace, $config['savekey']), '/');
|
|
|
|
|
|
$mimetypeArr = explode(',', strtolower($config['mimetype']));
|
|
|
$typeArr = explode('/', $fileInfo['type']);
|
|
|
|
|
|
//检查文件大小
|
|
|
if (!$file->checkSize($size)) {
|
|
|
$this->error("起过最大可上传文件限制");
|
|
|
}
|
|
|
|
|
|
//验证文件后缀
|
|
|
if ($config['mimetype'] !== '*' &&
|
|
|
(
|
|
|
!in_array($suffix, $mimetypeArr)
|
|
|
|| (stripos($typeArr[0] . '/', $config['mimetype']) !== false && (!in_array($fileInfo['type'], $mimetypeArr) && !in_array($typeArr[0] . '/*', $mimetypeArr)))
|
|
|
)
|
|
|
) {
|
|
|
$this->error(__('上传格式限制'));
|
|
|
}
|
|
|
|
|
|
$savekey = '/' . $object;
|
|
|
|
|
|
$uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1);
|
|
|
$fileName = substr($savekey, strripos($savekey, '/') + 1);
|
|
|
//先上传到本地
|
|
|
$splInfo = $file->move(ROOT_PATH . '/public' . $uploadDir, $fileName);
|
|
|
if ($splInfo) {
|
|
|
$extparam = $this->request->post();
|
|
|
$filePath = $splInfo->getRealPath() ?: $splInfo->getPathname();
|
|
|
|
|
|
$sha1 = sha1_file($filePath);
|
|
|
$imagewidth = $imageheight = 0;
|
|
|
if (in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf', 'pdf'])) {
|
|
|
$imgInfo = getimagesize($splInfo->getPathname());
|
|
|
$imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth;
|
|
|
$imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight;
|
|
|
}
|
|
|
} else {
|
|
|
$attachment = null;
|
|
|
//默认普通上传文件
|
|
|
$file = $this->request->file('file');
|
|
|
$params = array(
|
|
|
'admin_id' => session('admin.id'),
|
|
|
'user_id' => $this->auth->id,
|
|
|
'filesize' => $fileInfo['size'],
|
|
|
'imagewidth' => $imagewidth,
|
|
|
'imageheight' => $imageheight,
|
|
|
'imagetype' => $suffix,
|
|
|
'imageframes' => 0,
|
|
|
'mimetype' => $fileInfo['type'],
|
|
|
'url' => $uploadDir . $splInfo->getSaveName(),
|
|
|
'uploadtime' => time(),
|
|
|
'storage' => 'local',
|
|
|
'sha1' => $sha1,
|
|
|
'extparam' => json_encode($extparam),
|
|
|
);
|
|
|
$attachment = Attachment::create(array_filter($params), true);
|
|
|
$policy = array(
|
|
|
'saveKey' => ltrim($savekey, '/'),
|
|
|
);
|
|
|
$auth = new Auth($config['accessKey'], $config['secretKey']);
|
|
|
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
|
|
|
$multipart = [
|
|
|
['name' => 'token', 'contents' => $token],
|
|
|
[
|
|
|
'name' => 'file',
|
|
|
'contents' => fopen($filePath, 'r'),
|
|
|
'filename' => $fileName,
|
|
|
]
|
|
|
];
|
|
|
try {
|
|
|
$upload = new Upload($file);
|
|
|
$attachment = $upload->upload();
|
|
|
} catch (UploadException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
$res = $client->request('POST', $config['uploadurl'], [
|
|
|
'multipart' => $multipart
|
|
|
]);
|
|
|
$code = $res->getStatusCode();
|
|
|
//成功不做任何操作
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
$attachment->delete();
|
|
|
unlink($filePath);
|
|
|
$this->error("上传失败");
|
|
|
}
|
|
|
|
|
|
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
|
|
}
|
|
|
$url = '/' . $object;
|
|
|
|
|
|
//上传成功后将存储变更为qiniu
|
|
|
$attachment->storage = 'qiniu';
|
|
|
$attachment->save();
|
|
|
$this->success("上传成功", $url);
|
|
|
} else {
|
|
|
$this->error('上传失败');
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -306,7 +357,159 @@ class Common extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/Common/AgreementOperation)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="battery_id", type="string", required=true, description="电池类型ID")
|
|
|
* @ApiParams (name="type", type="string", required=true, description="操作:1=同意,2=拒绝,3=修改租金,4=终止协议,5=删除协议")
|
|
|
* @ApiParams (name="id", type="string", required=true, description="协议ID")
|
|
|
* @ApiParams (name="money", type="int", required=true, description="修改后的金额")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
)
|
|
|
*/
|
|
|
public function AgreementOperation()
|
|
|
{
|
|
|
$UserId = $this->IsToken($this->request->header());
|
|
|
$params = $this->request->param();
|
|
|
$IsSeller = Db::name('agreement')
|
|
|
->alias('a')
|
|
|
->join('seller s', 's.id=a.seller_id')
|
|
|
->where('s.user_id', $UserId)
|
|
|
->where('a.id', $params['id'])
|
|
|
->find();
|
|
|
if (empty($IsSeller)) {
|
|
|
$this->error('参数错误', 0);
|
|
|
}
|
|
|
//同意签订协议
|
|
|
if ($params['type'] == 1) {
|
|
|
$res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 1, 'updatetime' => time(), 'EXP_time' => time() + 86400 * 30]);
|
|
|
}
|
|
|
//拒绝签订协议
|
|
|
if ($params['type'] == 2) {
|
|
|
$res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 4, 'updatetime' => time()]);
|
|
|
//拒绝签订协议 给予用户退款
|
|
|
$OrderSn = Db::name('agreement')->where('id', $params['id'])->value('OrderSn');
|
|
|
$PayOrderInfo = Db::name('pay_order')->where('OrderSn', $OrderSn)->where('type', 1)->find();
|
|
|
$TuiMoney = $PayOrderInfo['UpMoney'] + $PayOrderInfo['Money'];
|
|
|
//配置
|
|
|
$config = [
|
|
|
'app_id' => 'wx6a9080f20326f817',
|
|
|
'payment' => [
|
|
|
'merchant_id' => '1603658973',
|
|
|
'key' => '8695A8185xyzKcdEVfreewayShenzhen',
|
|
|
'cert_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_cert.pem', // XXX: 绝对路径!!!!
|
|
|
'key_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_key.pem', // XXX: 绝对路径!!!!
|
|
|
],
|
|
|
];
|
|
|
$app = Factory::officialAccount($config);
|
|
|
try {
|
|
|
$result = $app->refund->byTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $TuiMoney); // 总金额 100, 退款 80,操作员:商户号
|
|
|
//更改订单状态为已退款
|
|
|
Db::name('pay_order')->where('OrderSn', $OrderSn)->where('PayOrder', $PayOrderInfo['PayOrder'])->update(['type' => 0]);
|
|
|
} catch (Exception $e) {
|
|
|
$e->getMessage();
|
|
|
}
|
|
|
if (!$result) {
|
|
|
$this->error('退款失败', 0);
|
|
|
die;
|
|
|
}
|
|
|
}
|
|
|
//修改租金
|
|
|
if ($params['type'] == 3) {
|
|
|
$res = Db::name('agreement')->where('id', $params['id'])->update(['MonthMoney' => $params['money'], 'updatetime' => time()]);
|
|
|
}
|
|
|
//终止协议
|
|
|
if ($params['type'] == 4) {
|
|
|
$res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 2, 'updatetime' => time()]);
|
|
|
}
|
|
|
//删除协议
|
|
|
if ($params['type'] == 5) {
|
|
|
$res = Db::name('agreement')->where('id', $params['id'])->delete();
|
|
|
}
|
|
|
$this->res($res);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 公共接口
|
|
|
* @ApiTitle (押金退还操作)
|
|
|
* @ApiSummary (押金退还操作)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/Common/TuikuanOperation)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="type", type="string", required=true, description="操作:1=通过,2=拒绝,3=删除记录")
|
|
|
* @ApiParams (name="id", type="string", required=true, description="协议ID")
|
|
|
* @ApiParams (name="bili", type="string", required=true, description="退款百分比/ 1为百分之100/0.1为百分之10")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
)
|
|
|
*/
|
|
|
public function TuikuanOperation()
|
|
|
{
|
|
|
$UserId = $this->IsToken($this->request->header());
|
|
|
$params = $this->request->param();
|
|
|
$IsSeller = Db::name('agreement')
|
|
|
->alias('a')
|
|
|
->join('seller s', 's.id=a.seller_id')
|
|
|
->where('s.user_id', $UserId)
|
|
|
->where('a.id', $params['id'])
|
|
|
->value('seller_id');
|
|
|
if (empty($IsSeller)) {
|
|
|
$this->error('参数错误', 0);
|
|
|
}
|
|
|
$OrderInfo = Db::name('agreement')->where('id', $params['id'])->find();
|
|
|
if ($params['type'] == 3) {
|
|
|
$res = Db::name('tuikuan')->where('OrderSn', $OrderInfo['OrderSn'])->where('seller_id', $IsSeller)->delete();
|
|
|
} else {
|
|
|
$IsUpdateAgreement = Db::name('agreement')->where('id', $params['id'])->update(['refind_status' => $params['type']]);
|
|
|
if (!$IsUpdateAgreement) {
|
|
|
$this->error('协议状态更改失败', 0);
|
|
|
}
|
|
|
$res = Db::name('tuikuan')->where('OrderSn', $OrderInfo['OrderSn'])->where('seller_id', $IsSeller)->update(['status' => $params['status']]);
|
|
|
if ($params['type'] == 1) {
|
|
|
//拒绝签订协议 给予用户退款
|
|
|
$OrderSn = Db::name('agreement')->where('id', $params['id'])->value('OrderSn');
|
|
|
$PayOrderInfo = Db::name('pay_order')->where('OrderSn', $OrderSn)->where('type', 1)->find();
|
|
|
$TuiMoney = $PayOrderInfo['UpMoney'] * $params['bili'] + $PayOrderInfo['Money'];
|
|
|
//配置
|
|
|
$config = [
|
|
|
'app_id' => 'wx6a9080f20326f817',
|
|
|
'payment' => [
|
|
|
'merchant_id' => '1603658973',
|
|
|
'key' => '8695A8185xyzKcdEVfreewayShenzhen',
|
|
|
'cert_path' => ' / home / wwwroot / fast / book / addons / epay / certs / apiclient_cert . pem', // XXX: 绝对路径!!!!
|
|
|
'key_path' => ' / home / wwwroot / fast / book / addons / epay / certs / apiclient_key . pem', // XXX: 绝对路径!!!!
|
|
|
],
|
|
|
];
|
|
|
$app = Factory::officialAccount($config);
|
|
|
try {
|
|
|
$result = $app->refund->byTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $TuiMoney); // 总金额 100, 退款 80,操作员:商户号
|
|
|
//更改订单状态为已退款
|
|
|
Db::name('pay_order')->where('OrderSn', $OrderSn)->where('PayOrder', $PayOrderInfo['PayOrder'])->update(['type' => 0]);
|
|
|
} catch (Exception $e) {
|
|
|
$e->getMessage();
|
|
|
}
|
|
|
if (!$result) {
|
|
|
$this->error('退款失败', 0);
|
|
|
die;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$this->res($res);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 公共接口
|
|
|
* @ApiTitle (删除订单)
|
|
|
* @ApiSummary (删除订单)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/Common/DeleteOrder)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="OrderSn", type="string", required=true, description="订单号")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
...
|
...
|
@@ -314,4 +517,80 @@ class Common extends Api |
|
|
'msg':'返回成功',
|
|
|
)
|
|
|
*/
|
|
|
public function DeleteOrder()
|
|
|
{
|
|
|
$UserId = $this->IsToken($this->request->header());
|
|
|
$OrderSn = input('OrderSn');
|
|
|
$Arr = Db::name('order')
|
|
|
->alias('o')
|
|
|
->join('stor s', 's.id=a.stor_id')
|
|
|
->where('s.user_id', $UserId)
|
|
|
->where('o.OrderSn', $OrderSn)
|
|
|
->find();
|
|
|
if (empty($Arr)) {
|
|
|
$this->error('参数错误', 0);
|
|
|
die;
|
|
|
}
|
|
|
$res = Db::name('order')->where('OrderSn', $OrderSn)->delete();
|
|
|
$this->res($res);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 公共接口
|
|
|
* @ApiTitle (账户押金操作)
|
|
|
* @ApiSummary (账户押金操作)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/Common/UpMoneyOperation)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="OrderSn", type="string", required=true, description="订单号")
|
|
|
* @ApiParams (name="type", type="int", required=true, description="操作:1=取消签约,2=删除,3=退还押金")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
)
|
|
|
*/
|
|
|
public function UpMoneyOperation()
|
|
|
{
|
|
|
$UserId = $this->IsToken($this->request->header());
|
|
|
$params = $this->request->param();
|
|
|
$OrderInfo = Db::name('agreement')->where('OrderSn', $params['OrderSn'])->where('user_id', $UserId)->find();
|
|
|
if (empty($OrderInfo)) {
|
|
|
$this->error('参数错误', 0);
|
|
|
}
|
|
|
if ($params['type'] == 1) {
|
|
|
if ($OrderInfo['status'] != 0) {
|
|
|
$this->error('不能取消签约', 0);
|
|
|
}
|
|
|
$res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->update(['status' => 4]);
|
|
|
$this->Tuikuan($params['OrderSn']);
|
|
|
}
|
|
|
if ($params['type'] == 2) {
|
|
|
if ($OrderInfo['status'] == 2 || $OrderInfo['status'] == 4) {
|
|
|
$res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->delete();
|
|
|
} else {
|
|
|
$this->error('不能删除订单', 0);
|
|
|
die;
|
|
|
}
|
|
|
}
|
|
|
if ($params['type'] == 3) {
|
|
|
$res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->update(['status' => 2, 'refind_status' => 0]);
|
|
|
$data = [
|
|
|
'user_id' => $UserId,
|
|
|
'OrderSn' => $params['OrderSn'],
|
|
|
'status' => 0,
|
|
|
'seller_id' => $OrderInfo['seller_id'],
|
|
|
'createtime' => time(),
|
|
|
'updatetime' => time()
|
|
|
];
|
|
|
$IsSave = Db::name('tuikuan')->insert($data);
|
|
|
if (!$IsSave) {
|
|
|
$this->error('添加退款记录失败', 0);
|
|
|
die;
|
|
|
}
|
|
|
}
|
|
|
$this->res($res);
|
|
|
}
|
|
|
} |
...
|
...
|
|