game2006api/webapp/services/ChipPageService.php
hujiabin c3ffbb68bd 1
2023-07-07 13:30:10 +08:00

62 lines
1.6 KiB
PHP

<?php
namespace services;
require_once('models/ChipPage.php');
require_once('mt/StarLevel.php');
use models\ChipPage;
use phpcommon\SqlHelper;
class ChipPageService extends BaseService
{
const MAX_CHIP_SLOT_NUM = 30;
const INIT_CHIP_PAGE_NUM = 3;
public function init(){
$count = ChipPage::getCount();
if (!$count){
for ($i=0;$i<self::INIT_CHIP_PAGE_NUM;$i++){
ChipPage::addChipPage();
}
}
}
public function initChipPage(){
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_chip_page',
array(
'account_id'=> myself()->_getAccountId()
)
);
if ($rows){
foreach ($rows as $row){
$this->refreshSlotState($row);
}
}
}
public function refreshSlotState($row){
$data = emptyReplace(json_decode($row['data'], true), array());
$userInfo = myself()->_getOrmUserInfo();
$maxSlot = \mt\StarLevel::getMaxSlot($userInfo['star_num']);
foreach ($data as &$val){
if ($maxSlot < $val['slot_id'] && $val['state'] == 0){
$val['state'] = 0;
}else{
$val['state'] = 1;
}
}
SqlHelper::update(
myself()->_getSelfMysql(),
't_chip_page',
array(
'idx' => $row['idx']
),
array(
'data' => json_encode($data),
)
);
}
}