diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 0ecb5b2..86b135b 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -1132,6 +1132,75 @@ class Goods extends Base return $this->renderSuccess('获取成功', $syncAddresses); } + /** + * 盒子自动下架日志 + */ + public function offshelf_log(Request $request) + { + $goods_id = trim(input('get.goods_id')); + $start_time = trim(input('get.start_time')); + $end_time = trim(input('get.end_time')); + + $whe = []; + + if ($goods_id) { + $whe[] = ['goods_id', '=', $goods_id]; + } + + if ($start_time && $end_time) { + $start = strtotime($start_time); + $end = strtotime($end_time . ' 23:59:59'); + $whe[] = ['create_time', 'between', [$start, $end]]; + } elseif ($start_time) { + $start = strtotime($start_time); + $whe[] = ['create_time', '>=', $start]; + } elseif ($end_time) { + $end = strtotime($end_time . ' 23:59:59'); + $whe[] = ['create_time', '<=', $end]; + } + + // 获取日志数据 + $list = Db::name('goods_offshelf_log') + ->where($whe) + ->order('id desc') + ->paginate([ + 'list_rows' => $this->page, + 'query' => request()->param(), + ]); + + // 获取所有相关的盒子信息 + $goodsIds = array_column($list->items(), 'goods_id'); + $goodsInfo = []; + + if (!empty($goodsIds)) { + $goods = Db::name('goods') + ->field('id, title, status') + ->whereIn('id', $goodsIds) + ->select() + ->toArray(); + + foreach ($goods as $item) { + $goodsInfo[$item['id']] = [ + 'title' => $item['title'], + 'status' => $item['status'] + ]; + } + } + + // 转换时间戳并处理数据 + $listItems = $list->items(); + foreach ($listItems as &$item) { + $item['create_time_text'] = date('Y-m-d H:i:s', $item['create_time']); + $item['goods_title'] = isset($goodsInfo[$item['goods_id']]) ? $goodsInfo[$item['goods_id']]['title'] : '未知盒子'; + $item['goods_status'] = isset($goodsInfo[$item['goods_id']]) ? $goodsInfo[$item['goods_id']]['status'] : 2; // 默认下架状态 + } + + View::assign('list', $listItems); + View::assign('page', $list->render()); + View::assign('count', $list->total()); + return View::fetch('Goods/offshelf/log'); + } + /** * 同步盒子数据 */ @@ -1203,6 +1272,54 @@ class Goods extends Base } } + /** + * 清空盒子抽奖数据 + */ + public function clear_goods_data(Request $request) + { + $id = $request->post('id/d'); + if (!$id) { + return $this->renderError('盒子ID不能为空'); + } + + // 检查盒子是否存在 + $goods = GoodsModel::where(['id' => $id])->find(); + if (!$goods) { + return $this->renderError('盒子不存在'); + } + + Db::startTrans(); + try { + // 清空订单表 + $orderCount = Db::name('order')->where('goods_id', $id)->delete(); + + // 清空订单详情表 + $orderListCount = Db::name('order_list')->where('goods_id', $id)->delete(); + + // 提交事务 + Db::commit(); + + // 记录管理员操作日志 + AdminGoodsLog::add_goods_log( + session('admin_id'), + $id, + 0, + json_encode(['operation' => '清空抽奖数据前']), + json_encode([ + 'operation' => '清空抽奖数据后', + 'clear_order_count' => $orderCount, + 'clear_order_list_count' => $orderListCount + ]) + ); + + return $this->renderSuccess("操作成功,共清空订单 {$orderCount} 条,订单详情 {$orderListCount} 条"); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->renderError('操作失败:' . $e->getMessage()); + } + } + /** * 生成UUID */ diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 5ebcfad..c0c167c 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -166,6 +166,8 @@ Route::rule('yushou_rili', 'Goods/yushou_rili', 'GET|POST'); Route::rule('yushou_rili_add', 'Goods/yushou_rili_add', 'GET|POST'); Route::rule('yushou_rili_edit', 'Goods/yushou_rili_edit', 'GET|POST'); Route::rule('yushou_rili_del', 'Goods/yushou_rili_del', 'GET|POST'); +Route::rule('offshelf_log', 'Goods/offshelf_log', 'GET|POST'); +Route::rule('clear_goods_data', 'Goods/clear_goods_data', 'POST'); Route::rule('draw_raffle', 'Draw/goods', 'GET|POST'); Route::rule('draw_edit', 'Draw/draw_edit', 'GET|POST'); Route::rule('drawlist', 'Draw/drawlist', 'GET|POST'); diff --git a/app/admin/view/Goods/goods.html b/app/admin/view/Goods/goods.html index 98e9d69..c869a7d 100755 --- a/app/admin/view/Goods/goods.html +++ b/app/admin/view/Goods/goods.html @@ -44,6 +44,7 @@
添加盒子 + 自动下架日志 共有数据: {$count}条
@@ -124,18 +125,7 @@ {/if} - - - - - - - - - - - - + {if $vo['show_is'] eq 1} @@ -182,11 +172,11 @@ 同步 - - - - - +
+ + 清空抽奖 +
@@ -231,6 +221,18 @@ }); } + //查看自动下架日志 + function offshelf_log() { + var url = "{:url('/admin/offshelf_log')}"; + layer.open({ + type: 2, + title: '盒子自动下架日志', + shadeClose: false, + shade: 0.3, + area: ['90%', '90%'], + content: url, + }); + } //编辑奖品 function goodsextendlist_edit(goods_id, title) { @@ -366,6 +368,31 @@ } + + // 清空盒子抽奖数据 + function clear_goods_data(id) { + layer.confirm('警告:清空抽奖数据将删除该盒子所有订单记录,且无法恢复!确定要继续吗?', { + btn: ['确定', '取消'], + title: '危险操作确认', + skin: 'layui-layer-danger' + }, function (index) { + var url = "{:url('/admin/clear_goods_data')}"; + var load = layer.load(2); + var $ = layui.$; + $.post(url, { "id": id }, function (data) { + if (data.status == 1) { + layer.msg(data.msg, { icon: 1, time: 2000 }, function () { + location.reload(); + }); + } else { + layer.msg(data.msg, { icon: 2, anim: 6, time: 2000 }, function () { + layer.close(load); + }); + } + }); + layer.close(index); + }); + } diff --git a/app/admin/view/Goods/offshelf/log.html b/app/admin/view/Goods/offshelf/log.html new file mode 100644 index 0000000..5c033b1 --- /dev/null +++ b/app/admin/view/Goods/offshelf/log.html @@ -0,0 +1,148 @@ +{include file="Public:header2"/} + + +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ +
+ +
+ 共有数据: {$count}条 +
+
+ + + + + + + + + + + + + + + + {volist name="list" id="vo"} + + + + + + + + + + + + {/volist} + + {if condition="empty($list)"} + + + + {/if} + + +
ID盒子ID盒子名称当前利润率(%)配置下架利润(%)订单总价值出货总价值下架时间操作
{$vo.id}{$vo.goods_id}{$vo.goods_title}{$vo.profit_rate}%{$vo.xiajia_lirun}%{$vo.order_total}{$vo.goods_total}{$vo.create_time_text} + + 查看盒子 + + {if condition="$vo.goods_status neq 1"} +
+ + 上架盒子 + + {/if} +
暂时没有数据!
+
+ {$page|raw} +
+
+
+
+ {include file="Public:footer"/} + + + + \ No newline at end of file