ztt 1 year ago
parent a38c1172b7
commit e706d91c9d
  1. 10
      app/api/service/statistics/CommissionData.php
  2. 8
      app/api/service/statistics/Data.php
  3. 96
      app/api/service/statistics/OrderData.php
  4. 11
      app/api/service/statistics/RefundData.php
  5. 10
      app/api/service/statistics/UserData.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,

@ -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);
}
}

@ -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();
}
}

@ -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,

@ -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,

Loading…
Cancel
Save