diff --git a/app/model/Zone.php b/app/model/Zone.php new file mode 100644 index 0000000..516399c --- /dev/null +++ b/app/model/Zone.php @@ -0,0 +1,18 @@ +select(); + return $zone->toArray(); + } + + + + +} \ No newline at end of file diff --git a/app/model/ZoneAmountParam.php b/app/model/ZoneAmountParam.php new file mode 100644 index 0000000..a13a20d --- /dev/null +++ b/app/model/ZoneAmountParam.php @@ -0,0 +1,50 @@ +select()->toArray(); + } + + $totalWeight = 0; + foreach ($data as $pattern) { + $totalWeight += $pattern['weight']; + } + + // 随机金额 + $amount = '0.00'; + + // 生成随机数 + $randomNumber = rand(1, $totalWeight); + + foreach ($data as $pattern) { + $randomNumber -= $pattern['weight']; + if ($randomNumber <= 0) { + $amount = $pattern['amount']; + break; + } + } + + return [ + 'data' => $data, + 'amount' => $amount + ]; + } + +} \ No newline at end of file diff --git a/app/model/ZoneGoods.php b/app/model/ZoneGoods.php new file mode 100644 index 0000000..72fffe9 --- /dev/null +++ b/app/model/ZoneGoods.php @@ -0,0 +1,21 @@ + 1]; + if (isset($param['zone_id'])) $where['zone_id'] = $param['zone_id']; + $field = 'zone_id,title,important,price,cover_image'; + $list = self::where($where)->field($field)->order('id desc')->select()->toArray(); + foreach ($list as &$item) { + $item['cover_image'] = get_image_url($item['cover_image']); + } + return $list; + } + +} \ No newline at end of file diff --git a/app/model/ZoneGoodsParam.php b/app/model/ZoneGoodsParam.php new file mode 100644 index 0000000..651e8c9 --- /dev/null +++ b/app/model/ZoneGoodsParam.php @@ -0,0 +1,47 @@ +field('amount,image,probability,awards')->select()->toArray(); + + $ZoneAmountParam = []; + foreach ($list as &$item) { + + $item['image'] = get_image_url($item['image']); + if ($item['awards'] != 1) { + # 获取无奖项随机金额 + $item['amount'] = ZoneAmountParam::getRandAmount($ZoneAmountParam); + $ZoneAmountParam = $item['data']; + } + } + return $list; + } + + /** + * 获取中奖金额 + * @author whj + * @date 2023-08-28 17:50 + */ + public static function getAwardsAmount($id) + { + $data = self::where(['id' => $id,'awards' => 1])->field('amount')->find(); + return $data ?: false; + } + +} \ No newline at end of file