StatisticalController.php 3.0 KB
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class StatisticalController extends AdminBaseController{

    /**
     * 财务统计
     */
    public function financial_list(){

        //平台订单金额统计
        $where = [
            'indent_type' => 1
        ];
        $where2 = [
            'indent_type' => 2
        ];
        $where3 = [
            'type' => 1
        ];
        if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
            $start_time = strtotime($_POST['start_time']);
            $end_time = strtotime($_POST['end_time']);
            $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
            $where2['create_time'] = [['>=',$start_time],['<=',$end_time]];
            $where3['time'] = [['>=',$start_time],['<=',$end_time]];
        }
        $platform = Db::name('indent') -> where($where) -> where("state = 2 or state = 3 or state = 5") -> select();
        $platform_money = 0;
        foreach ($platform as $key => $val){
            $platform_money += $val['money'];
        }
        $this -> assign('platform_money',$platform_money);
        //业务员订单金额统计
        $salesman = Db::name('indent') -> where($where2) -> where("state = 2 or state = 3 or state = 5") -> select();
        $salesman_money = 0;
        foreach ($salesman as $key => $val){
            $salesman_money += $val['money'];
        }
        $this -> assign('salesman_money',$salesman_money);
        // 业务员总余额
        $users_where = [
            'a.create_time' => ['>=', 0],
            'a.status' => ['in',[2,3]]
        ];
        $total_balance = Db::name('my_user') -> alias('a')
            ->field('a.*,b.user_nickname')
            ->join('user b','a.uid = b.id','LEFT')
            ->where($users_where)
            ->order(['a.balance'=>'DESC','a.create_time'=>'DESC'])
            ->sum('a.balance');
        $this -> assign('total_balance',$total_balance);
        //显示平台抽成收益
        $income = Db::name('income_money') -> where($where3) -> select();
        $income_money = 0;
        foreach ($income as $key => $val){
            $income_money += $val['money'];
        }
        $this -> assign('income_money',$income_money);
        return $this -> fetch();

    }


    /**
     *支出统计
     */
    public function spending_list(){

        $where = [
            'state' => 1
        ];
        if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
            $start_time = strtotime($_POST['start_time']);
            $end_time = strtotime($_POST['end_time']);
            $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
        }
        $money_expend = Db::name('money_expend') -> where($where) -> select();
        $money = 0;
        foreach ($money_expend as $key => $val){
            $money += $val['money'];
        }
        $this -> assign('money',$money);
        return $this -> fetch();

    }


























}