diff --git a/application/admin/controller/BulletinBoard.php b/application/admin/controller/BulletinBoard.php index 11ca281a..bf70c2af 100644 --- a/application/admin/controller/BulletinBoard.php +++ b/application/admin/controller/BulletinBoard.php @@ -1,9 +1,13 @@ ', 0)->sum('order_amount'); + //年卡订单 + $yearCardOrderMoney = OrderYearcard::where('status', 1)->sum('pay_fee'); + //订单管理 + $orderGoods = OrderGoods::where('status', 1)->sum('total_fee'); + //充值订单 + $rechargeOrderMoney = OrderRecharge::where('pay_status', 1)->sum('order_amount'); + + // 计算月销售总额(所有订单类型的总和) + $monthlySales = ($orderMoney ?: 0) + ($yearCardOrderMoney ?: 0) + ($orderGoods ?: 0) + ($rechargeOrderMoney ?: 0); + + // 计算月订单量(本月订单数量) + $monthlyOrders = Order::where('status','<>', 0) + ->whereTime('create_time', 'month') + ->count(); + $monthlyOrders += OrderYearcard::where('status', 1) + ->whereTime('createtime', 'month') + ->count(); + $monthlyOrders += OrderGoods::where('status', 1) + ->whereTime('createtime', 'month') + ->count(); + $monthlyOrders += OrderRecharge::where('pay_status', 1) + ->whereTime('create_time', 'month') + ->count(); + + // 计算月客户数(本月新增用户) + $monthlyCustomers = User::whereTime('create_time', 'month') + ->where('del', 0) + ->count(); + + // 计算同比(上个月的数据) + $lastMonthSales = Order::where('status','<>', 0) + ->whereTime('create_time', 'last month') + ->sum('order_amount'); + $lastMonthSales += OrderYearcard::where('status', 1) + ->whereTime('createtime', 'last month') + ->sum('pay_fee'); + $lastMonthSales += OrderGoods::where('status', 1) + ->whereTime('createtime', 'last month') + ->sum('total_fee'); + $lastMonthSales += OrderRecharge::where('pay_status', 1) + ->whereTime('create_time', 'last month') + ->sum('order_amount'); + + $lastMonthOrders = Order::where('status','<>', 0) + ->whereTime('create_time', 'last month') + ->count(); + $lastMonthOrders += OrderYearcard::where('status', 1) + ->whereTime('createtime', 'last month') + ->count(); + $lastMonthOrders += OrderGoods::where('status', 1) + ->whereTime('createtime', 'last month') + ->count(); + $lastMonthOrders += OrderRecharge::where('pay_status', 1) + ->whereTime('create_time', 'last month') + ->count(); + + $lastMonthCustomers = User::whereTime('create_time', 'last month') + ->where('del', 0) + ->count(); + + // 计算同比变化率 + $salesCompare = $lastMonthSales > 0 ? round((($monthlySales - $lastMonthSales) / $lastMonthSales) * 100, 2) : 0; + $ordersCompare = $lastMonthOrders > 0 ? round((($monthlyOrders - $lastMonthOrders) / $lastMonthOrders) * 100, 2) : 0; + $customersCompare = $lastMonthCustomers > 0 ? round((($monthlyCustomers - $lastMonthCustomers) / $lastMonthCustomers) * 100, 2) : 0; + + // 统计本月客户分析(老客户 vs 新客户) + // 本月所有用户ID列表 + $monthUsers = User::whereTime('create_time', 'month') + ->where('del', 0) + ->column('id'); + + // 如果本月有用户,查询这些用户中哪些有订单(老客户) + $oldCustomerCount = 0; + $newCustomerCount = 0; + if (!empty($monthUsers)) { + // 查询本月注册的用户中,在Order表中有订单的用户(老客户) + // 只要有订单就算老客户,不限制订单时间 + $oldCustomerIds = Order::where('status','<>', 0) + ->where('user_id', 'in', $monthUsers) + ->where('user_id', '>', 0) + ->distinct(true) + ->column('user_id'); + + $oldCustomerCount = count($oldCustomerIds); + // 本月注册但没下过单的(新客户) + $newCustomerCount = count($monthUsers) - $oldCustomerCount; + } + + // 传递数据到视图 + $this->assign([ + 'monthlySales' => $monthlySales, + 'monthlyOrders' => $monthlyOrders, + 'monthlyCustomers' => $monthlyCustomers, + 'salesCompare' => $salesCompare, + 'ordersCompare' => $ordersCompare, + 'customersCompare' => $customersCompare, + 'oldCustomers' => $oldCustomerCount, // 老客户数量(本月注册且下过单的) + 'newCustomers' => $newCustomerCount, // 新客户数量(本月注册但没下过单的) + ]); + return $this->fetch(); } @@ -18,6 +124,14 @@ class BulletinBoard extends AdminBase //地图上显示注册用户位置 public function map() { + //查询商品订单 + $orderMoney = Order::where('status','<>', 0)->sum('order_amount'); + //年卡订单 + $yearCardOrderMoney = OrderYearcard::where('status', 1)->sum('pay_fee'); + //订单管理 + $orderGoods = OrderGoods::where('status', 1)->sum('total_fee'); + //充值订单 + $rechargeOrderMoney = OrderRecharge::where('pay_status', 1)->sum('order_amount'); return $this->fetch(); } diff --git a/application/admin/controller/Invoice.php b/application/admin/controller/Invoice.php index e522a41d..3d2c13ea 100644 --- a/application/admin/controller/Invoice.php +++ b/application/admin/controller/Invoice.php @@ -129,11 +129,6 @@ class Invoice extends AdminBase $this->_error('上传失败'); } } - - // 处理文件路径(转换为完整URL用于显示) - if (!empty($invoice['document'])) { - $invoice['document'] = UrlServer::getFileUrl($invoice['document']); - } // 查询订单列表 $orders = Db::name('order') @@ -143,6 +138,14 @@ class Invoice extends AdminBase ->limit(100) ->select(); + + + $invoice = InvoiceLog::with(['invoice'])->where('id',$id)->find(); + // 处理文件路径(转换为完整URL用于显示) + if (!empty($invoice['document'])) { + $currentDomain = $_SERVER['HTTP_HOST']; + $invoice['document'] = 'http://'.$currentDomain.'/public/'.$invoice['document']; + } $this->assign([ 'invoice' => $invoice, 'orders' => $orders, diff --git a/application/admin/model/Invoice.php b/application/admin/model/Invoice.php index 6bc8d81d..caea4986 100644 --- a/application/admin/model/Invoice.php +++ b/application/admin/model/Invoice.php @@ -16,3 +16,4 @@ class Invoice extends Model + diff --git a/application/admin/model/OrderGoods.php b/application/admin/model/OrderGoods.php new file mode 100644 index 00000000..b6e217ad --- /dev/null +++ b/application/admin/model/OrderGoods.php @@ -0,0 +1,10 @@ + 0) { + return '↑ ' + Math.abs(compare).toFixed(2) + '%'; + } else if (compare < 0) { + return '↓ ' + Math.abs(compare).toFixed(2) + '%'; + } else { + return '持平'; + } + } + + // 渲染月销售总额 + $('#monthly-sales').text('¥' + formatMoney(statisticsData.monthlySales)); + $('#sales-compare').html(formatCompare(statisticsData.salesCompare)); + + // 渲染月订单量 + $('#monthly-orders').text(statisticsData.monthlyOrders); + $('#orders-compare').html(formatCompare(statisticsData.ordersCompare)); + + // 渲染月客户数 + $('#monthly-customers').text(statisticsData.monthlyCustomers); + $('#customers-compare').html(formatCompare(statisticsData.customersCompare)); + } function initCharts() { // 月客户分析 - 饼图 @@ -466,8 +513,8 @@ layui.config({ formatter: '{b}: {d}%' }, data: [ - {value: 28, name: '老客', itemStyle: {color: '#FFB6C1'}}, - {value: 72, name: '新客', itemStyle: {color: '#FF69B4'}} + {value: statisticsData.oldCustomers, name: '老客', itemStyle: {color: '#FFB6C1'}}, + {value: statisticsData.newCustomers, name: '新客', itemStyle: {color: '#FF69B4'}} ] }] }); diff --git a/application/admin/view/invoice/edit.html b/application/admin/view/invoice/edit.html index c94d4d2c..e0e3b642 100644 --- a/application/admin/view/invoice/edit.html +++ b/application/admin/view/invoice/edit.html @@ -32,7 +32,7 @@
{if $invoice.document}
- {$invoice.document} + {$invoice.document} 已上传
{/if} diff --git a/application/api/logic/UserAddressLogic.php b/application/api/logic/UserAddressLogic.php index 7b702f0b..390cca7c 100644 --- a/application/api/logic/UserAddressLogic.php +++ b/application/api/logic/UserAddressLogic.php @@ -175,7 +175,7 @@ class UserAddressLogic 'district_id' => $post['district_id'], 'address' => $post['address'], 'is_default' => $post['is_default'], - 'update_time' => time() + 'updatetime' => time() ]; $result = Db::name('user_address') @@ -203,7 +203,7 @@ class UserAddressLogic $data = [ 'del' => 1, - 'update_time' => time() + 'updatetime' => time() ]; return Db::name('user_address') diff --git a/application/api/server/CityService.php b/application/api/server/CityService.php index 39e39152..94700aab 100644 --- a/application/api/server/CityService.php +++ b/application/api/server/CityService.php @@ -180,7 +180,6 @@ class CityService // 缓存结果(缓存1小时) Cache::store('redis')->set($cacheKey, $data, 3600); - return [ 'success' => true, 'msg' => '获取成功',