diff --git a/app/admin/controller/Cardextractor.php b/app/admin/controller/Cardextractor.php index e173f86..c33037e 100755 --- a/app/admin/controller/Cardextractor.php +++ b/app/admin/controller/Cardextractor.php @@ -478,7 +478,7 @@ class Cardextractor extends Base // if (!$goods) { // return $this->renderError("请求参数错误"); // } - $data = Shang::where('id','<',39) ->order('sort desc,id asc') + $data = Shang::where('id','<',39)->whereOr('id','>',113) ->order('id desc') ->select()->toArray(); #概率 $pro = array_sum(array_column($data, 'pro')); @@ -495,25 +495,25 @@ class Cardextractor extends Base public function card_shang_add(Request $request) { if (!$request->isPost()) { - $goods_id = request()->param('goods_id/d', 0); - $goods = GoodsModel::where(['id' => $goods_id])->find(); - if (!$goods) { - return $this->renderError("请求参数错误"); - } - if ($goods['type'] != 4) { - return $this->renderError("请求参数错误1"); - } - View::assign('goods_id', $goods_id); + // $goods_id = request()->param('goods_id/d', 0); + // $goods = GoodsModel::where(['id' => $goods_id])->find(); + // if (!$goods) { + // return $this->renderError("请求参数错误"); + // } + // if ($goods['type'] != 4) { + // return $this->renderError("请求参数错误1"); + // } + View::assign('goods_id', 0); return View::fetch("Cardextractor/card_shang_add"); } else { $data = input('post.'); - if (empty($data['goods_id'])) { - return $this->renderError("请求参数错误"); - } - $goods = GoodsModel::where(['id' => $data['goods_id']])->find(); - if (!$goods) { - return $this->renderError("请求参数错误1"); - } + // if (empty($data['goods_id'])) { + // return $this->renderError("请求参数错误"); + // } + // $goods = GoodsModel::where(['id' => $data['goods_id']])->find(); + // if (!$goods) { + // return $this->renderError("请求参数错误1"); + // } if (empty($data['title'])) { return $this->renderError("请输入等级名称"); } @@ -523,9 +523,9 @@ class Cardextractor extends Base if (RegZero($data['sort'])) { return $this->renderError("排序输入不规范,请输入整数"); } - if (empty($data['imgurl'])) { - return $this->renderError("请上传等级图标"); - } + // if (empty($data['imgurl'])) { + // return $this->renderError("请上传等级图标"); + // } $data['update_time'] = time(); $dd = Shang::insert($data); if ($dd) { diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 0158a52..2f24b8b 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -12,7 +12,7 @@ use app\common\model\GoodsList; use app\common\model\AdminGoodsLog; use think\facade\Db; use app\common\model\Shang; - +use app\common\model\Reward; class Goods extends Base { /** @@ -232,6 +232,55 @@ class Goods extends Base $data['integral_is'] = 0; $data['category_id'] = 0; $data['stock'] = 1; + } elseif ($data['type'] == 15) { + // 福利屋类型处理 + $data['stock'] = 0; // 隐藏套数 + $data['lock_is'] = 0; // 隐藏锁箱类型 + $data['lock_time'] = 0; // 隐藏锁箱时间 + $data['coupon_is'] = 0; // 隐藏发券开关 + $data['coupon_pro'] = 0; // 隐藏发券概率 + $data['integral_is'] = 0; // 隐藏发积分开关 + $data['prize_num'] = 0; + $data['category_id'] = 0; + $data['is_flw'] = 1; // 标记为福利屋 + + // 处理时间字段 + if (!empty($data['flw_start_time'])) { + $data['flw_start_time'] = strtotime($data['flw_start_time']); + } else { + return $this->renderError("请选择开始时间"); + } + + if (!empty($data['flw_end_time'])) { + $data['flw_end_time'] = strtotime($data['flw_end_time']); + } else { + return $this->renderError("请选择结束时间"); + } + + if (!empty($data['open_time'])) { + $data['open_time'] = strtotime($data['open_time']); + } else { + return $this->renderError("请选择开奖时间"); + } + + // 验证时间逻辑 + if ($data['flw_start_time'] >= $data['flw_end_time']) { + return $this->renderError("开始时间必须早于结束时间"); + } + + if ($data['flw_end_time'] >= $data['open_time']) { + return $this->renderError("结束时间必须早于开奖时间"); + } + + // 验证抽奖门槛 + if (!isset($data['choujiang_xianzhi']) || $data['choujiang_xianzhi'] === '') { + $data['choujiang_xianzhi'] = 0; + } else if (!is_numeric($data['choujiang_xianzhi']) || intval($data['choujiang_xianzhi']) < 0) { + return $this->renderError("抽奖门槛必须是非负整数"); + } + + // 默认未开奖 + $data['is_open'] = 0; } else { return $this->renderError("盒子类型选择错误"); } @@ -407,11 +456,61 @@ class Goods extends Base $data['lock_is'] = 0; $data['lock_time'] = 0; $data['prize_num'] = 0; + $data['show_is'] = 0; $data['coupon_is'] = 0; $data['coupon_pro'] = 0; $data['integral_is'] = 0; $data['category_id'] = 0; $data['stock'] = 1; + } elseif ($type == 15) { + // 福利屋类型处理 + $data['stock'] = 0; // 隐藏套数 + $data['lock_is'] = 0; // 隐藏锁箱类型 + $data['lock_time'] = 0; // 隐藏锁箱时间 + $data['coupon_is'] = 0; // 隐藏发券开关 + $data['coupon_pro'] = 0; // 隐藏发券概率 + $data['integral_is'] = 0; // 隐藏发积分开关 + $data['prize_num'] = 0; + $data['category_id'] = 0; + $data['is_flw'] = 1; // 标记为福利屋 + + // 处理时间字段 + if (!empty($data['flw_start_time'])) { + $data['flw_start_time'] = strtotime($data['flw_start_time']); + } else { + return $this->renderError("请选择开始时间"); + } + + if (!empty($data['flw_end_time'])) { + $data['flw_end_time'] = strtotime($data['flw_end_time']); + } else { + return $this->renderError("请选择结束时间"); + } + + if (!empty($data['open_time'])) { + $data['open_time'] = strtotime($data['open_time']); + } else { + return $this->renderError("请选择开奖时间"); + } + + // 验证时间逻辑 + if ($data['flw_start_time'] >= $data['flw_end_time']) { + return $this->renderError("开始时间必须早于结束时间"); + } + + if ($data['flw_end_time'] >= $data['open_time']) { + return $this->renderError("结束时间必须早于开奖时间"); + } + + // 验证抽奖门槛 + if (!isset($data['choujiang_xianzhi']) || $data['choujiang_xianzhi'] === '') { + $data['choujiang_xianzhi'] = 0; + } else if (!is_numeric($data['choujiang_xianzhi']) || intval($data['choujiang_xianzhi']) < 0) { + return $this->renderError("抽奖门槛必须是非负整数"); + } + + // 默认未开奖 + $data['is_open'] = 0; } else { return $this->renderError("盒子类型选择错误"); } @@ -521,7 +620,7 @@ class Goods extends Base if ($type == 1 || $type == 3 || $type == 5 || $type == 6 || $type == 10 || $type == 11) { $whe[] = ['num', '=', 1]; - } elseif ($type == 2 || $type == 8 || $type == 9) { + } elseif ($type == 2 || $type == 8 || $type == 9 || $type == 15) { $whe[] = ['num', '=', 0]; } else { return $this->renderError('请求参数错误1'); @@ -572,6 +671,8 @@ class Goods extends Base $shang = Shang::where('id', 'between', [34, 38])->select()->toArray(); } elseif ($info['type'] == 3) { $shang = Shang::where('id', 'between', [4, 33])->select()->toArray(); + } elseif ($info['type'] == 15) { + $shang = Shang::where('id', '>=', 114)->select()->toArray(); } else { return $this->renderError('请求参数错误1'); } @@ -615,6 +716,8 @@ class Goods extends Base if ($today_time >= $data['sale_time']) { return $this->renderError('预售时间请在今天之后'); } + } elseif ($type == 15) { + $data['sale_time'] = 0; } else { return $this->err('奖品类型选择错误'); } @@ -649,7 +752,7 @@ class Goods extends Base $prize_code = getPrizeCode() . '_' . time(); $data['prize_code'] = $prize_code; - } else if ($type == 3) { + } elseif ($type == 3) { if ($data['shang_id'] == 1 || $data['shang_id'] == 2 || $data['shang_id'] == 3 || $data['shang_id'] == 5) { if ($data['stock'] != 1) { return $this->renderError('特殊奖品库存请设置为1'); @@ -672,18 +775,19 @@ class Goods extends Base if (RegInt($data['prize_num']) && $data['shang_id'] == 5) { return $this->renderError("擂台赏抽全局赏数量设置错误,请设置大于0的整数"); } + } elseif ($type == 15) { + $prize_code = getPrizeCode() . '_' . time(); + $data['prize_code'] = $prize_code; + if (RegInt($data['stock'])) { + return $this->renderError('奖品数量设置错误,请设置大于0的整数'); + } } else { return $this->err('请求参数错误'); } if (RegZero($data['sort'])) { return $this->renderError('排序请输入整数'); } - // if ($data['card_no']) { -// $card_no_info = GoodsList::field('id')->where('card_no', '=', $data['card_no'])->find(); -// if ($card_no_info) { -// return $this->renderError('赠送编号已存在'); -// } -// } else { + $data['card_no'] = NULL; // } @@ -729,6 +833,8 @@ class Goods extends Base $shang = Shang::where('id', '<=', 33)->where('id', '<>', 5)->select()->toArray(); } elseif ($info['type'] == 2 || $info['type'] == 8 || $info['type'] == 9) { $shang = Shang::where('id', 'between', [34, 38])->select()->toArray(); + } elseif ($info['type'] == 15) { + $shang = Shang::where('id', '>=', 114)->select()->toArray(); } elseif ($info['type'] == 3) { $shang = Shang::where('id', 'between', [4, 33])->select()->toArray(); } else { @@ -780,6 +886,8 @@ class Goods extends Base if ($today_time >= $data['sale_time']) { return $this->renderError('预售时间请在今天之后'); } + } elseif ($data['goods_type'] == 3) { + $data['sale_time'] = 0; } else { return $this->err('奖品类型选择错误'); } @@ -788,7 +896,7 @@ class Goods extends Base $data['reward_num'] = 0; // - if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11) { + if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11 || $type == 15) { } elseif ($type == 2 || $type == 8 || $type == 9) { if (RegMoney($data['real_pro'] * 1000)) { @@ -804,17 +912,8 @@ class Goods extends Base if (RegZero($data['sort'])) { return $this->renderError('排序请输入整数'); } - // if ($data['card_no']) { -// $card_no_info = GoodsList::field('id') -// ->where('prize_code', '<>', $goods['prize_code']) -// ->where('card_no', '=', trim($data['card_no'])) -// ->find(); -// if ($card_no_info) { -// return $this->renderError('赠送编号已存在'); -// } -// } else { + $data['card_no'] = NULL; - // } if (empty($data['imgurl'])) { return $this->renderError('请上传图片'); @@ -845,9 +944,9 @@ class Goods extends Base $prize_code = GoodsList::field('prize_code') ->where(['id' => $id]) ->value('prize_code'); - if (!$prize_code) { - return $this->renderError("请勿重复操作"); - } + // if (!$prize_code) { + // return $this->renderError("请勿重复操作"); + // } #删除奖品 $res = GoodsList::field('id') ->where(['prize_code' => $prize_code]) @@ -1325,49 +1424,120 @@ class Goods extends Base */ public function clear_goods_data(Request $request) { - $id = $request->post('id/d'); - if (!$id) { - return $this->renderError('盒子ID不能为空'); + if (!$request->isPost()) { + return $this->renderError('请求方式错误'); } - // 检查盒子是否存在 + $id = $request->post('id/d'); $goods = GoodsModel::where(['id' => $id])->find(); if (!$goods) { return $this->renderError('盒子不存在'); } + // 开启事务 Db::startTrans(); try { - // 清空订单表 - $orderCount = Db::name('order')->where('goods_id', $id)->delete(); + // 删除相关订单数据 + Db::name('order')->where('goods_id', $id)->delete(); + Db::name('order_list')->where('goods_id', $id)->delete(); - // 清空订单详情表 - $orderListCount = Db::name('order_list')->where('goods_id', $id)->delete(); + // 重置奖品剩余数量 + Db::name('goods_list')->where('goods_id', $id)->update(['surplus_stock' => Db::raw('stock')]); - // 提交事务 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} 条"); + return $this->renderSuccess('盒子抽奖数据已清空'); } catch (\Exception $e) { - // 回滚事务 Db::rollback(); return $this->renderError('操作失败:' . $e->getMessage()); } } + /** + * 复制盒子 + */ + public function copy_goods(Request $request) + { + if (!$request->isPost()) { + return $this->renderError('请求方式错误'); + } + + $id = $request->post('id/d'); + $goods = GoodsModel::where(['id' => $id])->find(); + if (!$goods) { + return $this->renderError('盒子不存在'); + } + + // 开启事务 + Db::startTrans(); + try { + // 复制盒子基本信息 + $goodsData = $goods->toArray(); + unset($goodsData['id']); + unset($goodsData['delete_time']); + + // 修改标题,添加"复制"标识 + $goodsData['title'] = $goodsData['title'] . '(复制)'; + $goodsData['status'] = 2; // 默认下架状态 + $goodsData['addtime'] = time(); + $goodsData['async_code'] = ''; // 清空同步代码,避免混淆 + + // 插入新盒子 + $newGoods = new GoodsModel(); + $newGoods->save($goodsData); + $newGoodsId = $newGoods->id; + + // 复制盒子奖品 + $goodsLists = GoodsList::where(['goods_id' => $id])->select(); + foreach ($goodsLists as $item) { + $listData = $item->toArray(); + unset($listData['id']); + $listData['goods_id'] = $newGoodsId; + $listData['addtime'] = time(); + if ($listData['reward_id'] && $listData['reward_id'] != '') { + $reward = Reward::where(['reward_id' => $listData['reward_id']])->select(); + $listData['reward_id'] = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);//$this->generateUUID(); + if ($reward) { + $rewards = $reward->toArray(); + foreach ($rewards as $item2) { + unset($item2['id']); + $item2['reward_id'] = $listData['reward_id']; + $item2['create_time'] = time(); + $item2['update_time'] = time(); + Reward::insert($item2); + } + + } + } + // 插入新奖品 + $newGoodsList = new GoodsList(); + $newGoodsList->save($listData); + + // 如果有扩展奖品,也进行复制 + if ($goods['type'] == 1 || $goods['type'] == 11) { + $goodsExtends = Db::name('goods_extend_list') + ->where(['goods_list_id' => $item['id']]) + ->select() + ->toArray(); + + foreach ($goodsExtends as $extend) { + unset($extend['id']); + $extend['goods_id'] = $newGoodsId; + $extend['goods_list_id'] = $newGoodsList->id; + $extend['addtime'] = time(); + + Db::name('goods_extend_list')->insert($extend); + } + } + } + + Db::commit(); + return $this->renderSuccess('盒子复制成功'); + } catch (\Exception $e) { + Db::rollback(); + return $this->renderError('复制失败:' . $e->getMessage()); + } + } + /** * 生成UUID */ diff --git a/app/admin/controller/Reward.php b/app/admin/controller/Reward.php index 12dba13..1ceb167 100644 --- a/app/admin/controller/Reward.php +++ b/app/admin/controller/Reward.php @@ -17,20 +17,20 @@ class Reward extends Base { $reward_type = trim(input('get.reward_type', '')); $keyword = trim(input('get.keyword')); - + $where = []; if (!empty($keyword)) { $where[] = ['title', 'like', '%' . $keyword . '%']; } - + if ($reward_type !== '') { $where[] = ['reward_type', '=', $reward_type]; } - + $field = "*"; $order = "id desc"; $data = RewardModel::getList($where, $field, $order, $this->page); - + // 获取关联的优惠券信息 foreach ($data['list'] as $key => &$item) { if ($item['reward_type'] == 1 && !empty($item['reward_id'])) { @@ -38,15 +38,15 @@ class Reward extends Base $item['coupon'] = $coupon; } } - + View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $data['page']); View::assign('reward_type', $reward_type); - + return View::fetch("Reward/index"); } - + /** * 添加奖励 */ @@ -56,17 +56,17 @@ class Reward extends Base // 获取优惠券列表供选择 $coupons = Coupon::where('status', 0)->select(); View::assign('coupons', $coupons); - + return View::fetch("Reward/add"); } else { $data = input('post.'); - + // 处理优惠券类型的特殊情况 if ($data['reward_type'] == 1) { if (empty($data['reward_id'])) { return $this->renderError("请选择优惠券"); } - + // 获取优惠券信息,设置默认标题 if (empty($data['title'])) { $coupon = Coupon::find($data['reward_id']); @@ -78,12 +78,12 @@ class Reward extends Base // 非优惠券类型,reward_id设为0 $data['reward_id'] = 0; } - + $data['create_time'] = time(); $data['update_time'] = time(); - + $result = RewardModel::insertGetId($data); - + if ($result) { return $this->renderSuccess("添加成功"); } else { @@ -91,7 +91,7 @@ class Reward extends Base } } } - + /** * 编辑奖励 */ @@ -99,31 +99,31 @@ class Reward extends Base { if (!$request->isPost()) { $id = input('get.id/d', 0); - + if (empty($id)) { return $this->renderError("参数错误"); } - + $info = RewardModel::find($id); if (empty($info)) { return $this->renderError("奖励不存在"); } - + // 获取优惠券列表供选择 $coupons = Coupon::where('status', 0)->select(); - + View::assign('info', $info); View::assign('coupons', $coupons); - + return View::fetch("Reward/edit"); } else { $data = input('post.'); $id = isset($data['id']) ? intval($data['id']) : 0; - + if (empty($id)) { return $this->renderError("参数错误"); } - + // 处理优惠券类型的特殊情况 if ($data['reward_type'] == 1) { if (empty($data['reward_id'])) { @@ -133,11 +133,11 @@ class Reward extends Base // 非优惠券类型,reward_id设为0 $data['reward_id'] = 0; } - + $data['update_time'] = time(); - + $result = RewardModel::where('id', $id)->update($data); - + if ($result !== false) { return $this->renderSuccess("编辑成功"); } else { @@ -145,27 +145,27 @@ class Reward extends Base } } } - + /** * 删除奖励 */ public function delete(Request $request) { $id = input('post.id/d', 0); - + if (empty($id)) { return $this->renderError("参数错误"); } - + $result = RewardModel::destroy($id); - + if ($result) { return $this->renderSuccess("删除成功"); } else { return $this->renderError("删除失败"); } } - + /** * 修改状态 */ @@ -173,13 +173,13 @@ class Reward extends Base { $id = input('post.id/d', 0); $status = input('post.status/d', 0); - + if (empty($id)) { return $this->renderError("参数错误"); } - + $result = RewardModel::where('id', $id)->update(['status' => $status, 'update_time' => time()]); - + if ($result !== false) { return $this->renderSuccess("状态更新成功"); } else { @@ -193,19 +193,19 @@ class Reward extends Base public function getRewardsByRewardId(Request $request) { $reward_id = trim(input('get.reward_id', '')); - + if (empty($reward_id)) { return json([ - 'code' => 1, + 'status' => 0, 'msg' => '参数错误', 'data' => [] ]); } - + try { // 查询对应的奖励列表 $rewards = RewardModel::where('reward_id', $reward_id)->select()->toArray(); - + // 处理优惠券数据 foreach ($rewards as &$reward) { if ($reward['reward_type'] == 1) { // 优惠券类型 @@ -216,18 +216,63 @@ class Reward extends Base } } } - + return json([ - 'code' => 0, + 'status' => 1, 'msg' => '获取成功', 'data' => $rewards ]); } catch (\Exception $e) { return json([ - 'code' => 1, + 'status' => 0, 'msg' => '获取奖励失败: ' . $e->getMessage(), 'data' => [] ]); } } -} \ No newline at end of file + + /** + * 添加奖励 + */ + public function addReward(Request $request) + { + + $data = input('post.'); + //签到奖励 + $reward = json_decode($data['reward'], true); + $reward_id = $data['reward_id']; + $reward_id_pre = $data['reward_id_pre']; + if (!$reward_id_pre) { + $reward_id_pre = "MHCC"; + } + if (!$reward_id || $reward_id == '') { + $reward_id = $reward_id_pre . date('YmdHis') . mt_rand(1000, 9999); + } + + // 开启事务 + \think\facade\Db::startTrans(); + try { + RewardModel::where('reward_id', $reward_id)->delete(); + if (!empty($reward) && is_array($reward)) { + foreach ($reward as $item) { + $rewardData = [ + 'reward_type' => $item['reward_type'], + 'reward_value' => isset($item['reward_value']) && !empty($item['reward_value']) ? $item['reward_value'] : 0, + 'reward_extend' => isset($item['coupon_id']) && !empty($item['coupon_id']) ? $item['coupon_id'] : 0, + 'description' => '', + 'create_time' => time(), + 'update_time' => time(), + 'reward_id' => $reward_id + ]; + RewardModel::insert($rewardData); + } + } + \think\facade\Db::commit(); + return $this->renderSuccess("更新成功", ['reward_id' => $reward_id]); + } catch (\Exception $e) { + \think\facade\Db::rollback(); + return $this->renderError("更新失败: " . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index cd1bb6b..13fca4b 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -180,6 +180,7 @@ 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('copy_goods', 'Goods/copy_goods', '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'); @@ -365,6 +366,7 @@ Route::rule('reward_edit', 'Reward/edit', 'GET|POST'); Route::rule('reward_delete', 'Reward/delete', 'POST'); Route::rule('reward_status', 'Reward/status', 'POST'); Route::rule('get_rewards_by_id', 'Reward/getRewardsByRewardId', 'GET'); +Route::rule('reward_add_json', 'Reward/addReward', 'POST'); // 签到配置 Route::get('sign_config', 'SignConfig/index'); diff --git a/app/admin/view/Cardextractor/card_shang.html b/app/admin/view/Cardextractor/card_shang.html index 07a28d2..b5a1b9c 100755 --- a/app/admin/view/Cardextractor/card_shang.html +++ b/app/admin/view/Cardextractor/card_shang.html @@ -5,13 +5,14 @@
| 等级名称 | 等级图标 | 发光特效 | @@ -24,6 +25,7 @@|
|---|---|---|---|
| {$vo['id']} | {$vo['title']} | {if $vo['imgurl']} |
{if $vo['special_imgurl']} |
diff --git a/app/admin/view/Cardextractor/card_shang_add.html b/app/admin/view/Cardextractor/card_shang_add.html
index f8dcfbb..b8b335a 100755
--- a/app/admin/view/Cardextractor/card_shang_add.html
+++ b/app/admin/view/Cardextractor/card_shang_add.html
@@ -25,6 +25,12 @@
+