Bläddra i källkod

预估报价
统计分析总览

Gao 2 år sedan
förälder
incheckning
0c4058f635

+ 114 - 0
application/admin/controller/Overview.php

@@ -0,0 +1,114 @@
+<?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();
+    }
+
+}

+ 333 - 0
application/admin/view/overview/index.html

@@ -0,0 +1,333 @@
+<style type="text/css">
+    .sm-st {
+        background: #fff;
+        padding: 20px;
+        -webkit-border-radius: 3px;
+        -moz-border-radius: 3px;
+        border-radius: 3px;
+        margin-bottom: 20px;
+    }
+
+    .sm-st-icon {
+        width: 60px;
+        height: 60px;
+        display: inline-block;
+        line-height: 60px;
+        text-align: center;
+        font-size: 30px;
+        background: #eee;
+        -webkit-border-radius: 5px;
+        -moz-border-radius: 5px;
+        border-radius: 5px;
+        float: left;
+        margin-right: 10px;
+        color: #fff;
+    }
+
+    .sm-st-info {
+        padding-top: 2px;
+    }
+
+    .sm-st-info span {
+        display: block;
+        font-size: 24px;
+        font-weight: 600;
+    }
+
+    .orange {
+        background: #fa8564 !important;
+    }
+
+    .tar {
+        background: #45cf95 !important;
+    }
+
+    .sm-st .green {
+        background: #86ba41 !important;
+    }
+
+    .pink {
+        background: #AC75F0 !important;
+    }
+
+    .yellow-b {
+        background: #fdd752 !important;
+    }
+
+    .stat-elem {
+
+        background-color: #fff;
+        padding: 18px;
+        border-radius: 40px;
+
+    }
+
+    .stat-info {
+        text-align: center;
+        background-color: #fff;
+        border-radius: 5px;
+        margin-top: -5px;
+        padding: 8px;
+        -webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.05);
+        box-shadow: 0 1px 0px rgba(0, 0, 0, 0.05);
+        font-style: italic;
+    }
+
+    .stat-icon {
+        text-align: center;
+        margin-bottom: 5px;
+    }
+
+    .st-red {
+        background-color: #F05050;
+    }
+
+    .st-green {
+        background-color: #27C24C;
+    }
+
+    .st-violet {
+        background-color: #7266ba;
+    }
+
+    .st-blue {
+        background-color: #23b7e5;
+    }
+
+    .stats .stat-icon {
+        color: #28bb9c;
+        display: inline-block;
+        font-size: 26px;
+        text-align: center;
+        vertical-align: middle;
+        width: 50px;
+        float: left;
+    }
+
+    .stat {
+        white-space: nowrap;
+        overflow: hidden;
+        text-overflow: ellipsis;
+        display: inline-block;
+    }
+
+    .stat .value {
+        font-size: 20px;
+        line-height: 24px;
+        overflow: hidden;
+        text-overflow: ellipsis;
+        font-weight: 500;
+    }
+
+    .stat .name {
+        overflow: hidden;
+        text-overflow: ellipsis;
+        margin: 5px 0;
+    }
+
+    .stat.lg .value {
+        font-size: 26px;
+        line-height: 28px;
+    }
+
+    .stat-col {
+        margin:0 0 10px 0;
+    }
+    .stat.lg .name {
+        font-size: 16px;
+    }
+
+    .stat-col .progress {
+        height: 2px;
+    }
+
+    .stat-col .progress-bar {
+        line-height: 2px;
+        height: 2px;
+    }
+
+    .item {
+        padding: 30px 0;
+    }
+
+
+    #statistics .panel {
+        min-height: 150px;
+    }
+
+    #statistics .panel h5 {
+        font-size: 14px;
+    }
+</style>
+<div class="panel panel-default panel-intro">
+
+    <div class="panel-body">
+
+
+        <form class="form-horizontal form-commonsearch nice-validator n-default n-bootstrap" novalidate="" method="post"
+              action="" id="form">
+            <div class="row">
+                <div class="row">
+                    <div class="form-group">
+                        <label for="createtime" class="control-label col-xs-2" style="width: 6%">日期</label>
+                        <div class="col-xs-5" style="width: 20%">
+                            <input type="hidden" class="form-control operate" name="createtime-operate"
+                                   data-name="createtime" value="RANGE" readonly="">
+                            <input type="text" class="form-control datetimerange" name="startTime" value="{$post_time}"
+                                   id="start_time" data-index="12" onfocus="getdaterangepicker(form)"
+                                   autocomplete="off" style="width: 100%">
+                        </div>
+                        <div class="col-xs-5">
+                            <button type="submit" class="btn btn-success" formnovalidate="">提交</button>
+                            <button type="reset" class="btn btn-default">重置</button>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </form>
+
+
+    </div>
+
+
+</div>
+
+<div class="panel panel-default panel-intro">
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+
+                <div class="row">
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-red"><i class="fa fa-leaf"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$sale}</span>
+                                总销售额
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-violet"><i class="fa fa-magic"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$sale_num}</span>
+                                总订单数
+                            </div>
+                        </div>
+                    </div>
+
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-red"><i class="fa fa-users"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$register}</span>
+                                新增用户数
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-violet"><i class="fa fa-users"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$buy}</span>
+                                下单客户数
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-blue"><i class="fa fa-rocket"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$gross_profit}</span>
+                                毛利
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-sm-3 col-xs-6">
+                        <div class="sm-st clearfix">
+                            <span class="sm-st-icon st-green"><i class="fa fa-rmb"></i></span>
+                            <div class="sm-st-info">
+                                <span>{$gross_profit_margin}%</span>
+                                毛利率
+                            </div>
+                        </div>
+                    </div>
+
+
+                </div>
+                <div class="row">
+                    <div class="col-lg-6">
+                        <div id="echart" class="btn-refresh" style="height:300px;width:50%;"></div>
+                    </div>
+                    <div class="col-lg-6">
+                        <div id="echart1" class="btn-refresh" style="height:300px;width:50%;"></div>
+                    </div>
+
+                </div>
+
+
+            </div>
+
+            <div class="tab-pane fade" id="two">
+                <div class="row">
+                    <div class="col-xs-12">
+                        {:__('Custom zone')}
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
+<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
+<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
+<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css"/>
+<script>
+    $('input[name="dates"]').daterangepicker();
+
+    function getdaterangepicker(form) {
+        //绑定日期时间元素事件
+        if ($(".datetimerange", form).size() > 0) {
+            require(['bootstrap-daterangepicker'], function () {
+                var ranges = {};
+                ranges[__('Today')] = [Moment().startOf('day'), Moment().endOf('day')];
+                ranges[__('Yesterday')] = [Moment().subtract(1, 'days').startOf('day'), Moment().subtract(1, 'days').endOf('day')];
+                ranges[__('Last 7 Days')] = [Moment().subtract(6, 'days').startOf('day'), Moment().endOf('day')];
+                ranges[__('Last 30 Days')] = [Moment().subtract(29, 'days').startOf('day'), Moment().endOf('day')];
+                ranges[__('This Month')] = [Moment().startOf('month'), Moment().endOf('month')];
+                ranges[__('Last Month')] = [Moment().subtract(1, 'month').startOf('month'), Moment().subtract(1, 'month').endOf('month')];
+                var options = {
+                    timePicker: false,
+                    autoUpdateInput: false,
+                    timePickerSeconds: true,
+                    timePicker24Hour: true,
+                    autoApply: true,
+                    locale: {
+                        format: 'YYYY-MM-DD HH:mm:ss',
+                        customRangeLabel: __("Custom Range"),
+                        applyLabel: __("Apply"),
+                        cancelLabel: __("Clear"),
+                    },
+                    ranges: ranges,
+                };
+                var origincallback = function (start, end) {
+                    $(this.element).val(start.format(this.locale.format) + " - " + end.format(this.locale.format));
+                    $(this.element).trigger('blur');
+                };
+                $(".datetimerange", form).each(function () {
+                    var callback = typeof $(this).data('callback') == 'function' ? $(this).data('callback') : origincallback;
+                    $(this).on('apply.daterangepicker', function (ev, picker) {
+                        callback.call(picker, picker.startDate, picker.endDate);
+                    });
+                    $(this).on('cancel.daterangepicker', function (ev, picker) {
+                        $(this).val('').trigger('blur');
+                    });
+                    $(this).daterangepicker($.extend(true, options, $(this).data()), callback);
+                });
+            });
+        }
+    }
+</script>

+ 5 - 1
application/api/controller/Programme.php

@@ -25,7 +25,7 @@ class Programme extends Api
     /**
      * 预估报价
      * @ApiMethod (POST)
-     * @ApiParams (name=form,description="key为规格id,对象:num购买数量,num_install安装数量,{1:{num:1,num_install:2}})
+     * @ApiParams (name=sku,description="key为规格id,对象:num购买数量,num_install安装数量,{1:{num:1,num_install:2}})
      * ApiReturnParams (name=logo,description=logo)
      * @ApiReturnParams (name=name,description=商品名称)
      * @ApiReturnParams (name=sku,description=规格)
@@ -33,6 +33,8 @@ class Programme extends Api
      * @ApiReturnParams (name=amount_install,description=安装费)
      * @ApiReturnParams (name=amount_total,description=共计)
      *@ApiReturnParams (name=total,description=预估报价)
+     * @ApiReturnParams (name=num,description=采购数量)
+     * @ApiReturnParams (name=num_install,description=安装数量)
     */
     public function calculate(){
         $sku = input('sku');
@@ -51,6 +53,8 @@ class Programme extends Api
             $goods[$k]['logo'] = $nowGoods['logo'];
             $goods[$k]['name'] = $nowGoods['name'];
             $goods[$k]['sku'] = $goodsSku['name'];
+            $goods[$k]['num'] = $v['num'];
+            $goods[$k]['num_install'] = $v['num_install'];
             $goods[$k]['amount'] = $goodsSku['amount'];//单价
             $goods[$k]['amount_install']=InstallService::getFee([$k=>$v]);//安装费
             $goods[$k]['amount_total']=bcmul($goodsSku['amount'],$v['num']);

+ 79 - 0
public/assets/js/backend/overview.js

@@ -0,0 +1,79 @@
+define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
+
+    var Controller = {
+        index: function () {
+
+            // 基于准备好的dom,初始化echarts实例
+            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
+            var myChart1 = Echarts.init(document.getElementById('echart1'), 'walden');
+
+            // 指定图表的配置项和数据
+            var option = {
+                xAxis: {
+                    type: 'category',
+                    data: Config.type_column
+                },
+                yAxis: {
+                    type: 'value'
+                },
+
+                series: [
+                    {
+
+                        data: Config.type_data,
+                        type: 'bar',
+                        showBackground: true,
+                        backgroundStyle: {
+                            color: 'rgba(180, 180, 180, 0.2)'
+                        }
+                    }
+                ]
+            };
+
+            var option1 = {
+                title: {
+                    text: '支付方式占比',
+
+                    left: 'center'
+                },
+                tooltip: {
+                    trigger: 'item'
+                },
+                legend: {
+                    orient: 'vertical',
+                    left: 'left'
+                },
+                series: [
+                    {
+                        type: 'pie',
+                        radius: '50%',
+                        data: [
+                            { value: Config.type_data[0], name: Config.type_column[0] },
+                            { value: Config.type_data[1], name: Config.type_column[1]},
+                            { value: Config.type_data[2], name: Config.type_column[2]},
+                            { value: Config.type_data[3], name: Config.type_column[3]},
+                            { value: Config.type_data[4], name: Config.type_column[4]},
+                            { value: Config.type_data[5], name: Config.type_column[5]}
+                        ],
+                        emphasis: {
+                            itemStyle: {
+                                shadowBlur: 10,
+                                shadowOffsetX: 0,
+                                shadowColor: 'rgba(0, 0, 0, 0.5)'
+                            }
+                        }
+                    }
+                ]
+            };
+
+
+            // 使用刚指定的配置项和数据显示图表。
+            myChart.setOption(option);
+            myChart1.setOption(option1);
+
+        }
+
+    };
+
+    return Controller;
+});