StoreStatistics.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/4/16 0016
  6. * Time: 10:39
  7. */
  8. namespace app\admin\controller\record;
  9. use app\admin\controller\AuthController;
  10. use crmeb\services\UtilService as Util;
  11. use app\admin\model\record\StoreStatistics as StatisticsModel;
  12. /**
  13. * Class StoreStatistics
  14. * @package app\admin\controller\record
  15. */
  16. class StoreStatistics extends AuthController
  17. {
  18. /**
  19. * 显示列表
  20. */
  21. public function index()
  22. {
  23. $where = Util::getMore([
  24. ['date', ''],
  25. ['export', ''],
  26. ['data', '']
  27. ], $this->request);
  28. $where['date'] = $this->request->param('date');
  29. $where['data'] = $this->request->param('data');
  30. $where['export'] = $this->request->param('export');
  31. $trans = StatisticsModel::trans();//最近交易
  32. $seckill = StatisticsModel::getSeckill($where);//秒杀商品
  33. $ordinary = StatisticsModel::getOrdinary($where);//普通商品
  34. $pink = StatisticsModel::getPink($where);//拼团商品
  35. $recharge = StatisticsModel::getRecharge($where);//充值
  36. $extension = StatisticsModel::getExtension($where);//推广金
  37. $orderCount = [
  38. urlencode('微信支付') => StatisticsModel::getTimeWhere($where, StatisticsModel::statusByWhere('weixin'))->count(),
  39. urlencode('余额支付') => StatisticsModel::getTimeWhere($where, StatisticsModel::statusByWhere('yue'))->count(),
  40. urlencode('线下支付') => StatisticsModel::getTimeWhere($where, StatisticsModel::statusByWhere('offline'))->count(),
  41. ];
  42. $Statistic = [
  43. ['name' => '营业额', 'type' => 'line', 'data' => []],
  44. ['name' => '支出', 'type' => 'line', 'data' => []],
  45. ['name' => '盈利', 'type' => 'line', 'data' => []],
  46. ];
  47. $orderinfos = StatisticsModel::getOrderInfo($where);
  48. $orderinfo = $orderinfos['orderinfo'];
  49. $orderDays = [];
  50. if (empty($orderinfo)) {
  51. $orderDays[] = date('Y-m-d', time());
  52. $Statistic[0]['data'][] = 0;
  53. $Statistic[1]['data'][] = 0;
  54. $Statistic[2]['data'][] = 0;
  55. }
  56. foreach ($orderinfo as $info) {
  57. $orderDays[] = $info['pay_time'];
  58. $Statistic[0]['data'][] = $info['total_price'] + $info['pay_postage'];
  59. $Statistic[1]['data'][] = $info['coupon_price'] + $info['deduction_price'] + $info['cost'];
  60. $Statistic[2]['data'][] = ($info['total_price'] + $info['pay_postage']) - ($info['coupon_price'] + $info['deduction_price'] + $info['cost']);
  61. }
  62. $price = $orderinfos['price'] + $orderinfos['postage'];
  63. $cost = $orderinfos['deduction'] + $orderinfos['coupon'] + $orderinfos['cost'];
  64. $Consumption = StatisticsModel::getConsumption($where)['number'];
  65. $header = [
  66. ['name' => '总营业额', 'class' => 'fa-line-chart', 'value' => '¥' . $price, 'color' => 'red'],
  67. ['name' => '总支出', 'class' => 'fa-area-chart', 'value' => '¥' . ($cost + $extension), 'color' => 'lazur'],
  68. ['name' => '总盈利', 'class' => 'fa-bar-chart', 'value' => '¥' . bcsub($price, $cost, 0), 'color' => 'navy'],
  69. ['name' => '新增消费', 'class' => 'fa-pie-chart', 'value' => '¥' . ($Consumption == 0 ? 0 : $Consumption), 'color' => 'yellow']
  70. ];
  71. $data = [
  72. ['value' => $orderinfos['cost'], 'name' => '商品成本'],
  73. ['value' => $orderinfos['coupon'], 'name' => '优惠券抵扣'],
  74. ['value' => $orderinfos['deduction'], 'name' => '积分抵扣'],
  75. ['value' => $extension, 'name' => '推广人佣金']
  76. ];
  77. $this->assign(StatisticsModel::systemTable($where));
  78. $this->assign(compact('where', 'trans', 'orderCount', 'orderDays', 'header', 'Statistic', 'ordinary', 'pink', 'recharge', 'data', 'seckill'));
  79. $this->assign('price', StatisticsModel::getOrderPrice($where));
  80. return $this->fetch();
  81. }
  82. }