diff --git a/.cursor/rules/mhbase.mdc b/.cursor/rules/mhbase.mdc old mode 100644 new mode 100755 diff --git a/.env b/.env index 89cab74..d30629e 100755 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -APP_DEBUG = true +APP_DEBUG = false [APP] DEFAULT_TIMEZONE = Asia/Shanghai @@ -6,12 +6,12 @@ DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 -DATABASE = xinglanmh_shequt -USERNAME = xinglanmh_shequt -PASSWORD = t3aihzA23RcB6RT8 +DATABASE = youda_test +USERNAME = youda_test +PASSWORD = youda_test HOSTPORT = 3306 CHARSET = utf8 -DEBUG = true +DEBUG = false [LANG] default_lang = zh-cn diff --git a/README_AUTO_OFFSHELF.md b/README_AUTO_OFFSHELF.md old mode 100644 new mode 100755 diff --git a/app/admin/controller/AdvertType.php b/app/admin/controller/AdvertType.php old mode 100644 new mode 100755 diff --git a/app/admin/controller/Base.php b/app/admin/controller/Base.php index 6af5dfa..44ce15a 100755 --- a/app/admin/controller/Base.php +++ b/app/admin/controller/Base.php @@ -22,11 +22,36 @@ class Base extends MyController public $admin_id = 0; public $config = []; + + /** + * 访问白名单,无需验证登录 + * @var array + */ + protected $whiteList = [ + // 格式:'控制器/方法' => true + // 例如:'login/index' => true, + 'goods/sync_goods' => true, + ]; + /** * 后台初始化 */ public function initialize() { + // 获取当前控制器和方法 + $controller = strtolower(request()->controller()); + $action = strtolower(request()->action()); + $currentRoute = $controller . '/' . $action; + + // 检查是否在白名单中 + if (isset($this->whiteList[$currentRoute]) && $this->whiteList[$currentRoute] === true) { + // 在白名单中,跳过登录验证 + $this->config = getConfig('base'); + View::assign("config", $this->config); + return; + } + + // 不在白名单中,进行登录验证 if (!session('admin_id') || !session('admin_token')) { echo ""; die; diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 55b3b7c..f1ba70d 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -52,6 +52,18 @@ class Goods extends Base $list = $query->page($page, $limit)->select()->toArray(); + // 获取盒子ID集合 + $goodsIds = array_column($list, 'id'); + + // 获取盒子扩展信息 + $goodsExtendList = []; + if (!empty($goodsIds)) { + $goodsExtends = \app\common\model\GoodsExtend::whereIn('goods_id', $goodsIds)->select()->toArray(); + foreach ($goodsExtends as $extend) { + $goodsExtendList[$extend['goods_id']] = $extend; + } + } + // 处理图片路径 foreach ($list as &$item) { $item['imgurl'] = imageUrl($item['imgurl']); @@ -60,6 +72,14 @@ class Goods extends Base } // 添加格式化时间 $item['addtime_text'] = date('Y-m-d H:i', $item['addtime']); + + // 添加扩展信息 + $item['goods_extend'] = isset($goodsExtendList[$item['id']]) ? $goodsExtendList[$item['id']] : null; + + // 修改时间处理 + if(isset($item['update_time']) && $item['update_time']){ + $item['update_time_text'] = date('Y-m-d H:i', $item['update_time']); + } } return $this->renderTable('获取成功', $count, $list); @@ -72,7 +92,7 @@ class Goods extends Base { // 查询可用的盒子类型 $goodsTypeList = Db::name('goods_type') - ->field('value,sort_order,remark,is_fenlei,fl_name') + ->field('value,sort_order,remark,is_fenlei,fl_name,pay_wechat,pay_balance,pay_currency,pay_currency2,pay_coupon,is_deduction') ->where('is_fenlei', 1) ->order('sort_order') ->select() @@ -142,7 +162,7 @@ class Goods extends Base } $data['prize_num'] = 0; $data['category_id'] = 0; - } elseif ($data['type'] == 2 || $data['type'] == 16) { + } elseif ($data['type'] == 2 || $data['type'] == 16 || $data['type'] == 17) { $data['stock'] = 0; $data['lock_is'] = 0; $data['lock_time'] = 0; @@ -390,7 +410,7 @@ class Goods extends Base } $data['prize_num'] = 0; $data['category_id'] = 0; - } elseif ($type == 2 || $type == 16) { + } elseif ($type == 2 || $type == 16 || $type == 17) { $data['stock'] = 0; $data['lock_is'] = 0; $data['lock_time'] = 0; @@ -642,7 +662,7 @@ class Goods extends Base if ($type == 1 || $type == 3 || $type == 5 || $type == 6 || $type == 10 || $type == 11) { $where[] = ['num', '=', 1]; - } elseif ($type == 2 || $type == 8 || $type == 9 || $type == 15 || $type == 16) { + } elseif ($type == 2 || $type == 8 || $type == 9 || $type == 15 || $type == 16 || $type == 17) { $where[] = ['num', '=', 0]; } else { return $this->renderError('请求参数错误1'); @@ -687,7 +707,7 @@ class Goods extends Base } $real_pro1 += $goods_list_item['real_pro']; } - if ($type == 2 || $type == 8 || $type == 9 || $type == 15 || $type == 16) { + if ($type == 2 || $type == 8 || $type == 9 || $type == 15 || $type == 16 || $type == 17) { $goods_list[] = ['title' => '宝箱概率合计', 'real_pro' => $real_pro1, 'id' => -1]; } $item['children'] = $goods_list; @@ -715,7 +735,7 @@ class Goods extends Base if( $goods_list_id){ $shang = Shang::where('id', '<=', 33)->where('id', '>', 5)->select()->toArray(); } - } elseif ($info['type'] == 2 || $info['type'] == 8 || $info['type'] == 9 || $info['type'] == 16) { + } elseif ($info['type'] == 2 || $info['type'] == 8 || $info['type'] == 9 || $info['type'] == 16 || $info['type'] == 17 ) { $shang = Shang::where('id', 'between', [34, 38])->select()->toArray(); } elseif ($info['type'] == 3) { $shang = Shang::where('id', 'between', [4, 33])->select()->toArray(); @@ -833,7 +853,13 @@ class Goods extends Base if (RegInt($data['stock'])) { return $this->renderError('奖品数量设置错误,请设置大于0的整数'); } - } else { + } elseif ($type == 17) { + $prize_code = getPrizeCode() . '_' . time(); + $data['prize_code'] = $prize_code; + $data['surplus_stock'] = $data['stock']; + + } + else { return $this->err('请求参数错误'); } if (RegZero($data['sort'])) { @@ -887,7 +913,7 @@ class Goods extends Base if( $goods_list_id){ $shang = Shang::where('id', '<=', 33)->where('id', '>', 5)->select()->toArray(); } - } elseif ($info['type'] == 2 || $info['type'] == 8 || $info['type'] == 9 || $info['type'] == 16) { + } elseif ($info['type'] == 2 || $info['type'] == 8 || $info['type'] == 9 || $info['type'] == 16 || $info['type'] == 17 ) { $shang = Shang::where('id', 'between', [34, 38])->select()->toArray(); } elseif ($info['type'] == 15) { $shang = Shang::where('id', '>=', 114)->select()->toArray(); @@ -955,7 +981,7 @@ class Goods extends Base if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11 || $type == 15) { - } elseif ($type == 2 || $type == 8 || $type == 9 || $type == 16) { + } elseif ($type == 2 || $type == 8 || $type == 9 || $type == 16 || $type == 17) { if (RegMoney($data['real_pro'] * 10000)) { return $this->renderError('真实概率设置错误,最多保留四位小数'); } @@ -1667,4 +1693,180 @@ class Goods extends Base } } + /** + * 盒子扩展设置 + */ + public function goods_extend(Request $request) + { + $goods_id = $request->param('goods_id/d'); + if (!$goods_id) { + return $this->renderError("参数错误"); + } + + // 获取盒子信息 + $goods = GoodsModel::where('id', $goods_id)->find(); + if (!$goods) { + return $this->renderError("盒子不存在"); + } + + if ($request->isPost()) { + $data = $request->post(); + + // 验证参数 + $data['goods_id'] = $goods_id; + $data['pay_wechat'] = isset($data['pay_wechat']) ? 1 : 0; + $data['pay_balance'] = isset($data['pay_balance']) ? 1 : 0; + $data['pay_currency'] = isset($data['pay_currency']) ? 1 : 0; + $data['pay_currency2'] = isset($data['pay_currency2']) ? 1 : 0; + $data['pay_coupon'] = isset($data['pay_coupon']) ? 1 : 0; + $data['is_deduction'] = isset($data['is_deduction']) ? 1 : 0; + + // 查询是否已存在 + $exist = \app\common\model\GoodsExtend::getByGoodsId($goods_id); + + Db::startTrans(); + try { + if ($exist) { + // 更新 + \app\common\model\GoodsExtend::where('goods_id', $goods_id)->update($data); + } else { + // 新增 + \app\common\model\GoodsExtend::create($data); + } + Db::commit(); + return json(['status' => 1, 'msg' => '保存成功']); + } catch (\Exception $e) { + Db::rollback(); + return json(['status' => 0, 'msg' => '保存失败: ' . $e->getMessage()]); + } + } + + // 获取扩展设置 + $extend = \app\common\model\GoodsExtend::getByGoodsId($goods_id); + + if (!$extend) { + // 从goods_type表获取默认值 + $goodsType = Db::name('goods_type') + ->field('pay_wechat, pay_balance, pay_currency, pay_currency2, pay_coupon, is_deduction') + ->where('value', $goods['type']) + ->find(); + + if ($goodsType) { + // 如果找到了盒子类型的默认配置 + $extend = [ + 'goods_id' => $goods_id, + 'pay_wechat' => $goodsType['pay_wechat'], + 'pay_balance' => $goodsType['pay_balance'], + 'pay_currency' => $goodsType['pay_currency'], + 'pay_currency2' => $goodsType['pay_currency2'], + 'pay_coupon' => $goodsType['pay_coupon'], + 'is_deduction' => $goodsType['is_deduction'] + ]; + } else { + // 如果没找到,使用默认值 + $extend = [ + 'goods_id' => $goods_id, + 'pay_wechat' => 1, + 'pay_balance' => 1, + 'pay_currency' => 1, + 'pay_currency2' => 1, + 'pay_coupon' => 1, + 'is_deduction' => 1 + ]; + } + } + + View::assign('goods', $goods); + View::assign('extend', $extend); + return View::fetch("Goods/goods_extend"); + } + + /** + * 删除盒子扩展设置 + */ + public function goods_extend_del(Request $request) + { + $goods_id = $request->param('goods_id/d'); + if (!$goods_id) { + return json(['status' => 0, 'msg' => '参数错误']); + } + + // 获取盒子信息 + $goods = GoodsModel::where('id', $goods_id)->find(); + if (!$goods) { + return json(['status' => 0, 'msg' => '盒子不存在']); + } + + // 删除扩展设置 + $result = \app\common\model\GoodsExtend::deleteByGoodsId($goods_id); + if ($result) { + return json(['status' => 1, 'msg' => '删除成功']); + } else { + return json(['status' => 0, 'msg' => '删除失败或扩展设置不存在']); + } + } + + /** + * 更新盒子排序 + */ + public function update_goods_sort(Request $request) + { + $id = $request->post('id/d'); + $sort = $request->post('sort/d'); + + if (empty($id)) { + return json(['status' => 0, 'msg' => '参数错误']); + } + + // 验证排序值 + if (!is_numeric($sort) || $sort < 0) { + return json(['status' => 0, 'msg' => '排序值必须是非负整数']); + } + + // 获取盒子信息 + $goods = GoodsModel::where('id', $id)->find(); + if (!$goods) { + return json(['status' => 0, 'msg' => '盒子不存在']); + } + + // 更新排序值 + $result = GoodsModel::where('id', $id)->update(['sort' => $sort]); + if ($result) { + return json(['status' => 1, 'msg' => '更新成功']); + } else { + return json(['status' => 0, 'msg' => '更新失败']); + } + } + + /** + * 更新奖品排序 + */ + public function goodslist_edit_sort(Request $request) + { + $id = $request->post('id/d'); + $sort = $request->post('sort/d'); + + if (empty($id)) { + return json(['status' => 0, 'msg' => '参数错误']); + } + + // 验证排序值 + if (!is_numeric($sort) || $sort < 0) { + return json(['status' => 0, 'msg' => '排序值必须是非负整数']); + } + + // 获取奖品信息 + $goodsList = GoodsList::where('id', $id)->find(); + if (!$goodsList) { + return json(['status' => 0, 'msg' => '奖品不存在']); + } + + // 更新排序值 + $result = GoodsList::where('id', $id)->update(['sort' => $sort]); + if ($result) { + return json(['status' => 1, 'msg' => '更新成功']); + } else { + return json(['status' => 0, 'msg' => '更新失败']); + } + } } diff --git a/app/admin/controller/GoodsExtend.php b/app/admin/controller/GoodsExtend.php deleted file mode 100755 index 209ad4a..0000000 --- a/app/admin/controller/GoodsExtend.php +++ /dev/null @@ -1,219 +0,0 @@ -param('goods_id/d', 0); - $num = $request->param('num/d', 1); - $info = GoodsModel::where(['id' => $goods_id])->find(); - if (!$info) { - return $this->renderError('请求参数错误'); - } - - $type = $info['type']; - $title = trim(input('get.title')); - $lian_ji_type = input('get.lian_ji_type'); - $whe = array(); - $whe[] = ['goods_id', '=', $goods_id]; - if ($num > $info['stock']) { - $num = $info['stock']; - } - - if ($type == 1 || $type == 3 || $type == 5 || $type == 6 || $type == 10 || $type == 11) { - if ($num <= 0) { - $num = 1; - } - if ($num != 0) { - $whe[] = ['num', '=', $num]; - } - } elseif ($type == 2 || $type == 8 || $type == 9) { - $whe[] = ['num', '=', 0]; - } else { - return $this->renderError('请求参数错误1'); - } - if (!empty($title)) { - $whe[] = ['title', 'like', '%' . $title . '%']; - } - if (!empty($lian_ji_type)) { - $whe[] = ['lian_ji_type', '=', $lian_ji_type]; - } - $field = "*"; - $order = "sort desc,shang_id asc,id asc"; - $data = GoodsList::getList($whe, $field, $order, 150); - $stock = array_sum(array_column($data['list'], 'stock')); - $surplus_stock = array_sum(array_column($data['list'], 'surplus_stock')); - $reward_num_count = $stock - $surplus_stock; - - - //GoodsModel - $goodsExtendLists = GoodsExtendListModel::getGoodsExtendList($goods_id); - // $idArray = array_map(function($item) { - // return $item['id']; - // }, $data); - // Shang::where(['id' => $value['shang_id']])->value('title'); - $real_pro = 0; - $goods_extend_reward_num = 0; - foreach ($data['list'] as &$value) { - $value['shang'] = Shang::where(['id' => $value['shang_id']])->value('title'); - $real_pro += $value['real_pro']; - // $value['rownum'] = $goodsExtendLists::where(['id' => $goods_id])->find(); - //找到匹配的数据 - $value['goods_extend_reward_num'] = 0; - $value['goods_extend_rawrd_type'] = 0; - $value['goods_extend'] = []; - if (count($goodsExtendLists) > 0) { - - - - foreach ($goodsExtendLists as $item) { - // $temp_goods_extend_data = GoodsExtendListModel::where('prize_code', '=', $goods["prize_code"])->find(); - // if ($item['prize_code'] == $value['prize_code']) { - if ($item['goods_list_id'] == $value['id']) { - $goods_extend_reward_num = $item['reward_num']; // 替换为你需要的字段名 - $value['goods_extend_reward_num'] = $goods_extend_reward_num; - $value['goods_extend'] = $item; - $value['goods_extend_rawrd_type'] = $item['rawrd_type']; - $value['goods_extend_reward_num_1'] = $item['reward_num_1']; - break; // 找到第一个匹配的对象后退出循环 - } - } - } - } - View::assign('list', $data['list']); - View::assign('count', $data['count']); - View::assign('page', $data['page']); - View::assign('goods_id', $goods_id); - View::assign('type', $type); - View::assign('goods_model', $info); - View::assign('num', $num ); - View::assign('real_pro', $real_pro); - View::assign('reward_num_count',$reward_num_count); - return View::fetch("GoodsExtend/goodsextendlist"); - - } - - /** - * 编辑奖品 - */ - public function goodsextendlist_edit(Request $request) - { - $id = 0; - if (!$request->isPost()) { - $id = $request->param('id/d', 0); - - $goods_extend_list_model = GoodsExtendListModel::getGoodsIdExtendList($id); - View::assign('goods_extend', $goods_extend_list_model); - return View::fetch('GoodsExtend/goodsextend_edit'); - } else { - - $data = input('post.'); - if (empty($data['ids'])) { - return $this->renderError('请求参数错误1'); - } - if (empty($data['value'])) { - return $this->renderError('请求参数错误1'); - } - - // if (RegZero($data['value'])) { - // return $this->renderError('请输入整数'); - // } - if (RegZero($data['goodid'])) { - return $this->renderError('请求参数错误'); - } - $value = $data['value']; - $ids = $data['ids']; - $goodid = $data['goodid']; - $save_goods_extend_data = []; - - // rawrd_type:3, - // reward_num:0, - // reward_num1:0, - // reward_num2:0 - // $ordinary_prize = GoodsList::where('goods_id', '=', $goods_id) - // ->where('num', '=', $num) - // ->where('shang_id', 'between', self::$shang_prize_id) - // ->order('sort desc,shang_id asc') - // ->select()->toArray(); - - foreach ($ids as $item) { - $goods_list_id = intval($item); - if ($goods_list_id > 0) { - $goods = GoodsList::where(['id' => $goods_list_id])->find(); - if ($goods) { - // $temp_goods_extend_data = GoodsExtendListModel::where('prize_code', '=', $goods["prize_code"])->find(); //getGoodsIdExtendList($goods_list_id); - $temp_goods_extend_data = GoodsExtendListModel::where('goods_list_id', '=', $goods_list_id)->find(); //getGoodsIdExtendList($goods_list_id); - if ($temp_goods_extend_data === null) { - // 创建新的数据 - $temp_goods_extend_data = new GoodsExtendListModel(); - } - - // 更新现有数据 - $temp_goods_extend_data->goods_list_id = $item; - $temp_goods_extend_data->reward_num = $value['reward_num']; - $temp_goods_extend_data->rawrd_type = $value['rawrd_type']; - $temp_goods_extend_data->reward_num_1 = $value['reward_num_1']; - $temp_goods_extend_data->goods_id = $goodid; - $temp_goods_extend_data->prize_code = $goods["prize_code"]; - $save_goods_extend_data[] = $temp_goods_extend_data; - } - } - } - // 保存数据到数据库中 - foreach ($save_goods_extend_data as $data) { - $data->save(); // save() 方法将自动处理是插入还是更新 - } - return $this->renderSuccess('编辑成功'); - - } - } - - - /** - * 编辑奖品 - */ - public function goodsextendlist_del(Request $request) - { - if (!$request->isPost()) { - return $this->renderError(''); - } else { - $data = input('post.'); - if (empty($data['goods_list_id'])) { - return $this->renderError('请求参数错误1'); - } - - $goods_list_id = $data['goods_list_id']; - $save_goods_extend_data = GoodsExtendListModel::where('goods_list_id', '=', $goods_list_id)->select(); - // 保存数据到数据库中 - foreach ($save_goods_extend_data as $data) { - if ($data) { - $data->delete(); // delete() 方法将从数据库中删除该对象 - } - - } - - - return $this->renderSuccess('编辑成功'); - - } - } - - -} diff --git a/app/admin/controller/GoodsType.php b/app/admin/controller/GoodsType.php old mode 100644 new mode 100755 diff --git a/app/admin/controller/Reward.php b/app/admin/controller/Reward.php old mode 100644 new mode 100755 diff --git a/app/admin/controller/SignConfig.php b/app/admin/controller/SignConfig.php old mode 100644 new mode 100755 diff --git a/app/admin/controller/WelfareHouse.php b/app/admin/controller/WelfareHouse.php old mode 100644 new mode 100755 diff --git a/app/admin/middleware/DomainBind.php b/app/admin/middleware/DomainBind.php old mode 100644 new mode 100755 index 66925c3..6f8eb6c --- a/app/admin/middleware/DomainBind.php +++ b/app/admin/middleware/DomainBind.php @@ -43,11 +43,11 @@ class DomainBind if (!$this->checkDomain($domain)) { // 记录被拒绝的请求 \think\facade\Log::warning('域名访问被拒绝: ' . $domain . ', 路径: ' . $path); - return $this->error('域名未授权,无法访问', 403); + return $this->error('未授权,无法访问', 403); } // 域名允许,记录请求信息(可选,仅用于调试) - \think\facade\Log::info('域名访问通过: ' . $domain . ', 路径: ' . $path); + // \think\facade\Log::info('域名访问通过: ' . $domain . ', 路径: ' . $path); // 域名允许,继续处理请求 return $next($request); @@ -92,7 +92,7 @@ class DomainBind // 1. 从配置文件中获取额外允许的域名 try { - $configDomains = Config::get('admin.api_domains', []); + $configDomains = Config::get('api.admin_domains', []); if (!empty($configDomains) && is_array($configDomains)) { foreach ($configDomains as $d) { $d = trim($d); diff --git a/app/admin/route/app.php b/app/admin/route/app.php index eb4f8b6..48a7ece 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -174,6 +174,7 @@ Route::rule('goodslist', 'Goods/goodslist', 'GET|POST'); Route::rule('goodslist_add', 'Goods/goodslist_add', 'GET|POST'); Route::rule('goodslist_edit', 'Goods/goodslist_edit', 'GET|POST'); Route::rule('goodslist_del', 'Goods/goodslist_del', 'GET|POST'); +Route::rule('goodslist_edit_sort', 'Goods/goodslist_edit_sort', 'POST'); Route::rule('give', 'Goods/give', 'GET|POST'); Route::rule('give_add', 'Goods/give_add', 'GET|POST'); Route::rule('give_edit', 'Goods/give_edit', 'GET|POST'); @@ -195,13 +196,14 @@ Route::rule('drawlist_del', 'Draw/drawlist_del', 'GET|POST'); Route::rule('draw_add', 'Draw/draw_add', 'GET|POST'); Route::rule('get_sync_addresses', 'Goods/get_sync_addresses', 'GET'); Route::rule('sync_goods', 'Goods/sync_goods', 'POST'); +Route::any('goods_edit', 'Goods/goods_edit'); +Route::any('goods_del', 'Goods/goods_del'); +Route::any('goodslist', 'Goods/goodslist'); +Route::any('goods_extend', 'Goods/goods_extend'); +Route::any('goods_extend_del', 'Goods/goods_extend_del'); +Route::post('update_goods_sort', 'Goods/update_goods_sort'); + -#============================ -#盒子扩展 -#============================ -Route::rule('goodsextendlist', 'GoodsExtend/goodsextendlist', 'GET|POST'); -Route::rule('goodsextendlist_edit', 'GoodsExtend/goodsextendlist_edit', 'GET|POST'); -Route::rule('goodsextendlist_del', 'GoodsExtend/goodsextendlist_del', 'POST'); #============================ #Order.php订单管理 #============================ diff --git a/app/admin/view/AdvertType/add.html b/app/admin/view/AdvertType/add.html old mode 100644 new mode 100755 diff --git a/app/admin/view/AdvertType/list_all.html b/app/admin/view/AdvertType/list_all.html old mode 100644 new mode 100755 diff --git a/app/admin/view/Config/miniprogram.html b/app/admin/view/Config/miniprogram.html old mode 100644 new mode 100755 diff --git a/app/admin/view/Config/systemconfig.html b/app/admin/view/Config/systemconfig.html index 64bb0e5..48d36b1 100755 --- a/app/admin/view/Config/systemconfig.html +++ b/app/admin/view/Config/systemconfig.html @@ -150,6 +150,24 @@