167 lines
5.1 KiB
PHP
167 lines
5.1 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
require_once('models/ChipPage.php');
|
|
require_once('models/Hero.php');
|
|
require_once('services/ChipPageService.php');
|
|
|
|
use models\Chip;
|
|
use models\ChipPage;
|
|
use models\Hero;
|
|
use services\ChipPageService;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ChipPageController extends BaseAuthedController
|
|
{
|
|
|
|
public function showChipPage(){
|
|
$heroUid = getReqVal('hero_unnid',0);
|
|
$heroDb = Hero::find($heroUid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
if (!$chipPageDb){
|
|
ChipPage::addChipPage($heroUid);
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
}
|
|
$chipPageService = new services\ChipPageService();
|
|
$chipPageService->refreshSlotState($chipPageDb,$heroDb);
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
$chipPageDto = ChipPage::toDtoInfo($chipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
public function useChip(){
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$slotId = getReqVal('slot_id',0);
|
|
$chip_unnid = getReqVal('chip_unnid',0);
|
|
if (!$hero_unnid || !$slotId || !$chip_unnid){
|
|
$this->_rspErr(1, 'Missing parameter');
|
|
return ;
|
|
}
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
if ($slotId > ChipPageService::MAX_CHIP_SLOT_NUM || $slotId < 0 ){
|
|
$this->_rspErr(1,'No card slot exists');
|
|
return ;
|
|
}
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
if ( $data[$slotId-1]['state'] != 1){
|
|
$this->_rspErr(1,'Unlocked state');
|
|
return ;
|
|
}
|
|
$chipDb = Chip::find($chip_unnid);
|
|
if (! $chipDb){
|
|
$this->_rspErr(1, "You don't have the chip yet");
|
|
return;
|
|
}
|
|
|
|
if ($chipDb['inlay_state'] == 1){
|
|
$this->_rspErr(1, "The used chip");
|
|
return;
|
|
}
|
|
switch ($slotId%3){
|
|
case 1 : $type = 1;break;
|
|
case 2 : $type = 2;break;
|
|
case 0 : $type = 3;break;
|
|
default:$type = 0;
|
|
}
|
|
|
|
if ($chipDb['chip_type'] != $type){
|
|
$this->_rspErr(1, "Type mismatch");
|
|
return;
|
|
}
|
|
if ( $data[$slotId-1]['chip_id'] ){
|
|
|
|
Chip::updateInlayState($data[$slotId-1]['chip_id'],0);
|
|
}
|
|
$data[$slotId-1]['chip_id'] = $chip_unnid;
|
|
|
|
Chip::updateInlayState($chip_unnid,1);
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
public function removeChipOne(){
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$slotId = getReqVal('slot_id',0);
|
|
if (!$hero_unnid || !$slotId){
|
|
$this->_rspErr(1, 'Missing parameter');
|
|
return ;
|
|
}
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
foreach ($data as &$value){
|
|
if ($value['slot_id'] == $slotId){
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
$value['chip_id'] = 0;
|
|
}
|
|
}
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
public function removeChipAll(){
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
foreach ($data as &$value){
|
|
if ($value['chip_id']){
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
$value['chip_id'] = 0;
|
|
}
|
|
}
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
|
|
} |