3 changed files with 97 additions and 34 deletions
@ -0,0 +1,61 @@ |
|||
<?php |
|||
|
|||
namespace app\controller\admin; |
|||
|
|||
use app\service\invoice\InvoiceIssuanceService; |
|||
use app\util\ReturnCode; |
|||
use think\facade\Db; |
|||
use think\Response; |
|||
use app\model\InvoiceFinalReport as InvoiceFinalReportModel; |
|||
|
|||
class InvoiceFinalReport extends Base |
|||
{ |
|||
|
|||
public function index(): Response |
|||
{ |
|||
|
|||
$param = $this->request->get(); |
|||
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); |
|||
$where = [['status', '=', 3]]; |
|||
|
|||
if (isset($param['expire_time']) && !empty($param['expire_time'])) { |
|||
$where = ['expire_time', '=', strtotime($param['expire_time'])]; |
|||
} |
|||
|
|||
$list = Db::table('invoice_issuance') |
|||
->where($where) |
|||
->field('expire_time, sum(amount) as amount_sum') |
|||
->group('expire_time') |
|||
->page($limit) |
|||
->select() |
|||
->toArray(); |
|||
$select = Db::table('invoice_issuance')->where('status', 3)->field('count(expire_time)')->group('expire_time')->select(); |
|||
$total = count($select); |
|||
foreach ($list as &$item) { |
|||
$count = (new InvoiceFinalReportModel())->where('report_time', $item['expire_time'])->count(); |
|||
$item['status'] = $count ? 1 : 0; |
|||
$item['status_str'] = $item['status'] == 1 ? '已结报' : '未结报'; |
|||
$item['expire_time'] = date("Y-m", $item['expire_time']); |
|||
} |
|||
|
|||
return $this->buildSuccess([ |
|||
'list' => $list, |
|||
'total' => $total |
|||
]); |
|||
} |
|||
|
|||
public function report(): Response |
|||
{ |
|||
try { |
|||
$param = $this->request->get(); |
|||
validate()->rule(['report_time|结报日期' => 'require|date'])->check($param); |
|||
$report_time = $param['report_time']; |
|||
$InvoiceIssuanceService = new InvoiceIssuanceService(); |
|||
$result = $InvoiceIssuanceService->summaryReport(strtotime($report_time)); |
|||
if ($result !== true) throw new \Exception($result); |
|||
return $this->buildSuccess(); |
|||
} catch (\Exception $e) { |
|||
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, $e->getMessage()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue