feat: 修改了WorkbenchController和WorkbenchLogic类,添加了根据时间段获取商品统计数据的功能。

This commit is contained in:
mkm 2024-06-12 15:05:44 +08:00
parent 0a693d5e37
commit c03acdb57a
2 changed files with 37 additions and 189 deletions

View File

@ -232,48 +232,16 @@ class WorkbenchController extends BaseAdminController
*/
public function get_basic()
{
$data = [
"browse" => [
"num" => 11353,
"percent" => "330.03"
],
"user" => [
"num" => 538,
"percent" => "47.39"
],
"cart" => [
"num" => 1181,
"percent" => "43.67"
],
"order" => [
"num" => 105753,
"percent" => "-68.07"
],
"pay" => [
"num" => 2476,
"percent" => "-99.24"
],
"payPrice" => [
"num" => 163490.54,
"percent" => "-87.50"
],
"cost" => [
"num" => 72147.8,
"percent" => "-93.33"
],
"refundPrice" => [
"num" => 2321.81,
"percent" => "1447.87"
],
"refund" => [
"num" => 39,
"percent" => "8.33"
],
"payPercent" => [
"num" => "15.61",
"percent" => "-6.58"
]
$startTime=$this->request->get('start_time');//开始时间
$endTime=$this->request->get('end_time');//结束时间
if(empty($startTime)){//如果没有传开始时间则默认获取最近7天的数据
$startTime=strtotime(date('Y-m-d'));
$endTime=$startTime+86400;
}
$where=[
['create_time','between',[$startTime,$endTime]]
];
$data=WorkbenchLogic::get_basic($where);
return $this->data($data);
}

View File

@ -16,6 +16,8 @@ namespace app\admin\logic;
use app\common\logic\BaseLogic;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_visit\StoreVisit;
use app\common\service\ConfigService;
use app\common\service\FileService;
@ -37,162 +39,40 @@ class WorkbenchLogic extends BaseLogic
public static function index()
{
return [
// 版本信息
'version' => self::versionInfo(),
// 今日数据
'today' => self::today(),
// 常用功能
'menu' => self::menu(),
// 近15日访客数
'visitor' => self::visitor(),
// 服务支持
'support' => self::support()
];
}
//-------------------------------商品统计---------------------------------------//
/**
* @notes 常用功能
* @return array[]
* @author 乔峰
* @date 2021/12/29 16:40
* 商品概况
*/
public static function menu(): array
public static function get_basic($where)
{
$browse=StoreVisit::where($where)->count();
$user=0;
$cart=0;
$order=StoreOrder::where($where)->count();
$pay=StoreOrder::where($where)->where('paid',1)->count();
$payPrice=StoreOrder::where($where)->where('paid',1)->count('pay_price');
$cost=StoreOrder::where($where)->where('paid',1)->sum('cost');
$refundPrice=StoreOrder::where($where)->where('status','in',[-1,-2])->sum('refund_price');
$refund=StoreOrder::where($where)->where('status','in',[-1,-2])->count();
$payPercent=0;
return [
[
'name' => '管理员',
'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
'url' => '/permission/admin'
],
[
'name' => '角色管理',
'image' => FileService::getFileUrl(config('project.default_image.menu_role')),
'url' => '/permission/role'
],
[
'name' => '部门管理',
'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
'url' => '/organization/department'
],
[
'name' => '素材中心',
'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
'url' => '/material/index'
],
[
'name' => '菜单权限',
'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
'url' => '/permission/menu'
],
[
'name' => '网站信息',
'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
'url' => '/setting/website/information'
],
'browse'=>['num'=>$browse,'title'=>'浏览量'],//浏览量
'user'=>['num'=>$user,'title'=>'访客数'],//访客数
'cart'=>['num'=>$cart,'title'=>'加购人数'],//加购人数
'order'=>['num'=>$order,'title'=>'订单量'],//订单量
'pay'=>['num'=>$pay,'title'=>'支付订单量'],//支付订单量
'payPrice'=>['num'=>$payPrice,'title'=>'支付金额'],//支付金额
'cost'=>['num'=>$cost,'title'=>'成本'],//成本
'refundPrice'=>['num'=>$refundPrice,'title'=>'退款金额'],//退款金额
'refund'=>['num'=>$refund,'title'=>'退款订单量'],//退款订单量
'payPercent'=>['num'=>$payPercent,'title'=>'支付转化率'],//支付转化率
];
}
/**
* @notes 版本信息
* @return array
* @author 乔峰
* @date 2021/12/29 16:08
*/
public static function versionInfo(): array
{
return [
'version' => config('project.version'),
'website' => config('project.website.url'),
'name' => ConfigService::get('website', 'name'),
'based' => 'vue3.x、ElementUI、MySQL',
'channel' => [
'website' => 'https://gitee.com/MuZJun/gather-admin.git',
'gitee' => 'https://gitee.com/MuZJun/gather-vue.git',
]
];
}
/**
* @notes 今日数据
* @return int[]
* @author 乔峰
* @date 2021/12/29 16:15
*/
public static function today(): array
{
return [
'time' => date('Y-m-d H:i:s'),
// 今日销售额
'today_sales' => 100,
// 总销售额
'total_sales' => 1000,
// 今日访问量
'today_visitor' => 10,
// 总访问量
'total_visitor' => 100,
// 今日新增用户量
'today_new_user' => 30,
// 总用户量
'total_new_user' => 3000,
// 订单量 (笔)
'order_num' => 12,
// 总订单量
'order_sum' => 255
];
}
/**
* @notes 访问数
* @return array
* @author 乔峰
* @date 2021/12/29 16:57
*/
public static function visitor(): array
{
$num = [];
$date = [];
for ($i = 0; $i < 15; $i++) {
$where_start = strtotime("- " . $i . "day");
$date[] = date('Y/m/d', $where_start);
$num[$i] = rand(0, 100);
}
return [
'date' => $date,
'list' => [
['name' => '访客数', 'data' => $num]
]
];
}
/**
* @notes 服务支持
* @return array[]
* @author 乔峰
* @date 2022/7/18 11:18
*/
public static function support()
{
return [
[
'image' => FileService::getFileUrl(config('project.default_image.qq_group')),
'title' => '官方公众号',
'desc' => '关注官方公众号',
],
[
'image' => FileService::getFileUrl(config('project.default_image.customer_service')),
'title' => '添加企业客服微信',
'desc' => '想了解更多请添加客服',
]
];
}
}
}