<?php
|
|
namespace app\operations\service\commoNstatistics;
|
|
use app\common\library\helper;
|
use app\operations\model\order\Order as OrderModel;
|
use app\operations\model\order\OrderRefund as OrderRefundModel;
|
use app\operations\model\product\Product as ProductModel;
|
use app\operations\model\order\OrderProduct as OrderProductModel;
|
|
/**
|
* 订单数据概况
|
*/
|
class OrderService
|
{
|
// 商户id
|
private $shop_supplier_id;
|
|
public function __construct($shop_supplier_id)
|
{
|
$this->shop_supplier_id = $shop_supplier_id;
|
}
|
/**
|
* 获取数据概况
|
*/
|
public function getData($search_time='')
|
{
|
$today = date('Y-m-d');
|
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
$start_day = '2020-1-1';//默认查询全部
|
$end_day = null;
|
if(!empty($search_time)){
|
$start_day = array_shift($search_time);
|
$end_day = array_pop($search_time);
|
}
|
|
$data = [
|
// 成交额(元)
|
'order_total_price' => [
|
'total' => helper::number2($this->getOrderData($start_day, $end_day, 'order_total_price')),
|
'today' => helper::number2($this->getOrderData($today, null, 'order_total_price')),
|
'yesterday' => helper::number2($this->getOrderData($yesterday, null, 'order_total_price'))
|
],
|
// 支付订单数
|
'order_total' => [
|
'total' => number_format($this->getOrderData($start_day, $end_day, 'order_total')),
|
'today' => number_format($this->getOrderData($today, null, 'order_total')),
|
'yesterday' => number_format($this->getOrderData($yesterday, null, 'order_total'))
|
],
|
// 下单用户数
|
'order_user_total' => [
|
'total' => $this->getOrderData($start_day, $end_day, 'order_user_total'),
|
'today' => $this->getOrderData($today, null, 'order_user_total'),
|
'yesterday' => $this->getOrderData($yesterday, null, 'order_user_total')
|
],
|
// 退款成功总金额
|
'order_refund_money' => [
|
'total' => $this->getOrderRefundData($start_day, $end_day, 'order_refund_money'),
|
'today' => $this->getOrderRefundData($today, null, 'order_refund_money'),
|
'yesterday' => $this->getOrderRefundData($yesterday, null, 'order_refund_money')
|
],
|
// 退款成功订单数
|
'order_refund_total' => [
|
'total' => $this->getOrderRefundData($start_day, $end_day, 'order_refund_total'),
|
'today' => $this->getOrderRefundData($today, null, 'order_refund_total'),
|
'yesterday' => $this->getOrderRefundData($yesterday, null, 'order_refund_total')
|
],
|
];
|
|
// 客单价
|
$data['order_per_price'] = [
|
'total' => $data['order_user_total']['total'] == 0?0:helper::number2($data['order_total_price']['total']/$data['order_user_total']['total']),
|
'today' => $data['order_user_total']['today'] == 0?0:helper::number2($data['order_total_price']['today']/$data['order_user_total']['today']),
|
'yesterday' => $data['order_user_total']['yesterday'] == 0?0:helper::number2($data['order_total_price']['yesterday']/$data['order_user_total']['yesterday'])
|
];
|
return $data;
|
}
|
|
/**
|
* 通过时间段查询订单数据
|
*/
|
public function getDataByDate($days)
|
{
|
$data = [];
|
foreach ($days as $day) {
|
$data[] = [
|
'day' => $day,
|
'total_money' => $this->getOrderData($day, null, 'order_total_price'),
|
'total_num' => $this->getOrderData($day, null, 'order_total')
|
];
|
}
|
return $data;
|
}
|
|
/**
|
* 通过时间段查询退款订单数据
|
*/
|
public function getRefundByDate($days)
|
{
|
$data = [];
|
foreach ($days as $day) {
|
$data[] = [
|
'day' => $day,
|
'total_money' => $this->getOrderRefundData($day, null, 'order_refund_money'),
|
'total_num' => $this->getOrderRefundData($day, null, 'order_refund_total')
|
];
|
}
|
return $data;
|
}
|
|
/**
|
* 获取订单数据
|
*/
|
private function getOrderData($startDate = null, $endDate = null, $type)
|
{
|
return (new OrderModel)->getOrderData($startDate, $endDate, $type, $this->shop_supplier_id);
|
}
|
|
/**
|
* 获取订单退款数据
|
*/
|
private function getOrderRefundData($startDate = null, $endDate = null, $type)
|
{
|
return (new OrderRefundModel)->getOrderRefundData($startDate, $endDate, $type, $this->shop_supplier_id);
|
}
|
|
/**
|
* 获取数据概况
|
*/
|
public function getProductData()
|
{
|
$today = date('Y-m-d');
|
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
$where["product_status"] = 10;
|
if($this->shop_supplier_id > 0){
|
$where["shop_supplier_id"] = $this->shop_supplier_id;
|
}
|
$data = [
|
// 在售商品
|
'sale' => [
|
'today' => number_format((new ProductModel)->getProductTotal($where)),
|
'yesterday' => '--'
|
],
|
// 未付款商品(件)
|
'no_pay' => [
|
'today' => number_format($this->getOrderProductData($today, null, 'no_pay')),
|
'yesterday' => number_format($this->getOrderProductData($yesterday, null, 'no_pay'))
|
],
|
// 已付款商品(件)
|
'pay' => [
|
'today' => number_format($this->getOrderProductData($today, null, 'pay')),
|
'yesterday' => number_format($this->getOrderProductData($yesterday, null, 'pay'))
|
],
|
];
|
return $data;
|
}
|
|
/**
|
* 获取订单商品数据
|
*/
|
private function getOrderProductData($startDate = null, $endDate = null, $type)
|
{
|
return (new OrderProductModel)->getProductData($startDate, $endDate, $type, $this->shop_supplier_id);
|
}
|
|
|
/**
|
* 通过时间段查询商品订单数据
|
*/
|
public function getProductDataByDate($days)
|
{
|
$data = [];
|
foreach ($days as $day) {
|
$data[] = [
|
'day' => $day,
|
'total_num' => $this->getOrderProductData($day, null, 'pay')
|
];
|
}
|
return $data;
|
}
|
}
|