正在显示
6 个修改的文件
包含
777 行增加
和
60 行删除
@@ -3,13 +3,12 @@ | @@ -3,13 +3,12 @@ | ||
3 | namespace app\api\controller; | 3 | namespace app\api\controller; |
4 | 4 | ||
5 | use app\common\controller\Api; | 5 | use app\common\controller\Api; |
6 | -use app\common\exception\UploadException; | ||
7 | -use app\common\library\Upload; | ||
8 | use app\common\model\Area; | 6 | use app\common\model\Area; |
9 | use app\common\model\Version; | 7 | use app\common\model\Version; |
10 | -use fast\Random; | 8 | +use Qiniu\Auth; |
11 | use think\Config; | 9 | use think\Config; |
12 | use think\Hook; | 10 | use think\Hook; |
11 | +use EasyWeChat\Factory; | ||
13 | use think\Db; | 12 | use think\Db; |
14 | 13 | ||
15 | /** | 14 | /** |
@@ -63,70 +62,122 @@ class Common extends Api | @@ -63,70 +62,122 @@ class Common extends Api | ||
63 | } | 62 | } |
64 | 63 | ||
65 | /** | 64 | /** |
66 | - * 上传文件 | 65 | + * 上传文件-七牛 |
66 | + * | ||
67 | + * @ApiTitle (上传文件-七牛) | ||
68 | + * @ApiSummary (测试描述信息) | ||
67 | * @ApiMethod (POST) | 69 | * @ApiMethod (POST) |
68 | - * @param File $file 文件流 | 70 | + * @ApiParams (name="file", type="file", required=true, description="用户名") |
69 | */ | 71 | */ |
70 | - public function upload() | 72 | + public function uploadQiniu() |
71 | { | 73 | { |
72 | - Config::set('default_return_type', 'json'); | ||
73 | - //必须设定cdnurl为空,否则cdnurl函数计算错误 | ||
74 | - Config::set('upload.cdnurl', ''); | ||
75 | - $chunkid = $this->request->post("chunkid"); | ||
76 | - if ($chunkid) { | ||
77 | - if (!Config::get('upload.chunking')) { | ||
78 | - $this->error(__('Chunk file disabled')); | ||
79 | - } | ||
80 | - $action = $this->request->post("action"); | ||
81 | - $chunkindex = $this->request->post("chunkindex/d"); | ||
82 | - $chunkcount = $this->request->post("chunkcount/d"); | ||
83 | - $filename = $this->request->post("filename"); | ||
84 | - $method = $this->request->method(true); | ||
85 | - if ($action == 'merge') { | ||
86 | - $attachment = null; | ||
87 | - //合并分片文件 | ||
88 | - try { | ||
89 | - $upload = new Upload(); | ||
90 | - $attachment = $upload->merge($chunkid, $chunkcount, $filename); | ||
91 | - } catch (UploadException $e) { | ||
92 | - $this->error($e->getMessage()); | ||
93 | - } | ||
94 | - $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); | ||
95 | - } elseif ($method == 'clean') { | ||
96 | - //删除冗余的分片文件 | ||
97 | - try { | ||
98 | - $upload = new Upload(); | ||
99 | - $upload->clean($chunkid); | ||
100 | - } catch (UploadException $e) { | ||
101 | - $this->error($e->getMessage()); | ||
102 | - } | ||
103 | - $this->success(); | ||
104 | - } else { | ||
105 | - //上传分片文件 | ||
106 | - //默认普通上传文件 | 74 | + $config = get_addon_config('qiniu'); |
107 | $file = $this->request->file('file'); | 75 | $file = $this->request->file('file'); |
108 | - try { | ||
109 | - $upload = new Upload($file); | ||
110 | - $upload->chunk($chunkid, $chunkindex, $chunkcount); | ||
111 | - } catch (UploadException $e) { | ||
112 | - $this->error($e->getMessage()); | 76 | + if (!$file || !$file->isValid()) { |
77 | + $this->error("请上传有效的文件"); | ||
113 | } | 78 | } |
114 | - $this->success(); | 79 | + $fileInfo = $file->getInfo(); |
80 | + $filePath = $file->getRealPath() ?: $file->getPathname(); | ||
81 | + preg_match('/(\d+)(\w+)/', $config['maxsize'], $matches); | ||
82 | + $type = strtolower($matches[2]); | ||
83 | + $typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3]; | ||
84 | + $size = (int)$config['maxsize'] * pow(1024000, isset($typeDict[$type]) ? $typeDict[$type] : 0); | ||
85 | + | ||
86 | + $suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION)); | ||
87 | + $suffix = $suffix ? $suffix : 'file'; | ||
88 | + | ||
89 | + $md5 = md5_file($filePath); | ||
90 | + $search = ['$(year)', '$(mon)', '$(day)', '$(etag)', '$(ext)']; | ||
91 | + $replace = [date("Y"), date("m"), date("d"), $md5, '.' . $suffix]; | ||
92 | + $object = ltrim(str_replace($search, $replace, $config['savekey']), '/'); | ||
93 | + | ||
94 | + $mimetypeArr = explode(',', strtolower($config['mimetype'])); | ||
95 | + $typeArr = explode('/', $fileInfo['type']); | ||
96 | + | ||
97 | + //检查文件大小 | ||
98 | + if (!$file->checkSize($size)) { | ||
99 | + $this->error("起过最大可上传文件限制"); | ||
115 | } | 100 | } |
116 | - } else { | ||
117 | - $attachment = null; | ||
118 | - //默认普通上传文件 | ||
119 | - $file = $this->request->file('file'); | ||
120 | - try { | ||
121 | - $upload = new Upload($file); | ||
122 | - $attachment = $upload->upload(); | ||
123 | - } catch (UploadException $e) { | ||
124 | - $this->error($e->getMessage()); | 101 | + |
102 | + //验证文件后缀 | ||
103 | + if ($config['mimetype'] !== '*' && | ||
104 | + ( | ||
105 | + !in_array($suffix, $mimetypeArr) | ||
106 | + || (stripos($typeArr[0] . '/', $config['mimetype']) !== false && (!in_array($fileInfo['type'], $mimetypeArr) && !in_array($typeArr[0] . '/*', $mimetypeArr))) | ||
107 | + ) | ||
108 | + ) { | ||
109 | + $this->error(__('上传格式限制')); | ||
125 | } | 110 | } |
126 | 111 | ||
127 | - $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); | 112 | + $savekey = '/' . $object; |
113 | + | ||
114 | + $uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1); | ||
115 | + $fileName = substr($savekey, strripos($savekey, '/') + 1); | ||
116 | + //先上传到本地 | ||
117 | + $splInfo = $file->move(ROOT_PATH . '/public' . $uploadDir, $fileName); | ||
118 | + if ($splInfo) { | ||
119 | + $extparam = $this->request->post(); | ||
120 | + $filePath = $splInfo->getRealPath() ?: $splInfo->getPathname(); | ||
121 | + | ||
122 | + $sha1 = sha1_file($filePath); | ||
123 | + $imagewidth = $imageheight = 0; | ||
124 | + if (in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf', 'pdf'])) { | ||
125 | + $imgInfo = getimagesize($splInfo->getPathname()); | ||
126 | + $imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth; | ||
127 | + $imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight; | ||
128 | } | 128 | } |
129 | + $params = array( | ||
130 | + 'admin_id' => session('admin.id'), | ||
131 | + 'user_id' => $this->auth->id, | ||
132 | + 'filesize' => $fileInfo['size'], | ||
133 | + 'imagewidth' => $imagewidth, | ||
134 | + 'imageheight' => $imageheight, | ||
135 | + 'imagetype' => $suffix, | ||
136 | + 'imageframes' => 0, | ||
137 | + 'mimetype' => $fileInfo['type'], | ||
138 | + 'url' => $uploadDir . $splInfo->getSaveName(), | ||
139 | + 'uploadtime' => time(), | ||
140 | + 'storage' => 'local', | ||
141 | + 'sha1' => $sha1, | ||
142 | + 'extparam' => json_encode($extparam), | ||
143 | + ); | ||
144 | + $attachment = Attachment::create(array_filter($params), true); | ||
145 | + $policy = array( | ||
146 | + 'saveKey' => ltrim($savekey, '/'), | ||
147 | + ); | ||
148 | + $auth = new Auth($config['accessKey'], $config['secretKey']); | ||
149 | + $token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy); | ||
150 | + $multipart = [ | ||
151 | + ['name' => 'token', 'contents' => $token], | ||
152 | + [ | ||
153 | + 'name' => 'file', | ||
154 | + 'contents' => fopen($filePath, 'r'), | ||
155 | + 'filename' => $fileName, | ||
156 | + ] | ||
157 | + ]; | ||
158 | + try { | ||
159 | + $client = new \GuzzleHttp\Client(); | ||
160 | + $res = $client->request('POST', $config['uploadurl'], [ | ||
161 | + 'multipart' => $multipart | ||
162 | + ]); | ||
163 | + $code = $res->getStatusCode(); | ||
164 | + //成功不做任何操作 | ||
165 | + } catch (\GuzzleHttp\Exception\ClientException $e) { | ||
166 | + $attachment->delete(); | ||
167 | + unlink($filePath); | ||
168 | + $this->error("上传失败"); | ||
169 | + } | ||
170 | + | ||
171 | + $url = '/' . $object; | ||
129 | 172 | ||
173 | + //上传成功后将存储变更为qiniu | ||
174 | + $attachment->storage = 'qiniu'; | ||
175 | + $attachment->save(); | ||
176 | + $this->success("上传成功", $url); | ||
177 | + } else { | ||
178 | + $this->error('上传失败'); | ||
179 | + } | ||
180 | + return; | ||
130 | } | 181 | } |
131 | 182 | ||
132 | 183 | ||
@@ -306,7 +357,9 @@ class Common extends Api | @@ -306,7 +357,9 @@ class Common extends Api | ||
306 | * @ApiMethod (POST) | 357 | * @ApiMethod (POST) |
307 | * @ApiRoute (/api/Common/AgreementOperation) | 358 | * @ApiRoute (/api/Common/AgreementOperation) |
308 | * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | 359 | * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") |
309 | - * @ApiParams (name="battery_id", type="string", required=true, description="电池类型ID") | 360 | + * @ApiParams (name="type", type="string", required=true, description="操作:1=同意,2=拒绝,3=修改租金,4=终止协议,5=删除协议") |
361 | + * @ApiParams (name="id", type="string", required=true, description="协议ID") | ||
362 | + * @ApiParams (name="money", type="int", required=true, description="修改后的金额") | ||
310 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | 363 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") |
311 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | 364 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") |
312 | * @ApiReturn ({ | 365 | * @ApiReturn ({ |
@@ -314,4 +367,230 @@ class Common extends Api | @@ -314,4 +367,230 @@ class Common extends Api | ||
314 | 'msg':'返回成功', | 367 | 'msg':'返回成功', |
315 | ) | 368 | ) |
316 | */ | 369 | */ |
370 | + public function AgreementOperation() | ||
371 | + { | ||
372 | + $UserId = $this->IsToken($this->request->header()); | ||
373 | + $params = $this->request->param(); | ||
374 | + $IsSeller = Db::name('agreement') | ||
375 | + ->alias('a') | ||
376 | + ->join('seller s', 's.id=a.seller_id') | ||
377 | + ->where('s.user_id', $UserId) | ||
378 | + ->where('a.id', $params['id']) | ||
379 | + ->find(); | ||
380 | + if (empty($IsSeller)) { | ||
381 | + $this->error('参数错误', 0); | ||
382 | + } | ||
383 | + //同意签订协议 | ||
384 | + if ($params['type'] == 1) { | ||
385 | + $res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 1, 'updatetime' => time(), 'EXP_time' => time() + 86400 * 30]); | ||
386 | + } | ||
387 | + //拒绝签订协议 | ||
388 | + if ($params['type'] == 2) { | ||
389 | + $res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 4, 'updatetime' => time()]); | ||
390 | + //拒绝签订协议 给予用户退款 | ||
391 | + $OrderSn = Db::name('agreement')->where('id', $params['id'])->value('OrderSn'); | ||
392 | + $PayOrderInfo = Db::name('pay_order')->where('OrderSn', $OrderSn)->where('type', 1)->find(); | ||
393 | + $TuiMoney = $PayOrderInfo['UpMoney'] + $PayOrderInfo['Money']; | ||
394 | + //配置 | ||
395 | + $config = [ | ||
396 | + 'app_id' => 'wx6a9080f20326f817', | ||
397 | + 'payment' => [ | ||
398 | + 'merchant_id' => '1603658973', | ||
399 | + 'key' => '8695A8185xyzKcdEVfreewayShenzhen', | ||
400 | + 'cert_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_cert.pem', // XXX: 绝对路径!!!! | ||
401 | + 'key_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_key.pem', // XXX: 绝对路径!!!! | ||
402 | + ], | ||
403 | + ]; | ||
404 | + $app = Factory::officialAccount($config); | ||
405 | + try { | ||
406 | + $result = $app->refund->byTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $TuiMoney); // 总金额 100, 退款 80,操作员:商户号 | ||
407 | + //更改订单状态为已退款 | ||
408 | + Db::name('pay_order')->where('OrderSn', $OrderSn)->where('PayOrder', $PayOrderInfo['PayOrder'])->update(['type' => 0]); | ||
409 | + } catch (Exception $e) { | ||
410 | + $e->getMessage(); | ||
411 | + } | ||
412 | + if (!$result) { | ||
413 | + $this->error('退款失败', 0); | ||
414 | + die; | ||
415 | + } | ||
416 | + } | ||
417 | + //修改租金 | ||
418 | + if ($params['type'] == 3) { | ||
419 | + $res = Db::name('agreement')->where('id', $params['id'])->update(['MonthMoney' => $params['money'], 'updatetime' => time()]); | ||
420 | + } | ||
421 | + //终止协议 | ||
422 | + if ($params['type'] == 4) { | ||
423 | + $res = Db::name('agreement')->where('id', $params['id'])->update(['status' => 2, 'updatetime' => time()]); | ||
424 | + } | ||
425 | + //删除协议 | ||
426 | + if ($params['type'] == 5) { | ||
427 | + $res = Db::name('agreement')->where('id', $params['id'])->delete(); | ||
428 | + } | ||
429 | + $this->res($res); | ||
430 | + } | ||
431 | + | ||
432 | + | ||
433 | + /** | ||
434 | + * 公共接口 | ||
435 | + * @ApiTitle (押金退还操作) | ||
436 | + * @ApiSummary (押金退还操作) | ||
437 | + * @ApiMethod (POST) | ||
438 | + * @ApiRoute (/api/Common/TuikuanOperation) | ||
439 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
440 | + * @ApiParams (name="type", type="string", required=true, description="操作:1=通过,2=拒绝,3=删除记录") | ||
441 | + * @ApiParams (name="id", type="string", required=true, description="协议ID") | ||
442 | + * @ApiParams (name="bili", type="string", required=true, description="退款百分比/ 1为百分之100/0.1为百分之10") | ||
443 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
444 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
445 | + * @ApiReturn ({ | ||
446 | + 'code':'1', | ||
447 | + 'msg':'返回成功', | ||
448 | + ) | ||
449 | + */ | ||
450 | + public function TuikuanOperation() | ||
451 | + { | ||
452 | + $UserId = $this->IsToken($this->request->header()); | ||
453 | + $params = $this->request->param(); | ||
454 | + $IsSeller = Db::name('agreement') | ||
455 | + ->alias('a') | ||
456 | + ->join('seller s', 's.id=a.seller_id') | ||
457 | + ->where('s.user_id', $UserId) | ||
458 | + ->where('a.id', $params['id']) | ||
459 | + ->value('seller_id'); | ||
460 | + if (empty($IsSeller)) { | ||
461 | + $this->error('参数错误', 0); | ||
462 | + } | ||
463 | + $OrderInfo = Db::name('agreement')->where('id', $params['id'])->find(); | ||
464 | + if ($params['type'] == 3) { | ||
465 | + $res = Db::name('tuikuan')->where('OrderSn', $OrderInfo['OrderSn'])->where('seller_id', $IsSeller)->delete(); | ||
466 | + } else { | ||
467 | + $IsUpdateAgreement = Db::name('agreement')->where('id', $params['id'])->update(['refind_status' => $params['type']]); | ||
468 | + if (!$IsUpdateAgreement) { | ||
469 | + $this->error('协议状态更改失败', 0); | ||
470 | + } | ||
471 | + $res = Db::name('tuikuan')->where('OrderSn', $OrderInfo['OrderSn'])->where('seller_id', $IsSeller)->update(['status' => $params['status']]); | ||
472 | + if ($params['type'] == 1) { | ||
473 | + //拒绝签订协议 给予用户退款 | ||
474 | + $OrderSn = Db::name('agreement')->where('id', $params['id'])->value('OrderSn'); | ||
475 | + $PayOrderInfo = Db::name('pay_order')->where('OrderSn', $OrderSn)->where('type', 1)->find(); | ||
476 | + $TuiMoney = $PayOrderInfo['UpMoney'] * $params['bili'] + $PayOrderInfo['Money']; | ||
477 | + //配置 | ||
478 | + $config = [ | ||
479 | + 'app_id' => 'wx6a9080f20326f817', | ||
480 | + 'payment' => [ | ||
481 | + 'merchant_id' => '1603658973', | ||
482 | + 'key' => '8695A8185xyzKcdEVfreewayShenzhen', | ||
483 | + 'cert_path' => ' / home / wwwroot / fast / book / addons / epay / certs / apiclient_cert . pem', // XXX: 绝对路径!!!! | ||
484 | + 'key_path' => ' / home / wwwroot / fast / book / addons / epay / certs / apiclient_key . pem', // XXX: 绝对路径!!!! | ||
485 | + ], | ||
486 | + ]; | ||
487 | + $app = Factory::officialAccount($config); | ||
488 | + try { | ||
489 | + $result = $app->refund->byTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $TuiMoney); // 总金额 100, 退款 80,操作员:商户号 | ||
490 | + //更改订单状态为已退款 | ||
491 | + Db::name('pay_order')->where('OrderSn', $OrderSn)->where('PayOrder', $PayOrderInfo['PayOrder'])->update(['type' => 0]); | ||
492 | + } catch (Exception $e) { | ||
493 | + $e->getMessage(); | ||
494 | + } | ||
495 | + if (!$result) { | ||
496 | + $this->error('退款失败', 0); | ||
497 | + die; | ||
498 | + } | ||
499 | + } | ||
500 | + } | ||
501 | + $this->res($res); | ||
502 | + } | ||
503 | + | ||
504 | + | ||
505 | + /** | ||
506 | + * 公共接口 | ||
507 | + * @ApiTitle (删除订单) | ||
508 | + * @ApiSummary (删除订单) | ||
509 | + * @ApiMethod (POST) | ||
510 | + * @ApiRoute (/api/Common/DeleteOrder) | ||
511 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
512 | + * @ApiParams (name="OrderSn", type="string", required=true, description="订单号") | ||
513 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
514 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
515 | + * @ApiReturn ({ | ||
516 | + 'code':'1', | ||
517 | + 'msg':'返回成功', | ||
518 | + ) | ||
519 | + */ | ||
520 | + public function DeleteOrder() | ||
521 | + { | ||
522 | + $UserId = $this->IsToken($this->request->header()); | ||
523 | + $OrderSn = input('OrderSn'); | ||
524 | + $Arr = Db::name('order') | ||
525 | + ->alias('o') | ||
526 | + ->join('stor s', 's.id=a.stor_id') | ||
527 | + ->where('s.user_id', $UserId) | ||
528 | + ->where('o.OrderSn', $OrderSn) | ||
529 | + ->find(); | ||
530 | + if (empty($Arr)) { | ||
531 | + $this->error('参数错误', 0); | ||
532 | + die; | ||
533 | + } | ||
534 | + $res = Db::name('order')->where('OrderSn', $OrderSn)->delete(); | ||
535 | + $this->res($res); | ||
536 | + } | ||
537 | + | ||
538 | + | ||
539 | + /** | ||
540 | + * 公共接口 | ||
541 | + * @ApiTitle (账户押金操作) | ||
542 | + * @ApiSummary (账户押金操作) | ||
543 | + * @ApiMethod (POST) | ||
544 | + * @ApiRoute (/api/Common/UpMoneyOperation) | ||
545 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
546 | + * @ApiParams (name="OrderSn", type="string", required=true, description="订单号") | ||
547 | + * @ApiParams (name="type", type="int", required=true, description="操作:1=取消签约,2=删除,3=退还押金") | ||
548 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
549 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
550 | + * @ApiReturn ({ | ||
551 | + 'code':'1', | ||
552 | + 'msg':'返回成功', | ||
553 | + ) | ||
554 | + */ | ||
555 | + public function UpMoneyOperation() | ||
556 | + { | ||
557 | + $UserId = $this->IsToken($this->request->header()); | ||
558 | + $params = $this->request->param(); | ||
559 | + $OrderInfo = Db::name('agreement')->where('OrderSn', $params['OrderSn'])->where('user_id', $UserId)->find(); | ||
560 | + if (empty($OrderInfo)) { | ||
561 | + $this->error('参数错误', 0); | ||
562 | + } | ||
563 | + if ($params['type'] == 1) { | ||
564 | + if ($OrderInfo['status'] != 0) { | ||
565 | + $this->error('不能取消签约', 0); | ||
566 | + } | ||
567 | + $res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->update(['status' => 4]); | ||
568 | + $this->Tuikuan($params['OrderSn']); | ||
569 | + } | ||
570 | + if ($params['type'] == 2) { | ||
571 | + if ($OrderInfo['status'] == 2 || $OrderInfo['status'] == 4) { | ||
572 | + $res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->delete(); | ||
573 | + } else { | ||
574 | + $this->error('不能删除订单', 0); | ||
575 | + die; | ||
576 | + } | ||
577 | + } | ||
578 | + if ($params['type'] == 3) { | ||
579 | + $res = Db::name('agreement')->where('id', $OrderInfo['id'])->where('user_id', $UserId)->update(['status' => 2, 'refind_status' => 0]); | ||
580 | + $data = [ | ||
581 | + 'user_id' => $UserId, | ||
582 | + 'OrderSn' => $params['OrderSn'], | ||
583 | + 'status' => 0, | ||
584 | + 'seller_id' => $OrderInfo['seller_id'], | ||
585 | + 'createtime' => time(), | ||
586 | + 'updatetime' => time() | ||
587 | + ]; | ||
588 | + $IsSave = Db::name('tuikuan')->insert($data); | ||
589 | + if (!$IsSave) { | ||
590 | + $this->error('添加退款记录失败', 0); | ||
591 | + die; | ||
592 | + } | ||
593 | + } | ||
594 | + $this->res($res); | ||
595 | + } | ||
317 | } | 596 | } |
@@ -33,6 +33,12 @@ class Index extends Api | @@ -33,6 +33,12 @@ class Index extends Api | ||
33 | * @ApiParams (name="CompanyPeopleNum", type="string", required=true, description="公司员工数") | 33 | * @ApiParams (name="CompanyPeopleNum", type="string", required=true, description="公司员工数") |
34 | * @ApiParams (name="image", type="string", required=true, description="营业执照或负责人身份证照片") | 34 | * @ApiParams (name="image", type="string", required=true, description="营业执照或负责人身份证照片") |
35 | * @ApiParams (name="Status", type="string", required=true, description="审核状态:0=待审核,1=审核通过,2=审核未通过") | 35 | * @ApiParams (name="Status", type="string", required=true, description="审核状态:0=待审核,1=审核通过,2=审核未通过") |
36 | + * @ApiParams (name="CompanyName", type="string", required=true, description="公司或商号名称") | ||
37 | + * @ApiParams (name="fa_address", type="string", required=true, description="法定地址") | ||
38 | + * @ApiParams (name="yingye_address", type="string", required=true, description="营业地址") | ||
39 | + * @ApiParams (name="mianji", type="string", required=true, description="营业场地面积") | ||
40 | + * @ApiParams (name="tel", type="string", required=true, description="通信地址") | ||
41 | + * @ApiParams (name="web", type="string", required=true, description="万维地址") | ||
36 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | 42 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") |
37 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | 43 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") |
38 | * @ApiReturn ({ | 44 | * @ApiReturn ({ |
@@ -394,7 +400,7 @@ class Index extends Api | @@ -394,7 +400,7 @@ class Index extends Api | ||
394 | $params = $this->request->param(); | 400 | $params = $this->request->param(); |
395 | if ($params['type'] == 0 || $params['type'] == 1 || $params['type'] == 3) { | 401 | if ($params['type'] == 0 || $params['type'] == 1 || $params['type'] == 3) { |
396 | $map['a.status'] = ['eq', $params['type']]; | 402 | $map['a.status'] = ['eq', $params['type']]; |
397 | - }else{ | 403 | + } else { |
398 | $map['a.status'] = ['IN', '2,4']; | 404 | $map['a.status'] = ['IN', '2,4']; |
399 | } | 405 | } |
400 | $Arr = Db::name('agreement') | 406 | $Arr = Db::name('agreement') |
@@ -437,4 +443,297 @@ class Index extends Api | @@ -437,4 +443,297 @@ class Index extends Api | ||
437 | } | 443 | } |
438 | $this->success('成功', $data); | 444 | $this->success('成功', $data); |
439 | } | 445 | } |
446 | + | ||
447 | + | ||
448 | + /** | ||
449 | + * 首页接口 | ||
450 | + * @ApiTitle (押金退还列表) | ||
451 | + * @ApiSummary (押金退还列表) | ||
452 | + * @ApiMethod (POST) | ||
453 | + * @ApiRoute (/api/Index/UpMoneyList) | ||
454 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
455 | + * @ApiParams (name="type", type="string", required=true, description="状态:0=待审核,1=已通过,2=已拒绝") | ||
456 | + * @ApiParams (name="pages", type="string", required=true, description="pages") | ||
457 | + * @ApiParams (name="rows", type="string", required=true, description="rows") | ||
458 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
459 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
460 | + * @ApiReturn ({ | ||
461 | + 'code':'1', | ||
462 | + 'msg':'返回成功', | ||
463 | + 'data':{ | ||
464 | + }) | ||
465 | + */ | ||
466 | + public function UpMoneyList() | ||
467 | + { | ||
468 | + $UserId = $this->IsToken($this->request->header()); | ||
469 | + $params = $this->request->param(); | ||
470 | + $Arr = Db::name('tuikuan') | ||
471 | + ->alias('a') | ||
472 | + ->join('seller s', 's.id=a.seller_id') | ||
473 | + ->join('user u', 'u.id=a.user_id') | ||
474 | + ->where('s.user_id', $UserId) | ||
475 | + ->where('a.status', $params['type']) | ||
476 | + ->page($params['pages'], $params['rows']) | ||
477 | + ->order('id desc') | ||
478 | + ->field('a.id,a.OrderSn,u.avatar,u.nickname,a.updatetime,a.status'); | ||
479 | + $Count = Db::name('agreement') | ||
480 | + ->alias('a') | ||
481 | + ->join('seller s', 's.id=a.seller_id') | ||
482 | + ->join('user u', 'u.id=a.user_id') | ||
483 | + ->where('s.user_id', $UserId) | ||
484 | + ->where('a.status', $params['type']) | ||
485 | + ->order('id desc') | ||
486 | + ->field('a.id,a.OrderSn,u.avatar,u.nickname,a.updatetime,a.status'); | ||
487 | + if (empty($Arr)) { | ||
488 | + $data = [ | ||
489 | + 'Count' => 0, | ||
490 | + 'List' => [] | ||
491 | + ]; | ||
492 | + } else { | ||
493 | + foreach ($Arr as $k => $v) { | ||
494 | + $List[$k]['id'] = $v['id']; | ||
495 | + $List[$k]['OrderSn'] = $v['OrderSn']; | ||
496 | + $List[$k]['avatar'] = $v['avatar']; | ||
497 | + $List[$k]['nickname'] = $v['nickname']; | ||
498 | + $List[$k]['updatetime'] = date('Y-m-d H:i:s', $v['updatetime']); | ||
499 | + $List[$k]['status'] = $v['status']; | ||
500 | + } | ||
501 | + $data = [ | ||
502 | + 'Count' => count($Count), | ||
503 | + 'List' => $List | ||
504 | + ]; | ||
505 | + } | ||
506 | + $this->success('成功', $data); | ||
507 | + } | ||
508 | + | ||
509 | + | ||
510 | + /** | ||
511 | + * 首页接口 | ||
512 | + * @ApiTitle (首页地图门店) | ||
513 | + * @ApiSummary (首页地图门店) | ||
514 | + * @ApiMethod (POST) | ||
515 | + * @ApiRoute (/api/Index/MapStor) | ||
516 | + * @ApiParams (name="battery_code", type="string", required=true, description="电池编码") | ||
517 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
518 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
519 | + * @ApiReturn ({ | ||
520 | + 'code':'1', | ||
521 | + 'msg':'返回成功', | ||
522 | + 'data':{ | ||
523 | + }) | ||
524 | + */ | ||
525 | + public function MapStor() | ||
526 | + { | ||
527 | + $Arr = Db::name('stor')->select(); | ||
528 | + $Code = input('battery_code'); | ||
529 | + $map['BatteryCode'] = ['IN', $Code]; | ||
530 | + //用户电池分类ID | ||
531 | + $Id = Db::name('battery_code')->where($map)->value('id'); | ||
532 | + if (empty($Id)) { | ||
533 | + $this->error('系统没有找到该电池分类', 0); | ||
534 | + die; | ||
535 | + } | ||
536 | + if (empty($Arr)) { | ||
537 | + $List = []; | ||
538 | + } else { | ||
539 | + $i = 0; | ||
540 | + foreach ($Arr as $k => $v) { | ||
541 | + $List[$k]['id'] = $v['id']; | ||
542 | + $List[$k]['name'] = $v['name']; | ||
543 | + $List[$k]['lng'] = $v['lng']; | ||
544 | + $List[$k]['lat'] = $v['lat']; | ||
545 | + $JsonArr = json_decode($v['Battery'], true); | ||
546 | + foreach ($JsonArr as $k1 => $v1) { | ||
547 | + if ($v1['type_id'] == $Id) { | ||
548 | + $List[$k]['num'] = $v1['num']; | ||
549 | + $i++; | ||
550 | + } | ||
551 | + } | ||
552 | + if ($i == 0) { | ||
553 | + $List[$k]['num'] = 0; | ||
554 | + } | ||
555 | + } | ||
556 | + } | ||
557 | + $this->success('成功', $List); | ||
558 | + } | ||
559 | + | ||
560 | + | ||
561 | + /** | ||
562 | + * 首页接口 | ||
563 | + * @ApiTitle (去换电) | ||
564 | + * @ApiSummary (去换电) | ||
565 | + * @ApiMethod (POST) | ||
566 | + * @ApiRoute (/api/Index/GoGoing) | ||
567 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
568 | + * @ApiParams (name="id", type="string", required=true, description="门店id") | ||
569 | + * @ApiParams (name="battery_code", type="string", required=true, description="电池编号") | ||
570 | + * @ApiParams (name="manufactor", type="string", required=true, description="厂家") | ||
571 | + * @ApiParams (name="Voltage", type="string", required=true, description="电压") | ||
572 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
573 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
574 | + * @ApiReturn ({ | ||
575 | + 'code':'1', | ||
576 | + 'msg':'返回成功', | ||
577 | + 'data':{ | ||
578 | + }) | ||
579 | + */ | ||
580 | + public function GoGoing() | ||
581 | + { | ||
582 | + $UserId = $this->IsToken($this->request->header()); | ||
583 | + $params = $this->request->param(); | ||
584 | + $map['BatteryCode'] = ['IN', $params['battery_code']]; | ||
585 | + //用户电池分类ID | ||
586 | + $Id = Db::name('battery_code')->where($map)->value('id'); | ||
587 | + if (empty($Id)) { | ||
588 | + $this->error('系统没有找到该电池分类', 0); | ||
589 | + die; | ||
590 | + } | ||
591 | + $IsAgreement = Db::name('stor') | ||
592 | + ->alias('r') | ||
593 | + ->join('seller s', 'r.user_id=s.user_id') | ||
594 | + ->join('agreement a', 'a.seller_id=s.id') | ||
595 | + ->where('a.user_id', $UserId) | ||
596 | + ->find(); | ||
597 | + if (empty($IsAgreement)) { | ||
598 | + $this->error('请先签订协议', '', '99998'); | ||
599 | + } | ||
600 | + $OrderSn = $this->order_sn(); | ||
601 | + $data = [ | ||
602 | + 'OrderSn' => $OrderSn, | ||
603 | + 'stor_id' => $params['id'], | ||
604 | + 'user_id' => $UserId, | ||
605 | + 'battery_id' => $Id, | ||
606 | + 'battery_code' => $params['battery_code'], | ||
607 | + 'manufactor' => $params['manufactor'], | ||
608 | + 'Voltage' => $params['Voltage'], | ||
609 | + 'status' => 0, | ||
610 | + 'EXP_time' => time() + 60 * 30, | ||
611 | + 'createtime' => time(), | ||
612 | + 'updatetime' => time() | ||
613 | + ]; | ||
614 | + $res = Db::name('order')->insert($data); | ||
615 | + $this->res($res); | ||
616 | + } | ||
617 | + | ||
618 | + | ||
619 | + /** | ||
620 | + * 首页接口 | ||
621 | + * @ApiTitle (我的订单) | ||
622 | + * @ApiSummary (我的订单) | ||
623 | + * @ApiMethod (POST) | ||
624 | + * @ApiRoute (/api/Index/MyOrder) | ||
625 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
626 | + * @ApiParams (name="pages", type="string", required=true, description="pages") | ||
627 | + * @ApiParams (name="rows", type="string", required=true, description="rows") | ||
628 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
629 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
630 | + * @ApiReturn ({ | ||
631 | + 'code':'1', | ||
632 | + 'msg':'返回成功', | ||
633 | + 'data':{ | ||
634 | + }) | ||
635 | + */ | ||
636 | + public function MyOrder() | ||
637 | + { | ||
638 | + $UserId = $this->IsToken($this->request->header()); | ||
639 | + $params = $this->request->param(); | ||
640 | + $Arr = Db::name('order') | ||
641 | + ->alias('o') | ||
642 | + ->join('stor s', 's.id=a.stor_id') | ||
643 | + ->where('s.user_id', $UserId) | ||
644 | + ->page($params['pages'], $params['rows']) | ||
645 | + ->join('user u', 'u.id=o.user_id') | ||
646 | + ->join('battery_code b', 'b.id=o.battery_id') | ||
647 | + ->order('id desc') | ||
648 | + ->field('o.id,o.OrderSn,o.battery_code,u.nickname,u.avatar,o.status,o.createtime,o.ok_time,b.title,o.manufactor,o.Voltage,o.yes_time'); | ||
649 | + $Count = Db::name('order') | ||
650 | + ->alias('o') | ||
651 | + ->join('stor s', 's.id=a.stor_id') | ||
652 | + ->where('s.user_id', $UserId) | ||
653 | + ->join('user u', 'u.id=o.user_id') | ||
654 | + ->order('id desc') | ||
655 | + ->field('o.id,o.OrderSn,o.battery_code,u.nickname,u.avatar,o.status,o.createtime,o.ok_time,b.title,o.manufactor,o.Voltage,o.yes_time'); | ||
656 | + if (empty($Arr)) { | ||
657 | + $data = [ | ||
658 | + 'Count' => 0, | ||
659 | + 'List' => [] | ||
660 | + ]; | ||
661 | + } else { | ||
662 | + foreach ($Arr as $k => $v) { | ||
663 | + $List[$k]['id'] = $v['id']; | ||
664 | + $List[$k]['OrderSn'] = $v['OrderSn']; | ||
665 | + $List[$k]['battery_code'] = $v['battery_code']; | ||
666 | + $List[$k]['nickname'] = $v['nickname']; | ||
667 | + $List[$k]['avatar'] = $v['avatar']; | ||
668 | + $List[$k]['status'] = $v['status']; | ||
669 | + $List[$k]['createtime'] = $v['createtime']; | ||
670 | + $List[$k]['ok_time'] = $v['ok_time']; | ||
671 | + $List[$k]['title'] = $v['title']; | ||
672 | + $List[$k]['manufactor'] = $v['manufactor']; | ||
673 | + $List[$k]['Voltage'] = $v['Voltage']; | ||
674 | + $List[$k]['yes_time'] = $v['yes_time']; | ||
675 | + } | ||
676 | + $data = [ | ||
677 | + 'Count' => count($Count), | ||
678 | + 'List' => $List | ||
679 | + ]; | ||
680 | + } | ||
681 | + $this->success('成功', $data); | ||
682 | + } | ||
683 | + | ||
684 | + | ||
685 | + /** | ||
686 | + * 首页接口 | ||
687 | + * @ApiTitle (账户押金) | ||
688 | + * @ApiSummary (账户押金) | ||
689 | + * @ApiMethod (POST) | ||
690 | + * @ApiRoute (/api/Index/MyUpMoney) | ||
691 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
692 | + * @ApiParams (name="pages", type="string", required=true, description="pages") | ||
693 | + * @ApiParams (name="rows", type="string", required=true, description="rows") | ||
694 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
695 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
696 | + * @ApiReturn ({ | ||
697 | + 'code':'1', | ||
698 | + 'msg':'返回成功', | ||
699 | + 'data':{ | ||
700 | + }) | ||
701 | + */ | ||
702 | + public function MyUpMoney() | ||
703 | + { | ||
704 | + $UserId = $this->IsToken($this->request->header()); | ||
705 | + $params = $this->request->param(); | ||
706 | + $Arr = Db::name('agreement') | ||
707 | + ->alias('a') | ||
708 | + ->where('a.user_id', $UserId) | ||
709 | + ->page($params['pages'], $params['rows']) | ||
710 | + ->order('id desc') | ||
711 | + ->field('a.id,a.OrderSn,a.UpMoney,a.Money,a.status,a.refind_status,a.CompanyName'); | ||
712 | + $Count = Db::name('agreement') | ||
713 | + ->alias('a') | ||
714 | + ->where('a.user_id', $UserId) | ||
715 | + ->order('id desc') | ||
716 | + ->field('a.id,a.OrderSn,a.UpMoney,a.Money,a.status,a.refind_status,a.CompanyName'); | ||
717 | + if (empty($Arr)) { | ||
718 | + $data = [ | ||
719 | + 'Count' => 0, | ||
720 | + 'List' => [] | ||
721 | + ]; | ||
722 | + } else { | ||
723 | + foreach ($Arr as $k => $v) { | ||
724 | + $List[$k]['id'] = $v['id']; | ||
725 | + $List[$k]['OrderSn'] = $v['OrderSn']; | ||
726 | + $List[$k]['UpMoney'] = $v['UpMoney']; | ||
727 | + $List[$k]['Money'] = $v['Money']; | ||
728 | + $List[$k]['status'] = $v['status']; | ||
729 | + $List[$k]['refind_status'] = $v['refind_status']; | ||
730 | + $List[$k]['CompanyName'] = $v['CompanyName']; | ||
731 | + } | ||
732 | + $data = [ | ||
733 | + 'Count' => count($Count), | ||
734 | + 'List' => $List | ||
735 | + ]; | ||
736 | + } | ||
737 | + $this->success('成功', $data); | ||
738 | + } | ||
440 | } | 739 | } |
@@ -124,4 +124,113 @@ class Pay extends Api | @@ -124,4 +124,113 @@ class Pay extends Api | ||
124 | } | 124 | } |
125 | echo $pay->success('支付成功'); | 125 | echo $pay->success('支付成功'); |
126 | } | 126 | } |
127 | + | ||
128 | + | ||
129 | + /** | ||
130 | + * 支付接口 | ||
131 | + * @ApiTitle (充值租金) | ||
132 | + * @ApiSummary (充值租金) | ||
133 | + * @ApiMethod (POST) | ||
134 | + * @ApiRoute (/api/Pay/AddMoney) | ||
135 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
136 | + * @ApiParams (name="OrderSn", type="integer", required=true, description="订单号") | ||
137 | + * @ApiParams (name="Money", type="integer", required=true, description="充值金额") | ||
138 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
139 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
140 | + * @ApiReturn ({ | ||
141 | + 'code':'1', | ||
142 | + 'msg':'返回成功', | ||
143 | + 'data':{ | ||
144 | + }) | ||
145 | + */ | ||
146 | + public function AddMoney() | ||
147 | + { | ||
148 | + $UserId = $this->IsToken($this->request->header()); | ||
149 | + $OrderSn = input('OrderSn'); | ||
150 | + $Money = input('Money'); | ||
151 | + $UserInfo = Db::name('user')->where('id', $UserId)->find(); | ||
152 | + $PayOrder = $this->PayOrder(); | ||
153 | + $domain = $this->request->domain(); | ||
154 | + //生成交易流水 | ||
155 | + $data = [ | ||
156 | + 'PayOrder' => $PayOrder, | ||
157 | + 'OrderSn' => $OrderSn, | ||
158 | + 'type' => 1, | ||
159 | + 'status' => 0, | ||
160 | + 'user_id' => $UserId, | ||
161 | + 'money' => $Money, | ||
162 | + 'createtime' => time(), | ||
163 | + 'updatetime' => time() | ||
164 | + ]; | ||
165 | + $InsertPayOrder = Db::name('pay_order')->insert($data); | ||
166 | + if (!$InsertPayOrder) { | ||
167 | + $this->error('支付订单生成失败', 0); | ||
168 | + } | ||
169 | + $data = [ | ||
170 | + 'amount' => $Money, | ||
171 | + 'orderid' => $PayOrder, | ||
172 | + 'type' => "wechat", | ||
173 | + 'title' => "充值租金", | ||
174 | + 'notifyurl' => $domain . "/api/pay/AddMoneyNotify/paytype/wechat", | ||
175 | + 'returnurl' => $domain . "/api/pay/baidu", | ||
176 | + 'method' => "miniapp", | ||
177 | + 'openid' => $UserInfo['openid'] | ||
178 | + ]; | ||
179 | + $return = \addons\epay\library\Service::submitOrder($data); | ||
180 | + echo $return; | ||
181 | + } | ||
182 | + | ||
183 | + | ||
184 | + /** | ||
185 | + * 订单接口 | ||
186 | + * @ApiTitle (充值租金回调) | ||
187 | + * @ApiSummary (充值租金回调) | ||
188 | + * @ApiMethod (POST) | ||
189 | + * @ApiRoute (/api/Pay/AddMoneyNotify) | ||
190 | + * @ApiParams (name="paytype", type="string", required=true, description="") | ||
191 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
192 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
193 | + * @ApiReturn ({ | ||
194 | + 'code':'1', | ||
195 | + 'msg':'返回成功' | ||
196 | + }) | ||
197 | + */ | ||
198 | + public function AddMoneyNotify() | ||
199 | + { | ||
200 | + $paytype = $this->request->param('paytype'); | ||
201 | + $pay = \addons\epay\library\Service::checkNotify($paytype); | ||
202 | + if (!$pay) { | ||
203 | + echo '签名错误'; | ||
204 | + die; | ||
205 | + } | ||
206 | + $data = $pay->verify(); | ||
207 | + try { | ||
208 | + $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100; | ||
209 | + //$data['out_trade_no'] 支付单号 | ||
210 | + $order_sn = $data['out_trade_no']; | ||
211 | + $order = Db::name('pay_order')->where('PayOrder', $order_sn)->find(); | ||
212 | + if ($order['status'] == 2) { | ||
213 | + return $pay->success('支付成功'); | ||
214 | + die; | ||
215 | + } | ||
216 | + //在此编写订单逻辑 | ||
217 | + //修改支付订单状态 | ||
218 | + $UpdateStatus = Db::name('pay_order')->where('PayOrder', $data['out_trade_no'])->update( | ||
219 | + [ | ||
220 | + 'status' => 1, | ||
221 | + 'updatetime' => time(), | ||
222 | + 'WeChatOrder' => $data['transaction_id'] | ||
223 | + ] | ||
224 | + ); | ||
225 | + $OrderInfo = Db::name('agreement')->where('OrderSn', $order['OrderSn'])->find(); | ||
226 | + $Money = $OrderInfo['Money'] + $order['money']; | ||
227 | + Db::name('agreement')->where('OrderSn', $order['OrderSn'])->update(['Money' => $Money]); | ||
228 | + if (!$UpdateStatus) { | ||
229 | + $this->error('修改支付订单状态失败', 0); | ||
230 | + die; | ||
231 | + } | ||
232 | + } catch (Exception $e) { | ||
233 | + } | ||
234 | + echo $pay->success('支付成功'); | ||
235 | + } | ||
127 | } | 236 | } |
@@ -84,6 +84,8 @@ class User extends Api | @@ -84,6 +84,8 @@ class User extends Api | ||
84 | $rult = Db::name("user")->where(['openid' => $openid])->find(); | 84 | $rult = Db::name("user")->where(['openid' => $openid])->find(); |
85 | $return = [ | 85 | $return = [ |
86 | 'token' => $rult['token'], | 86 | 'token' => $rult['token'], |
87 | + 'avatar' => $param['avatar'], | ||
88 | + 'nickname' => $param['nickname'] | ||
87 | ]; | 89 | ]; |
88 | $this->success('成功', $return); | 90 | $this->success('成功', $return); |
89 | } | 91 | } |
@@ -14,7 +14,7 @@ use think\Response; | @@ -14,7 +14,7 @@ use think\Response; | ||
14 | use think\Route; | 14 | use think\Route; |
15 | use think\Validate; | 15 | use think\Validate; |
16 | use think\Db; | 16 | use think\Db; |
17 | - | 17 | +use EasyWeChat\Factory; |
18 | /** | 18 | /** |
19 | * API控制器基类 | 19 | * API控制器基类 |
20 | */ | 20 | */ |
@@ -388,4 +388,32 @@ class Api | @@ -388,4 +388,32 @@ class Api | ||
388 | $PayOrder = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99)); | 388 | $PayOrder = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99)); |
389 | return $PayOrder; | 389 | return $PayOrder; |
390 | } | 390 | } |
391 | + | ||
392 | + | ||
393 | + public function Tuikuan($OrderSn){ | ||
394 | + $PayOrderInfo = Db::name('pay_order')->where('OrderSn', $OrderSn)->where('type', 1)->find(); | ||
395 | + $TuiMoney = $PayOrderInfo['UpMoney'] + $PayOrderInfo['Money']; | ||
396 | + //配置 | ||
397 | + $config = [ | ||
398 | + 'app_id' => 'wx6a9080f20326f817', | ||
399 | + 'payment' => [ | ||
400 | + 'merchant_id' => '1603658973', | ||
401 | + 'key' => '8695A8185xyzKcdEVfreewayShenzhen', | ||
402 | + 'cert_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_cert.pem', // XXX: 绝对路径!!!! | ||
403 | + 'key_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_key.pem', // XXX: 绝对路径!!!! | ||
404 | + ], | ||
405 | + ]; | ||
406 | + $app = Factory::officialAccount($config); | ||
407 | + try { | ||
408 | + $result = $app->refund->byTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $TuiMoney); // 总金额 100, 退款 80,操作员:商户号 | ||
409 | + //更改订单状态为已退款 | ||
410 | + Db::name('pay_order')->where('OrderSn', $OrderSn)->where('PayOrder', $PayOrderInfo['PayOrder'])->update(['type' => 0]); | ||
411 | + } catch (Exception $e) { | ||
412 | + $e->getMessage(); | ||
413 | + } | ||
414 | + if (!$result) { | ||
415 | + $this->error('退款失败', 0); | ||
416 | + die; | ||
417 | + } | ||
418 | + } | ||
391 | } | 419 | } |
此 diff 太大无法显示。
-
请 注册 或 登录 后发表评论