diff --git a/app/controller/admin/Index.php b/app/controller/admin/Index.php index e70e360..418315a 100644 --- a/app/controller/admin/Index.php +++ b/app/controller/admin/Index.php @@ -77,6 +77,14 @@ class Index extends Base { } } + $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) { @@ -112,8 +120,7 @@ class Index extends Base { ['report_time', '<', $end_time] ]; - $result = (new InvoiceFinalReport())->where($where)->field('sum(`ydzse`) as ydzse_sum')->find(); - $amountArr[$key] = $result['ydzse_sum'] ?? 0; + $amountArr[$key] = (new InvoiceFinalReport())->getSumAmount($where); } return $this->buildSuccess([ diff --git a/app/model/InvoiceFinalReport.php b/app/model/InvoiceFinalReport.php index 8d0aac7..a8b1f1e 100644 --- a/app/model/InvoiceFinalReport.php +++ b/app/model/InvoiceFinalReport.php @@ -7,4 +7,10 @@ use think\Model; class InvoiceFinalReport extends Model { + + public function getSumAmount($where) + { + $result = $this->where($where)->field('sum(`ydzse`) as ydzse_sum')->find(); + return $result['ydzse_sum'] ? number_format($result['ydzse_sum'], 2, '.', ',') : 0; + } }