提交
This commit is contained in:
@@ -118,9 +118,6 @@ class Auth extends Base
|
|||||||
|
|
||||||
return $this->ok([
|
return $this->ok([
|
||||||
'isLogin' => true,
|
'isLogin' => true,
|
||||||
'user' => [
|
|
||||||
'id' => $userId,
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +138,6 @@ class Auth extends Base
|
|||||||
'expires_in' => MINIAPI_TOKEN_EXPIRE,
|
'expires_in' => MINIAPI_TOKEN_EXPIRE,
|
||||||
'openid' => $openid,
|
'openid' => $openid,
|
||||||
'user' => [
|
'user' => [
|
||||||
'id' => intval($user['id']),
|
|
||||||
'mobile' => $user['mobile'] ?? $mobile,
|
'mobile' => $user['mobile'] ?? $mobile,
|
||||||
'nickname' => $user['nickname'] ?? '微信用户',
|
'nickname' => $user['nickname'] ?? '微信用户',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -113,6 +113,73 @@ class Order extends Base
|
|||||||
], 'ok');
|
], '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
|
private function fetchOrderDetail(string $orderSn, string $business, int $userId): array
|
||||||
{
|
{
|
||||||
$model = $this->businessModel($business);
|
$model = $this->businessModel($business);
|
||||||
@@ -194,4 +261,33 @@ class Order extends Base
|
|||||||
$value = str_replace([',', '¥', '¥', '元', ' '], '', $value);
|
$value = str_replace([',', '¥', '¥', '元', ' '], '', $value);
|
||||||
return preg_match('/^\d+(\.\d+)?$/', $value) ? $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Route::group('miniapi', function () {
|
|||||||
Route::get('order/lists', 'Order/lists');
|
Route::get('order/lists', 'Order/lists');
|
||||||
Route::get('order/detail', 'Order/detail');
|
Route::get('order/detail', 'Order/detail');
|
||||||
Route::post('order/pay', 'Order/pay');
|
Route::post('order/pay', 'Order/pay');
|
||||||
|
Route::post('order/addInvoice', 'Order/addInvoice');
|
||||||
|
|
||||||
Route::get('ocr/signature', 'Ocr/signature');
|
Route::get('ocr/signature', 'Ocr/signature');
|
||||||
Route::post('upload/image', 'Upload/image');
|
Route::post('upload/image', 'Upload/image');
|
||||||
|
|||||||
Reference in New Issue
Block a user