84 lines
1.8 KiB
PHP
84 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/19
|
|
* Time: 18:49
|
|
*/
|
|
|
|
namespace app\models;
|
|
|
|
|
|
use common\services\GameConfigServices;
|
|
use yii\base\Model;
|
|
|
|
/**
|
|
* 道具
|
|
*/
|
|
class ConfigItem extends Model
|
|
{
|
|
public $id;
|
|
public $name;
|
|
public $sell_gold;//卖出价格
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id', 'default', 'value' => 0],
|
|
['id', 'number', 'integerOnly' => true],
|
|
|
|
['name', 'default', 'value' => ''],
|
|
|
|
['sell_gold', 'default', 'value' => 0],
|
|
['sell_gold', 'number', 'integerOnly' => true],
|
|
];
|
|
}
|
|
|
|
public static function findAllByConfig()
|
|
{
|
|
$list = [];
|
|
$configList = GameConfigServices::getParamByPath('item_list');
|
|
foreach ($configList as $configItem) {
|
|
$item = new ConfigItem();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->name = $configItem['name'];
|
|
$item->sell_gold = $configItem['sell_gold'];
|
|
|
|
array_push($list, $item);
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
public static function findConfigByID($id)
|
|
{
|
|
$configItem = GameConfigServices::getParamByPath('item_list.'.$id);
|
|
|
|
$item = new ConfigItem();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->name = $configItem['name'];
|
|
$item->sell_gold = $configItem['sell_gold'];
|
|
|
|
return $item;
|
|
}
|
|
|
|
public function saveConfig()
|
|
{
|
|
$config = GameConfigServices::getGameConfig();
|
|
|
|
$config['item_list'][$this->id]['sell_gold'] = $this->sell_gold;
|
|
|
|
return GameConfigServices::saveGameConfig($config);
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => '道具ID',
|
|
'name' => '名称',
|
|
'sell_gold' => '玩家卖出价格',
|
|
];
|
|
}
|
|
} |