From 4320b8042699efd7a6c66f997e241cd6dfc08e20 Mon Sep 17 00:00:00 2001 From: gaofeng <1212121@qq.com> Date: Wed, 17 Jun 2026 16:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/miniapi/controller/Auth.php | 4 -- app/miniapi/controller/Order.php | 96 ++++++++++++++++++++++++++++++++ route/app.php | 1 + 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/app/miniapi/controller/Auth.php b/app/miniapi/controller/Auth.php index 850258c..90612bf 100644 --- a/app/miniapi/controller/Auth.php +++ b/app/miniapi/controller/Auth.php @@ -118,9 +118,6 @@ class Auth extends Base return $this->ok([ 'isLogin' => true, - 'user' => [ - 'id' => $userId, - ], ]); } @@ -141,7 +138,6 @@ class Auth extends Base 'expires_in' => MINIAPI_TOKEN_EXPIRE, 'openid' => $openid, 'user' => [ - 'id' => intval($user['id']), 'mobile' => $user['mobile'] ?? $mobile, 'nickname' => $user['nickname'] ?? '微信用户', ], diff --git a/app/miniapi/controller/Order.php b/app/miniapi/controller/Order.php index 8b6f302..8997b28 100644 --- a/app/miniapi/controller/Order.php +++ b/app/miniapi/controller/Order.php @@ -113,6 +113,73 @@ class Order extends Base ], 'ok'); } + public function addInvoice() + { + $userId = $this->requireLogin(); + if (!is_int($userId)) { + return $userId; + } + + $data = $this->postData(); + $business = $this->businessCode((string)($data['business'] ?? 'evus')); + $orderSn = trim((string)($data['order_sn'] ?? '')); + if ($orderSn === '') { + return $this->fail('参数错误'); + } + if ($error = $this->validateInvoiceData($data)) { + return $error; + } + + $detail = $this->fetchOrderDetail($orderSn, $business, $userId); + if (isset($detail['error'])) { + return $this->fail($detail['error'], intval($detail['code'] ?? 0)); + } + + $payload = $this->invoicePayload($data, $business, $userId); + $orderUrl = trim((string)config('app.order_url')); + if ($orderUrl === '') { + return $this->fail('发票接口未配置'); + } + + $response = Httpcurl::request(rtrim($orderUrl, '/') . '/add_invoice', 'post', $payload); + $result = $this->decodeResponse($response, 'miniapi add invoice'); + if (empty($result)) { + return $this->fail('操作失败,请重新填写'); + } + if (intval($result['code'] ?? 0) !== 1) { + return $this->fail((string)($result['msg'] ?? '操作失败,请重新填写')); + } + + return $this->ok([], (string)($result['msg'] ?? '提交成功')); + } + + private function validateInvoiceData(array $data) + { + $required = [ + 'order_id' => '订单信息', + 'phone' => '手机号', + 'title' => '客户名称', + 'tax_number' => '税号', + 'link_person' => '联系人', + 'link_email' => '邮箱', + ]; + foreach ($required as $field => $label) { + if (trim((string)($data[$field] ?? '')) === '') { + if ($field === 'order_id') { + return $this->fail('订单信息异常,请刷新后重试'); + } + return $this->fail('请填写' . $label); + } + } + + $taxLength = strlen(trim((string)$data['tax_number'])); + if (!in_array($taxLength, [15, 17, 18, 20], true)) { + return $this->fail('购方税号仅支持15、17、18、20位'); + } + + return null; + } + private function fetchOrderDetail(string $orderSn, string $business, int $userId): array { $model = $this->businessModel($business); @@ -194,4 +261,33 @@ class Order extends Base $value = str_replace([',', '¥', '¥', '元', ' '], '', $value); return preg_match('/^\d+(\.\d+)?$/', $value) ? $value : ''; } + + private function invoicePayload(array $data, string $business, int $userId): array + { + $fields = [ + 'phone', + 'title', + 'tax_number', + 'link_person', + 'link_email', + 'address', + 'mobile', + 'bank', + 'account', + 'order_id', + 'order_sn', + ]; + $payload = []; + foreach ($fields as $field) { + $payload[$field] = trim((string)($data[$field] ?? '')); + } + + $site = (array)config('app.miniapi_site', []); + $payload['invoiceType'] = $this->businessInvoiceType($business); + $payload['model'] = $this->businessModel($business); + $payload['principals'] = (string)($site['principals'] ?? ''); + $payload['uid'] = $userId; + + return $payload; + } } diff --git a/route/app.php b/route/app.php index 35709e7..3473273 100644 --- a/route/app.php +++ b/route/app.php @@ -31,6 +31,7 @@ Route::group('miniapi', function () { Route::get('order/lists', 'Order/lists'); Route::get('order/detail', 'Order/detail'); Route::post('order/pay', 'Order/pay'); + Route::post('order/addInvoice', 'Order/addInvoice'); Route::get('ocr/signature', 'Ocr/signature'); Route::post('upload/image', 'Upload/image');