yijia-webman/app/controller/SalesController.php

69 lines
1.8 KiB
PHP

<?php
namespace app\controller;
use support\Request;
use app\model\SaleLog;
class SalesController
{
//日销量额统计
public function index(Request $request)
{
return view('sales/index');
}
//商品销量统计
public function goods(Request $request)
{
return view('sales/goods');
}
//获取日销额统计
public function apiGetSales(Request $request)
{
$start = $request->get('start', '');
$end = $request->get('end', '');
if(empty($start)){
$start = date('Y-m-d', strtotime('-30 days'));
}
if(empty($end)){
$end = date('Y-m-d');
}
$data = SaleLog::getSales($start, $end);
$soldAt = $data->column('sold_at');
$totalSales = $data->column('total_sales');
return json(['code' => 0, 'data' => ['sold_at' => $soldAt, 'total_sales' => $totalSales]]);
}
public function apiGetSalesGoods(Request $request)
{
$start = $request->get('start', '');
$end = $request->get('end', '');
$order = $request->get('order', 'total_sales');
if(empty($start)){
$start = date('Y-m-d', strtotime('-30 days'));
}
if(empty($end)){
$end = date('Y-m-d');
}
$data = SaleLog::getSalesGoods($start, $end, $order);
$goodsName = $data->column('goods_name');
$totalSales = $data->column('total_sales');
$totalNum = $data->column('total_num');
$totalNumSmall = $data->column('total_num_small');
return json(['code' => 0, 'data' => [
'goods_name' => $goodsName,
'total_sales' => $totalSales,
'total_num' => $totalNum,
'total_num_small' => $totalNumSmall
]
]);
}
}