刮刮后端接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
class ZoneGoodsParam extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
/**
* 获取刮奖参数
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getList($where = [])
{
$where['status'] = 1;
$list = self::where($where)->field('id,amount,image,probability,awards')->order('probability')->select()->toArray();
$ZoneAmountParam = [];
$sumProbability = 0;
foreach ($list as &$item) {
if ($item['image']) $item['image'] = get_image_url($item['image']);
if ($item['awards'] != 1) {
# 获取无奖项随机金额
$res = ZoneAmountParam::getRandAmount($ZoneAmountParam);
$item['amount'] = $res['amount'];
$ZoneAmountParam = $res['data'];
}
$sumProbability += $item['probability'];
}
# 概率未补全则自动补全 归1
if ($sumProbability < 1 && strpos($sumProbability,'.') !== false) {
for ($i = 1; $i <= 10; $i++) {
$residueProbability = 1 - $sumProbability;
$res = ZoneAmountParam::getRandAmount($ZoneAmountParam);
$list[] = [
'id' => 0,
'amount' => $res['amount'],
'image' => rand_icon('icon',true),
'probability' => $residueProbability / 10,
'awards' => 0
];
}
}
return $list;
}
/**
* 获取中奖金额
*/
public static function getAwardsAmount($id)
{
$data = self::where(['id' => $id,'awards' => 1])->field('amount')->find();
return $data ?: false;
}
}