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 @@
| 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} + | +
| 暂时没有数据! | +||||||||