IndexController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\statistics\controllers;
  3. use common\helpers\ArrayHelper;
  4. use Yii;
  5. use common\helpers\DateHelper;
  6. use common\helpers\ResultHelper;
  7. use addons\TinyShop\merchant\controllers\BaseController;
  8. /**
  9. * Class IndexController
  10. * @package addons\TinyShop\merchant\modules\statistics\controllers
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class IndexController extends BaseController
  14. {
  15. /**
  16. * 首页
  17. *
  18. * @return string
  19. * @throws \yii\web\NotFoundHttpException
  20. */
  21. public function actionIndex()
  22. {
  23. $thisMonth = DateHelper::thisMonth();
  24. $yesterday = DateHelper::yesterday();
  25. $today = DateHelper::today();
  26. $yesterdayData = $todayData = [
  27. 'product_count' => 0,
  28. 'pay_money' => 0.00,
  29. 'count' => 0,
  30. ];
  31. $dayStatByTime = Yii::$app->tinyShopService->orderStat->getDayStatByTime($yesterday['start']);
  32. foreach ($dayStatByTime as $item) {
  33. $time = strtotime($item['day']);
  34. if ($time >= $yesterday['start'] && $time <= $yesterday['end']) {
  35. $yesterdayData['product_count'] += (int)$item['product_count'];
  36. $yesterdayData['pay_money'] += (double)$item['pay_money'];
  37. $yesterdayData['count'] += $item['count'];
  38. }
  39. if ($time >= $today['start'] && $time <= $today['end']) {
  40. $todayData['product_count'] += (int)$item['product_count'];
  41. $todayData['pay_money'] += (double)$item['pay_money'];
  42. $todayData['count'] += $item['count'];
  43. }
  44. }
  45. return $this->render($this->action->id, [
  46. 'orderTotalList' => ArrayHelper::map(Yii::$app->tinyShopService->order->getOrderCountGroupByStatus(), 'order_status', 'count'),
  47. 'orderCount' => Yii::$app->tinyShopService->order->findCount(),
  48. 'orderThisMouthStat' => Yii::$app->tinyShopService->orderStat->getStatByTime($thisMonth['start']),
  49. 'productWarningStockCount' => Yii::$app->tinyShopService->product->getWarningStockCount(),
  50. 'productSellCount' => Yii::$app->tinyShopService->product->findSellCount(),
  51. 'productWarehouseCount' => Yii::$app->tinyShopService->product->findWarehouseCount(),
  52. 'productEvaluateCount' => Yii::$app->tinyShopService->productEvaluate->getCount(),
  53. 'productRank' => Yii::$app->tinyShopService->product->getRank(),
  54. 'yesterdayData' => $yesterdayData,
  55. 'todayData' => $todayData,
  56. ]);
  57. }
  58. /**
  59. * 运营报告
  60. *
  61. * 24小时/周/月下单商品数
  62. * 24小时/周/月下单金额
  63. */
  64. public function actionSusRes($type = '')
  65. {
  66. if (Yii::$app->request->isAjax) {
  67. $data = Yii::$app->tinyShopService->orderStat->getBetweenProductMoneyAndCountStatToEchant($type);
  68. return ResultHelper::json(200, '获取成功', $data);
  69. }
  70. return $this->render($this->action->id, [
  71. 'total' => Yii::$app->tinyShopService->order->getStatByTime(0),
  72. ]);
  73. }
  74. /**
  75. * 订单指定时间内数量
  76. *
  77. * @param $type
  78. * @return array
  79. */
  80. public function actionOrderBetweenCount($type)
  81. {
  82. $data = Yii::$app->tinyShopService->orderStat->getBetweenCountStatToEchant($type);
  83. return ResultHelper::json(200, '获取成功', $data);
  84. }
  85. }
粤ICP备19079148号