103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/19
|
|
* Time: 18:49
|
|
*/
|
|
|
|
namespace app\models;
|
|
|
|
|
|
use common\services\GameConfigServices;
|
|
use common\utils\EnumUtil;
|
|
use yii\base\Model;
|
|
|
|
/**
|
|
* 转盘抽奖
|
|
*/
|
|
class LotteryDraw extends Model
|
|
{
|
|
public $id;
|
|
public $type;
|
|
public $value;
|
|
public $count;
|
|
public $odds;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id', 'default', 'value' => 0],
|
|
['id', 'number', 'integerOnly' => true],
|
|
|
|
['type', 'default', 'value' => EnumUtil::LOTTERY_TYPE_GOLD],
|
|
['type', 'in', 'range' => EnumUtil::LOTTERY_LIST],
|
|
|
|
['value', 'default', 'value' => 0],
|
|
['value', 'number', 'integerOnly' => true],
|
|
|
|
['count', 'default', 'value' => 1],
|
|
['count', 'number', 'integerOnly' => true],
|
|
|
|
['odds', 'default', 'value' => 1],
|
|
['odds', 'number', 'integerOnly' => true],
|
|
];
|
|
}
|
|
|
|
public static function findAllByConfig()
|
|
{
|
|
$list = [];
|
|
$configList = GameConfigServices::getParamByPath('lottery');
|
|
foreach ($configList as $configItem) {
|
|
$item = new LotteryDraw();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->type = $configItem['type'];
|
|
$item->value = $configItem['value'];
|
|
$item->count = $configItem['count'];
|
|
$item->odds = $configItem['odds'];
|
|
|
|
array_push($list, $item);
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
public static function findConfigByID($id)
|
|
{
|
|
$configItem = GameConfigServices::getParamByPath('lottery.' . $id);
|
|
|
|
$item = new LotteryDraw();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->type = $configItem['type'];
|
|
$item->value = $configItem['value'];
|
|
$item->count = $configItem['count'];
|
|
$item->odds = $configItem['odds'];
|
|
|
|
return $item;
|
|
}
|
|
|
|
public function saveConfig()
|
|
{
|
|
$config = GameConfigServices::getGameConfig();
|
|
|
|
$config['lottery'][$this->id]['type'] = $this->type;
|
|
$config['lottery'][$this->id]['value'] = $this->value;
|
|
$config['lottery'][$this->id]['count'] = $this->count;
|
|
$config['lottery'][$this->id]['odds'] = $this->odds;
|
|
|
|
return GameConfigServices::saveGameConfig($config);
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'id',
|
|
'type' => '类型',
|
|
'value' => '值',
|
|
'count' => '数量',
|
|
'odds' => '相对概率',
|
|
];
|
|
}
|
|
} |