123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\Admin;
- use app\admin\model\User;
- use app\common\controller\Backend;
- use app\common\model\Attachment;
- use app\common\model\SysConfig;
- use fast\Date;
- use think\Db;
- /**
- * 控制台
- *
- * @icon fa fa-dashboard
- * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
- */
- class Overview extends Backend
- {
- /**
- * 查看
- */
- public function index()
- {
- try {
- \think\Db::execute("SET @@sql_mode='';");
- } catch (\Exception $e) {
- }
- $postTime = input('startTime','');
- $where = [];
- $map = [];
- if($postTime){
- $time = explode(' - ',$postTime);
- $startTime = strtotime($time[0]);
- $endTime = strtotime($time[1]);
- $where['create_time'] = array('between',[$startTime,$endTime]);
- $map['createtime'] = array('between',[$startTime,$endTime]);
- }
- //总销售额
- $sale = Db('Orders')->where($where)->where('status','in','5,10,20')->sum('amount_pay');
- $refund = Db('OrderInfoRefund')->where($where)->where('refund_status',20)->sum('amount');
- $sale = bcsub($sale,$refund);
- //总销售数量
- $saleNum = Db('Orders')->where($where)->where('status','in','5,10,20')->count();
- $refundNum = Db('OrderInfoRefund')->where($where)->where('refund_status',20)->count();
- $saleNum = bcsub($saleNum,$refundNum);
- //新增用户数
- $register = Db('User')->where($map)->count();
- //下单用户数
- $buy = Db('Orders')->where($where)->where('status','in','5,10,20')->group('user_id')->count();
- //毛利、毛利率
- $install = Db('Orders')->where($where)->where('status','in','5,10,20')->sum('amount_install');//总安装费
- $orderIds = Db('Orders')->where($where)->where('status','in','5,10,20')->column('id');
- $cost = Db('OrderInfo')->where('order_id','in',$orderIds)->sum('amount_cost');//总成本
- $gross_profit = bcsub($sale,$install);
- $gross_profit = bcsub($gross_profit,$cost);
- $gross_profit_margin = 0;
- if($sale > 0)$gross_profit_margin = round($gross_profit/$sale,2)*100;//毛利率
- //支付方式
- $orderList = Db("Orders")->where($where)
- ->field('pay_type, COUNT(*) AS nums')
- ->group('pay_type')
- ->select();
- $payTotalCount = Db("Orders")->where($where)->where('status','in','5,10,20,30')->count();
- $payTypeList = [];
- $payTypeList1 = [];
- foreach ($orderList as $k => $v) {
- if($v['pay_type'] == 1){
- $v['pay_type'] = '企业网银支付';
- }elseif ($v['pay_type'] == 2){
- $v['pay_type'] = '微信支付';
- }elseif ($v['pay_type'] == 3){
- $v['pay_type'] = '支付宝支付';
- }elseif ($v['pay_type'] == 4){
- $v['pay_type'] = '银联支付';
- }elseif ($v['pay_type'] == 5){
- $v['pay_type'] = '代付支付';
- }elseif ($v['pay_type'] == 6){
- $v['pay_type'] = '线下支付支付';
- }
- $rate = 0;
- if($payTotalCount > 0)$rate = round($v['nums']/$payTotalCount,2)*100;
- $rate = $rate.'%';
- $payTypeList[$v['pay_type']] = $v['nums'];
- $payTypeList1[$v['pay_type']] = $rate;
- }
- $this->view->assign([
- 'sale' => $sale,
- 'sale_num' => $saleNum,
- 'register' => $register,
- 'buy' => $buy,
- 'gross_profit'=>$gross_profit,
- 'gross_profit_margin'=>$gross_profit_margin,
- 'post_time'=>$postTime
- ]);
- $this->assignconfig('type_column', array_keys($payTypeList));
- $this->assignconfig('type_data', array_values($payTypeList));
- $this->assignconfig('type_column1', array_keys($payTypeList1));
- $this->assignconfig('type_data1', array_values($payTypeList1));
- return $this->view->fetch();
- }
- }
|