diff --git a/README.md b/README.md index c2a217a..edea654 100755 --- a/README.md +++ b/README.md @@ -68,8 +68,15 @@ composer require yzalis/identicon composer require topthink/think-image php think UserStatisticsHour ``` +## +1. 接入微信小程序订单(需要订单页面,订单详情页面) +2. 修改前端支付页面,当抽数不够时,只显示对应的按钮。 +3. +SELECT goods_id,goods_title,goods_price,order_total,order_zhe_total,price,use_money,use_integral,use_money2,addtime,pay_time,prize_num,use_coupon FROM `order` where user_id=21544 and status=1 + +## 原抽无限赏奖逻辑(内存消耗过大,不在使用) ```sh // #组合中奖商品 diff --git a/app/admin/controller/Statistics.php b/app/admin/controller/Statistics.php index 0aff64a..d605d80 100755 --- a/app/admin/controller/Statistics.php +++ b/app/admin/controller/Statistics.php @@ -23,100 +23,93 @@ class Statistics extends Base public function profit(Request $request) { + $goodId = trim(input('get.goodId')); $title = trim(input('get.title')); - $id = trim(input('get.goodId')); $status = trim(input('get.status')); $type = trim(input('get.type')); $addtime = trim(input('get.addtime')); // 构建查询条件 - $whe = []; - if ($title) - $whe[] = ['title', 'like', '%' . $title . '%']; - if ($id) - $whe[] = ['id', '=', $id]; - if ($status) - $whe[] = ['status', '=', $status]; - if ($type) - $whe[] = ['type', '=', $type]; + $where = [['delete_time', '=', null]]; + if ($goodId) { + $where[] = ['id', '=', $goodId]; + } + if ($title) { + $where[] = ['title', 'like', '%' . $title . '%']; + } + if ($status) { + $where[] = ['status', '=', $status]; + } + if ($type) { + $where[] = ['type', '=', $type]; + } // 解析时间范围 - $whe3 = []; - $whe4 = []; + $startTime = 0; + $endTime = time(); if ($addtime) { - [$start_time, $end_time] = $this->parseTimeRange($addtime); - $whe3[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; - $whe4[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; + $times = explode(' - ', $addtime); + $startTime = strtotime($times[0]); + $endTime = strtotime($times[1]); } - // 获取商品ID列表 - $goodList = GoodsModel::where($whe)->column('id'); - if (empty($goodList)) { + // 获取测试用户ID + $testUsers = User::where('istest', '>', 0)->column('id'); + $testUserIds = empty($testUsers) ? [0] : $testUsers; + $testUserIdsStr = implode(',', $testUserIds); - View::assign([ + // 构建SQL查询 + $query = Db::name('goods')->alias('goods') + ->field([ + 'goods.id', + 'goods.title', + 'goods.imgurl', + 'goods.price', + 'goods.stock', + 'goods.status', + 'goods.type', + '(SELECT COALESCE(sum(use_money), 0) + COALESCE(sum(price), 0) FROM `order` WHERE status=1 AND (price>0 OR use_money>0) AND pay_time > ' . $startTime . ' and pay_time < ' . $endTime . ' AND goods_id=goods.id AND status=1 AND user_id NOT IN (' . $testUserIdsStr . ')) AS use_money', + '(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS sc_money', + '(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND LENGTH(recovery_num)>0 AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS re_money', + '(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND LENGTH(send_num)>0 AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS fh_money', + '(SELECT count(1) FROM `order_list` WHERE goods_id=goods.id AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ' and parent_goods_list_id=0 ) AS cj_count' + ]) + ->where($where) + ->order(['goods.id' => 'desc']); - 'sum_dingdan' => 0, - 'sum_shiji' => 0, - 'sum_chuhuo' => 0, - 'price_all' => 0, - 'sum_shijilirun' => 0, - 'sum_dingdanlirun' => 0, - 'use_money_all' => 0, - 'order_total_all' => 0, - 'list' => [], - 'count' => 0, - 'page' => '', - ]); - return View::fetch("Statistics/profit"); + // 获取列表数据 + $list = $query->select()->toArray(); + + // 计算总金额 + $totalIncome = 0; + $totalCost = 0; + $totalProfit = 0; + $totalReMoney = 0; + $totalFhMoney = 0; + + foreach ($list as &$item) { + // 计算单个盒子的利润和利润率 + $item['profit'] = $item['use_money'] - $item['sc_money']; + $item['profit_rate'] = $item['use_money'] > 0 ? round(($item['profit'] / $item['use_money']) * 100, 2) : 0; + $item['is_negative'] = $item['profit'] < 0; + + // 计算总金额 + $totalIncome += $item['use_money']; + $totalCost += $item['sc_money']; + $totalReMoney += $item['re_money']; + $totalFhMoney += $item['fh_money']; } - // 获取测试用户ID列表 - $userList = User::where('istest', '>', 0)->column('id'); - - // 订单筛选条件 - $whe3[] = ['user_id', 'not in', $userList]; - $whe3[] = ['status', '=', 1]; - $whe3[] = ['goods_id', 'in', $goodList]; - - $whe4[] = ['user_id', 'not in', $userList]; - $whe4[] = ['goods_id', 'in', $goodList]; - - // 统计订单数据 - $orderTotals = OrderModel::where($whe3) - ->field('SUM(order_total) as order_total_all, - SUM(order_zhe_total) as order_zhe_total_all, - SUM(price) as price_all, - SUM(use_money) as use_money_all') - ->find(); - - $goodslistMoneyAll = OrderList::where($whe4)->sum('goodslist_money'); - - // 获取商品列表 - $data = GoodsModel::getList($whe, "*", "id desc", 20); - - // 计算每个商品的订单详情 - foreach ($data['list'] as &$value) { - $value = array_merge($value, $this->calculateOrderDetails($value['id'], $userList, $addtime)); - } - - // 计算利润 - $sum_shijilirun = round($orderTotals->order_zhe_total_all - $goodslistMoneyAll, 2); - $sum_dingdanlirun = round($orderTotals->order_total_all - $goodslistMoneyAll, 2); + $totalProfit = $totalIncome - $totalCost; // 传递数据给视图 View::assign([ - - 'sum_dingdan' => $orderTotals->order_total_all, - 'sum_shiji' => $orderTotals->order_zhe_total_all, - 'sum_chuhuo' => $goodslistMoneyAll, - 'price_all' => $orderTotals->price_all, - 'sum_shijilirun' => $sum_shijilirun, - 'sum_dingdanlirun' => $sum_dingdanlirun, - 'use_money_all' => $orderTotals->use_money_all, - 'order_total_all' => $orderTotals->order_total_all, - 'list' => $data['list'], - 'count' => $data['count'], - 'page' => $data['page'], + 'list' => $list, + 'totalIncome' => $totalIncome, + 'totalCost' => $totalCost, + 'totalProfit' => $totalProfit, + 'totalReMoney' => $totalReMoney, + 'totalFhMoney' => $totalFhMoney, ]); return View::fetch("Statistics/profit"); @@ -413,5 +406,148 @@ class Statistics extends Base return View::fetch('Statistics/userstatistics'); } + /** + * 订单列表 + */ + public function orderList(Request $request) + { + $goodsId = $request->param('goods_id', 0, 'intval'); + + // 获取测试用户ID + $testUsers = User::where('istest', '>', 0)->column('id'); + + // 查询条件 + $where = [ + ['status', '=', 1], + ['goods_id', '=', $goodsId] + ]; + + if (!empty($testUsers)) { + $where[] = ['user_id', 'not in', $testUsers]; + } + + // 获取订单列表 + $list = OrderModel::where($where) + ->append(['user_info']) + ->order('id', 'desc') + ->paginate(['list_rows' => 50, 'query' => request()->param()]); + + // 传递数据给视图 + View::assign([ + 'list' => $list, + 'page' => $list->render(), + 'goods_id' => $goodsId + ]); + + return View::fetch("Statistics/orderList"); + } + + /** + * 出货列表 + */ + public function goodsList(Request $request) + { + $goodsId = $request->param('goods_id', 0, 'intval'); + + // 获取测试用户ID + $testUsers = User::where('istest', '>', 0)->column('id'); + + // 查询条件 + $where = [ + ['goods_id', '=', $goodsId] + ]; + + if (!empty($testUsers)) { + $where[] = ['user_id', 'not in', $testUsers]; + } + + // 获取出货列表 + $list = OrderList::where($where) + ->order('id', 'desc') + ->paginate(['list_rows' => 50, 'query' => request()->param()]); + + // 传递数据给视图 + View::assign([ + 'list' => $list, + 'page' => $list->render(), + 'goods_id' => $goodsId + ]); + + return View::fetch("Statistics/goodsList"); + } + + /** + * 兑换列表 + */ + public function exchangeList(Request $request) + { + $goodsId = $request->param('goods_id', 0, 'intval'); + + // 获取测试用户ID + $testUsers = User::where('istest', '>', 0)->column('id'); + + // 查询条件 + $where = [ + ['goods_id', '=', $goodsId] + ]; + + $where[] = ['recovery_num', '!=', '']; + // $where[] = ['recovery_num', '!=', null]; + + if (!empty($testUsers)) { + $where[] = ['user_id', 'not in', $testUsers]; + } + + // 获取兑换列表 + $list = OrderList::where($where) + ->order('id', 'desc') + ->paginate(['list_rows' => 50, 'query' => request()->param()]); + + // 传递数据给视图 + View::assign([ + 'list' => $list, + 'page' => $list->render(), + 'goods_id' => $goodsId + ]); + + return View::fetch("Statistics/exchangeList"); + } + + /** + * 发货列表 + */ + public function shipmentList(Request $request) + { + $goodsId = $request->param('goods_id', 0, 'intval'); + + // 获取测试用户ID + $testUsers = User::where('istest', '>', 0)->column('id'); + + // 查询条件 + $where = [ + ['goods_id', '=', $goodsId] + ]; + + $where[] = ['send_num', '<>', '']; + // $where[] = ['send_num', '<>', null]; + + if (!empty($testUsers)) { + $where[] = ['user_id', 'not in', $testUsers]; + } + + // 获取发货列表 + $list = OrderList::where($where) + ->order('id', 'desc') + ->paginate(['list_rows' => 50, 'query' => request()->param()]); + + // 传递数据给视图 + View::assign([ + 'list' => $list, + 'page' => $list->render(), + 'goods_id' => $goodsId + ]); + + return View::fetch("Statistics/shipmentList"); + } } diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 48a7ece..54360bb 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -312,6 +312,14 @@ Route::rule('productcate_del', 'ProductCate/del', 'GET|POST'); Route::rule('statistics_profit', 'Statistics/profit', 'GET'); //数据看台 Route::rule('statistics_dataStand', 'Statistics/DataStand', 'GET'); +//兑换列表 +Route::rule('statistics_exchangeList', 'Statistics/exchangeList', 'GET'); +//发货列表 +Route::rule('statistics_shipmentList', 'Statistics/shipmentList', 'GET'); +//出货列表 +Route::rule('statistics_orderList', 'Statistics/goodsList', 'GET'); +//支付订单 +Route::rule('statistics_order', 'Statistics/orderList', 'GET'); //利润支出 Route::rule('ProfitExpenses', 'Profit/index', 'GET'); diff --git a/app/admin/view/Goods/goods_extend.html b/app/admin/view/Goods/goods_extend.html old mode 100644 new mode 100755 diff --git a/app/admin/view/Statistics/exchangeList.html b/app/admin/view/Statistics/exchangeList.html new file mode 100644 index 0000000..aefa6a9 --- /dev/null +++ b/app/admin/view/Statistics/exchangeList.html @@ -0,0 +1,73 @@ +{include file="Public:header2"/} + +
+| 序号 | +ID | +订单ID | +用户ID | +兑换单号 | +盒子ID | +奖品ID | +奖品名称 | +奖品图片 | +奖品价值 | +兑换价值 | +奖品类型 | +添加时间 | +选择时间 | +
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {$i} | +{$vo.id} | +{$vo.order_id} | +{$vo.user_id} | +{$vo.recovery_num} | +{$vo.goods_id} | +{$vo.goodslist_id} | +{$vo.goodslist_title} | +
+ |
+ ¥ {$vo.goodslist_price} | +¥ {$vo.goodslist_money} | ++ {if condition="$vo.goodslist_type eq 1"} + 现货 + {elseif condition="$vo.goodslist_type eq 2"} + 预售 + {elseif condition="$vo.goodslist_type eq 3"} + 货币 + {elseif condition="$vo.goodslist_type eq 4"} + 宝箱 + {/if} + | +{$vo.addtime|date="Y-m-d H:i:s"} | +{$vo.choice_time|date="Y-m-d H:i:s"} | +
| 暂时没有数据! | +|||||||||||||