From e047ce999404b6a35eed8b5168e3beb148f7cd2f Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Mon, 4 Nov 2024 14:58:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=94=9F=E6=B4=BB=E5=95=86?= =?UTF-8?q?=E5=AE=B6=E6=B7=BB=E5=8A=A0=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LocalStore.php | 7 +++ app/api/logic/LocalStoreLogic.php | 81 +++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/app/api/controller/LocalStore.php b/app/api/controller/LocalStore.php index 563341c9..2b61a937 100755 --- a/app/api/controller/LocalStore.php +++ b/app/api/controller/LocalStore.php @@ -492,4 +492,11 @@ class LocalStore extends Api $size = $this->request->get('page_size', $this->page_size); return JsonServer::success('', LocalStoreLogic::inBindList($this->user_id, $page, $size)); } + + // 获取统计数据 + public function countData() + { + $form = $this->request->post(); + LocalStoreLogic::countData($form, $this->user_id); + } } \ No newline at end of file diff --git a/app/api/logic/LocalStoreLogic.php b/app/api/logic/LocalStoreLogic.php index cdd468b1..4977ead8 100644 --- a/app/api/logic/LocalStoreLogic.php +++ b/app/api/logic/LocalStoreLogic.php @@ -14,6 +14,7 @@ use app\common\model\user\User; use app\common\server\UrlServer; use think\facade\Config; use think\facade\Db; +use app\common\model\localstore\LocalGoodsOrder; class LocalStoreLogic extends Logic { @@ -765,6 +766,86 @@ class LocalStoreLogic extends Logic return $data; } + public static function countData($post, $user_id) + { + $where = [ + ['lstore_id', '=', $post['lstore_id']], + ['user_id', '=', $user_id], + ['state', '=', 1] + ]; + + $model = new LocalGoodsOrder(); + + // 历史订单总和 + $history_total_amount = $model->where($where)->sum('goods_total_price'); + + // 本月业绩总和 + $current_month_start = date('Y-m-01 00:00:00'); // 当月开始日期 + $current_month_end = date('Y-m-t 23:59:59'); // 当月结束日期 + $current_month_total_amount = $model + ->where($where) + ->where([ + ['dtime', '>=', $current_month_start], + ['dtime', '<=', $current_month_end] + ])->sum('goods_total_price'); + + // 上月业绩总和 + $last_month_start = date('Y-m-01 00:00:00', strtotime('-1 month')); // 上月开始日期 + $last_month_end = date('Y-m-t 23:59:59', strtotime('-1 month')); // 上月结束日期 + $last_month_total_amount = $model + ->where($where) + ->where([ + ['dtime', '>=', $last_month_start], + ['dtime', '<=', $last_month_end] + ])->sum('goods_total_price'); + + // 当日营业额 + $current_day_start = date('Y-m-d 00:00:00'); + $current_day_end = date('Y-m-d 23:59:59'); + $current_day_total_amount = $model + ->where($where) + ->where([ + ['dtime', '>=', $current_day_start], + ['dtime', '<=', $current_day_end] + ])->sum('goods_total_price'); + + // 统计当日数据: 总共支付交易笔数 report = 1(日报) report = 2(月报) + $trade_where = $where; + unset($trade_where[2]); + + $count_trade = $model + ->where($post['report'] == 1 ? $trade_where : $where) + ->where([ + ['dtime', '>=', $post['report'] == 1 ? $current_day_start : $current_month_start], + ['dtime', '<=', $post['report'] == 1 ? $current_day_end : $current_month_end] + ])->count(); + + // 支付成功交易笔数 + $success_trade = $model + ->where($post['report'] == 1 ? $trade_where : $where) + ->where([ + ['dtime', '>=', $post['report'] == 1 ? $current_day_start : $current_month_start], + ['dtime', '<=', $post['report'] == 1 ? $current_day_end : $current_month_end] + ])->count(); + + // 单笔交易 + if ($post['report'] == 1) { + $average_price = $success_trade > 0 ? $current_day_total_amount / $success_trade : 0; + } elseif ($post['report'] == 2) { + $average_price = $success_trade > 0 ? $current_month_total_amount / $success_trade : 0; + } + + return [ + 'history_total_amount' => $history_total_amount, + 'current_month_total_amount' => $current_month_total_amount, + 'last_month_total_amount' => $last_month_total_amount, + 'current_day_total_amount' => $current_day_total_amount, + 'count_trade' => $count_trade, + 'success_trade' => $success_trade, + 'average_price' => $average_price + ]; + } + private static function crate_bind_menu($rule) { $menu = [];