game2006api/webapp/controller/SavingPotController.class.php
2024-10-11 12:05:19 +08:00

144 lines
5.0 KiB
PHP

<?php
require_once('services/PropertyChgService.php');
require_once('services/AwardService.php');
require_once('mt/ServerTaskTime.php');
require_once('mt/Parameter.php');
require_once('mt/RookieTask.php');
require_once('models/Hero.php');
use models\Hero;
use phpcommon\SqlHelper;
class SavingPotController extends BaseAuthedController {
public function info(){
$info = array(
'bind_gold' => $this->_getDailyV(TN_DAILY_BIND_GOLD, 0),
'draw_state' => $this->_getDailyV(TN_DAILY_DRAW_BIND_GOLD_STATE, 0),
'up_times' => $this->_getDailyV(TN_DAILY_TIER_N_HERO_TIMES, 0),
);
$this->_rspData(array(
'data' => $info
));
}
public function smashOpenS(){
$state = $this->_getDailyV(TN_DAILY_DRAW_BIND_GOLD_STATE, 0);
if ($state > 0){
$this->_rspErr(1, "Run out today");
return;
}
$bindGold = $this->_getDailyV(TN_DAILY_BIND_GOLD, 0);
if ($bindGold <= 0){
$this->_rspErr(1, "piggy bank empty");
return;
}
$rateRange = \mt\Parameter::getListValue('saving_withdraw_rate_range',0);
$rate = rand($rateRange[0]*100,$rateRange[1]*100)/100;
$normal = \mt\Parameter::getVal('bind_to_normal',0);
$gold = max(1,floor($bindGold * $rate * $normal));
$items = array(
array(
"item_id" => V_ITEM_GOLD,
"item_num" => $gold,
)
);
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
$this->_addItems($items, $awardService,$propertyChgService);
$this->_setDailyV(TN_DAILY_DRAW_BIND_GOLD_STATE, 0,1);
$this->_setDailyV(TN_DAILY_BIND_GOLD, 0,0);
myself()->_callModelStatic('RookieTask','incTaskVal',mt\RookieTask::PIGGY_BANK_OPEN_TIMES_COND,1);
SqlHelper::insert
(myself()->_getSelfMysql(),
't_user_bind_gold_record',
array(
'account_id' => myself()->_getAccountId(),
'way' => 2,
'amount' => $gold,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
$this->_rspData(array(
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
public function drawGoldS(){
$state = $this->_getDailyV(TN_DAILY_DRAW_BIND_GOLD_STATE, 0);
if ($state > 0){
$this->_rspErr(1, "Run out today");
return;
}
$bindGold = $this->_getDailyV(TN_DAILY_BIND_GOLD, 0);
if ($bindGold <= 0){
$this->_rspErr(1, "piggy bank empty");
return;
}
$upTimes = $this->_getDailyV(TN_DAILY_TIER_N_HERO_TIMES, 0);
if ($upTimes < 1){
$this->_rspErr(1, "No completion condition");
return;
}
$normal = \mt\Parameter::getVal('bind_to_normal',0);
$gold = max(1,floor($bindGold * $normal));
$items = array(
array(
"item_id" => V_ITEM_GOLD,
"item_num" => $gold,
)
);
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
$this->_addItems($items, $awardService,$propertyChgService);
$this->_setDailyV(TN_DAILY_DRAW_BIND_GOLD_STATE, 0,1);
$this->_setDailyV(TN_DAILY_BIND_GOLD, 0,0);
myself()->_callModelStatic('RookieTask','incTaskVal',mt\RookieTask::PIGGY_BANK_DRAW_TIMES_COND,1);
SqlHelper::insert
(myself()->_getSelfMysql(),
't_user_bind_gold_record',
array(
'account_id' => myself()->_getAccountId(),
'way' => 1,
'amount' => $gold,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
$this->_rspData(array(
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
public function getRecord(){
$page = getReqVal('page', 0);
$out = array(
'pagination' => array(),
'rows' => array()
);
SqlHelper::rawQueryPage(
myself()->_getSelfMysql(),
'SELECT * FROM t_user_bind_gold_record where account_id=:account_id',
array(
':account_id' => myself()->_getAccountId()
),
array(
'page' => $page,
'perPage' => 8,
'orderBy' => "ORDER BY createtime DESC",
'handle' => function ($row) use(&$out) {
array_push($out['rows'], $row);
}
),
$out['pagination']
);
myself()->_rspData($out);
}
}