diff --git a/app/controller/admin/WechatUser.php b/app/controller/admin/WechatUser.php index 2751d20..453890f 100644 --- a/app/controller/admin/WechatUser.php +++ b/app/controller/admin/WechatUser.php @@ -129,22 +129,15 @@ class WechatUser extends Base $error_array = []; foreach ($excel_array as $key => $data) { $key = $key + 1; - // 验证不能为空 - $is_empty = false; - foreach ($data as $value) { - if (empty($value)) { - $is_empty = true; - break; - } - } - if ($is_empty) { - continue; - } $phone = $data[0]; - $email = $data[1]; + $email = $data[1] ?? ''; $pucode = $data[2]; - $taxId = $data[3]; + $taxId = $data[3] ?? ''; $type = $data[4]; + // 验证不能为空 + if (empty($phone) || empty($pucode) || empty($type)) { + continue; + } if (!preg_match('/^1[3-9]\d{9}$/', $phone)) { $error_array[] = "第{$key}行:手机号格式不符合"; continue; @@ -161,16 +154,19 @@ class WechatUser extends Base $error_array[] = "第{$key}行:手机号或用户编号错误"; continue; } - - if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { - $error_array[] = "第{$key}行:邮箱格式不符合"; - continue; + if ($email) { + if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { + $error_array[] = "第{$key}行:邮箱格式不符合"; + continue; + } } - $str = '0-9A-HJ-NPQRTUWXY'; - $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; - if (!preg_match($pattern, $taxId)) { - $error_array[] = "第{$key}行:纳税人编号格式不符合"; - continue; + if ($taxId) { + $str = '0-9A-HJ-NPQRTUWXY'; + $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; + if (!preg_match($pattern, $taxId)) { + $error_array[] = "第{$key}行:纳税人编号格式不符合"; + continue; + } } $typeArr = ['单位', '个人']; if (!in_array($type, $typeArr)) { diff --git a/app/controller/api/InvoiceIssuance.php b/app/controller/api/InvoiceIssuance.php index 7a0aded..a627a20 100644 --- a/app/controller/api/InvoiceIssuance.php +++ b/app/controller/api/InvoiceIssuance.php @@ -141,12 +141,11 @@ class InvoiceIssuance extends Base $userRes = (new WechatUser())->where('id', $wechat_user_id)->find(); $data['email'] = $userRes['email']; - $pucode = (new WechatPucode())->where('wechat_user_id', $wechat_user_id)->value('pucode'); + $feeUserInfo = []; + if (!isset($data['tax_number']) || empty($userRes['email'])) { + $pucode = (new WechatPucode())->where('wechat_user_id', $wechat_user_id)->value('pucode'); - $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode); - - if ($data['title'] != $feeUserInfo['UserName'] && isset($data['tax_number'])) { - unset($data['tax_number']); + $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode); } if (empty($data['email'])) { @@ -190,7 +189,7 @@ class InvoiceIssuance extends Base $wechat_user_id = $this->request->wechat_user_id; - $pucode = $param['pucode'] ?? ''; + $pucode = $params['pucode'] ?? ''; if (!$pucode) { $pucode = WechatPucode::where('wechat_user_id', $wechat_user_id)->order('create_time desc')->value('pucode'); if (!$pucode) throw new \Exception('请先绑定用户编号'); diff --git a/app/service/invoice/InvoiceIssuanceService.php b/app/service/invoice/InvoiceIssuanceService.php index 3e1343a..ba08da6 100644 --- a/app/service/invoice/InvoiceIssuanceService.php +++ b/app/service/invoice/InvoiceIssuanceService.php @@ -188,13 +188,18 @@ class InvoiceIssuanceService * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function getTaxNumber($invoice_head_id) + public function getTaxNumber($invoice_head_id, $CertificateCode = '') { $bdznsrsbh = '91440300772709730N'; // 被代征纳税人识别号 【默认大工业水务税号】 // 如果是企业 需要取填写抬头的税号 $invoice_head = (new InvoiceHead())->where('id', $invoice_head_id)->where('type', 0)->field('tax_number')->find(); if ($invoice_head) { $bdznsrsbh = $invoice_head['tax_number'] ?? ''; + if (!empty($CertificateCode) && $bdznsrsbh != $CertificateCode) { + $bdznsrsbh = $CertificateCode; + } + } elseif (!empty($CertificateCode)) { + $bdznsrsbh = $CertificateCode; } return $bdznsrsbh; } @@ -219,10 +224,6 @@ class InvoiceIssuanceService $feeUsers = $this->getFeeUserData($pucode); - $bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号 - - $feeUsers['bdznsrsbh'] = $bdznsrsbh; - // 获取用户应收费信息 $FeeComputeDetail = self::getFeeComputeDetail($pucode, date("Ym", $invoiceIssuance['expire_time'])); if ($FeeComputeDetail['MsgID'] != 1) { @@ -240,6 +241,9 @@ class InvoiceIssuanceService $feeUsers['WaterPrice'] = $FeeComputeDetail['WaterPrice']; $feeUsers['ThisLastReadingTime'] = $FeeComputeDetail['ThisLastReadingTime']; + $CertificateCode = !empty($feeUsers['CertificateCode']) ? $feeUsers['CertificateCode'] : ''; + $bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id'],$CertificateCode); // 被代征纳税人识别号 + $feeUsers['bdznsrsbh'] = $bdznsrsbh; // 保存 $ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate); @@ -314,8 +318,8 @@ class InvoiceIssuanceService if (!isset($queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms'])) { throw new FuncException('异常信息返回有误'); } - // 查询待开具电子缴款 - $queryIssuedPaymentVoucher = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh); + // 查询待开具电子缴款(无法调用) + //$queryIssuedPaymentVoucher = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh); // 保存用户异常状态 $ycms = $queryUploadErrorData['data']['mxGrid']['sbMxsjVOList']['ycms']; // 数据异常描述 diff --git a/app/service/user/UserService.php b/app/service/user/UserService.php index 17392ac..5779c6f 100644 --- a/app/service/user/UserService.php +++ b/app/service/user/UserService.php @@ -80,9 +80,9 @@ class UserService extends BaseService if ($id) { - $puCodeQuery = (new WechatPucode())->where('wechat_user_id', $id)->find(); + $puCodeQuery = (new WechatPucode())->where('pucode', $pucode)->where('wechat_user_id', $id)->find(); if ($puCodeQuery) { - $puCodeQuery->pucode = $pucode; + $puCodeQuery->wechat_user_id = $id; $puCodeQuery->create_time = time(); $puCodeQuery->save(); } else { @@ -98,20 +98,22 @@ class UserService extends BaseService 'wechat_user_id' => $id ]; - $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); + if ($tax_number) { + $headQuery = (new InvoiceHead())->where($headSave)->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;