初始化项目
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\service\statistics;
|
||||
|
||||
use app\common\service\BaseService;
|
||||
use app\store\service\statistics\data\Survey;
|
||||
use app\store\service\statistics\data\Trade7days;
|
||||
use app\store\service\statistics\data\GoodsRanking;
|
||||
use app\store\service\statistics\data\UserExpendRanking;
|
||||
|
||||
/**
|
||||
* 数据概况服务类
|
||||
* Class Data
|
||||
* @package app\store\service\statistics
|
||||
*/
|
||||
class Data extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取数据概况
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return array
|
||||
*/
|
||||
public function getSurveyData($startDate = null, $endDate = null)
|
||||
{
|
||||
return (new Survey)->getSurveyData($startDate, $endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 近7日走势
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactionTrend()
|
||||
{
|
||||
return (new Trade7days)->getTransactionTrend();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品销售榜
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGoodsRanking()
|
||||
{
|
||||
return (new GoodsRanking)->getGoodsRanking();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户消费榜
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function geUserExpendRanking()
|
||||
{
|
||||
return (new UserExpendRanking)->getUserExpendRanking();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\service\statistics\data;
|
||||
|
||||
use app\common\service\BaseService;
|
||||
use app\store\model\OrderGoods as OrderGoodsModel;
|
||||
use app\common\enum\order\OrderStatus as OrderStatusEnum;
|
||||
use app\common\enum\order\PayStatus as OrderPayStatusEnum;
|
||||
|
||||
/**
|
||||
* 数据统计-商品销售榜
|
||||
* Class GoodsRanking
|
||||
* @package app\store\service\statistics\data
|
||||
*/
|
||||
class GoodsRanking extends BaseService
|
||||
{
|
||||
/**
|
||||
* 商品销售榜
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGoodsRanking()
|
||||
{
|
||||
return (new OrderGoodsModel)->alias('o_goods.o_goods')
|
||||
->field([
|
||||
'o_goods.goods_id',
|
||||
// 这里采用聚合函数获取goods_name, 因为mysql5.7使用group的报错问题
|
||||
'MAX(goods_name) AS goods_name',
|
||||
'SUM(total_pay_price) AS sales_volume',
|
||||
'SUM(total_num) AS total_sales_num'
|
||||
])
|
||||
->join('order', 'order.order_id = o_goods.order_id')
|
||||
->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS)
|
||||
->where('order.order_status', '<>', OrderStatusEnum::FAIL)
|
||||
// 这里如果写入goods_name的话,会出现同商品ID不同name的数据
|
||||
->group('o_goods.goods_id')
|
||||
// order:此处按总销售额排序,如需按销量改为total_sales_num
|
||||
->order(['sales_volume' => 'DESC'])
|
||||
->limit(10)
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\service\statistics\data;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\service\BaseService;
|
||||
use app\store\model\User as UserModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\store\model\recharge\Order as RechargeOrderModel;
|
||||
use app\common\enum\order\PayStatus as PayStatusEnum;
|
||||
use app\common\enum\recharge\order\PayStatus as RechargePayStatusEnum;
|
||||
|
||||
/**
|
||||
* 数据概况
|
||||
* Class Survey
|
||||
* @package app\store\service\statistics\data
|
||||
*/
|
||||
class Survey extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取数据概况
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return array
|
||||
*/
|
||||
public function getSurveyData($startDate = null, $endDate = null)
|
||||
{
|
||||
return [
|
||||
// 用户数量
|
||||
'userTotal' => $this->getUserTotal($startDate, $endDate),
|
||||
// 消费人数
|
||||
'consumeUsers' => $this->getConsumeUsers($startDate, $endDate),
|
||||
// 支付订单数
|
||||
'orderTotal' => $this->getOrderTotal($startDate, $endDate),
|
||||
// 销售额(元)
|
||||
'orderTotalPrice' => $this->getOrderTotalPrice($startDate, $endDate),
|
||||
// 商品总量
|
||||
'goodsTotal' => $this->getGoodsTotal($startDate, $endDate),
|
||||
// 用户充值总额
|
||||
'rechargeTotalMoney' => $this->getRechargeTotalMoney($startDate, $endDate),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户总量
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return string
|
||||
*/
|
||||
private function getUserTotal($startDate = null, $endDate = null)
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
// 查询总记录
|
||||
$value = (new UserModel)->where($filter)
|
||||
->where('is_delete', '=', '0')
|
||||
->count();
|
||||
return number_format($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费人数
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return string
|
||||
*/
|
||||
public function getConsumeUsers($startDate = null, $endDate = null)
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['pay_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['pay_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
// 查询总记录
|
||||
$value = (new 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 string
|
||||
*/
|
||||
private function getOrderTotal($startDate = null, $endDate = null)
|
||||
{
|
||||
return number_format((new OrderModel)->getPayOrderTotal($startDate, $endDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款订单总额
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return string
|
||||
*/
|
||||
private function getOrderTotalPrice($startDate = null, $endDate = null)
|
||||
{
|
||||
return helper::number2((new OrderModel)->getOrderTotalPrice($startDate, $endDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品总量
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return string
|
||||
*/
|
||||
private function getGoodsTotal($startDate = null, $endDate = null)
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
// 查询总记录
|
||||
$value = (new GoodsModel)->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->count();
|
||||
return number_format($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值总额
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return float|int
|
||||
*/
|
||||
private function getRechargeTotalMoney($startDate = null, $endDate = null)
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['pay_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['pay_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
// 查询总记录
|
||||
$value = (new RechargeOrderModel)->where($filter)
|
||||
->where('pay_status', '=', RechargePayStatusEnum::SUCCESS)
|
||||
->sum('actual_money');
|
||||
return helper::number2($value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\service\statistics\data;
|
||||
|
||||
use app\common\service\BaseService;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 近7日走势
|
||||
* Class Trade7days
|
||||
* @package app\store\service\statistics\data
|
||||
*/
|
||||
class Trade7days extends BaseService
|
||||
{
|
||||
/* @var OrderModel $GoodsModel */
|
||||
private $OrderModel;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
/* 初始化模型 */
|
||||
$this->OrderModel = new OrderModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 近7日走势
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactionTrend()
|
||||
{
|
||||
// 最近七天日期
|
||||
$lately7days = $this->getLately7days();
|
||||
return [
|
||||
'date' => $lately7days,
|
||||
'orderTotal' => $lately7days,
|
||||
'orderTotalPrice' => $this->getOrderTotalPriceByDate($lately7days)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近七天日期
|
||||
*/
|
||||
private function getLately7days()
|
||||
{
|
||||
// 获取当前周几
|
||||
$date = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$date[] = date('Y-m-d', strtotime('-' . $i . ' days'));
|
||||
}
|
||||
return array_reverse($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某天的总销售额
|
||||
* @param null $day
|
||||
* @return string
|
||||
*/
|
||||
private function getOrderTotalPrice($day = null)
|
||||
{
|
||||
return helper::number2($this->OrderModel->getOrderTotalPrice($day, $day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单总量 (指定日期)
|
||||
* @param $days
|
||||
* @return array
|
||||
*/
|
||||
private function getOrderTotalPriceByDate($days)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($days as $day) {
|
||||
$data[] = $this->getOrderTotalPrice($day);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\service\statistics\data;
|
||||
|
||||
use app\store\model\User as UserModel;
|
||||
use app\common\service\BaseService;
|
||||
|
||||
/**
|
||||
* 数据统计-用户消费榜
|
||||
* Class UserExpendRanking
|
||||
* @package app\store\service\statistics\data
|
||||
*/
|
||||
class UserExpendRanking extends BaseService
|
||||
{
|
||||
/**
|
||||
* 用户消费榜
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getUserExpendRanking()
|
||||
{
|
||||
return (new UserModel)->field(['user_id', 'nick_name', 'expend_money'])
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['expend_money' => 'DESC'])
|
||||
->limit(10)
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user