Browse Source

结报统计接口优化

master
wanghongjun 11 months ago
parent
commit
01ac7aa8cc
  1. 26
      app/controller/api/InvoiceIssuance.php
  2. 24
      app/model/InvoiceHead.php
  3. 2
      app/service/invoice/InvoiceIssuanceService.php

26
app/controller/api/InvoiceIssuance.php

@ -7,7 +7,6 @@ use app\model\InvoiceIssuance as InvoiceIssuanceModel;
use app\model\InvoiceIssuanceData; use app\model\InvoiceIssuanceData;
use app\model\WechatPucode; use app\model\WechatPucode;
use app\service\invoice\InvoiceIssuanceService; use app\service\invoice\InvoiceIssuanceService;
use app\service\webService\FeeService;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\validate\InvoiceHeadValidate; use app\validate\InvoiceHeadValidate;
use app\validate\InvoiceIssuanceValidate; use app\validate\InvoiceIssuanceValidate;
@ -130,13 +129,17 @@ class InvoiceIssuance extends Base
try { try {
$wechat_user_id = $this->request->wechat_user_id; $wechat_user_id = $this->request->wechat_user_id;
$field = 'type, title, tax_number';
$where = [
['wechat_user_id', '=', $wechat_user_id],
['tax_number', '<>', ''],
];
$data = (new InvoiceHead())->where($where)->field($field)->order('id', 'DESC')->find();
if (!$data) {
$pucode = (new WechatPucode())->where('wechat_user_id', $wechat_user_id)->value('pucode'); $pucode = (new WechatPucode())->where('wechat_user_id', $wechat_user_id)->value('pucode');
$FeeService = new FeeService($pucode); $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode);
$feeUserInfo = $FeeService->getUsers();
if (!$feeUserInfo) {
throw new \Exception('用户信息获取失败');
}
$data = [ $data = [
'title' => $feeUserInfo['UserName'] ?? '', 'title' => $feeUserInfo['UserName'] ?? '',
]; ];
@ -145,14 +148,7 @@ class InvoiceIssuance extends Base
$data['type'] = 1; $data['type'] = 1;
} }
$data['tax_number'] = empty($feeUserInfo['CertificateCode']) ? $feeUserInfo['CertificateCode'] : ''; $data['tax_number'] = empty($feeUserInfo['CertificateCode']) ? $feeUserInfo['CertificateCode'] : '';
}
// if ($data['type'] === 0) {
// $data['address'] = $feeUserInfo['MaillingAddress'];
// $data['telephone'] = $feeUserInfo['Telephone'];
// $data['bank_name'] = $feeUserInfo['BankName'];
// $data['bank_account'] = $feeUserInfo['BankAccountCode'];
// }
return $this->buildSuccess($data); return $this->buildSuccess($data);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->buildFailed(ReturnCode::NOT_EXISTS, $e->getMessage()); return $this->buildFailed(ReturnCode::NOT_EXISTS, $e->getMessage());
@ -200,7 +196,7 @@ class InvoiceIssuance extends Base
//验证 、 新建抬头、获取抬头id //验证 、 新建抬头、获取抬头id
validate(InvoiceHeadValidate::class)->scene('type')->check($params); validate(InvoiceHeadValidate::class)->scene('type')->check($params);
validate(InvoiceHeadValidate::class)->scene('type'.$params['type'])->check($params); validate(InvoiceHeadValidate::class)->scene('type'.$params['type'])->check($params);
$data['invoice_head_id'] = InvoiceHead::createHead($wechat_user_id,$params); $data['invoice_head_id'] = InvoiceHead::createHead($wechat_user_id, $params);
if ($id) { if ($id) {
validate(InvoiceIssuanceValidate::class)->scene('edit')->check($params); validate(InvoiceIssuanceValidate::class)->scene('edit')->check($params);

24
app/model/InvoiceHead.php

@ -2,6 +2,8 @@
namespace app\model; namespace app\model;
use app\service\invoice\InvoiceIssuanceService;
use fast\FuncException;
use think\Model; use think\Model;
class InvoiceHead extends Model class InvoiceHead extends Model
@ -9,14 +11,22 @@ class InvoiceHead extends Model
public static $typeArr = ['单位', '个人']; public static $typeArr = ['单位', '个人'];
/**
*
* @param $wechat_user_id
* @param $data
* @return mixed
* @throws FuncException
*/
public static function createHead($wechat_user_id, $data) public static function createHead($wechat_user_id, $data)
{ {
if (isset($data['tax_number']) && $data['tax_number'] == 'undefined') $data['tax_number'] = ''; $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($data['pucode']);
$param = [ $param = [
'type' => $data['type'], 'type' => $data['type'],
'title' => $data['title'], 'title' => $feeUserInfo['UserName'] ?? '',
'tax_number' => $data['tax_number'], 'tax_number' => $feeUserInfo['CertificateCode'] ?? '',
'wechat_user_id' => $wechat_user_id 'wechat_user_id' => $wechat_user_id
]; ];
@ -25,10 +35,10 @@ class InvoiceHead extends Model
return $id; return $id;
} }
$param['address'] = $data['address'] ?? ''; $param['address'] = $feeUserInfo['MaillingAddress'] ?? '';
$param['telephone'] = $data['telephone'] ?? ''; $param['telephone'] = $feeUserInfo['Telephone'] ?? '';
$param['bank_name'] = $data['bank_name'] ?? ''; $param['bank_name'] = $feeUserInfo['BankName'] ?? '';
$param['bank_account'] = $data['bank_account'] ?? ''; $param['bank_account'] = $feeUserInfo['BankAccountCode'] ?? '';
$param['create_time'] = time(); $param['create_time'] = time();

2
app/service/invoice/InvoiceIssuanceService.php

@ -190,7 +190,7 @@ class InvoiceIssuanceService
* @return array|mixed * @return array|mixed
* @throws FuncException * @throws FuncException
*/ */
private function getFeeUserData($pucode) public function getFeeUserData($pucode)
{ {
$FeeService = new FeeService($pucode); $FeeService = new FeeService($pucode);
$feeUsers = $FeeService->getUsers(); $feeUsers = $FeeService->getUsers();

Loading…
Cancel
Save