diff --git a/README.md b/README.md index ea59ef4..c2a217a 100755 --- a/README.md +++ b/README.md @@ -68,3 +68,56 @@ composer require yzalis/identicon composer require topthink/think-image php think UserStatisticsHour ``` + + +原抽无限赏奖逻辑(内存消耗过大,不在使用) +```sh + // #组合中奖商品 + // $all_goods_id = []; + // foreach ($goodslist as $value) { + // $real_pro1 = $value['real_pro']; + // $real_pro = $real_pro1 * 100000; + // for ($i = 1; $i <= $real_pro; $i++) { + // $all_goods_id[] = $value['id']; + // } + // } + + // for ($i = 0; $i < $prize_num; $i++) { + // #随机打乱 + // shuffle($all_goods_id); + // shuffle($all_goods_id); + // $prize_id = $all_goods_id[0]; + // $prize_info = GoodsList::where(['id' => $prize_id])->find(); + // #编号 + // $luck_no = OrderList::field('id') + // ->where('goods_id', '=', $goods_id) + // ->where('num', '=', 0) + // ->where('order_type', '=', $order_type) + // ->order('id desc') + // ->value('luck_no'); + // $luck_no++; + // #新增记录 + // $save_prize_info = [ + // 'order_id' => $order_id, + // 'user_id' => $user_id, + // 'status' => 0,#0未操作 1选择兑换 2选择发货 + // 'goods_id' => $goods_id, + // 'num' => 0, + // 'shang_id' => $prize_info['shang_id'], + // 'goodslist_id' => $prize_info['id'], + // 'goodslist_title' => $prize_info['title'], + // 'goodslist_imgurl' => $prize_info['imgurl'], + // 'goodslist_price' => $prize_info['price'], + // 'goodslist_money' => $prize_info['money'], + // 'goodslist_type' => $prize_info['goods_type'], + // 'goodslist_sale_time' => $prize_info['sale_time'], + // 'addtime' => time(), + // 'prize_code' => $prize_info['prize_code'], + // 'order_type' => $order_type, + // 'luck_no' => $luck_no, + // ]; + // #入库=== + // $res[] = OrderList::insert($save_prize_info); + // } + +``` \ No newline at end of file diff --git a/app/admin/controller/Advert.php b/app/admin/controller/Advert.php index 97ac90f..5b0e42d 100755 --- a/app/admin/controller/Advert.php +++ b/app/admin/controller/Advert.php @@ -53,6 +53,7 @@ class Advert extends Base */ public function add(Request $request) { + if (!$request->isPost()) { $types = AdvertTypeModel::order('sort asc, id asc')->select(); View::assign('types', $types); diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index deb155c..f1f9771 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -770,7 +770,7 @@ class Goods extends Base if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11) { } elseif ($type == 2 || $type == 8 || $type == 9) { - if (RegMoney($data['real_pro']*100)) { + if (RegMoney($data['real_pro']*1000)) { return $this->renderError('真实概率设置错误,最多保留两位小数'); } } else if ($type == 3) { diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index e92ec57..d0999fe 100755 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -965,9 +965,10 @@ class User extends Base { $id = input('id'); View::assign('id',$id); + View::assign('user_id',$id); $nickname = input('nickname'); View::assign('nickname',$nickname); - return View::fetch(); + return View::fetch('User/user_order'); } /** diff --git a/app/admin/controller/WelfareHouse.php b/app/admin/controller/WelfareHouse.php new file mode 100644 index 0000000..1b3ff50 --- /dev/null +++ b/app/admin/controller/WelfareHouse.php @@ -0,0 +1,135 @@ +isAjax()) { + $param = input('param.'); + $limit = $param['limit'] ?? 15; + $offset = $param['offset'] ?? 0; + + $where = []; + if (!empty($param['name'])) { + $where[] = ['name', 'like', '%' . $param['name'] . '%']; + } + + $count = WelfareHouseModel::where($where)->count(); + $list = WelfareHouseModel::where($where) + ->order('sort asc, id desc') + ->limit($offset, $limit) + ->select(); + + return json([ + 'code' => 0, + 'msg' => '', + 'count' => $count, + 'data' => $list + ]); + // json(['total' => $count, 'rows' => $list]); + } + + return View::fetch(); + } + + // 添加 + public function add() + { + if (request()->isPost()) { + $param = input('post.'); + + $validate = validate([ + 'name|名称' => 'require', + 'image|图片' => 'require', + 'url|跳转路径' => 'require', + 'sort|排序' => 'require|number', + ]); + + if (!$validate->check($param)) { + return json(['status' => 0, 'msg' => $validate->getError()]); + } + + $param['status'] = isset($param['status']) ? 1 : 0; + $result = WelfareHouseModel::create($param); + + if ($result) { + return json(['status' => 1, 'msg' => '添加成功']); + } else { + return json(['status' => 0, 'msg' => '添加失败']); + } + } + + return View::fetch(); + } + + // 编辑 + public function edit() + { + $id = input('id'); + $info = WelfareHouseModel::find($id); + if (!$info) { + return json(['status' => 0, 'msg' => '数据不存在']); + } + + if (request()->isPost()) { + $param = input('post.'); + + $validate = validate([ + 'name|名称' => 'require', + 'image|图片' => 'require', + 'url|跳转路径' => 'require', + 'sort|排序' => 'require|number', + ]); + + if (!$validate->check($param)) { + return json(['status' => 0, 'msg' => $validate->getError()]); + } + + $param['status'] = isset($param['status']) ? 1 : 0; + $result = WelfareHouseModel::update($param); + + if ($result) { + return json(['status' => 1, 'msg' => '编辑成功']); + } else { + return json(['status' => 0, 'msg' => '编辑失败']); + } + } + + View::assign('info', $info); + return View::fetch(); + } + + // 删除 + public function del() + { + $id = input('id'); + $result = WelfareHouseModel::destroy($id); + + if ($result) { + return json(['status' => 1, 'msg' => '删除成功']); + } else { + return json(['status' => 0, 'msg' => '删除失败']); + } + } + + // 修改状态 + public function status() + { + $id = input('id'); + $status = input('status'); + + $result = WelfareHouseModel::where('id', $id)->update(['status' => $status]); + + if ($result) { + return json(['status' => 1, 'msg' => '操作成功']); + } else { + return json(['status' => 0, 'msg' => '操作失败']); + } + } +} \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index f7dfe53..dd1ad6f 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -333,4 +333,13 @@ Route::post('goodstype/add', 'GoodsType/add'); Route::rule('goodstype/edit', 'GoodsType/edit', 'GET|POST'); Route::post('goodstype/delete', 'GoodsType/delete'); Route::post('goodstype/status', 'GoodsType/status'); -Route::get('goodstype/getTypeList', 'GoodsType/getTypeList'); \ No newline at end of file +Route::get('goodstype/getTypeList', 'GoodsType/getTypeList'); + +#============================ +#WelfareHouse.php福利屋管理 +#============================ +Route::rule('welfare_house', 'WelfareHouse/index', 'GET|POST'); +Route::rule('welfare_house_add', 'WelfareHouse/add', 'GET|POST'); +Route::rule('welfare_house_edit', 'WelfareHouse/edit', 'GET|POST'); +Route::rule('welfare_house_del', 'WelfareHouse/del', 'POST'); +Route::rule('welfare_house_status', 'WelfareHouse/status', 'POST'); \ No newline at end of file diff --git a/app/admin/view/public/footer.html b/app/admin/view/public/footer.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/app/admin/view/public/footer.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/admin/view/public/header.html b/app/admin/view/public/header.html new file mode 100644 index 0000000..f677c2f --- /dev/null +++ b/app/admin/view/public/header.html @@ -0,0 +1,57 @@ + + + + + 后台管理 -{$config.title} + + + + + + + + +
+
+
+ + + +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/public/header2.html b/app/admin/view/public/header2.html new file mode 100644 index 0000000..4fcd896 --- /dev/null +++ b/app/admin/view/public/header2.html @@ -0,0 +1,18 @@ + + + + + 后台管理 - {$config.title} + + + + + + + + + \ No newline at end of file diff --git a/app/admin/view/welfare_house/add.html b/app/admin/view/welfare_house/add.html new file mode 100644 index 0000000..3bab475 --- /dev/null +++ b/app/admin/view/welfare_house/add.html @@ -0,0 +1,104 @@ +{include file="Public:header2"/} +
+
+
+
+
添加福利屋
+
+
+
+ +
+ +
+
+
+ +
+ + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+
+
+{include file="Public:footer"/} + diff --git a/app/admin/view/welfare_house/edit.html b/app/admin/view/welfare_house/edit.html new file mode 100644 index 0000000..5f395c2 --- /dev/null +++ b/app/admin/view/welfare_house/edit.html @@ -0,0 +1,105 @@ +{include file="Public:header2"/} +
+
+
+
+
编辑福利屋
+
+
+ +
+ +
+ +
+
+
+ +
+ + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+
+
+{include file="Public:footer"/} + diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index c71245a..2130b82 100755 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -43,10 +43,10 @@ class Notify extends Base // 获取微信支付配置 $wxpayConfig = \app\common\helper\WxPayHelper::getWxPayConfig(); $merchant = $wxpayConfig['merchant']; - + // 使用随机商户的密钥 static::$secretKey = $merchant['keys']; - + // 获取公众号密钥 static::$secretKeyAccount = getConfig('wechatofficialaccount')['keys']; } @@ -1186,21 +1186,41 @@ class Notify extends Base ->where($where) ->select()->toArray(); if ($goodslist) { - #组合中奖商品 - $all_goods_id = []; - foreach ($goodslist as $value) { - $real_pro = $value['real_pro'] * 10000; - for ($i = 1; $i <= $real_pro; $i++) { - $all_goods_id[] = $value['id']; - } + + // 计算总概率 + $totalProbability = array_sum(array_column($goodslist, 'real_pro')); + + // 构建概率区间 + $probabilityRanges = []; + $currentRange = 0; + foreach ($goodslist as $good) { + $rangeStart = $currentRange; + $currentRange += $good['real_pro']; + $probabilityRanges[] = [ + 'id' => $good['id'], + 'start' => $rangeStart, + 'end' => $currentRange + ]; } for ($i = 0; $i < $prize_num; $i++) { - #随机打乱 - shuffle($all_goods_id); - shuffle($all_goods_id); - $prize_id = $all_goods_id[0]; + // 生成随机数 (保持与原始方法相同的精度:100000) + + $maxRand = (int) ($totalProbability * 100000); + $random = mt_rand(0, $maxRand) / 100000; + + // 查找中奖奖品 + $prize_id = null; + foreach ($probabilityRanges as $range) { + if ($random >= $range['start'] && $random < $range['end']) { + $prize_id = $range['id']; + break; + } + } + + // 获取奖品信息 $prize_info = GoodsList::where(['id' => $prize_id])->find(); + #编号 $luck_no = OrderList::field('id') ->where('goods_id', '=', $goods_id) @@ -1209,6 +1229,7 @@ class Notify extends Base ->order('id desc') ->value('luck_no'); $luck_no++; + #新增记录 $save_prize_info = [ 'order_id' => $order_id, @@ -1229,10 +1250,12 @@ class Notify extends Base 'order_type' => $order_type, 'luck_no' => $luck_no, ]; + #入库=== $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(); @@ -1960,7 +1983,7 @@ class Notify extends Base { //微信官方发货 $wxServer = new \app\common\server\Wx($this->app); - + $access_token = $wxServer->get_access_token(); $open_id = Db::name('user')->where('id', $user_id)->value('openid'); $wxServer->post_order($open_id, $access_token, $order_num); diff --git a/app/api/controller/WelfareHouse.php b/app/api/controller/WelfareHouse.php new file mode 100644 index 0000000..f12ecb8 --- /dev/null +++ b/app/api/controller/WelfareHouse.php @@ -0,0 +1,19 @@ +order('sort asc, id desc') + ->select() + ->toArray(); + + return json(['status' => 1, 'msg' => '获取成功', 'data' => $list]); + } +} \ No newline at end of file diff --git a/app/api/route/app.php b/app/api/route/app.php index 25bca7e..e3af10a 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -169,4 +169,9 @@ Route::any('mall_orderbuy', 'Mall/mall_orderbuy'); Route::rule('goods/receive_sync', 'Goods/receive_sync', 'POST'); // 配置信息接口 -Route::rule('config', 'Config/index', 'GET'); \ No newline at end of file +Route::rule('config', 'Config/index', 'GET'); + +#============================ +#WelfareHouse.php福利屋 +#============================ +Route::any('welfare_house_list', 'WelfareHouse/getList'); \ No newline at end of file diff --git a/app/common/model/WelfareHouse.php b/app/common/model/WelfareHouse.php new file mode 100644 index 0000000..da460ac --- /dev/null +++ b/app/common/model/WelfareHouse.php @@ -0,0 +1,26 @@ + '禁用', 1 => '启用']; + return $status[$data['status']]; + } + + // 图片获取器 + public function getImageAttr($value) + { + return imageUrl($value); + } +} \ No newline at end of file diff --git a/config/menu.php b/config/menu.php index 33e49d3..929f3a8 100755 --- a/config/menu.php +++ b/config/menu.php @@ -180,6 +180,10 @@ return [ 'url' => '/admin/advert', 'name' => '图片管理', ], + [ + 'url' => '/admin/welfare_house', + 'name' => '福利屋管理', + ], ], ], [ diff --git a/public/storage/poster/share/6157.png b/public/storage/poster/share/6157.png new file mode 100644 index 0000000..c3f70ed Binary files /dev/null and b/public/storage/poster/share/6157.png differ