153 lines
4.5 KiB
PHP
153 lines
4.5 KiB
PHP
<?php
|
|
|
|
|
|
namespace models;
|
|
require_once('models/Chip.php');
|
|
require_once('mt/ChipAttr.php');
|
|
require_once('services/ChipPageService.php');
|
|
|
|
use mt\ChipAttr;
|
|
use phpcommon\SqlHelper;
|
|
use services\ChipPageService;
|
|
|
|
class ChipPage extends BaseModel
|
|
{
|
|
|
|
public static function find($hero_unnid){
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_chip_page',
|
|
array(
|
|
'hero_uniid' => $hero_unnid
|
|
)
|
|
);
|
|
return $row;
|
|
}
|
|
|
|
|
|
public static function toDtoInfo($row){
|
|
$data = emptyReplace(json_decode($row['data'], true), array());
|
|
foreach ($data as &$value){
|
|
$chipDb = Chip::find($value['chip_id']);
|
|
if ( !$chipDb ) {
|
|
$value['chip_id'] = 0;
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
}
|
|
}
|
|
self::update($row['hero_uniid'],array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newRow = self::find($row['hero_uniid']);
|
|
$newData = emptyReplace(json_decode($newRow['data'], true), array());
|
|
$attrs = array();
|
|
foreach ($newData as $key=>$value){
|
|
$newData[$key]['item_id'] = 0;
|
|
if ($value['chip_id']){
|
|
$chipDb = Chip::find($value['chip_id']);
|
|
$newData[$key]['item_id'] = $chipDb['item_id'];
|
|
$rand_attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array());
|
|
foreach ($rand_attr as $val){
|
|
array_push($attrs,$val);
|
|
}
|
|
}
|
|
}
|
|
$item = [];
|
|
foreach ($attrs as $k=>$v){
|
|
if (!isset($item[$v['attr_id']])){
|
|
$item[$v['attr_id']] = $v;
|
|
}else{
|
|
$item[$v['attr_id']]['val']+= $v['val'];
|
|
}
|
|
}
|
|
$info = array(
|
|
'idx' => $newRow['idx'],
|
|
'hero_uniid' => $newRow['hero_uniid'],
|
|
'data' => $newData,
|
|
'attr' => $item
|
|
);
|
|
return $info;
|
|
}
|
|
|
|
public static function toDtoBattle($row){
|
|
$data = emptyReplace(json_decode($row['data'], true), array());
|
|
foreach ($data as &$value){
|
|
$chipDb = Chip::find($value['chip_id']);
|
|
if ( !$chipDb ) {
|
|
$value['chip_id'] = 0;
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
}
|
|
}
|
|
self::update($row['hero_uniid'],array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newRow = self::find($row['hero_uniid']);
|
|
$newData = emptyReplace(json_decode($newRow['data'], true), array());
|
|
$attrs = array();
|
|
foreach ($newData as $key=>$value){
|
|
if ($value['chip_id']){
|
|
$chipDb = Chip::find($value['chip_id']);
|
|
$rand_attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array());
|
|
foreach ($rand_attr as $val){
|
|
array_push($attrs,$val);
|
|
}
|
|
}
|
|
}
|
|
$item = [];
|
|
foreach ($attrs as $k=>$v){
|
|
if (!isset($item[$v['attr_id']])){
|
|
$item[$v['attr_id']] = $v;
|
|
}else{
|
|
$item[$v['attr_id']]['val']+= $v['val'];
|
|
}
|
|
}
|
|
return $item;
|
|
}
|
|
|
|
public static function update($hero_uniid,$fieldsKv){
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_chip_page',
|
|
array(
|
|
'hero_uniid'=> $hero_uniid,
|
|
),
|
|
$fieldsKv
|
|
);
|
|
}
|
|
|
|
public static function addChipPage($hero_uniid){
|
|
$data = array();
|
|
for ($i=1;$i <= ChipPageService::MAX_CHIP_SLOT_NUM;$i++){
|
|
array_push(
|
|
$data,
|
|
array(
|
|
'slot_id'=>$i,
|
|
'state'=>0,
|
|
'chip_id'=>0,
|
|
)
|
|
);
|
|
}
|
|
|
|
$info = array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'hero_uniid' => $hero_uniid,
|
|
'data' => json_encode($data),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
);
|
|
// SqlHelper::insert(
|
|
// myself()->_getSelfMysql(),
|
|
// 't_chip_page',
|
|
// $info
|
|
// );
|
|
SqlHelper::upsert
|
|
(myself()->_getSelfMysql(),
|
|
't_chip_page',
|
|
array(
|
|
'hero_uniid' => $hero_uniid,
|
|
),
|
|
array(),
|
|
$info
|
|
);
|
|
}
|
|
|
|
} |