一键添加
This commit is contained in:
parent
1c38233e4e
commit
9ed05aa0a3
16
doc/Chip.py
16
doc/Chip.py
@ -178,6 +178,22 @@ class Chip(object):
|
|||||||
'response': [
|
'response': [
|
||||||
_common.RspHead(),
|
_common.RspHead(),
|
||||||
]
|
]
|
||||||
|
},{
|
||||||
|
'name': 'aKeySynthetic',
|
||||||
|
'desc': '芯片合成一键添加',
|
||||||
|
'group': 'Chip',
|
||||||
|
'url': 'webapp/index.php?c=Chip&a=aKeySynthetic',
|
||||||
|
'params': [
|
||||||
|
_common.ReqHead(),
|
||||||
|
['token_id', '', '源芯片token id'],
|
||||||
|
],
|
||||||
|
'response': [
|
||||||
|
_common.RspHead(),
|
||||||
|
['!data', [
|
||||||
|
['cost', '', '所添加芯片的总累计价值'],
|
||||||
|
['token_ids', '', '芯片token id 例如:token_id1 token_id2 token_id3'],
|
||||||
|
], '芯片信息']
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class ChipController extends BaseAuthedController
|
|||||||
$chipList = Chip::all($type);
|
$chipList = Chip::all($type);
|
||||||
$chipDtoList = array();
|
$chipDtoList = array();
|
||||||
foreach ($chipList as $item) {
|
foreach ($chipList as $item) {
|
||||||
if ($item['supper_state']==0 && $item['inlay_state']==0){
|
if ($item['supper_state']==0 && $item['inlay_state']==0 && $item['state']==0){
|
||||||
array_push($chipDtoList, Chip::toDto($item));
|
array_push($chipDtoList, Chip::toDto($item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ class ChipController extends BaseAuthedController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$chip_main = Chip::getChipByTokenId($token_id_main);
|
$chip_main = Chip::getChipByTokenId($token_id_main);
|
||||||
$upgrade_cost = \services\FormulaService::getChipUpgradeCost($chip_main['chip_grade']+1);
|
$upgrade_cost = \services\FormulaService::getChipUpgradeCost($chip_main['chip_grade']+1);
|
||||||
if ($upgrade_cost==0){
|
if ($upgrade_cost==0){
|
||||||
$this->_rspErr(1, 'Error in calculation formula');
|
$this->_rspErr(1, 'Error in calculation formula');
|
||||||
return;
|
return;
|
||||||
@ -296,11 +296,76 @@ class ChipController extends BaseAuthedController
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function aKeySynthetic(){
|
public function aKeySynthetic(){
|
||||||
|
$token_id = trim(getReqVal('token_id', 0));
|
||||||
|
if (! $token_id) {
|
||||||
|
$this->_rspErr(1, 'Please enter instructions');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$chip = Chip::getChipByTokenId($token_id);
|
||||||
|
$upgrade_cost =\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1); //芯片升星价值
|
||||||
|
|
||||||
|
$chipList = Chip::all(1);
|
||||||
|
$chipDtoList = array();
|
||||||
|
foreach ($chipList as $item) {
|
||||||
|
if ($item['supper_state']==0 && $item['inlay_state']==0 && $item['state']==0 && $item['token_id'] != $token_id && $item['chip_grade'] <= $chip['chip_grade']){
|
||||||
|
array_push($chipDtoList, $item);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$data = $this->_orderByChip($chipDtoList,'asc');
|
||||||
|
$chip_param = [];
|
||||||
|
$chip_param_out = [];
|
||||||
|
if (count($data) > 20) {
|
||||||
|
$cost = 0;
|
||||||
|
for ($i=0;$i<count($data);$i++){
|
||||||
|
$data[$i]['cost'] = \services\FormulaService::getChipCumulativeCost($data[$i]['chip_grade']);
|
||||||
|
if ($i<20){
|
||||||
|
$cost += $data[$i]['cost'];
|
||||||
|
array_push($chip_param,$data[$i]);
|
||||||
|
}else{
|
||||||
|
array_push($chip_param_out,$data[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($cost>$upgrade_cost){
|
||||||
|
$diff_cost = $cost - $upgrade_cost;
|
||||||
|
foreach ($chip_param as $k=>$value){
|
||||||
|
if ($diff_cost>$value['cost']){
|
||||||
|
$diff_cost -= $value['cost'];
|
||||||
|
unset($chip_param[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$chip_param = $this->_bestFun($upgrade_cost,$chip_param,$chip_param_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$cost = 0;
|
||||||
|
foreach ($data as $k=>$val){
|
||||||
|
$data[$k]['cost'] = \services\FormulaService::getChipCumulativeCost($data[$k]['chip_grade']);
|
||||||
|
$cost += $data[$k]['cost'];
|
||||||
|
}
|
||||||
|
if ($cost > $upgrade_cost){
|
||||||
|
$diff_cost = $cost - $upgrade_cost;
|
||||||
|
foreach ($data as $k=>$value){
|
||||||
|
if ($diff_cost>$value['cost']){
|
||||||
|
$diff_cost -= $value['cost'];
|
||||||
|
unset($data[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$chip_param = $data;
|
||||||
|
}
|
||||||
|
$cumulative_cost = 0;
|
||||||
|
$token_id_arr = [];
|
||||||
|
foreach ($chip_param as $value){
|
||||||
|
$cumulative_cost += $value['cost'];
|
||||||
|
array_push($token_id_arr,$value['token_id']);
|
||||||
|
}
|
||||||
|
$this->_rspData(['data'=>['cost'=>$cumulative_cost,'token_ids'=>implode(' ',$token_id_arr)]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function test(){
|
public function test(){
|
||||||
$chip = Chip::getChipByTokenId(1660629357);
|
$chip = Chip::getChipByTokenId(1660629357);
|
||||||
print_r($chip);
|
print_r($chip);
|
||||||
@ -461,4 +526,18 @@ class ChipController extends BaseAuthedController
|
|||||||
Chip::update($chip['token_id'],['lucky_temporary'=>$lucky_pro-$lucky, 'chip_grade'=>$new_grade]);
|
Chip::update($chip['token_id'],['lucky_temporary'=>$lucky_pro-$lucky, 'chip_grade'=>$new_grade]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _bestFun($upgrade_cost,$chip_param,$chip_param_out){
|
||||||
|
$cost = 0;
|
||||||
|
foreach ($chip_param as $v){
|
||||||
|
$cost += $v['cost'];
|
||||||
|
};
|
||||||
|
if ($cost>$upgrade_cost){
|
||||||
|
return $chip_param;
|
||||||
|
}else{
|
||||||
|
array_shift($chip_param);
|
||||||
|
array_push($chip_param,array_shift($chip_param_out));
|
||||||
|
return $this->_bestFun($upgrade_cost,$chip_param,$chip_param_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -103,7 +103,7 @@ class Chip extends BaseModel
|
|||||||
|
|
||||||
public static function internalAddItem($conn, $itemId, $itemNum, $accountId, $tokenId)
|
public static function internalAddItem($conn, $itemId, $itemNum, $accountId, $tokenId)
|
||||||
{
|
{
|
||||||
$grade = rand(1,15);//随机一个等级
|
$grade = rand(1,4);//随机一个等级
|
||||||
if (myself()->_isVirtualItem($itemId)) {
|
if (myself()->_isVirtualItem($itemId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user