发票管理apiadmin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

822 lines
29 KiB

<?php
namespace app\service\invoice;
use app\model\FinalReportData;
use app\model\FinalReportDate;
use app\model\InvoiceHead;
use app\model\InvoiceIssuance;
use app\model\InvoiceIssuanceData;
use app\service\user\UserService;
use app\service\webService\ChinaTaxes;
use app\service\webService\FeeService;
use fast\FuncException;
use think\App;
use think\facade\Log;
class InvoiceIssuanceService
{
/**
* 获取发票列表
* @param $param
* @param $wechat_user_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getListPage($param, $wechat_user_id): array
{
$limit = $params['limit'] ?? 10;
$where = [
['wechat_user_id', '=', $wechat_user_id],
['delete_time', '=', 0]
];
if (isset($param['start_date']) && !empty($param['start_date'])) {
$where[] = [
'create_time', '>=', strtotime($param['start_date'] . ' 00:00:00')
];
}
if (isset($param['end_date']) && !empty($param['end_date'])) {
$where[] = [
'create_time', '<=', strtotime($param['end_date'] . ' 23:59:59')
];
}
$model = (new InvoiceIssuance());
$data = $model->where($where)
->field('id,project_id,invoice_head_id,amount,create_time,status,serial_number,expire_time')
->order('create_time desc')
->paginate($limit, false)
->each(function ($item, $key) {
$InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id);
$item->serial_number = !empty($item->serial_number) ? $item->serial_number : $this->getSerialNumber();
$item->head_type = '';
$item->head_title = '';
if ($InvoiceHead) {
$item->head_type = InvoiceHead::$typeArr[$InvoiceHead['type']];
$item->head_title = $InvoiceHead['title'];
}
$item->project_id = InvoiceIssuance::$projectArr[$item->project_id] ?? '';
$item->status_str = InvoiceIssuance::$statusArr[$item->status];
$item->expire_time = date("Y-m", $item->expire_time);
});
return $data->toArray();
}
/**
* 获取订单编号
* @return string
*/
public function getSerialNumber(): string
{
return date("YmdHis") . rand(0000, 9999);
}
/**
* 验证缴费
* @param $pucode
* @param $expire_time
* @param $project_id
* @param string $merge 是否合并
* @param string $tax_number
* @return string[]
* @throws FuncException
*/
public static function validateFeePay($pucode, $expire_time, $project_id, string $merge = '', string $tax_number = ''): array
{
$expire_date = date('Ym', strtotime($expire_time));
$errorMsg = '该账单还未缴费,请先完成缴费。';
switch ($project_id) {
case 1:
case 2:
// 合并逻辑
if ($merge == '1') {
if (empty($tax_number)) {
throw new FuncException('请填写纳税人编号');
}
$pucodeArr = UserService::getTaxUser($tax_number);
if (empty($pucodeArr)) {
throw new FuncException('登录的用户id与纳税人编号不符,请重新输入');
}
$pucodeArr[] = $pucode;
$pucodeArr = array_unique($pucodeArr);
$amount = 0;
foreach ($pucodeArr as $newPuCode) {
$ComputeDetail = self::getFeeComputeDetail($newPuCode, $expire_date);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
$amount = bcadd($amount, $ComputeDetail['WaterAmount'], 2);
}
return ['amount' => $amount];
} else {
$ComputeDetail = self::getFeeComputeDetail($pucode, $expire_date);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
return ['amount' => $ComputeDetail['WaterAmount']];
}
default:
throw new FuncException('尚未开发,请耐心等待!');
}
}
/**
*
* @param $pucode
* @param $expire_date
* @return mixed
* @throws FuncException
*/
public static function getFeeComputeDetail($pucode, $expire_date)
{
$FeeService = new FeeService($pucode);
$param = [
'startCostYearMonth' => $expire_date,
'endCostYearMonth' => $expire_date,
'PaymentStatus' => 2,
];
$data = $FeeService->getComputeDetail($param);
unset($param['PaymentStatus']);
$data2 = $FeeService->getReadingDetail($param);
$data['ThisLastReadingTime'] = '';
if ($data2['MsgID'] != 1) {
$ThisReadingTime = $data2['ThisReadingTime'] ? self::optionReadingTime($data2['ThisReadingTime']) : '';
$LastReadingTime = $data2['LastReadingTime'] ? self::optionReadingTime($data2['LastReadingTime']) : '';
$data['ThisLastReadingTime'] = $ThisReadingTime . ' 至 ' . $LastReadingTime;
}
return $data;
}
/**
* 处理日期字符
* @param $date
* @return array|string|string[]
*/
protected static function optionReadingTime($date)
{
$date = str_replace('年','-',$date);
$date = str_replace('月','-',$date);
return str_replace('日','',$date);
}
/**
* 处理申请日期
* @param $expire_time
* @return array
*/
public function getInvoiceDate($expire_time): array
{
$expire_time = strtotime(date("Y-m",$expire_time));
return [
'nsqxDm' => date("m", $expire_time), // 申请月份
'skssqq' => date("Y-m-d", $expire_time), // 申请开始日期
'skssqz' => date("Y-m-d", strtotime('+1 month -1 day', $expire_time)),// 申请结束日期
];
}
/**
* 获取水务用户信息
* @param $pucode
* @return array|mixed
* @throws FuncException
*/
public function getFeeUserData($pucode)
{
$FeeService = new FeeService($pucode);
$feeUsers = $FeeService->getUsers();
if (!$feeUsers) {
throw new FuncException('未获取到用户信息');
}
return $feeUsers;
}
/**
* 获取被代征纳税人识别号
* @param $invoice_head_id // 抬头id
* @return mixed|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTaxNumber($invoice_head_id)
{
$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'] ?? '';
}
return $bdznsrsbh;
}
/**
* 开具完税证明
* @param $invoiceIssuance // 开票信息
* @return bool|string
*/
public function IssueAnInvoice($invoiceIssuance)
{
$sbpch = '';
try {
// 用户编码
$pucode = $invoiceIssuance['pucode'];
if (empty($invoiceIssuance['expire_time'])) {
throw new FuncException('申请日期不能为空');
}
$invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']);
$bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号
$puCodeUserData = [];
$pucodeArr = [$pucode];
if ($invoiceIssuance['merge'] == 1) {
$pucodeArr = UserService::getTaxUser($bdznsrsbh);
}
// 多组用户编号
foreach ($pucodeArr as $valPucode) {
$feeUsers = $this->getFeeUserData($valPucode);
$feeUsers['bdznsrsbh'] = $bdznsrsbh;
// 获取用户应收费信息
$FeeComputeDetail = self::getFeeComputeDetail($valPucode, date("Ym", $invoiceIssuance['expire_time']));
if ($FeeComputeDetail['MsgID'] != 1) {
throw new FuncException($FeeComputeDetail);
}
$feeUsers['jsyj'] = $FeeComputeDetail['WaterAmount'];
$feeUsers['zsfsmc'] = $FeeComputeDetail['chargetype'];
$feeUsers['jfrq'] = $FeeComputeDetail['WaterPayDate'];
$feeUsers['project_name'] = $invoiceIssuance['project_name'] ?? '';
$feeUsers['serial_number'] = $invoiceIssuance['serial_number'];
$feeUsers['WaterUsage'] = $FeeComputeDetail['WaterUsage'];
$feeUsers['WaterItem'] = $FeeComputeDetail['WaterItem'];
$feeUsers['WaterQty'] = $FeeComputeDetail['WaterQty'];
$feeUsers['WaterPrice'] = $FeeComputeDetail['WaterPrice'];
$feeUsers['ThisLastReadingTime'] = $FeeComputeDetail['ThisLastReadingTime'];
$puCodeUserData[] = $feeUsers;
}
// 保存
$is_continue = false;// 是否跳过加工
$jsyj = 0; // 总金额
$ChinaTaxes = new ChinaTaxes($puCodeUserData, $invoiceDate);
$savingDetailedData = $ChinaTaxes->savingDetailedData();
if (!isset($savingDetailedData['sbpch'])) {
$VoucherData = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh);
$bdzkjmxList = $VoucherData['bdzkjmxList'];
if (empty($bdzkjmxList)) {
throw new \Exception('未查询到待开具电子缴款凭证数据');
}
foreach ($bdzkjmxList as $bdzkjmxValue) {
foreach($bdzkjmxValue['bdzkjmxVO'] as $bdzkjmxVOValue) {
if ($bdzkjmxVOValue['yhbm'] == $pucode) {
$sbpch = $bdzkjmxVOValue['sbpch'];
$jsyj = $bdzkjmxVOValue['ydzse'];
$is_continue = true;
}
}
}
if (!$is_continue) throw new \Exception('未查询到用户开具电子缴款凭证数据');
} else {
// 批次号
$sbpch = $savingDetailedData['sbpch'];
}
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'sbpch', $sbpch);
// 委托 - 加工数据
$realTimeProcessing = ['code' => 0];
if (!$is_continue) {
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
}
if ($realTimeProcessing['code'] == 200 || $is_continue) {
// 处理加工成功返回数据
if (!$is_continue) {
if (!isset($realTimeProcessing['data']['mxGrid'])) {
throw new FuncException('加工数据有误');
}
$mxGrid = $realTimeProcessing['data']['mxGrid'];
if (isset($mxGrid['sbMxsjVOList'])) {
foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) {
if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj'];
}
}
}
// 加工成功 电子缴款申请
$issueElectronic = $ChinaTaxes->issueElectronic($sbpch, $bdznsrsbh);
if (!isset($issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID'])) {
throw new FuncException('文件唯一标识不存在');
}
$assetID = $issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID']; // 文件唯一标识
// 查询电子缴款凭证上链信息
$queryPaymentVoucher = $ChinaTaxes->queryPaymentVoucher($assetID);
//$mmq = $queryPaymentVoucher['mmq'];
$meta = $queryPaymentVoucher['meta'];
$data = $queryPaymentVoucher['data'];
// 拼接pdf
// 盖章
$requestData = ['data' => $data, 'meta' => $meta];
$deCompress = $this->deCompress($requestData);
if ($deCompress['status'] != 200) {
throw new FuncException('pdf数据解密失败');
}
if (!isset($deCompress['data']['pdfdata'])) {
throw new FuncException('pdf文件合并失败');
}
$pdfFilepath = $deCompress['data']['pdfdata'];//$this->savePdfFile($deCompress['data']['pdfdata']);
(new InvoiceIssuanceData())->saveData($invoiceIssuance['id'], $bdznsrsbh, $jsyj, $assetID, $pdfFilepath);
(new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 3, 'issuance_time' => time()]);
} else if ($realTimeProcessing['code'] == 302) {
// 加工失败
// 查询上传异常数据接口
$queryUploadErrorData = $ChinaTaxes->queryUploadErrorData($sbpch);
if (!isset($queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms'])) {
throw new FuncException('异常信息返回有误');
}
// 查询待开具电子缴款
$queryIssuedPaymentVoucher = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh);
// 保存用户异常状态
$ycms = $queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms']; // 数据异常描述
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $ycms);
// 开票失败
(new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 2]);
//throw new FuncException('加工失败流程待定!');
}
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
// 未获取到批次号报错
if (empty($sbpch)) {
}
$this->writeLog($e);
return $e->getMessage();
}
}
/**
* 用户更正数据后作废再发起
*/
public function cancelInitiateAgain($invoiceIssuance)
{
try {
$feeUsers = $this->getFeeUserData($invoiceIssuance['pucode']);
$InvoiceIssuanceWhere = ['invoice_issuance_id' => $invoiceIssuance['id'], 'status' => 1];
$InvoiceIssuanceData = (new InvoiceIssuanceData())->where($InvoiceIssuanceWhere)->find();
if (!$InvoiceIssuanceData) {
throw new FuncException('上次发起数据不存在');
}
$bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号
$sbpch = $InvoiceIssuanceData['sbpch'];
$ChinaTaxes = new ChinaTaxes($feeUsers, []);
$identityCheck = $ChinaTaxes->identityCheck($bdznsrsbh);
if (isset($identityCheck['zt']) && $identityCheck['zt'] == 'N') {
throw new FuncException($identityCheck['Yy']);// 返回校验不通过原因
}
// 代征明细数据虚拟户更正接口
$ChinaTaxes->collectionDetails($bdznsrsbh, $sbpch);
// 作废 3.2
$ChinaTaxes->invalidEntrustCollection($sbpch);
// 修改作废
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'status', 0, 2);
$result = $this->IssueAnInvoice($invoiceIssuance);
if ($result !== true) {
throw new \Exception($result);
}
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
$this->writeLog($e);
return $e->getMessage();
}
}
/**
* 保存 PDF
* @param $pdfBaseData
* @return string
*/
public function savePdfFile($pdfBaseData): string
{
$pdfStr = str_replace('data:application/pdf;base64,', '', $pdfBaseData);
$pdfDecode = base64_decode($pdfStr);
$d = '/';
$fileName = time() . rand(000000, 999999) . '.pdf';
$now_date = date("{$d}Y{$d}m{$d}d");
$downPath = 'pdffile' . $now_date;
$fileDirPath = (new App())->getRootPath() . 'public' . $d . $downPath;
$filenamePath = $fileDirPath . $d . $fileName;
$savePath = $downPath . $d . $fileName;
if (!file_exists($fileDirPath)) {
mkdir($fileDirPath, 0777, true);
}
file_put_contents($filenamePath, $pdfDecode);
return $savePath;
}
/**
* 保存汇总结报数据 (汇总、结报)
* @return bool|string
*/
public function saveSummaryReport()
{
try {
$report_date = date("Y-m");
$FinalReportDate = new FinalReportDate();
$frd_id = $FinalReportDate->where('report_date', $report_date)->value('id');
if (!$frd_id) {
$frdSave = [
'report_date' => $report_date,
'status' => 0,
'create_time' => time()
];
$frd_id = $FinalReportDate->insertGetId($frdSave);
}
$invoiceDate = $this->getInvoiceDate(strtotime($report_date));
$bdznsrsbh = $this->getTaxNumber(0); // 被征纳税人
$ChinaTaxes = new ChinaTaxes([], $invoiceDate);
$daiZhengSummaryQuery = $ChinaTaxes->daiZhengSummaryQuery($bdznsrsbh);
$FinalReportData = new FinalReportData();
$save = [];
if (isset($daiZhengSummaryQuery['cxwjbList'])) {
foreach ($daiZhengSummaryQuery['cxwjbList'] as $value) {
foreach ($value['cxwjbVO'] as $val) {
$sbpch = $val['sbpch']; // 申报批次号
$queryWhere = [
'frd_id' => $frd_id,
'sbpch' => $sbpch
];
$queryData = $FinalReportData->where($queryWhere)->field('id')->find();
if ($queryData) {
continue;
}
$queryWhere['ydzse'] = $val['ydzse'];
$queryWhere['create_time'] = time();
$save[] = $queryWhere;
}
}
}
if (!$save) {
throw new FuncException($daiZhengSummaryQuery['message'] ?? '数据储存失败');
}
$FinalReportData->saveAll($save);
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* 结报
* @param $frd_id
* @return bool|string
*/
public function finalReport($frd_id)
{
try {
$FinalReportDate = new FinalReportDate();
$data = $FinalReportDate->where('id', $frd_id)->find();
if (!$data) {
throw new \Exception('参数有误');
}
$zje = FinalReportData::getFrdSumAmount($frd_id);
if ($zje <= 0) {
throw new \Exception('结报金额为0');
}
$invoiceDate = $this->getInvoiceDate(strtotime($data['report_date']));
$ChinaTaxes = new ChinaTaxes([], $invoiceDate);
$result = $ChinaTaxes->daiZhengSummaryReport($zje);
if ($result['code'] == 200 && $result['message'] == '结报完成') {
$update = [
'status' => 1,
'report_time' => time()
];
FinalReportDate::update($update, ['id' => $frd_id]);
} else {
throw new FuncException($result['message'] ?? '结报失败');
}
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
public function writeLog($e)
{
Log::record('Exception message: ' . $e->getMessage());
Log::record('Exception file: ' . $e->getFile());
Log::record('Exception line: ' . $e->getLine());
Log::record('Exception trace: ' . $e->getTraceAsString());
}
/**
* 调用java sm4 解密
* @param array $data
* @return mixed
* @throws FuncException
*/
public function deCompress(array $data)
{
$java_decode_url = 'https://intp.xingtongworld.com/v1/tax/xt';
// 初始化cURL会话
$ch = curl_init();
// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, $java_decode_url); // 目标URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回结果而不是输出
curl_setopt($ch, CURLOPT_POST, true); // 发送POST请求
// 设置POST字段
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data')); // 设置HTTP头
// 跳过证书验证(不推荐在生产环境使用)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 跳过主机名验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// 执行cURL会话
$response = curl_exec($ch);
// 检查是否有错误发生
if (curl_errno($ch)) {
throw new FuncException('请求失败');
}
// 关闭cURL会话
curl_close($ch);
return json_decode($response, true);
}
/**
* 转发获取接口发票
* @param $data
* @return bool
*/
public function tempIssueAnInvoice($data): bool
{
try {
$resultData = $this->curl($data);
if (isset($resultData['code']) && $resultData['code'] == 1) {
$r_data = $resultData['data'];
// 存在错误
if (!empty($r_data['ycms'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $r_data['ycms']);
if (empty($r_data['sbpch'])) {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 2]);
// 第一次保存协议就失败
throw new \Exception($r_data['ycms']);
}
}
if (!empty($r_data['sbpch'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'sbpch', $r_data['sbpch']);
if (isset($r_data['i_i_d_data'])) {
$d_data = $r_data['i_i_d_data'];
// 拼接pdf 盖章
$requestData = ['data' => $d_data['pdf_data'], 'meta' => $d_data['pdf_meta']];
$deCompress = $this->deCompress($requestData);
if ($deCompress['status'] != 200) {
throw new FuncException('pdf数据解密失败');
}
if (!isset($deCompress['data']['pdfdata'])) {
throw new FuncException('pdf文件合并失败');
}
$pdfFilepath = $deCompress['data']['pdfdata'];//$this->savePdfFile($deCompress['data']['pdfdata']);
// 保存
(new InvoiceIssuanceData())->saveData($d_data['i_i_id'], $d_data['bdznsrsbh'], $d_data['jsyj'], $d_data['assetID'], $pdfFilepath);
}
if (isset($r_data['i_i_data'])) {
$i_i_data = $r_data['i_i_data'];
if ($i_i_data['status'] == 3) {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 3, 'issuance_time' => $i_i_data['issuance_time']]);
} else {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 2]);
}
}
}
} else {
throw new \Exception('请求失败');
}
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $e->getMessage());
//echo $e->getMessage() . '<br>';
return false;
}
}
/**
*
* @param array $data
* @param string $url
* @return mixed
* @throws \Exception
*/
private function curl(array $data, string $url = 'apiInvoiceIssuance')
{
$data_json = json_encode($data);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://intp.xingtongworld.com/api/test/" . $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_json,
CURLOPT_HTTPHEADER => [
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Connection: keep-alive",
"Content-Type: application/json",
],
]);
// 跳过证书验证(不推荐在生产环境使用)
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// 跳过主机名验证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new \Exception("cURL Error #:" . $err);
} else {
return json_decode($response, true);
}
}
/**
* 临时第三方代理结报数据保存
* @return bool|string
*/
public function tempSaveSummaryReport()
{
try {
$report_date = date("Y-m");
$FinalReportDate = new FinalReportDate();
$frd_id = $FinalReportDate->where('report_date', $report_date)->value('id');
if (!$frd_id) {
$frdSave = [
'report_date' => $report_date,
'status' => 0,
'create_time' => time()
];
$frd_id = $FinalReportDate->insertGetId($frdSave);
}
$data = $this->curl(['report_date' => $report_date], 'saveSummaryReport');
$FinalReportData = new FinalReportData();
if ($data['code'] == 1) {
$save = [];
foreach ($data['data'] as $val) {
$sbpch = $val['sbpch']; // 申报批次号
$queryWhere = [
'frd_id' => $frd_id,
'sbpch' => $sbpch
];
$queryData = $FinalReportData->where($queryWhere)->field('id')->find();
if ($queryData) {
continue;
}
$queryWhere['ydzse'] = $val['ydzse'];
$queryWhere['create_time'] = $val['create_time'];
$save[] = $queryWhere;
}
if (!$save) {
throw new FuncException('无新的结报数据');
}
$FinalReportData->saveAll($save);
} else {
throw new \Exception($data['msg']);
}
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* 临时结报
* @param $frd_id
* @return bool|string
*/
public function tempFinalReport($frd_id)
{
try {
$FinalReportDate = new FinalReportDate();
$data = $FinalReportDate->where('id', $frd_id)->find();
if (!$data) {
throw new \Exception('参数有误');
}
$zje = FinalReportData::getFrdSumAmount($frd_id);
if ($zje <= 0) {
throw new \Exception('结报金额为0');
}
$result = $this->curl(['report_date' => $data['report_date'], 'zje' => $zje], 'apiFinalReport');
if ($result['code'] == 1) {
$update = [
'status' => 1,
'report_time' => time()
];
FinalReportDate::update($update, ['id' => $frd_id]);
} else {
throw new FuncException($result['msg'] ?? '结报失败');
}
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}