2024-05-30 21:37:55 +08:00
|
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
2024-06-04 15:03:41 +08:00
|
|
|
|
// | gitee下载:https=>//gitee.com/likeshop_gitee/likeadmin
|
|
|
|
|
// | github下载:https=>//github.com/likeshop-github/likeadmin
|
|
|
|
|
// | 访问官网:https=>//www.likeadmin.cn
|
2024-05-30 21:37:55 +08:00
|
|
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
|
|
// +----------------------------------------------------------------------
|
2024-06-04 15:03:41 +08:00
|
|
|
|
// | author=> likeadminTeam
|
2024-05-30 21:37:55 +08:00
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
2024-08-22 17:28:24 +08:00
|
|
|
|
use app\admin\lists\statistics\StoreProductLists;
|
2024-08-02 11:01:17 +08:00
|
|
|
|
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists;
|
2024-08-03 18:04:52 +08:00
|
|
|
|
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists;
|
2024-12-10 14:33:27 +08:00
|
|
|
|
use app\admin\lists\warehouse_product_storege\WarehouseProductStoregeTwoLists;
|
2024-06-20 11:08:06 +08:00
|
|
|
|
use app\admin\logic\statistic\ProductStatisticLogic;
|
2024-06-19 19:02:14 +08:00
|
|
|
|
use app\admin\logic\statistic\TradeStatisticLogic;
|
2024-06-20 11:08:06 +08:00
|
|
|
|
use app\admin\logic\statistic\UserStatisticLogic;
|
2024-08-21 22:55:18 +08:00
|
|
|
|
use app\admin\logic\statistic\WarehouseLogic;
|
2024-05-30 21:37:55 +08:00
|
|
|
|
use app\admin\logic\WorkbenchLogic;
|
2024-06-20 14:19:09 +08:00
|
|
|
|
use app\store\logic\WorkbenchLogic as LogicWorkbenchLogic;
|
2024-06-12 18:16:53 +08:00
|
|
|
|
use DateInterval;
|
|
|
|
|
use DateTime;
|
2024-05-30 21:37:55 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 工作台
|
|
|
|
|
* Class WorkbenchCotroller
|
|
|
|
|
* @package app\admin\controller
|
|
|
|
|
*/
|
|
|
|
|
class WorkbenchController extends BaseAdminController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 工作台
|
|
|
|
|
* @author 乔峰
|
2024-06-04 15:03:41 +08:00
|
|
|
|
* @date 2021/12/29 17=>01
|
2024-05-30 21:37:55 +08:00
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
$result = WorkbenchLogic::index();
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
2024-06-20 14:19:09 +08:00
|
|
|
|
/**
|
2024-06-21 11:18:03 +08:00
|
|
|
|
* @notes 门店
|
2024-06-20 14:19:09 +08:00
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2021/12/29 17=>01
|
|
|
|
|
*/
|
|
|
|
|
public function store_index()
|
|
|
|
|
{
|
|
|
|
|
$params = $this->request->get();
|
2024-08-23 13:46:25 +08:00
|
|
|
|
if (!isset($params['store_id']) || $params['store_id'] == '') {
|
|
|
|
|
$params['store_id'] = 0;
|
2024-06-20 14:19:09 +08:00
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
if (!isset($params['start_time']) || $params['start_time'] == '') {
|
|
|
|
|
$time = explode('-', $this->getDay(''));
|
|
|
|
|
$params['start_time'] = $time[0];
|
|
|
|
|
$params['end_time'] = $time[1];
|
2024-06-20 14:19:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = LogicWorkbenchLogic::index($params);
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @notes 工作台
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2021/12/29 17=>01
|
|
|
|
|
*/
|
|
|
|
|
public function store_index_new()
|
|
|
|
|
{
|
|
|
|
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
|
|
|
|
$result = WorkbenchLogic::index($params);
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
2024-06-04 15:03:41 +08:00
|
|
|
|
|
|
|
|
|
//-------------------------------商品统计---------------------------------------//
|
2024-06-08 16:53:08 +08:00
|
|
|
|
|
2024-06-04 15:03:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* 商品概况
|
|
|
|
|
*/
|
|
|
|
|
public function get_basic()
|
|
|
|
|
{
|
2024-06-12 18:16:53 +08:00
|
|
|
|
$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;
|
2024-06-12 15:05:44 +08:00
|
|
|
|
}
|
2024-06-12 18:16:53 +08:00
|
|
|
|
$where = [
|
|
|
|
|
['create_time', 'between', [$startTime, $endTime]]
|
2024-06-04 15:03:41 +08:00
|
|
|
|
];
|
2024-06-12 18:16:53 +08:00
|
|
|
|
$data = WorkbenchLogic::get_basic($where);
|
2024-06-04 15:03:41 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 商品趋势
|
|
|
|
|
*/
|
|
|
|
|
public function get_trend()
|
|
|
|
|
{
|
2024-06-12 18:16:53 +08:00
|
|
|
|
$dates = [];
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$date = $this->request->get('date', '');
|
|
|
|
|
$days = 31;
|
|
|
|
|
if ($date) {
|
|
|
|
|
$arr = explode('-', $date);
|
|
|
|
|
if ($arr[0] == $arr[1]) {
|
|
|
|
|
$date = new DateTime($arr[0]);
|
|
|
|
|
$dates[] = $date->format("Y-m-d");
|
|
|
|
|
} else {
|
|
|
|
|
$datetime_start = new DateTime($arr[0]);
|
|
|
|
|
$datetime_end = new DateTime($arr[1]);
|
|
|
|
|
$days = $datetime_start->diff($datetime_end)->days;
|
|
|
|
|
for ($i = 0; $i <= $days; $i++) {
|
|
|
|
|
$date = new DateTime($datetime_start->format('Y-m-d'));
|
|
|
|
|
$date->modify('+' . $i . ' days');
|
|
|
|
|
$dates[] = $date->format('Y-m-d');
|
|
|
|
|
}
|
2024-06-22 14:56:13 +08:00
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
} else {
|
2024-06-22 14:56:13 +08:00
|
|
|
|
$today = new DateTime();
|
|
|
|
|
$thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
|
|
|
|
|
$thirtyDaysAgo->modify('-30 days');
|
|
|
|
|
for ($i = 0; $i < $days; $i++) {
|
|
|
|
|
$date = new DateTime($thirtyDaysAgo->format('Y-m-d'));
|
|
|
|
|
$date->modify('+' . $i . ' days');
|
|
|
|
|
$dates[] = $date->format('Y-m-d');
|
|
|
|
|
}
|
2024-06-12 18:16:53 +08:00
|
|
|
|
}
|
2024-06-04 15:03:41 +08:00
|
|
|
|
$data = [
|
2024-06-12 18:16:53 +08:00
|
|
|
|
"xAxis" => $dates,
|
2024-06-04 15:03:41 +08:00
|
|
|
|
"series" => [
|
|
|
|
|
[
|
|
|
|
|
"name" => "商品浏览量",
|
2024-06-12 18:16:53 +08:00
|
|
|
|
"data" => WorkbenchLogic::store_visit_count($dates),
|
2024-06-04 15:03:41 +08:00
|
|
|
|
"type" => "line",
|
|
|
|
|
"smooth" => "true",
|
|
|
|
|
"yAxisIndex" => 1
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"name" => "商品访客量",
|
2024-06-12 18:16:53 +08:00
|
|
|
|
"data" => WorkbenchLogic::store_visit_user($dates),
|
2024-06-04 15:03:41 +08:00
|
|
|
|
"type" => "line",
|
|
|
|
|
"smooth" => "true",
|
|
|
|
|
"yAxisIndex" => 1
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"name" => "支付金额",
|
2024-06-12 18:16:53 +08:00
|
|
|
|
"data" => WorkbenchLogic::payPrice($dates),
|
2024-06-04 15:03:41 +08:00
|
|
|
|
"type" => "bar"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"name" => "退款金额",
|
2024-06-12 18:16:53 +08:00
|
|
|
|
"data" => WorkbenchLogic::refundPrice($dates),
|
2024-06-04 15:03:41 +08:00
|
|
|
|
"type" => "bar"
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取商品排名数据
|
|
|
|
|
*/
|
|
|
|
|
public function get_product_ranking()
|
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$date = $this->request->get('date', '');
|
2024-06-20 11:08:06 +08:00
|
|
|
|
$where['create_time'] = $this->getDay($date);
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$data = (new ProductStatisticLogic())->get_product_ranking($where);
|
|
|
|
|
return $this->success('', $data);
|
2024-06-04 15:03:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------用户统计---------------------------------------//
|
2024-06-08 16:53:08 +08:00
|
|
|
|
|
2024-06-04 15:03:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户概况
|
|
|
|
|
*/
|
|
|
|
|
public function get_user_basic()
|
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$date = $this->request->get('date', '');
|
|
|
|
|
$store_id = $this->request->get('store_id');
|
2024-06-20 11:08:06 +08:00
|
|
|
|
$where['create_time'] = $this->getDay($date);
|
2024-08-23 13:46:25 +08:00
|
|
|
|
if ($store_id) {
|
2024-08-04 10:32:28 +08:00
|
|
|
|
$where['store_id'] = $store_id;
|
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$data = (new UserStatisticLogic())->getBasic($where);
|
2024-06-04 15:03:41 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户趋势
|
|
|
|
|
*/
|
|
|
|
|
public function get_user_trend()
|
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$date = $this->request->get('date', '');
|
|
|
|
|
$store_id = $this->request->get('store_id');
|
2024-06-20 11:08:06 +08:00
|
|
|
|
$where['create_time'] = $this->getDay($date);
|
2024-08-23 13:46:25 +08:00
|
|
|
|
if ($store_id) {
|
2024-08-04 10:32:28 +08:00
|
|
|
|
$where['store_id'] = $store_id;
|
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$data = (new UserStatisticLogic())->getTrend($where);
|
2024-06-20 11:08:06 +08:00
|
|
|
|
|
2024-06-04 15:03:41 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
//-------------------------------交易统计---------------------------------------//
|
|
|
|
|
//当日订单金额
|
2024-06-07 13:38:42 +08:00
|
|
|
|
public function top_trade()
|
2024-06-04 15:03:41 +08:00
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$logic = (new TradeStatisticLogic());
|
2024-06-19 19:02:14 +08:00
|
|
|
|
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
|
|
|
|
|
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
|
|
|
|
|
$rightOne = $logic->getTopRightOneTrade();
|
|
|
|
|
$rightTwo = $logic->getTopRightTwoTrade();
|
|
|
|
|
$right = ['today' => $rightOne, 'month' => $rightTwo];
|
|
|
|
|
$totalleft = [$leftToday, $leftyestoday];
|
|
|
|
|
$left = [];
|
|
|
|
|
foreach ($totalleft as $k => $v) {
|
|
|
|
|
$left['name'] = "当日订单金额";
|
|
|
|
|
$left['x'] = $v['curve']['x'];
|
|
|
|
|
$left['series'][$k]['money'] = round($v['total_money'], 2);
|
|
|
|
|
$left['series'][$k]['value'] = array_values($v['curve']['y']);
|
2024-06-12 18:16:53 +08:00
|
|
|
|
}
|
2024-06-19 19:02:14 +08:00
|
|
|
|
|
|
|
|
|
$data['left'] = $left;
|
|
|
|
|
$data['right'] = $right;
|
2024-06-04 15:03:41 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//交易趋势
|
|
|
|
|
public function bottom_trade()
|
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$date = $this->request->get('date', '');
|
|
|
|
|
$data = (new TradeStatisticLogic())->getBottomTrade(['data' => $this->getDay($date)]);
|
2024-06-04 15:03:41 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
2024-06-20 11:08:06 +08:00
|
|
|
|
|
2024-08-02 11:01:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* 实时商品统计
|
|
|
|
|
*/
|
2024-08-23 13:46:25 +08:00
|
|
|
|
public function product_order()
|
|
|
|
|
{
|
2024-08-02 11:01:17 +08:00
|
|
|
|
return $this->dataLists(new StoreOrderCartInfoGroupLists());
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-03 18:04:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 月销售商品统计
|
|
|
|
|
*/
|
2024-08-23 13:46:25 +08:00
|
|
|
|
public function product_month_order()
|
|
|
|
|
{
|
2024-08-03 18:04:52 +08:00
|
|
|
|
return $this->dataLists(new StoreOrderCartInfoGroupMonthLists());
|
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
/**
|
2024-06-20 11:08:06 +08:00
|
|
|
|
* 格式化时间
|
|
|
|
|
* @param $time
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDay($time)
|
|
|
|
|
{
|
|
|
|
|
if (strstr($time, '-') !== false) {
|
|
|
|
|
[$startTime, $endTime] = explode('-', $time);
|
|
|
|
|
if (!$startTime && !$endTime) {
|
|
|
|
|
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
|
|
|
|
|
} else {
|
2024-08-23 13:46:25 +08:00
|
|
|
|
if ($startTime == $endTime) {
|
|
|
|
|
return $startTime . '-' . $endTime . ' 23:59:59';
|
|
|
|
|
} else {
|
2024-06-21 14:48:28 +08:00
|
|
|
|
return $startTime . '-' . $endTime;
|
|
|
|
|
}
|
2024-06-20 11:08:06 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-23 13:46:25 +08:00
|
|
|
|
//-------------------------------统计仓库---------------------------------------//
|
2024-08-21 22:55:18 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2024-08-23 13:46:25 +08:00
|
|
|
|
* 统计仓库头
|
2024-08-21 22:55:18 +08:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function total_warehouse()
|
|
|
|
|
{
|
2024-08-23 13:46:25 +08:00
|
|
|
|
$data = WarehouseLogic::total_warehouse();
|
2024-08-21 22:55:18 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
2024-08-22 12:04:58 +08:00
|
|
|
|
|
2024-08-23 13:46:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* 统计仓库列表
|
2024-08-22 12:04:58 +08:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function warehouse_list()
|
|
|
|
|
{
|
2024-08-22 17:28:24 +08:00
|
|
|
|
return $this->dataLists(new StoreProductLists());
|
2024-08-23 13:46:25 +08:00
|
|
|
|
}
|
2024-08-22 17:28:24 +08:00
|
|
|
|
|
2024-08-23 13:46:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* 统计门店仓库总库存
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function total_warehouse_list()
|
2024-08-23 14:41:07 +08:00
|
|
|
|
{
|
2024-08-24 15:12:53 +08:00
|
|
|
|
$parmas = $this->request->get();
|
|
|
|
|
$data = WarehouseLogic::total_warehouse_list($parmas, $parmas['type'] ?? 1);
|
2024-08-23 14:41:07 +08:00
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-24 15:12:53 +08:00
|
|
|
|
/**
|
2024-08-23 14:41:07 +08:00
|
|
|
|
* 统计门店仓库总库存
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function total_warehouse_product_list()
|
2024-08-23 13:46:25 +08:00
|
|
|
|
{
|
2024-08-24 15:12:53 +08:00
|
|
|
|
$parmas = $this->request->get();
|
|
|
|
|
$data = WarehouseLogic::total_warehouse_product_list($parmas, $parmas['type'] ?? 1);
|
|
|
|
|
return $this->data($data);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-25 17:57:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* 负库存检测
|
|
|
|
|
*/
|
2024-08-24 15:12:53 +08:00
|
|
|
|
public function negative_inventory()
|
|
|
|
|
{
|
|
|
|
|
$parmas = $this->request->get();
|
2024-12-10 14:33:27 +08:00
|
|
|
|
if($parmas['type'] == 3){
|
|
|
|
|
return $this->dataLists(new WarehouseProductStoregeTwoLists());
|
|
|
|
|
}
|
2024-08-24 15:12:53 +08:00
|
|
|
|
$data = WarehouseLogic::negativeInventory($parmas);
|
2024-08-23 13:46:25 +08:00
|
|
|
|
return $this->data($data);
|
2024-08-22 12:04:58 +08:00
|
|
|
|
}
|
2024-08-25 17:57:48 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 负库存归零
|
|
|
|
|
*/
|
|
|
|
|
public function update_negative_zero()
|
|
|
|
|
{
|
|
|
|
|
$parmas = $this->request->get();
|
2025-01-06 12:04:18 +08:00
|
|
|
|
$res = WarehouseLogic::updateNegativeZero($parmas,$this->adminId);
|
2024-08-25 17:57:48 +08:00
|
|
|
|
if($res){
|
|
|
|
|
return $this->data([], '操作成功');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->data([], '操作失败', 400);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-01 15:51:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* 更新库存和价值
|
|
|
|
|
*/
|
|
|
|
|
public function stock_product_price()
|
|
|
|
|
{
|
|
|
|
|
$parmas = $this->request->get();
|
|
|
|
|
$res = WarehouseLogic::stockProductPrice($parmas);
|
|
|
|
|
if($res){
|
|
|
|
|
return $this->success('操作成功,请刷新页面',[],1,1);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->fail('操作失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-04 15:03:41 +08:00
|
|
|
|
}
|