From e706d91c9ddfc83864bc366bcb2d6e136ee292a8 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Tue, 27 Feb 2024 22:42:15 +0800 Subject: [PATCH] 1 --- app/api/service/statistics/CommissionData.php | 10 +- app/api/service/statistics/Data.php | 8 +- app/api/service/statistics/OrderData.php | 96 +++++++++++++++++-- app/api/service/statistics/RefundData.php | 11 ++- app/api/service/statistics/UserData.php | 10 +- 5 files changed, 122 insertions(+), 13 deletions(-) diff --git a/app/api/service/statistics/CommissionData.php b/app/api/service/statistics/CommissionData.php index 7b75de5f..7f2aa497 100644 --- a/app/api/service/statistics/CommissionData.php +++ b/app/api/service/statistics/CommissionData.php @@ -2,11 +2,19 @@ namespace app\api\service\statistics; +use app\api\model\dealer\Order; use app\common\service\BaseService; class CommissionData extends BaseService { - public function getCommissionData(): array + protected Order $dealerOrderModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->dealerOrderModel = new Order(); + } + public function getCommissionData($startDate = null, $endDate = null): array { return [ 'settleTotalMoney' => 0, diff --git a/app/api/service/statistics/Data.php b/app/api/service/statistics/Data.php index cd583309..8ef1fa27 100644 --- a/app/api/service/statistics/Data.php +++ b/app/api/service/statistics/Data.php @@ -17,7 +17,7 @@ class Data extends BaseService * @return mixed */ public function getOrderData($startDate = null, $endDate = null): array { - return (new OrderData())->getOrderData(); + return (new OrderData())->getOrderData($startDate = null, $endDate = null); } /** @@ -25,7 +25,7 @@ class Data extends BaseService * @return mixed */ public function getRefundData($startDate = null, $endDate = null): array { - return (new RefundData())->getRefundData(); + return (new RefundData())->getRefundData($startDate = null, $endDate = null); } /** @@ -33,7 +33,7 @@ class Data extends BaseService * @return mixed */ public function getUserData($startDate = null, $endDate = null): array { - return (new UserData())->getUserData(); + return (new UserData())->getUserData($startDate = null, $endDate = null); } /** @@ -41,6 +41,6 @@ class Data extends BaseService * @return mixed */ public function getCommissionData($startDate = null, $endDate = null) : array{ - return (new CommissionData())->getCommissionData(); + return (new CommissionData())->getCommissionData($startDate = null, $endDate = null); } } \ No newline at end of file diff --git a/app/api/service/statistics/OrderData.php b/app/api/service/statistics/OrderData.php index ad75c1c0..7dc3029e 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -2,19 +2,32 @@ namespace app\api\service\statistics; +use app\api\model\Order; +use app\common\enum\order\OrderStatus; +use app\common\enum\order\OrderStatus as OrderStatusEnum; +use app\common\enum\order\PayStatus as PayStatusEnum; use app\common\service\BaseService; class OrderData extends BaseService { - public function getOrderData(): array + //查询对象 + protected Order $orderModel; + + public function initialize() + { + parent::initialize(); + $this->orderModel = new Order(); + } + + public function getOrderData($startDate = null, $endDate = null): array { return [ //订单金额 - "orderMoney" => 0, - //订单数 - "orderCount" => 0, - //支持人数 - 'orderPayUser' => 0, + "orderMoney" => $this->getOrderTotalPrice($startDate, $endDate), + //下单总数 + "orderCount" => $this->getPayOrderTotal($startDate, $endDate), + //下单人数 + 'orderPayUser' => $this->getConsumeUsers($startDate, $endDate), //订单成本金额 'orderCostMoney' => 0, //预估利益 @@ -25,4 +38,75 @@ class OrderData extends BaseService 'payDealerCount' => 0 ]; } + + /** + * 获取某天的总销售额 + * @param null $startDate + * @param null $endDate + * @return float + */ + public function getOrderTotalPrice($startDate = null, $endDate = null): float + { + // 查询对象 + $query = $this->orderModel; + // 设置查询条件 + if (!is_null($startDate) && !is_null($endDate)) { + $query->where('pay_time', '>=', strtotime($startDate)) + ->where('pay_time', '<', strtotime($endDate) + 86400); + } + // 总销售额 + return $query->where('pay_status', '=', PayStatusEnum::SUCCESS) + ->where('order_status', '<>', OrderStatusEnum::CANCELLED) + ->where('is_delete', '=', 0) + ->sum('pay_price'); + } + + /** + * 消费人数 + * @param null $startDate + * @param null $endDate + * @return string + */ + public function getConsumeUsers($startDate = null, $endDate = null): string + { + // 检索查询条件 + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['pay_time', '>=', strtotime($startDate)]; + $filter[] = ['pay_time', '<', strtotime($endDate) + 86400]; + } + // 查询总记录 + $value = $this->orderModel->field('user_id') + ->where($filter) + ->where('pay_status', '=', PayStatusEnum::SUCCESS) + // ->where('order_status', '<>', OrderStatusEnum::CANCELLED) + ->where('is_delete', '=', '0') + ->group('user_id') + ->count(); + return number_format($value); + } + + /** + * 获取已付款订单总数 (可指定某天) + * @param null $startDate + * @param null $endDate + * @return int + */ + public function getPayOrderTotal($startDate = null, $endDate = null): int + { + $filter = [ + ['pay_status', '=', PayStatusEnum::SUCCESS], + ['order_status', '<>', OrderStatusEnum::CANCELLED] + ]; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['pay_time', '>=', strtotime($startDate)]; + $filter[] = ['pay_time', '<', strtotime($endDate) + 86400]; + } + // 获取订单总数量 + return $this->orderModel->where($filter) + ->where('is_delete', '=', 0) + ->count(); + } + + } \ No newline at end of file diff --git a/app/api/service/statistics/RefundData.php b/app/api/service/statistics/RefundData.php index 681d8e56..716a5099 100644 --- a/app/api/service/statistics/RefundData.php +++ b/app/api/service/statistics/RefundData.php @@ -2,11 +2,20 @@ namespace app\api\service\statistics; +use app\api\model\OrderRefund; use app\common\service\BaseService; class RefundData extends BaseService { - public function getRefundData(): array + protected OrderRefund $refundModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->refundModel = new OrderRefund(); + } + + public function getRefundData($startDate = null, $endDate = null): array { return [ 'refundCount' => 0, diff --git a/app/api/service/statistics/UserData.php b/app/api/service/statistics/UserData.php index 44bf0eab..1249f02e 100644 --- a/app/api/service/statistics/UserData.php +++ b/app/api/service/statistics/UserData.php @@ -2,11 +2,19 @@ namespace app\api\service\statistics; +use app\api\model\User; use app\common\service\BaseService; class UserData extends BaseService { - public function getUserData(): array + protected User $userModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->userModel = new User(); + } + public function getUserData($startDate = null, $endDate = null): array { return [ 'visitorCount' => 0,