game2006api/webapp/services/ChipPageService.php
2023-06-02 16:11:14 +08:00

88 lines
2.3 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){
// for ($i=0;$i<self::INIT_CHIP_PAGE_NUM;$i++){
// ChipPage::addChipPage();
// }
// }
if ($rows){
foreach ($rows as $row){
$this->refreshSlotState($row);
}
}
}
public function refreshSlotState($row){
$data = emptyReplace(json_decode($row['data'], true), array());
$userInfo = myself()->_getOrmUserInfo();
$starMeta = \mt\StarLevel::getCurrent($userInfo['star_num']);
if ($starMeta['unlock_chip_slot']){
foreach ($data as &$val){
if ($starMeta['unlock_chip_slot'] < $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),
)
);
}
// foreach ($data as &$val){
// if ($userInfo['level'] < $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),
// )
// );
}
}