123 lines
2.9 KiB
PHP
123 lines
2.9 KiB
PHP
<?php
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Bigwheel.php');
|
|
|
|
require_once('services/LogService.php');
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use services\LogService;
|
|
|
|
/*
|
|
{
|
|
"grid_list":
|
|
{
|
|
"grid_id": 123,
|
|
"grid_state": 0,
|
|
"item_id": 123,
|
|
"item_num": 314,
|
|
"buy_price": 314
|
|
}
|
|
}
|
|
*/
|
|
|
|
class BigwheelController extends BaseAuthedController {
|
|
|
|
const MAX_DRAW_TIMES = 9;
|
|
|
|
public function info()
|
|
{
|
|
$key = $this->getMidDataKey();
|
|
$data = $this->getAndCreateData($key);
|
|
$info = array();
|
|
$this->fillInfo($info, $data);
|
|
myself()->_rspData(array(
|
|
'info' => $info
|
|
));
|
|
}
|
|
|
|
public function drawS()
|
|
{
|
|
$key = $this->getMidDataKey();
|
|
$data = $this->getAndCreateData($key);
|
|
}
|
|
|
|
public function buyS()
|
|
{
|
|
$key = $this->getMidDataKey();
|
|
$data = $this->getAndCreateData($key);
|
|
}
|
|
|
|
private function getMidDataKey()
|
|
{
|
|
return myself()->_getModelConstant('MidData', 'BIG_WHEEL_TYPE');
|
|
}
|
|
|
|
private function getAndCreateData($key)
|
|
{
|
|
$data = myself()->_callModelStatic('MidData', 'getData', $key);
|
|
if (!empty($data)) {
|
|
$data = json_decode($data, true);
|
|
}
|
|
if (empty($data)) {
|
|
$data = array(
|
|
'drawed_times' => 0,
|
|
"grid_list" => array()
|
|
);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
private function fillInfo(&$info, &$data)
|
|
{
|
|
$info = array(
|
|
'drawed_times' => $data['drawed_times'],
|
|
'total_times' => self::MAX_DRAW_TIMES,
|
|
'single_cost' => 0,
|
|
'double_cost' => 0,
|
|
'items1' => array(),
|
|
'items2' => array(),
|
|
);
|
|
mt\Bigwheel::traverseMeta(
|
|
function ($meta) use(&$data, &$info) {
|
|
$item = array(
|
|
'grid_id' => $meta['id'],
|
|
'grid_state' => 0,
|
|
'item_id' => 0,
|
|
'item_num' => 0,
|
|
'buy_price' => 0,
|
|
);
|
|
$gridRef = null;
|
|
$this->getGridRefByGridId($data, $meta['id'], $girdRef);
|
|
if (!empty($gridRef)) {
|
|
$item = $gridRef;
|
|
}
|
|
switch ($meta['Wheel_type']) {
|
|
case 1:{
|
|
array_push($info['items1'], $item);
|
|
}
|
|
break;
|
|
case 2:{
|
|
array_push($info['items2'], $item);
|
|
}
|
|
break;
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
|
|
private function getGridRefByGridId(&$data, $gridId, &$gridRefOut)
|
|
{
|
|
foreach ($data['grid_list'] as &$grid) {
|
|
if ($grid['grid_id'] == $girdId) {
|
|
$gridRefOut = $grid;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|