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

131 lines
4.5 KiB

<?php
declare (strict_types=1);
namespace app\controller\admin;
use app\model\InvoiceFinalReport;
use app\model\InvoiceHead;
use app\model\WechatUser;
use app\util\ReturnCode;
use think\Response;
class Index extends Base {
public function upload(): Response {
$path = '/upload/' . date('Ymd', time()) . '/';
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
//过滤错误
if ($error) {
switch ($error) {
case 1:
$error_message = '您上传的文件超过了PHP.INI配置文件中UPLOAD_MAX-FILESIZE的大小';
break;
case 2:
$error_message = '您上传的文件超过了PHP.INI配置文件中的post_max_size的大小';
break;
case 3:
$error_message = '文件只被部分上传';
break;
case 4:
$error_message = '文件不能为空';
break;
default:
$error_message = '未知错误';
}
die($error_message);
}
$arr_name = explode('.', $name);
$hz = array_pop($arr_name);
$new_name = md5(time() . uniqid()) . '.' . $hz;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $path)) {
mkdir($_SERVER['DOCUMENT_ROOT'] . $path, 0755, true);
}
if (move_uploaded_file($tmp_name, $_SERVER['DOCUMENT_ROOT'] . $path . $new_name)) {
return $this->buildSuccess([
'fileName' => $new_name,
'fileUrl' => $this->request->domain() . $path . $new_name
]);
} else {
return $this->buildFailed(ReturnCode::FILE_SAVE_ERROR, '文件上传失败');
}
}
/**
*
* @return Response
*/
public function statistics(): Response
{
try {
$data = [];
$wechatUserTotal = (new WechatUser)->where('delete_time', 0)->count('id');
$data['wechat_user_total'] = $wechatUserTotal;
$data['invoice_head_data'] = [['type' => '机构', 'count' => 0], ['type' => '个人', 'count' => 0]];
$invoice_head_field = "type, count(id) as `count`";
$invoice_head_data = (new InvoiceHead)->field($invoice_head_field)->group('type')->select()->toArray();
if ($invoice_head_data) {
foreach ($invoice_head_data as $invoice_head_value) {
if ($invoice_head_value['type'] > 0) {
$data['invoice_head_data'][1]['count'] += $invoice_head_value['count'];
} else {
$data['invoice_head_data'][0]['count'] += $invoice_head_value['count'];
}
}
}
$finalReportArr = ['type' => '当月结报金额', 'count' => 0];
$where = [
['report_time', '>=', strtotime(date("Y-m"))],
['report_time', '<', strtotime('+1 month', strtotime(date("Y-m")))]
];
$finalReportArr['count'] = (new InvoiceFinalReport())->getSumAmount($where);
$data['invoice_head_data'][] = $finalReportArr;
return $this->buildSuccess($data);
} catch (\Exception $e) {
return $this->buildFailed(ReturnCode::RECORD_NOT_FOUND, '记录未找到');
}
}
/**
* 结报金额统计-月
* @return Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFinalReportData()
{
$dateArr = [];
$amountArr = [];
$nowDate = date('Y-m');
for ($i = 5; $i >= 1; $i--) {
$dateArr[] = date('Y-m', strtotime('-' . $i . ' month', strtotime($nowDate)));
$amountArr[] = 0;
}
$dateArr[] = $nowDate;
foreach ($dateArr as $key => $monthDate) {
$start_time = strtotime($monthDate);
$end_time = strtotime('+1 month', $start_time);
$where = [
['report_time', '>=', $start_time],
['report_time', '<', $end_time]
];
$amountArr[$key] = (new InvoiceFinalReport())->getSumAmount($where);
}
return $this->buildSuccess([
'date' => $dateArr,
'data' => $amountArr
]);
}
}