diff --git a/app/api/service/statistics/CommissionData.php b/app/api/service/statistics/CommissionData.php index 7f2aa497..e16b7c09 100644 --- a/app/api/service/statistics/CommissionData.php +++ b/app/api/service/statistics/CommissionData.php @@ -3,6 +3,7 @@ namespace app\api\service\statistics; use app\api\model\dealer\Order; +use app\common\library\helper; use app\common\service\BaseService; class CommissionData extends BaseService @@ -17,8 +18,32 @@ class CommissionData extends BaseService public function getCommissionData($startDate = null, $endDate = null): array { return [ - 'settleTotalMoney' => 0, - 'noSettleTotalMoney' => 0 + 'settleTotalMoney' => $this->getSettTotalMoney($startDate, $endDate), + 'noSettleTotalMoney' => $this->getNoSettleTotalMoney($startDate, $endDate) ]; } + + public function getSettTotalMoney($startDate = null, $endDate = null) { + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; + } + $first = $this->dealerOrderModel->where($filter)->where('is_settled','=', 1)->sum('first_money'); + $two = $this->dealerOrderModel->where($filter)->where('is_settled','=', 1)->sum('second_money'); + $three = $this->dealerOrderModel->where($filter)->where('is_settled','=', 1)->sum('third_money'); + return helper::number2($first + $two + $three); + } + + public function getNoSettleTotalMoney($startDate = null, $endDate = null) { + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; + } + $first = $this->dealerOrderModel->where($filter)->where('is_settled','=', 0)->sum('first_money'); + $two = $this->dealerOrderModel->where($filter)->where('is_settled','=', 0)->sum('second_money'); + $three = $this->dealerOrderModel->where($filter)->where('is_settled','=', 0)->sum('third_money'); + return helper::number2($first + $two + $three); + } } \ No newline at end of file diff --git a/app/api/service/statistics/Data.php b/app/api/service/statistics/Data.php index 8ef1fa27..bf72d69e 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($startDate = null, $endDate = null); + return (new OrderData())->getOrderData($startDate, $endDate); } /** @@ -25,7 +25,7 @@ class Data extends BaseService * @return mixed */ public function getRefundData($startDate = null, $endDate = null): array { - return (new RefundData())->getRefundData($startDate = null, $endDate = null); + return (new RefundData())->getRefundData($startDate, $endDate); } /** @@ -33,7 +33,7 @@ class Data extends BaseService * @return mixed */ public function getUserData($startDate = null, $endDate = null): array { - return (new UserData())->getUserData($startDate = null, $endDate = null); + return (new UserData())->getUserData($startDate, $endDate); } /** @@ -41,6 +41,6 @@ class Data extends BaseService * @return mixed */ public function getCommissionData($startDate = null, $endDate = null) : array{ - return (new CommissionData())->getCommissionData($startDate = null, $endDate = null); + return (new CommissionData())->getCommissionData($startDate, $endDate); } } \ No newline at end of file diff --git a/app/api/service/statistics/OrderData.php b/app/api/service/statistics/OrderData.php index 149f5304..79339518 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -8,6 +8,7 @@ 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\enum\user\IdentityEnum; +use app\common\library\helper; use app\common\service\BaseService; class OrderData extends BaseService @@ -52,15 +53,12 @@ class OrderData extends BaseService // 查询对象 $query = $this->orderModel; // 设置查询条件 - if (!is_null($startDate) && !is_null($endDate)) { - $query->where('pay_time', '>=', strtotime($startDate)) - ->where('pay_time', '<', strtotime($endDate) + 86400); - } + $filter = $this->getOrderFilter($startDate, $endDate); // 总销售额 - return $query->where('pay_status', '=', PayStatusEnum::SUCCESS) - ->where('order_status', '<>', OrderStatusEnum::CANCELLED) + $data = $query->where($filter) ->where('is_delete', '=', 0) ->sum('pay_price'); + return helper::number2($data); } /** @@ -72,16 +70,10 @@ class OrderData extends BaseService 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]; - } + $filter = $this->getOrderFilter($startDate, $endDate); // 查询总记录 $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(); @@ -96,14 +88,7 @@ class OrderData extends BaseService */ 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]; - } + $filter = $this->getOrderFilter($startDate, $endDate); // 获取订单总数量 return $this->orderModel->where($filter) ->where('is_delete', '=', 0) @@ -115,12 +100,40 @@ class OrderData extends BaseService */ public function getPayCount($order_type, $startDate = null, $endDate = null) : int { $query = new IdentityOrder(); - if(!empty($startDate) && !empty($endDate)) { - $query->where('create_time', '>=', strtotime($startDate)) - ->where('create_time', '<', strtotime($endDate) + 86400); + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } - return $query->where('order_type', '=', $order_type)->count(); + return $query->where($filter)->where('order_type', '=', $order_type)->count(); + } + + function getOrderFilter($startDate, $endDate): array + { + $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 $filter; + } + + /** + * 订单成本金额 + */ + public function getOrderCostMoney($startDate, $endDate): float + { + $filter = $this->getOrderFilter($startDate, $endDate); + // 获取订单总数量 + $data = $this->orderModel + ->where($filter) + ->where('is_delete', '=', 0) + ->sum('cost_price'); + return helper::number2($data); } -} \ No newline at end of file +} diff --git a/app/api/service/statistics/RefundData.php b/app/api/service/statistics/RefundData.php index 2271a279..c5f0d799 100644 --- a/app/api/service/statistics/RefundData.php +++ b/app/api/service/statistics/RefundData.php @@ -30,11 +30,12 @@ class RefundData extends BaseService public function getRefundCount($startDate = null, $endDate = null): int { $query = $this->refundModel; - if(!empty($startDate) && !empty($endDate)) { - $query->where('create_time', '>=', strtotime($startDate)) - ->where('create_time', '<', strtotime($endDate) + 86400); + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } - return $query->where('status', '=', RefundStatus::COMPLETED)->count(); + return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->count(); } /** @@ -42,11 +43,12 @@ class RefundData extends BaseService */ public function getRefundTotalMoney($startDate = null, $endDate = null): float { $query = $this->refundModel; - if(!empty($startDate) && !empty($endDate)) { - $query->where('create_time', '>=', strtotime($startDate)) - ->where('create_time', '<', strtotime($endDate) + 86400); + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } // 总销售额 - return $query->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money'); + return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money'); } } \ No newline at end of file diff --git a/app/api/service/statistics/UserData.php b/app/api/service/statistics/UserData.php index 39622583..03ef1d39 100644 --- a/app/api/service/statistics/UserData.php +++ b/app/api/service/statistics/UserData.php @@ -18,17 +18,24 @@ class UserData extends BaseService public function getUserData($startDate = null, $endDate = null): array { return [ - 'visitorCount' => 0, + 'visitorCount' => $this->getVisitorCount($startDate, $endDate), 'viewCount' => $this->getViewCount($startDate, $endDate), - 'newUserCount' => 0, + 'newUserCount' => $this->getNewUserCount($startDate, $endDate), ]; } /** * 用户访问总数 */ - public function getVisitorCount() { - + public function getVisitorCount($startDate = null, $endDate = null) { + $query = new GoodsBrowseLog(); + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['ctime', '>=', $startDate]; + $filter[] = ['ctime', '<', $endDate]; + } + $value = $query->where($filter)->group('user_id')->count(); + return number_format($value); } /** @@ -37,18 +44,25 @@ class UserData extends BaseService public function getViewCount($startDate = null, $endDate = null): string { $query = new GoodsBrowseLog(); - if(!empty($startDate) && !empty($endDate)) { - $query->where('create_time', '>=', strtotime($startDate)) - ->where('create_time', '<', strtotime($endDate) + 86400); + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['ctime', '>=', $startDate]; + $filter[] = ['ctime', '<', $endDate]; } - $value = $query->group('user_id')->count(); + $value = $query->where($filter)->count(); return number_format($value); } /** * 新用户数量 */ - public function getNewUserCount() { - + public function getNewUserCount($startDate = null, $endDate = null) { + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['create_time', '>=', strtotime($startDate)]; + $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; + } + $value = $this->userModel->where($filter)->group('user_id')->count(); + return number_format($value); } } \ No newline at end of file