diff --git a/.cursor/rules/mhbase.mdc b/.cursor/rules/mhbase.mdc index 8097a0c..1ba978e 100644 --- a/.cursor/rules/mhbase.mdc +++ b/.cursor/rules/mhbase.mdc @@ -10,6 +10,8 @@ alwaysApply: true 路由文件:app/admin/route/app.php 控制器文件夹:app/admin/controller 视图文件夹:app/admin/view + 视图模板文件夹:app/admin/Public + api项目文件夹:app/api 项目文件夹:app/api/controller 路由文件:app/api/route/app.php diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index f1f9771..02de763 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -113,6 +113,14 @@ class Goods extends Base if (RegZero($data['sort'])) { return $this->renderError("排序输入不规范,请输入整数"); } + // 检查daily_xiangou + if (!isset($data['daily_xiangou']) || $data['daily_xiangou'] === '') { + $data['daily_xiangou'] = 0; + } else if (!is_numeric($data['daily_xiangou']) || intval($data['daily_xiangou']) < 0) { + return $this->renderError("每日限购次数必须是非负整数"); + } else { + $data['daily_xiangou'] = intval($data['daily_xiangou']); + } if ($data['type'] == 1||$data['type'] == 11) { if (RegInt($data['stock'])) { return $this->renderError("库存输入不规范,请设置大于0的整数"); @@ -284,7 +292,12 @@ class Goods extends Base View::assign('item_card', $item_card); View::assign('type', $type); View::assign('info', $info); - // return $this->renderSuccess('',$info); + + // 确保daily_xiangou字段存在 + if (!isset($info['daily_xiangou'])) { + $info['daily_xiangou'] = 0; + } + return View::fetch("Goods/goods_edit"); } else { $data = input('post.'); @@ -304,6 +317,14 @@ class Goods extends Base if (RegZero($data['sort'])) { return $this->renderError("排序输入不规范,请输入整数"); } + // 检查daily_xiangou + if (!isset($data['daily_xiangou']) || $data['daily_xiangou'] === '') { + $data['daily_xiangou'] = 0; + } else if (!is_numeric($data['daily_xiangou']) || intval($data['daily_xiangou']) < 0) { + return $this->renderError("每日限购次数必须是非负整数"); + } else { + $data['daily_xiangou'] = intval($data['daily_xiangou']); + } $type = $info['type']; if ($type == 1||$type == 11) { if (RegInt($data['stock'])) { diff --git a/app/admin/view/Config/systemconfig.html b/app/admin/view/Config/systemconfig.html index a9de653..4f1cd9b 100755 --- a/app/admin/view/Config/systemconfig.html +++ b/app/admin/view/Config/systemconfig.html @@ -133,9 +133,26 @@ {/if} +
+ +
+ +
+
+
+ +
+ +
每日消费达到此金额后可签到,0表示不限制
+
+
+
@@ -532,6 +549,41 @@ return false; }); + // 复制并下载JSON格式按钮点击事件 + $('#copy-download-json').on('click', function () { + // 获取app-setting-form表单的所有值 + var formData = form.val('app-setting-form'); + + // 创建包含当前时间戳的JSON对象 + var jsonData = Object.assign({}, formData); + jsonData.update_time = Math.floor(Date.now() / 1000); // 添加时间戳(秒) + + // 格式化为JSON字符串 + var jsonString = JSON.stringify(jsonData, null, 2); + + // 复制到剪贴板 + var textArea = document.createElement("textarea"); + textArea.value = jsonString; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand('copy'); + document.body.removeChild(textArea); + + // 创建并下载JSON文件 + var blob = new Blob([jsonString], { type: 'application/json' }); + var link = document.createElement('a'); + link.href = URL.createObjectURL(blob); + link.download = 'app_setting_' + jsonData.update_time + '.json'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // 提示用户 + layer.msg('已复制到剪贴板并下载JSON文件', { icon: 1 }); + + return false; // 阻止表单提交 + }); + // UID类型切换事件 form.on('radio(uid_type)', function (data) { var value = this.value; diff --git a/app/admin/view/Goods/goods.html b/app/admin/view/Goods/goods.html index 6e5cf36..1f39733 100755 --- a/app/admin/view/Goods/goods.html +++ b/app/admin/view/Goods/goods.html @@ -207,6 +207,10 @@ } }, { field: 'stock', title: '套数', width: 80 }, + { field: 'daily_xiangou', title: '每日限购', width: 80, templet: function(d) { + return d.daily_xiangou > 0 ? d.daily_xiangou + '次' : '无限制'; + } + }, { field: 'lock_is', title: '锁箱模式', width: 90, templet: '#lockIsTpl' }, { field: 'show_is', title: '首页显示', width: 90, templet: '#showIsTpl' }, { field: 'is_auto_xiajia', title: '自动下架', width: 150, templet: '#autoOffshelfTpl' }, diff --git a/app/admin/view/Goods/goods_add.html b/app/admin/view/Goods/goods_add.html index 69da059..2b649af 100755 --- a/app/admin/view/Goods/goods_add.html +++ b/app/admin/view/Goods/goods_add.html @@ -76,6 +76,13 @@ class="layui-input" style="width: 600px"> +
+ +
+ +
+
@@ -279,7 +286,155 @@ }); // 检查盒子类型,根据类型显示不同的表单项 - // ... 现有代码 ... + form.on('radio(type)', function (data) { + var value = data.value; // 当前选中的value值 + + $("#goods_describe_div").hide(); + if (value == 1 || value == 11) { + $(".id_stock").show(); + $(".id_lock_is").show(); + $(".id_lock_time").show(); + $(".id_prize_num").hide(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").show(); + $(".sale_time").show(); + $("#div_daily_xiangou").show(); + + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").hide(); + $(".lingzhu_fan").hide(); + $(".lingzhu_shang_id").hide(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + } else if (value == 2) { + $(".id_stock").hide(); + $(".id_lock_is").hide(); + $(".id_lock_time").hide(); + $(".id_prize_num").hide(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").hide(); + $(".sale_time").hide(); + $("#div_daily_xiangou").hide(); + + //2023-11 + $(".rage_is").show(); + $(".rage").show(); + $(".item_card_id").show(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + } else if (value == 3) { + $(".id_stock").hide(); + $(".id_lock_is").hide(); + $(".id_lock_time").hide(); + $(".id_prize_num").show(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").hide(); + $(".sale_time").hide(); + + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").hide(); + $(".lingzhu_fan").hide(); + $(".lingzhu_shang_id").hide(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + } else if (value == 5 || value == 10) { + $(".id_stock").show(); + $(".id_lock_is").hide(); + $(".id_lock_time").hide(); + $(".id_prize_num").hide(); + $(".coupon_is").hide(); + $(".coupon_pro").hide(); + $(".integral_is").hide(); + $(".show_is").hide(); + $(".sale_time").hide(); + + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").hide(); + $(".lingzhu_fan").hide(); + $(".lingzhu_shang_id").hide(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + if (value == 10) { + + $("#goods_describe_div").show(); + } + } else if (value == 6) { + $(".id_stock").show(); + $(".id_lock_is").show(); + $(".id_lock_time").show(); + $(".id_prize_num").hide(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").show(); + $(".sale_time").show(); + $("div_quanju_xiangou").show(); + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").hide(); + $(".lingzhu_fan").hide(); + $(".lingzhu_shang_id").hide(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + } else if (value == 8) { + $(".id_stock").hide(); + $(".id_lock_is").hide(); + $(".id_lock_time").hide(); + $(".id_prize_num").hide(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").show(); + $(".sale_time").show(); + + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").show(); + $(".lingzhu_fan").show(); + $(".lingzhu_shang_id").show(); + $(".lian_ji_num").hide(); + $(".lian_ji_shang_id").hide(); + } else if (value == 9) { + $(".id_stock").hide(); + $(".id_lock_is").hide(); + $(".id_lock_time").hide(); + $(".id_prize_num").hide(); + $(".coupon_is").show(); + $(".coupon_pro").show(); + $(".integral_is").show(); + $(".show_is").show(); + $(".sale_time").show(); + + //2023-11 + $(".rage_is").hide(); + $(".rage").hide(); + $(".item_card_id").hide(); + $(".lingzhu_is").hide(); + $(".lingzhu_fan").hide(); + $(".lingzhu_shang_id").hide(); + $(".lian_ji_num").show(); + $(".lian_ji_shang_id").show(); + } + }); }); @@ -310,10 +465,11 @@ $(".lian_ji_num").hide(); $(".lian_ji_shang_id").hide(); $("#goods_describe_div").hide(); + $("#div_daily_xiangou").show(); // 初始显示每日限购次数 form.on('radio(type)', function (data) { var value = data.value; // 当前选中的value值 - + $("#div_daily_xiangou").show(); $("#goods_describe_div").hide(); if (value == 1 || value == 11) { $(".id_stock").show(); @@ -325,6 +481,7 @@ $(".integral_is").show(); $(".show_is").show(); $(".sale_time").show(); + $("#div_daily_xiangou").show(); // 显示每日限购 //2023-11 $(".rage_is").hide(); @@ -345,6 +502,7 @@ $(".integral_is").show(); $(".show_is").hide(); $(".sale_time").hide(); + $("#div_daily_xiangou").hide(); // 隐藏每日限购 //2023-11 $(".rage_is").show(); @@ -362,6 +520,7 @@ $(".integral_is").show(); $(".show_is").hide(); $(".sale_time").hide(); + $("#div_daily_xiangou").hide(); // 隐藏每日限购 //2023-11 $(".rage_is").hide(); @@ -382,6 +541,7 @@ $(".integral_is").hide(); $(".show_is").hide(); $(".sale_time").hide(); + //$("#div_daily_xiangou").hide(); // 隐藏每日限购 //2023-11 $(".rage_is").hide(); @@ -407,6 +567,7 @@ $(".show_is").show(); $(".sale_time").show(); $("div_quanju_xiangou").show(); + // 显示每日限购 //2023-11 $(".rage_is").hide(); $(".rage").hide(); @@ -426,6 +587,7 @@ $(".integral_is").show(); $(".show_is").show(); $(".sale_time").show(); + $("#div_daily_xiangou").hide(); // 隐藏每日限购 //2023-11 $(".rage_is").hide(); @@ -446,6 +608,7 @@ $(".integral_is").show(); $(".show_is").show(); $(".sale_time").show(); + $("#div_daily_xiangou").hide(); // 隐藏每日限购 //2023-11 $(".rage_is").hide(); diff --git a/app/admin/view/Goods/goods_edit.html b/app/admin/view/Goods/goods_edit.html index 9cef82d..6b7368b 100755 --- a/app/admin/view/Goods/goods_edit.html +++ b/app/admin/view/Goods/goods_edit.html @@ -79,6 +79,13 @@ placeholder="请输入每个箱子的限购次数" class="layui-input" style="width: 600px">
+
+ +
+ +
+
@@ -335,8 +342,8 @@ $(".show_is").show(); $(".new_is").show(); $(".sale_time").show(); - - //2023-11 + $("#div_daily_xiangou").show(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); @@ -356,8 +363,8 @@ $(".show_is").hide(); $(".new_is").show(); $(".sale_time").hide(); - - //2023-11 + $("#div_daily_xiangou").hide(); + $(".rage_is").show(); $(".rage").show(); $(".item_card_id").show(); @@ -377,8 +384,8 @@ $(".show_is").hide(); $(".new_is").show(); $(".sale_time").hide(); - - //2023-11 + $("#div_daily_xiangou").hide(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); @@ -397,8 +404,8 @@ $(".integral_is").hide(); $(".show_is").hide(); $(".sale_time").hide(); - - //2023-11 + $("#div_daily_xiangou").hide(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); @@ -422,8 +429,8 @@ $(".show_is").show(); $(".new_is").show(); $(".sale_time").show(); - $("div_quanju_xiangou").show(); - //2023-11 + $("#div_daily_xiangou").show(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); @@ -443,8 +450,8 @@ $(".show_is").show(); $(".new_is").show(); $(".sale_time").show(); - - //2023-11 + $("#div_daily_xiangou").hide(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); @@ -464,8 +471,8 @@ $(".show_is").show(); $(".new_is").show(); $(".sale_time").show(); - - //2023-11 + $("#div_daily_xiangou").hide(); + $(".rage_is").hide(); $(".rage").hide(); $(".item_card_id").hide(); diff --git a/app/admin/view/public/footer.html b/app/admin/view/public/footer.html deleted file mode 100644 index 0519ecb..0000000 --- a/app/admin/view/public/footer.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/app/admin/view/public/header.html b/app/admin/view/public/header.html deleted file mode 100644 index f677c2f..0000000 --- a/app/admin/view/public/header.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 后台管理 -{$config.title} - - - - - - - - -
-
-
- - - -
-
-
- - \ No newline at end of file diff --git a/app/admin/view/public/header2.html b/app/admin/view/public/header2.html deleted file mode 100644 index 4fcd896..0000000 --- a/app/admin/view/public/header2.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - 后台管理 - {$config.title} - - - - - - - - - \ No newline at end of file diff --git a/app/api/controller/Mall.php b/app/api/controller/Mall.php index 012a969..d1bbd55 100755 --- a/app/api/controller/Mall.php +++ b/app/api/controller/Mall.php @@ -69,7 +69,7 @@ class Mall extends Base $prize_num = request()->param('prize_num/d', 0); #抽几发 #盒子信息 - $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,is_shou_zhe,choujiang_xianzhi')->where(['id' => $goods_id]) + $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,is_shou_zhe,choujiang_xianzhi,daily_xiangou')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); @@ -89,6 +89,50 @@ class Mall extends Base return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } + + // 检查每日限购次数 + if (isset($goods['daily_xiangou']) && $goods['daily_xiangou'] > 0) { + // 计算今天的开始和结束时间戳 + $today_start = strtotime(date('Y-m-d 00:00:00', time())); + $today_end = strtotime(date('Y-m-d 23:59:59', time())); + + // 查询用户今天对该商品的购买次数 + $today_buy_count = Order::where([ + ['user_id', '=', $user_id], + ['goods_id', '=', $goods_id], + ['status', '=', 1], + ['addtime', '>=', $today_start], + ['addtime', '<=', $today_end] + ])->count(); + + // 如果今日购买次数已达到限制,返回错误 + if ($today_buy_count >= $goods['daily_xiangou']) { + return $this->renderError("该商品每日限购" . $goods['daily_xiangou'] . "次,今日已购买" . $today_buy_count . "次"); + } + } + $app_setting = getConfig('app_setting'); + if ($app_setting) { + $exchange_times = $app_setting["exchange_times"]; + if ($exchange_times && $app_setting["exchange_times"] > 0) { + // 计算今天的开始和结束时间戳 + $today_start = strtotime(date('Y-m-d 00:00:00', time())); + $today_end = strtotime(date('Y-m-d 23:59:59', time())); + + // 查询用户今天对该商品的购买次数 + $today_buy_count = Order::where([ + ['user_id', '=', $user_id], + ['goods_id', '=', $goods_id], + ['status', '=', 1], + ['addtime', '>=', $today_start], + ['addtime', '<=', $today_end] + ])->count(); + + // 如果今日购买次数已达到限制,返回错误 + if ($today_buy_count >= $exchange_times) { + return $this->renderError("商城每日限购" . $exchange_times . "次,今日已购买" . $today_buy_count . "次"); + } + } + } $where = []; $where[] = ['goods_id', '=', $goods_id]; @@ -166,7 +210,7 @@ class Mall extends Base ]); #开盒子 - $res[] = (new Notify($this->app))->infinite_drawprize_notice($user['id'], $order_id, $goods_id, $num); + $res[] = (new Notify($this->app))->infinite_shangchengshang_notice($user['id'], $order_id, $goods_id, $num); #结果集 $new_data = [ 'status' => 0, @@ -204,7 +248,7 @@ class Mall extends Base $is_mibao = request()->param('is_mibao/d', 0); //连击赏下 是否是抽的秘宝池 1是 0否 #盒子信息 - $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,choujiang_xianzhi')->where(['id' => $goods_id]) + $goods = Goodsmodel::field('id,title,imgurl_detail,type,price,status,choujiang_xianzhi,daily_xiangou')->where(['id' => $goods_id]) ->find(); if (!$goods) { return $this->renderError("盒子不存在"); @@ -224,6 +268,28 @@ class Mall extends Base return $this->renderError("消费满" . $choujiang_xianzhi . "元可参与 已消费" . round($user_price, 2) . "元"); } } + + // 检查每日限购次数 + if (isset($goods['daily_xiangou']) && $goods['daily_xiangou'] > 0) { + // 计算今天的开始和结束时间戳 + $today_start = strtotime(date('Y-m-d 00:00:00', time())); + $today_end = strtotime(date('Y-m-d 23:59:59', time())); + + // 查询用户今天对该商品的购买次数 + $today_buy_count = Order::where([ + ['user_id', '=', $user_id], + ['goods_id', '=', $goods_id], + ['status', '=', 1], + ['addtime', '>=', $today_start], + ['addtime', '<=', $today_end] + ])->count(); + + // 如果今日购买次数已达到限制,返回错误 + if ($today_buy_count >= $goods['daily_xiangou']) { + return $this->renderError("该商品每日限购" . $goods['daily_xiangou'] . "次,今日已购买" . $today_buy_count . "次"); + } + } + //秘宝池 $where = []; $where[] = ['goods_id', '=', $goods_id]; diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index 60cce45..44dbc48 100755 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -1070,6 +1070,9 @@ class Notify extends Base return $res; } + + + /** * 无限赏开奖逻辑 * @param $order 订单信息 @@ -1269,23 +1272,7 @@ class Notify extends Base #入库=== $res[] = OrderList::insert($save_prize_info); } - - //去除秘宝池次数 - if ($infinite_goods['type'] == 9 && $order['is_mibao'] == 1) { - User::where('id', $user_id)->dec('mb_number', $prize_num)->update(); - } - - //计算怒气值 - $this->rage($goods_id, $order_id, $user_id); - - //领主 - $this->ling_zhu($order, $order_id); - - //连击赏 - if ($infinite_goods['type'] == 9 && $order['is_mibao'] == 0) { - $this->lian_ji($order, $order_id); - } - + } else { $res[] = 0; } @@ -1908,4 +1895,62 @@ class Notify extends Base $open_id = Db::name('user')->where('id', $user_id)->value('openid'); $wxServer->post_order($open_id, $access_token, $order_num); } + + /** + * 无限赏开始抽赏====================================================== + * @param int $user_id 会员id + * @param int $order_id 订单ID + * @param int $box_id 盲盒id + */ + public function infinite_shangchengshang_notice($user_id = 0, $order_id = 0, $goods_id = 0, $num = 0) + { + + $res = []; + $order = Order::where(['id' => $order_id]) + ->where(['user_id' => $user_id]) + ->where(['goods_id' => $goods_id]) + ->where(['num' => $num]) + ->where(['status' => 0]) + ->find(); + if ($order == null && $num == 0) { + $order = Order::where(['id' => $order_id]) + ->where(['user_id' => $user_id]) + ->where(['goods_id' => $goods_id]) + ->where(['num' => 1]) + ->where(['status' => 0]) + ->find(); + if ($order != null) { + $order_type1 = $order['order_type']; + if ($order_type1 == 10) { + $num = 1; + } + } + } + if ($order) { + #改变状态 + $res[] = Order::field('status,pay_time') + ->where(['id' => $order['id']]) + ->update([ + 'status' => 1, + 'pay_time' => time(), + ]); + #扣余额 + if ($order['use_money'] > 0) { + $res[] = User::changeMoney($order['user_id'], -$order['use_money'], 3, '购买盒子' . $order['goods_title']); + } + #扣货币 + if ($order['use_integral'] > 0) { + $res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']); + } + #扣货币2 + if ($order['use_money2'] > 0) { + $res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']); + } + $res[] = $this->infinite_shangchengshang($order); + } else { + $res[] = 0; + } + + return $res; + } } \ No newline at end of file