GeneralController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\statistics\controllers;
  3. use Yii;
  4. use common\helpers\ResultHelper;
  5. use addons\TinyShop\merchant\controllers\BaseController;
  6. /**
  7. * Class GeneralController
  8. * @package addons\TinyShop\merchant\modules\statistics\controllers
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class GeneralController extends BaseController
  12. {
  13. /**
  14. * 销售分析
  15. *
  16. * 近30天下单金额
  17. * 近30天下单会员数
  18. * 近30天下单量
  19. * 近30天下单商品数
  20. * 近30天平均客单价
  21. * 近30天平均价格
  22. *
  23. * @return array|string
  24. */
  25. public function actionIndex()
  26. {
  27. $orderStat = Yii::$app->tinyShopService->orderStat->getStatByTime(time() - 60 * 60 * 24 * 30, ['count(distinct buyer_id) as member_count']);
  28. // 客单价
  29. $orderStat['customer_money'] = $orderStat['pay_money'] > 0 ? round($orderStat['pay_money'] / $orderStat['member_count'], 2) : 0;
  30. // 平均价格
  31. $orderStat['average_money'] = $orderStat['pay_money'] > 0 ? round($orderStat['pay_money'] / $orderStat['product_count'], 2) : 0;
  32. return $this->render($this->action->id, [
  33. 'orderStat' => $orderStat,
  34. ]);
  35. }
  36. /**
  37. * @return array|mixed
  38. */
  39. public function actionData()
  40. {
  41. $type = Yii::$app->request->get('type');
  42. $data = Yii::$app->tinyShopService->orderStat->getBetweenCountStatToEchant($type);
  43. return ResultHelper::json(200, '获取成功', $data);
  44. }
  45. }
粤ICP备19079148号