发票管理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.
 
 
 

137 lines
4.6 KiB

<?php
namespace app\service\invoice;
use app\model\InvoiceHead;
use app\model\InvoiceIssuance;
use app\service\webService\FeeService;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
use Endroid\QrCode\Label\Alignment\LabelAlignmentCenter;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\Writer\PngWriter;
use fast\FuncException;
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('project_id,invoice_head_id,amount,create_time,status')
->order('create_time desc')
->paginate($limit, false)
->each(function ($item, $key) {
$InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id);
$item->serial_number = date("YmdHis") . rand(0000, 9999);
$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 = InvoiceIssuance::$statusArr[$item->status];
});
return $data->toArray();
}
/**
*
* @param $pucode
* @param $expire_time
* @param $project_id
* @return string[]
* @throws FuncException
*/
public static function validateFeePay($pucode, $expire_time, $project_id): array
{
$expire_date = date('Ym', strtotime($expire_time));
$errorMsg = '该账单还未缴费,请先完成缴费。';
switch ($project_id) {
case 1:
$FeeService = new FeeService($pucode);
$param = [
'startCostYearMonth' => $expire_date,
'endCostYearMonth' => $expire_date,
'PaymentStatus' => 2,
];
$ComputeDetail = $FeeService->getComputeDetail($param);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
return ['amount' => $ComputeDetail['WaterAmount']];
case 2:
throw new FuncException('尚未开发,请耐心等待!');
default:
throw new FuncException('尚未开发,请耐心等待!');
}
}
/**
* 获取二维码
* @return string
*/
public static function getQrCode(): string
{
//$ChinaTaxes = new ChinaTaxes();
$codeUrl = 'http://www.longazi.vip/blog/22';//$ChinaTaxes->downTaxPaymentProve();
$result = Builder::create()
->writer(new PngWriter())
->writerOptions([])
->data($codeUrl)
->encoding(new Encoding('UTF-8'))
->errorCorrectionLevel(new ErrorCorrectionLevelHigh())
->size(300)
->margin(10)
->labelText('发票已开具,请扫描二维码获取发票!')
->labelFont(new NotoSans(20))
->labelAlignment(new LabelAlignmentCenter())
->validateResult(false)
->build();
return $result->getDataUri();
}
}