94 lines
2.1 KiB
PHP
94 lines
2.1 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 StoreItem extends Model
|
|
{
|
|
public $id;
|
|
public $name;
|
|
public $gold;
|
|
public $gem;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id', 'default', 'value' => 0],
|
|
['id', 'number', 'integerOnly' => true],
|
|
|
|
['name', 'default', 'value' => ''],
|
|
|
|
['gold', 'default', 'value' => 0],
|
|
['gold', 'number', 'integerOnly' => true],
|
|
|
|
['gem', 'default', 'value' => 0],
|
|
['gem', 'number', 'integerOnly' => true],
|
|
];
|
|
}
|
|
|
|
public static function findAllByConfig()
|
|
{
|
|
$list = [];
|
|
$configList = GameConfigServices::getParamByPath('store_list');
|
|
foreach ($configList as $configItem) {
|
|
$item = new StoreItem();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->gold = $configItem['gold'];
|
|
$item->gem = $configItem['gem'];
|
|
|
|
$item->name = GameConfigServices::getParamByPath(sprintf('item_list.%s.name', $configItem['item_id']));
|
|
|
|
array_push($list, $item);
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
public static function findConfigByID($id)
|
|
{
|
|
$configItem = GameConfigServices::getParamByPath('store_list.' . $id);
|
|
|
|
$item = new StoreItem();
|
|
|
|
$item->id = $configItem['id'];
|
|
$item->gold = $configItem['gold'];
|
|
$item->gem = $configItem['gem'];
|
|
|
|
$item->name = GameConfigServices::getParamByPath(sprintf('item_list.%s.name', $configItem['item_id']));
|
|
|
|
return $item;
|
|
}
|
|
|
|
public function saveConfig()
|
|
{
|
|
$config = GameConfigServices::getGameConfig();
|
|
|
|
$config['store_list'][$this->id]['gold'] = $this->gold;
|
|
$config['store_list'][$this->id]['gem'] = $this->gem;
|
|
|
|
return GameConfigServices::saveGameConfig($config);
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'id',
|
|
'name' => '名称',
|
|
'gold' => '金币',
|
|
'gem' => '钻石',
|
|
];
|
|
}
|
|
} |