From c8cbbc0763e6c365533f33ce4a42c1f8db26c80b Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Fri, 25 Apr 2025 14:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E6=8A=AC=E5=A4=B4=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BC=98=E5=8C=96=EF=BC=8C=E5=AF=BC=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/InvoiceIssuance.php | 4 +- app/model/InvoiceHead.php | 9 ++-- .../invoice/InvoiceIssuanceService.php | 7 +-- app/service/user/UserService.php | 53 +++++++++++++------ 4 files changed, 48 insertions(+), 25 deletions(-) diff --git a/app/controller/api/InvoiceIssuance.php b/app/controller/api/InvoiceIssuance.php index fd4e28a..715d4d3 100644 --- a/app/controller/api/InvoiceIssuance.php +++ b/app/controller/api/InvoiceIssuance.php @@ -85,13 +85,15 @@ class InvoiceIssuance extends Base throw new \Exception('纳税人编号格式错误'); } } + $wechat_user_id = $this->request->wechat_user_id; $res = InvoiceIssuanceService::validateFeePay( $param['pucode'], $param['expire_time'], $param['project_id'], $param['merge'], - $tax_number + $tax_number, + $wechat_user_id ); return $this->buildSuccess($res); diff --git a/app/model/InvoiceHead.php b/app/model/InvoiceHead.php index dd7c630..7fb15b3 100644 --- a/app/model/InvoiceHead.php +++ b/app/model/InvoiceHead.php @@ -23,12 +23,10 @@ class InvoiceHead extends Model $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($data['pucode']); - $tax_number = $feeUserInfo['CertificateCode'] ?? ''; - if (!$tax_number) $tax_number = $data['tax_number']; + $tax_number = $data['tax_number'] ?? ''; + if (!$tax_number) $tax_number = $feeUserInfo['CertificateCode'] ?? ''; $param = [ - 'type' => $data['type'], - 'title' => $feeUserInfo['UserName'] ?? '', 'tax_number' => $tax_number, 'wechat_user_id' => $wechat_user_id ]; @@ -38,6 +36,9 @@ class InvoiceHead extends Model return $id; } + $param['type'] = $data['type']; + $param['title'] = $feeUserInfo['UserName'] ?? ''; + $param['address'] = isset($feeUserInfo['MaillingAddress']) && !empty($feeUserInfo['MaillingAddress']) ? $feeUserInfo['MaillingAddress']: ''; $param['telephone'] = isset($feeUserInfo['Telephone']) && !empty($feeUserInfo['Telephone']) ? $feeUserInfo['Telephone']: ''; $param['bank_name'] = isset($feeUserInfo['BankName']) && !empty($feeUserInfo['BankName']) ? $feeUserInfo['BankName']: ''; diff --git a/app/service/invoice/InvoiceIssuanceService.php b/app/service/invoice/InvoiceIssuanceService.php index 384f1bc..03dc34e 100644 --- a/app/service/invoice/InvoiceIssuanceService.php +++ b/app/service/invoice/InvoiceIssuanceService.php @@ -85,10 +85,11 @@ class InvoiceIssuanceService * @param $project_id * @param string $merge 是否合并 * @param string $tax_number + * @param int $wechat_user_id * @return string[] * @throws FuncException */ - public static function validateFeePay($pucode, $expire_time, $project_id, string $merge = '', string $tax_number = ''): array + public static function validateFeePay($pucode, $expire_time, $project_id, string $merge = '', string $tax_number = '', int $wechat_user_id = 0): array { $expire_date = date('Ym', strtotime($expire_time)); @@ -103,7 +104,7 @@ class InvoiceIssuanceService throw new FuncException('请填写纳税人编号'); } - $pucodeArr = UserService::getTaxUser($tax_number); + $pucodeArr = UserService::getTaxUser($tax_number, $wechat_user_id); if (empty($pucodeArr)) { throw new FuncException('登录的用户id与纳税人编号不符,请重新输入'); } @@ -252,7 +253,7 @@ class InvoiceIssuanceService $pucodeArr = [$pucode]; if ($invoiceIssuance['merge'] == 1) { - $pucodeArr = UserService::getTaxUser($bdznsrsbh); + $pucodeArr = UserService::getTaxUser($bdznsrsbh, $invoiceIssuance['wechat_user_id']); } // 多组用户编号 diff --git a/app/service/user/UserService.php b/app/service/user/UserService.php index 278c49b..bd2cf8c 100644 --- a/app/service/user/UserService.php +++ b/app/service/user/UserService.php @@ -67,32 +67,50 @@ class UserService extends BaseService $save = [ 'nickname' => '导入用户', 'phone' => $phone, - 'email' => $email + 'email' => $email, + 'create_time' => time() ]; $id = (new WechatUser())->insertGetId($save); + } else { + $id = $query['id']; + $query->email = $email; + $query->save(); + } - if ($id) { + if ($id) { + $puCodeQuery = (new WechatPucode())->where('wechat_user_id', $id)->find(); + if ($puCodeQuery) { + $puCodeQuery->pucode = $pucode; + $puCodeQuery->create_time = time(); + $puCodeQuery->save(); + } else { $codeSave = [ 'wechat_user_id' => $id, 'pucode' => $pucode, 'create_time' => time() ]; (new WechatPucode())->save($codeSave); + } + + $headSave = [ + 'wechat_user_id' => $id + ]; - if ($codeSave) { - $headSave = [ - 'tax_number' => $tax_number, - ]; - $headQuery = InvoiceHead::where($headSave)->find(); - if (!$headQuery) { - $headSave['type'] = $type; - $headSave['phone'] = $phone; - $headSave['wechat_user_id'] = $id; - $headSave['create_time'] = time(); - (new InvoiceHead())->save($headSave); - } - } + $headQuery = (new InvoiceHead())->where($headSave)->order('id desc')->find(); + if ($headQuery) { + $headQuery->type = $type; + $headQuery->tax_number = $tax_number; + $headQuery->phone = $phone; + $headQuery->create_time = time(); + $headQuery->save(); + } else { + + $headSave['type'] = $type; + $headSave['tax_number'] = $tax_number; + $headSave['phone'] = $phone; + $headSave['create_time'] = time(); + (new InvoiceHead())->save($headSave); } return 1; @@ -100,10 +118,11 @@ class UserService extends BaseService return 0; } - public static function getTaxUser($tax_id) + public static function getTaxUser($tax_id, $wechat_user_id) { $where = [ - 'tax_number' => $tax_id + ['tax_number', '=', $tax_id], + ['wechat_user_id', '<>', $wechat_user_id], ]; $user_ids = InvoiceHead::where($where)->column('wechat_user_id');