添加商品统计、用户统计
This commit is contained in:
parent
324105c842
commit
3b03ecfa63
@ -226,6 +226,7 @@ class WorkbenchController extends BaseAdminController
|
|||||||
return $this->data($data);
|
return $this->data($data);
|
||||||
}
|
}
|
||||||
//-------------------------------商品统计---------------------------------------//
|
//-------------------------------商品统计---------------------------------------//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品概况
|
* 商品概况
|
||||||
*/
|
*/
|
||||||
@ -536,6 +537,7 @@ class WorkbenchController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------用户统计---------------------------------------//
|
//-------------------------------用户统计---------------------------------------//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户概况
|
* 获取用户概况
|
||||||
*/
|
*/
|
||||||
|
@ -4,16 +4,13 @@ namespace app\common\logic\store_order;
|
|||||||
|
|
||||||
use app\common\enum\OrderEnum;
|
use app\common\enum\OrderEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\enum\PayEnum;
|
|
||||||
use app\common\enum\YesNoEnum;
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\model\dict\DictType;
|
use app\common\model\dict\DictType;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
use app\common\model\store_product\StoreProduct;
|
|
||||||
use app\common\model\store_product_unit\StoreProductUnit;
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
use app\common\model\user\UserAddress;
|
|
||||||
use app\common\service\pay\PayService;
|
use app\common\service\pay\PayService;
|
||||||
use Exception;
|
use Exception;
|
||||||
use support\Cache;
|
use support\Cache;
|
||||||
@ -106,6 +103,7 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
return ['order' => $order, 'cart_list' => $cart_select];
|
return ['order' => $order, 'cart_list' => $cart_select];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新订单
|
* 创建新订单
|
||||||
* @return Object|bool|array
|
* @return Object|bool|array
|
||||||
@ -209,9 +207,9 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
* @param $extra
|
* @param $extra
|
||||||
* @return float|\think\db\Query
|
* @return float|\think\db\Query
|
||||||
*/
|
*/
|
||||||
public function storeOrderSumByDate($storeId, $start, $end, $extra = [])
|
public function storeOrderSumByDate($storeId, $start, $end, $extra = [], $field = 'pay_price')
|
||||||
{
|
{
|
||||||
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('create_time', $start, $end)->sum('pay_price');
|
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('pay_time', $start, $end)->sum($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ class WorkbenchController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[
|
#[
|
||||||
ApiDoc\Title('商品统计'),
|
ApiDoc\Title('商品统计(暂时不用)'),
|
||||||
ApiDoc\url('/store/workbench/product'),
|
ApiDoc\url('/store/workbench/product'),
|
||||||
ApiDoc\Method('GET'),
|
ApiDoc\Method('GET'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
@ -42,13 +42,14 @@ class WorkbenchController extends BaseAdminController
|
|||||||
]
|
]
|
||||||
public function product()
|
public function product()
|
||||||
{
|
{
|
||||||
$storeId = $this->request->adminInfo['store_id'];
|
$params = $this->request->get();
|
||||||
$result = WorkbenchLogic::index($storeId);
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
$result = WorkbenchLogic::product($params);
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[
|
#[
|
||||||
ApiDoc\Title('配送统计'),
|
ApiDoc\Title('配送统计(暂时不用)'),
|
||||||
ApiDoc\url('/store/workbench/delivery'),
|
ApiDoc\url('/store/workbench/delivery'),
|
||||||
ApiDoc\Method('GET'),
|
ApiDoc\Method('GET'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
@ -61,8 +62,98 @@ class WorkbenchController extends BaseAdminController
|
|||||||
public function delivery()
|
public function delivery()
|
||||||
{
|
{
|
||||||
$storeId = $this->request->adminInfo['store_id'];
|
$storeId = $this->request->adminInfo['store_id'];
|
||||||
$result = WorkbenchLogic::index($storeId);
|
$result = WorkbenchLogic::delivery($storeId);
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('商品统计-概况'),
|
||||||
|
ApiDoc\url('/store/workbench/get_basic'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||||
|
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function get_basic(\app\admin\controller\WorkbenchController $workbench)
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
return $workbench->get_basic();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('商品统计-图表'),
|
||||||
|
ApiDoc\url('/store/workbench/get_trend'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||||
|
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function get_trend(\app\admin\controller\WorkbenchController $workbench)
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
return $workbench->get_trend();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('商品统计-排行'),
|
||||||
|
ApiDoc\url('/store/workbench/get_product_ranking'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||||
|
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function get_product_ranking(\app\admin\controller\WorkbenchController $workbench)
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
return $workbench->get_product_ranking();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('用户统计-概况'),
|
||||||
|
ApiDoc\url('/store/workbench/get_user_basic'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||||
|
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function get_user_basic(\app\admin\controller\WorkbenchController $workbench)
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
return $workbench->get_user_basic();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('用户统计-图表'),
|
||||||
|
ApiDoc\url('/store/workbench/get_user_trend'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||||
|
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function get_user_trend(\app\admin\controller\WorkbenchController $workbench)
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
return $workbench->get_user_trend();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,11 @@ namespace app\store\logic;
|
|||||||
use app\common\enum\PayEnum;
|
use app\common\enum\PayEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\logic\store_order\StoreOrderLogic;
|
use app\common\logic\store_order\StoreOrderLogic;
|
||||||
|
use app\common\model\order\Cart;
|
||||||
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\store_visit\StoreVisit;
|
||||||
use app\common\service\ConfigService;
|
use app\common\service\ConfigService;
|
||||||
use app\common\service\FileService;
|
use app\common\service\FileService;
|
||||||
|
|
||||||
@ -50,10 +53,12 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
$data['cash_amount'] = StoreCashFinanceFlow::where('store_id', $params['store_id'])->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price');
|
$data['cash_amount'] = StoreCashFinanceFlow::where('store_id', $params['store_id'])->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price');
|
||||||
//核销订单金额
|
//核销订单金额
|
||||||
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]);
|
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]);
|
||||||
|
//门店收益金额
|
||||||
|
$data['income_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, [], 'profit');
|
||||||
//门店成交用户数
|
//门店成交用户数
|
||||||
$data['user_number'] = StoreOrder::where('store_id', $params['store_id'])
|
$data['user_number'] = StoreOrder::where('store_id', $params['store_id'])
|
||||||
->where('paid', 1)
|
->where('paid', 1)
|
||||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
->group('uid')
|
->group('uid')
|
||||||
->count();
|
->count();
|
||||||
if ($dateDiff->days == 1) {
|
if ($dateDiff->days == 1) {
|
||||||
@ -132,8 +137,8 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
];
|
];
|
||||||
$data['order_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
$data['order_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||||
->where('paid', 1)
|
->where('paid', 1)
|
||||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
->order('create_time', 'desc')
|
->order('pay_time', 'desc')
|
||||||
->limit(10)
|
->limit(10)
|
||||||
->select()->toArray();
|
->select()->toArray();
|
||||||
$data['pay_type'] = [
|
$data['pay_type'] = [
|
||||||
@ -289,4 +294,141 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function product($params)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$storeId = $params['store_id'];
|
||||||
|
$startTime = $params['start_time'];
|
||||||
|
$endTime = $params['end_time'];
|
||||||
|
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||||
|
$dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime));
|
||||||
|
$data['visit_count'] = StoreVisit::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->count();
|
||||||
|
$data['visit_user_count'] = StoreVisit::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->group('uid')->count();
|
||||||
|
$data['add_cart_count'] = Cart::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->withTrashed()->group('product_id')->count();
|
||||||
|
$data['add_order_count'] = StoreOrderCartInfo::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->withTrashed()->group('product_id')->count();
|
||||||
|
$data['pay_count'] = StoreOrder::alias('t1')
|
||||||
|
->join('store_order_cart_info t2', 't1.id = t2.oid')
|
||||||
|
->where('t1.store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->group('product_id')
|
||||||
|
->count();
|
||||||
|
$data['pay_amount'] = StoreOrder::where('store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->sum('pay_price');
|
||||||
|
$data['cost_amount'] = StoreOrder::where('store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->sum('cost');
|
||||||
|
$data['refund_amount'] = StoreOrder::where('store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->where('refund_status', '>', 0)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->sum('pay_price');
|
||||||
|
$data['refund_count'] = StoreOrder::alias('t1')
|
||||||
|
->join('store_order_cart_info t2', 't1.id = t2.oid')
|
||||||
|
->where('t1.store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->where('refund_status', '>', 0)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->group('product_id')
|
||||||
|
->count();
|
||||||
|
$payUserCount = StoreOrder::where('store_id', $storeId)
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->group('uid')
|
||||||
|
->count();
|
||||||
|
if ($data['visit_user_count'] == 0) {
|
||||||
|
$data['trans_rate'] = 0;
|
||||||
|
} else {
|
||||||
|
$data['trans_rate'] = bcdiv($payUserCount * 100, $data['visit_user_count'], 2);
|
||||||
|
}
|
||||||
|
//商品图表统计开始,未完成
|
||||||
|
if ($dateDiff->days == 1) {
|
||||||
|
$group = 'HOUR(pay_time)';
|
||||||
|
$i = 0;
|
||||||
|
while ($i < 24) {
|
||||||
|
$timeRange[] = date('H', strtotime("+$i hours", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price';
|
||||||
|
} elseif ($dateDiff->days <= 31) {
|
||||||
|
$group = 'DAY(pay_time)';
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $dateDiff->days) {
|
||||||
|
$timeRange[] = date('m-d', strtotime("+$i days", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
|
||||||
|
} else {
|
||||||
|
$group = 'MONTH(pay_time)';
|
||||||
|
$i = 0;
|
||||||
|
$month = 0;
|
||||||
|
if ($dateDiff->y > 0) {
|
||||||
|
$month = $dateDiff->y * 12;
|
||||||
|
}
|
||||||
|
if ($dateDiff->m > 0) {
|
||||||
|
$month += $dateDiff->m;
|
||||||
|
}
|
||||||
|
if ($dateDiff->d > 0) {
|
||||||
|
$month += 1;
|
||||||
|
}
|
||||||
|
while ($i < $month) {
|
||||||
|
$timeRange[] = date('Y-m', strtotime("+$i months", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
|
||||||
|
}
|
||||||
|
$orderList = StoreOrder::field($field)
|
||||||
|
->where('store_id', $params['store_id'])
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->group($group)
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
$userList = StoreOrder::field($field . ',count(uid) as user_num')
|
||||||
|
->where('store_id', $params['store_id'])
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||||
|
->group($group . ',uid')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
$orderList = reset_index($orderList, 'pay_time');
|
||||||
|
$userList = reset_index($userList, 'pay_time');
|
||||||
|
$orderListTmp = [];
|
||||||
|
$userListTmp = [];
|
||||||
|
$range = [];
|
||||||
|
foreach ($timeRange as $item) {
|
||||||
|
$range[] = $item;
|
||||||
|
if (!isset($orderList[$item])) {
|
||||||
|
$orderListTmp[$item] = 0;
|
||||||
|
} else {
|
||||||
|
$orderListTmp[$item] = $orderList[$item]['pay_price'];
|
||||||
|
}
|
||||||
|
if (!isset($userList[$item])) {
|
||||||
|
$userListTmp[$item] = 0;
|
||||||
|
} else {
|
||||||
|
$userListTmp[$item] = $userList[$item]['user_num'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['statistics'] = [
|
||||||
|
'range' => $range,
|
||||||
|
'data' => [
|
||||||
|
'order_amount' => array_values($orderListTmp),
|
||||||
|
'user_number' => array_values($userListTmp)
|
||||||
|
]
|
||||||
|
];
|
||||||
|
//商品图表统计结束
|
||||||
|
|
||||||
|
// 商品排行榜,未完成
|
||||||
|
$data['rank_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->order('create_time', 'desc')
|
||||||
|
->limit(10)
|
||||||
|
->select()->toArray();
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user