|
|
|
@ -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,11 +100,39 @@ 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($filter)->where('order_type', '=', $order_type)->count(); |
|
|
|
|
} |
|
|
|
|
return $query->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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|