diff --git a/app/adminapi/controller/consult_basic/ConsultStatisticsController.php b/app/adminapi/controller/consult_basic/ConsultStatisticsController.php index 5c8ebe904..a0bed050f 100644 --- a/app/adminapi/controller/consult_basic/ConsultStatisticsController.php +++ b/app/adminapi/controller/consult_basic/ConsultStatisticsController.php @@ -1,74 +1,97 @@ where([ - ['review_status','=', 1], - ['contract_type','=',0], - ['business_nature','=',3], - ['status','=',0] - ])->count(); - //已立项项目 - $approved_project_num = ConsultProject::field('id')->count(); - $result['data'] = [ - [ - 'name' => '待立项项目', - 'value' => $pending_project_num - ], - [ - 'name' => '已立项项目', - 'value' => $approved_project_num - ] - ]; - return $this->success('success',$result); + $date = $this->request->get('date', ''); + $where = []; + $time = getDay($date); + $res = ConsultStatisticsLogic::consultStatistics($where, $time); + return $this->data($res); + } + + public function project() + { + //待立项项目 + $pending_project_num = MarketingContract::field('id')->where([ + ['review_status', '=', 1], + ['contract_type', '=', 0], + ['business_nature', '=', 3], + ['status', '=', 0] + ])->count(); + //已立项项目 + $approved_project_num = ConsultProject::field('id')->count(); + $result['data'] = [ + [ + 'name' => '待立项项目', + 'value' => $pending_project_num + ], + [ + 'name' => '已立项项目', + 'value' => $approved_project_num + ] + ]; + return $this->success('success', $result); + } + + public function invoice() + { + $year = $this->request->get('year', date('Y')); + $contract_ids = ConsultProject::column('contract'); + //总开票金额 + $total_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->sum('apply_amount'); + //年度开票金额 + $year_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereYear('create_time', $year)->sum('apply_amount'); + //总到账金额 + $total_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->sum('amount'); + $year_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + //总结算金额 + $total_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->sum('amount'); + //年度结算金额 + $year_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; + $invoice_series = [ + 'name' => '开票金额', + 'data' => [] + ]; + $refund_series = [ + 'name' => '到账金额', + 'data' => [] + ]; + $settlement_series = [ + 'name' => '结算金额', + 'data' => [] + ]; + foreach ($column as &$v) { + $invoice_series['data'][] = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereMonth('create_time', $year . '-' . $v)->sum('apply_amount'); + $refund_series['data'][] = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $settlement_series['data'][] = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $v = $v . '月'; } - - public function invoice(){ - $year = $this->request->get('year',date('Y')); - $contract_ids = ConsultProject::column('contract'); - //总开票金额 - $total_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->sum('apply_amount'); - //年度开票金额 - $year_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->whereYear('create_time',$year)->sum('apply_amount'); - //总到账金额 - $total_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->sum('amount'); - $year_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - //总结算金额 - $total_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->sum('amount'); - //年度结算金额 - $year_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; - $invoice_series = [ - 'name' => '开票金额', - 'data' => [] - ]; - $refund_series = [ - 'name' => '到账金额', - 'data' => [] - ]; - $settlement_series = [ - 'name' => '结算金额', - 'data' => [] - ]; - foreach($column as &$v){ - $invoice_series['data'][] = FinancialInvoice::where('contract_id','in',$contract_ids)->whereMonth('create_time',$year.'-'.$v)->sum('apply_amount'); - $refund_series['data'][] = FinancialRefund::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $settlement_series['data'][] = FinancialSettlement::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $v = $v.'月'; - } - $result = compact('total_invoice_amount','year_invoice_amount','total_refund_amount','year_refund_amount','total_settlement_amount','year_settlement_amount', - 'column','invoice_series','refund_series','settlement_series'); - return $this->success('success',$result); - } - } \ No newline at end of file + $result = compact( + 'total_invoice_amount', + 'year_invoice_amount', + 'total_refund_amount', + 'year_refund_amount', + 'total_settlement_amount', + 'year_settlement_amount', + 'column', + 'invoice_series', + 'refund_series', + 'settlement_series' + ); + return $this->success('success', $result); + } +} diff --git a/app/adminapi/controller/financial/FinancialStatisticsController.php b/app/adminapi/controller/financial/FinancialStatisticsController.php index 6732b411c..e72d3f9b0 100644 --- a/app/adminapi/controller/financial/FinancialStatisticsController.php +++ b/app/adminapi/controller/financial/FinancialStatisticsController.php @@ -3,7 +3,8 @@ namespace app\adminapi\controller\financial; use app\adminapi\controller\BaseAdminController; - use app\common\model\financial\FinancialBidMargin; +use app\adminapi\logic\financial\FinancialStatisticsLogic; +use app\common\model\financial\FinancialBidMargin; use app\common\model\financial\FinancialBidMarginRecovery; use app\common\model\financial\FinancialBorrowMoney; use app\common\model\financial\FinancialInvoice; @@ -17,6 +18,15 @@ class FinancialStatisticsController extends BaseAdminController { + + public function index(){ + $date=$this->request->get('date',''); + $where=[]; + $time = getDay($date); + $res=FinancialStatisticsLogic::financialStatistics($where,$time); + return $this->data($res); + } + public function contracts(){ $year = $this->request->get('year',date('Y')); //统计合同总数 diff --git a/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php b/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php new file mode 100644 index 000000000..cdb1b27be --- /dev/null +++ b/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php @@ -0,0 +1,12 @@ +consultStatistics($param); + } +} + diff --git a/app/adminapi/logic/financial/FinancialStatisticsLogic.php b/app/adminapi/logic/financial/FinancialStatisticsLogic.php new file mode 100644 index 000000000..bd6811364 --- /dev/null +++ b/app/adminapi/logic/financial/FinancialStatisticsLogic.php @@ -0,0 +1,140 @@ + $datearr[0], 'end_time' => $datearr[1]]); + $marketingContract = new FinancialInvoice(); + $financialRefund = new FinancialRefund(); + $financialBidMargin = new FinancialBidMargin(); + $financialBidMarginRecovery = new FinancialBidMarginRecovery(); + $financialPerformanceMoneyApply = new FinancialPerformanceMoneyApply(); + $financialPerformanceMoneyRecovery = new FinancialPerformanceMoneyRecovery(); + $financialUsingFunds = new FinancialUsingFunds(); + $financialBorrowMoney = new FinancialBorrowMoney(); + $financialRepayment = new FinancialRepayment(); + //开票金额 + $total_apply_amount = $marketingContract->ContractFinancialMoney([], $time, 'sum', '', 'apply_amount'); + $apply_amount_value = $marketingContract->ContractFinancialMoney([], $time, 'group', 'create_time', 'apply_amount'); + $data[] = [ + 'title' => '开票金额', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'], + 'type' => 1, + ]; + //回款金额 + $total_amount = $financialRefund->statistics([], $time, 'sum', '', 'amount'); + $amount_value = $financialRefund->statistics([], $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '回款金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'], + 'type' => 1, + ]; + //结算金额 + // $total_capply_amount=$marketingContract->ContractFinancialMoney([],$time,'sum','','amount'); + // $total_apply_amount_value=$marketingContract->ContractFinancialMoney([],$time,'group','create_time','amount'); + // $data[]=[ + // 'title' => '回款金额', + // 'desc' => '', + // 'total_money' => $total_capply_amount, + // 'value' => $total_apply_amount_value['y'], + // 'type' => 1, + // ]; + + //保证金申请 + $total_bid_margin = $financialBidMargin->statistics([], $time, 'sum', '', 'bid_margin'); + $bid_margin_value = $financialBidMargin->statistics([], $time, 'group', 'create_time', 'bid_margin'); + $data[] = [ + 'title' => '保证金申请', + 'desc' => '', + 'total_money' => $total_bid_margin, + 'value' => $bid_margin_value['y'], + 'type' => 1, + ]; + //保证金回收 + $total_pay_amount = $financialBidMarginRecovery->statistics([], $time, 'sum', '', 'pay_amount'); + $pay_amount_value = $financialBidMarginRecovery->statistics([], $time, 'group', 'create_time', 'pay_amount'); + $data[] = [ + 'title' => '保证金回收', + 'desc' => '', + 'total_money' => $total_pay_amount, + 'value' => $pay_amount_value['y'], + 'type' => 1, + ]; + //履约申请 + $apply_amount = $financialPerformanceMoneyApply->statistics([], $time, 'sum', '', 'apply_amount'); + $apply_amount_value = $financialPerformanceMoneyApply->statistics([], $time, 'group', 'create_time', 'apply_amount'); + $data[] = [ + 'title' => '履约申请', + 'desc' => '', + 'total_money' => $apply_amount, + 'value' => $apply_amount_value['y'], + 'type' => 1, + ]; + //履约回收 + $recovery_amount = $financialPerformanceMoneyRecovery->statistics([], $time, 'sum', '', 'recovery_amount'); + $recovery_amount_value = $financialPerformanceMoneyRecovery->statistics([], $time, 'group', 'create_time', 'recovery_amount'); + $data[] = [ + 'title' => '履约回收', + 'desc' => '', + 'total_money' => $recovery_amount, + 'value' => $recovery_amount_value['y'], + 'type' => 1, + ]; + //用款 + $has_pay_amount = $financialUsingFunds->statistics([], $time, 'sum', '', 'has_pay_amount'); + $has_pay_amount_value = $financialUsingFunds->statistics([], $time, 'group', 'create_time', 'has_pay_amount'); + $data[] = [ + 'title' => '用款', + 'desc' => '', + 'total_money' => $has_pay_amount, + 'value' => $has_pay_amount_value['y'], + 'type' => 1, + ]; + //借款 + $amount = $financialBorrowMoney->statistics([], $time, 'sum', '', 'amount'); + $amount_value = $financialBorrowMoney->statistics([], $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '借款', + 'desc' => '', + 'total_money' => $amount, + 'value' => $amount_value['y'], + 'type' => 1, + ]; + //还款 + $amount = $financialRepayment->statistics([], $time, 'sum', '', 'amount'); + $amount_value = $financialRepayment->statistics([], $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '还款', + 'desc' => '', + 'total_money' => $amount, + 'value' => $amount_value['y'], + 'type' => 1, + ]; + return $data; + } +} diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php index 6d288a7c9..c87bb8a37 100755 --- a/app/common/model/BaseModel.php +++ b/app/common/model/BaseModel.php @@ -59,7 +59,29 @@ class BaseModel extends Model $dict = DictData::where('type_value', 'check_status')->column('name', 'value'); return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核'; } + /** + * 统计 + */ + public function statistics($where, $time, string $selectType, string $group = "", $sum = '') + { + switch ($selectType) { + case "sum": + $totalMoney = $this->where($where)->when(isset($time), function ($query) use ($time) { + $query->whereBetweenTime('create_time', strtotime($time['start_time']), strtotime($time['end_time'])); + })->sum($sum); + break; + case "group": + $totalMoney = $this->getCurveData($where, $time, "sum($sum)", $group); + break; + default: + throw new \Exception($this->name.':selectType参数错误'); + } + if ($group) { + $totalMoney = $this->trendYdata((array)$totalMoney, $time); + } + return $totalMoney; + } /** * 曲线统计 * @param $time diff --git a/app/common/model/financial/FinancialBidMargin.php b/app/common/model/financial/FinancialBidMargin.php index c4443b15b..2da2675b1 100644 --- a/app/common/model/financial/FinancialBidMargin.php +++ b/app/common/model/financial/FinancialBidMargin.php @@ -11,40 +11,40 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model\financial; - - - use app\common\model\BaseModel; - use app\common\model\dict\DictData; - use think\model\concern\SoftDelete; - - - /** - * 财务管理--投标保证金申请模型 - * Class FinancialBidMargin - * @package app\common\model\financial - */ - class FinancialBidMargin extends BaseModel + +namespace app\common\model\financial; + + +use app\common\model\BaseModel; +use app\common\model\dict\DictData; +use think\model\concern\SoftDelete; + + +/** + * 财务管理--投标保证金申请模型 + * Class FinancialBidMargin + * @package app\common\model\financial + */ +class FinancialBidMargin extends BaseModel +{ + use SoftDelete; + + protected $name = 'financial_bid_margin'; + protected $deleteTime = 'delete_time'; + + public function getPayTypeTextAttr($value, $data) { - use SoftDelete; - - protected $name = 'financial_bid_margin'; - protected $deleteTime = 'delete_time'; - - public function getPayTypeTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'financial_pay_type')->column('name', 'value'); - return !empty($data['pay_type']) ? $dict[$data['pay_type']] : ''; - } - - public function getEndDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getExpectedReturnDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - } \ No newline at end of file + $dict = DictData::where('type_value', 'financial_pay_type')->column('name', 'value'); + return !empty($data['pay_type']) ? $dict[$data['pay_type']] : ''; + } + + public function getEndDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getExpectedReturnDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } +} diff --git a/app/common/model/financial/FinancialBidMarginRecovery.php b/app/common/model/financial/FinancialBidMarginRecovery.php index a3813d087..fa0216028 100644 --- a/app/common/model/financial/FinancialBidMarginRecovery.php +++ b/app/common/model/financial/FinancialBidMarginRecovery.php @@ -11,55 +11,56 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model\financial; - - - use app\common\model\BaseModel; - use app\common\model\dict\DictData; - use think\model\concern\SoftDelete; - - - /** - * 财务管理--投标保证金回收模型 - * Class FinancialBidMarginRecovery - * @package app\common\model\financial - */ - class FinancialBidMarginRecovery extends BaseModel + +namespace app\common\model\financial; + + +use app\common\model\BaseModel; +use app\common\model\dict\DictData; +use think\model\concern\SoftDelete; + + +/** + * 财务管理--投标保证金回收模型 + * Class FinancialBidMarginRecovery + * @package app\common\model\financial + */ +class FinancialBidMarginRecovery extends BaseModel +{ + use SoftDelete; + + protected $name = 'financial_bid_margin_recovery'; + protected $deleteTime = 'delete_time'; + + public function getPayTypeTextAttr($value, $data) { - use SoftDelete; - - protected $name = 'financial_bid_margin_recovery'; - protected $deleteTime = 'delete_time'; - - public function getPayTypeTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'financial_pay_type')->column('name', 'value'); - return !empty($data['pay_type']) ? $dict[$data['pay_type']] : ''; - } - - public function getEndDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getExpectedReturnDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getPayDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getOperationDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getRecoveryDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - } \ No newline at end of file + $dict = DictData::where('type_value', 'financial_pay_type')->column('name', 'value'); + return !empty($data['pay_type']) ? $dict[$data['pay_type']] : ''; + } + + public function getEndDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getExpectedReturnDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getPayDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getOperationDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getRecoveryDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + +} diff --git a/app/common/model/financial/FinancialInvoice.php b/app/common/model/financial/FinancialInvoice.php index bc025afc9..a4a5deadd 100644 --- a/app/common/model/financial/FinancialInvoice.php +++ b/app/common/model/financial/FinancialInvoice.php @@ -11,30 +11,54 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model\financial; - - - use app\common\model\BaseModel; - use app\common\model\dict\DictData; - use think\model\concern\SoftDelete; - - - /** - * 财务管理--开票台账模型 - * Class FinancialInvoice - * @package app\common\model\financial - */ - class FinancialInvoice extends BaseModel + +namespace app\common\model\financial; + + +use app\common\model\BaseModel; +use app\common\model\dict\DictData; +use think\model\concern\SoftDelete; + + +/** + * 财务管理--开票台账模型 + * Class FinancialInvoice + * @package app\common\model\financial + */ +class FinancialInvoice extends BaseModel +{ + use SoftDelete; + + protected $name = 'financial_invoice'; + protected $deleteTime = 'delete_time'; + + public function getInvoiceTypeTextAttr($value, $data) { - use SoftDelete; - - protected $name = 'financial_invoice'; - protected $deleteTime = 'delete_time'; - - public function getInvoiceTypeTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'zjzx_invoice_type')->column('name', 'value'); - return !empty($data['invoice_type']) ? $dict[$data['invoice_type']] : ''; + $dict = DictData::where('type_value', 'zjzx_invoice_type')->column('name', 'value'); + return !empty($data['invoice_type']) ? $dict[$data['invoice_type']] : ''; + } + + /** + * 统计合同金额 + */ + public function ContractFinancialMoney($where, $time, string $selectType, string $group = "", $sum = '') + { + switch ($selectType) { + case "sum": + $totalMoney = $this->where($where)->when(isset($time), function ($query) use ($time) { + $query->whereBetweenTime('create_time', strtotime($time['start_time']), strtotime($time['end_time'])); + })->sum($sum); + break; + case "group": + $totalMoney = $this->getCurveData($where, $time, "sum($sum)", $group); + break; + default: + throw new \Exception('ContractFinancialMoney:selectType参数错误'); } - } \ No newline at end of file + + if ($group) { + $totalMoney = $this->trendYdata((array)$totalMoney, $time); + } + return $totalMoney; + } +}