Overview.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Admin;
  4. use app\admin\model\User;
  5. use app\common\controller\Backend;
  6. use app\common\model\Attachment;
  7. use app\common\model\SysConfig;
  8. use fast\Date;
  9. use think\Db;
  10. /**
  11. * 控制台
  12. *
  13. * @icon fa fa-dashboard
  14. * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
  15. */
  16. class Overview extends Backend
  17. {
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. try {
  24. \think\Db::execute("SET @@sql_mode='';");
  25. } catch (\Exception $e) {
  26. }
  27. $postTime = input('startTime','');
  28. $where = [];
  29. $map = [];
  30. if($postTime){
  31. $time = explode(' - ',$postTime);
  32. $startTime = strtotime($time[0]);
  33. $endTime = strtotime($time[1]);
  34. $where['create_time'] = array('between',[$startTime,$endTime]);
  35. $map['createtime'] = array('between',[$startTime,$endTime]);
  36. }
  37. //总销售额
  38. $sale = Db('Orders')->where($where)->where('status','in','5,10,20')->sum('amount_pay');
  39. $refund = Db('OrderInfoRefund')->where($where)->where('refund_status',20)->sum('amount');
  40. $sale = bcsub($sale,$refund);
  41. //总销售数量
  42. $saleNum = Db('Orders')->where($where)->where('status','in','5,10,20')->count();
  43. $refundNum = Db('OrderInfoRefund')->where($where)->where('refund_status',20)->count();
  44. $saleNum = bcsub($saleNum,$refundNum);
  45. //新增用户数
  46. $register = Db('User')->where($map)->count();
  47. //下单用户数
  48. $buy = Db('Orders')->where($where)->where('status','in','5,10,20')->group('user_id')->count();
  49. //毛利、毛利率
  50. $install = Db('Orders')->where($where)->where('status','in','5,10,20')->sum('amount_install');//总安装费
  51. $orderIds = Db('Orders')->where($where)->where('status','in','5,10,20')->column('id');
  52. $cost = Db('OrderInfo')->where('order_id','in',$orderIds)->sum('amount_cost');//总成本
  53. $gross_profit = bcsub($sale,$install);
  54. $gross_profit = bcsub($gross_profit,$cost);
  55. $gross_profit_margin = 0;
  56. if($sale > 0)$gross_profit_margin = round($gross_profit/$sale,2)*100;//毛利率
  57. //支付方式
  58. $orderList = Db("Orders")->where($where)
  59. ->field('pay_type, COUNT(*) AS nums')
  60. ->group('pay_type')
  61. ->select();
  62. $payTotalCount = Db("Orders")->where($where)->where('status','in','5,10,20,30')->count();
  63. $payTypeList = [];
  64. $payTypeList1 = [];
  65. foreach ($orderList as $k => $v) {
  66. if($v['pay_type'] == 1){
  67. $v['pay_type'] = '企业网银';
  68. }elseif ($v['pay_type'] == 2){
  69. $v['pay_type'] = '微信';
  70. }elseif ($v['pay_type'] == 3){
  71. $v['pay_type'] = '支付宝';
  72. }elseif ($v['pay_type'] == 4){
  73. $v['pay_type'] = '银联';
  74. }elseif ($v['pay_type'] == 5){
  75. $v['pay_type'] = '代付';
  76. }elseif ($v['pay_type'] == 6){
  77. $v['pay_type'] = '线下支付';
  78. }
  79. $rate = 0;
  80. if($payTotalCount > 0)$rate = round($v['nums']/$payTotalCount,2)*100;
  81. $rate = $rate.'%';
  82. $payTypeList[$v['pay_type']] = $v['nums'];
  83. $payTypeList1[$v['pay_type']] = $rate;
  84. }
  85. $this->view->assign([
  86. 'sale' => $sale,
  87. 'sale_num' => $saleNum,
  88. 'register' => $register,
  89. 'buy' => $buy,
  90. 'gross_profit'=>$gross_profit,
  91. 'gross_profit_margin'=>$gross_profit_margin,
  92. 'post_time'=>$postTime
  93. ]);
  94. $this->assignconfig('type_column', array_keys($payTypeList));
  95. $this->assignconfig('type_data', array_values($payTypeList));
  96. $this->assignconfig('type_column1', array_keys($payTypeList1));
  97. $this->assignconfig('type_data1', array_values($payTypeList1));
  98. return $this->view->fetch();
  99. }
  100. }