Merge branch 'hjb' of git.kingsome.cn:server/game2006api into hjb

This commit is contained in:
hujiabin 2024-08-01 15:49:25 +08:00
commit 68ad3df9f5
9 changed files with 434 additions and 13 deletions

View File

@ -5,19 +5,23 @@ class AAGameLog(object):
def __init__(self):
self.apis = [
{
'method': 'POST',
'name': 'customReport',
'desc': '上报自定义日志',
'desc': '上报自定义日志(httpbody自定义)',
'group': '!AAGameLog',
'url': 'https://gamelog-test.kingsome.cn/webapp/index.php?c=GameLog&a=customReport',
'params': [
'is_json_params': True,
'request_params': [
_common.ReqHead(),
['gameid', '', '游戏id'],
['channel', '', '渠道编号'],
['event_name', '', '事件名'],
['account_id', '', '账号Id'],
['session_id', '', '会话id'],
['account_id', '', '[可选]账号id(web端不要传该字段)'],
['session_id', '', '[可选]会话id(web端不要传该字段)'],
['localuuid', '', '本地唯一Id'],
],
'params': [
],
'response': [
_common.RspHead(),
]

View File

@ -418,16 +418,15 @@ class AAMarket(object):
},
{
'method': 'POST',
'name': '/api/recharge/history',
'name': '/api/recharge/history/:net_id/:account_address',
'desc': '充值-历史',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/recharge/history',
'url': 'https://market-test.kingsome.cn/api/recharge/history/:net_id/:account_address',
'headers': _common.JwtHeader,
'is_json_params': True,
'request_params': [
],
'params': [
['net_id', 0, '链id'],
],
'response': [
_common.RspHead(),

54
doc/Bigwheel.py Normal file
View File

@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
import _common
class Bigwheel(object):
def __init__(self):
self.apis = [
{
'name': 'info',
'desc': '转盘信息',
'group': 'Bigwheel',
'url': 'webapp/index.php?c=Bigwheel&a=info',
'params': [
_common.ReqHead(),
],
'response': [
_common.RspHead(),
['info', _common.BigwheelInfo(), '转盘信息'],
]
},
{
'name': 'drawS',
'desc': '抽奖',
'group': 'Bigwheel',
'url': 'webapp/index.php?c=Bigwheel&a=drawS',
'params': [
_common.ReqHead(),
['type', 0, '0:双勾选 1:第1档 2:第2档']
],
'response': [
_common.RspHead(),
['award', _common.Award(), '奖励信息'],
['property_chg', _common.PropertyChg(), '属性变更'],
['info', _common.BigwheelInfo(), '转盘信息'],
]
},
{
'name': 'buyS',
'desc': '购买',
'group': 'Bigwheel',
'url': 'webapp/index.php?c=Bigwheel&a=buyS',
'params': [
_common.ReqHead(),
['grid_id', 0, '格子id']
],
'response': [
_common.RspHead(),
['award', _common.Award(), '奖励信息'],
['property_chg', _common.PropertyChg(), '属性变更'],
['info', _common.BigwheelInfo(), '转盘信息'],
]
}
]

View File

@ -1845,3 +1845,26 @@ class RechargeHistory(object):
['amount', '', '货币数'],
['createtime', 0, '成交时间'],
]
class BigwheelGrid(object):
def __init__(self):
self.fields = [
['grid_id', 0, '格子id(Bigwheel表里的id字段)'],
['grid_state', 0, '0:未抽 1:已抽到且商品属于你 2:已抽到且商品还未属于你(需要购买)'],
['item_id', 0, '道具id(state>0时有效)'],
['item_num', 0, '道具数量(state>0时有效)'],
['buy_price', 0, '购买价格(state=2时有效)'],
]
class BigwheelInfo(object):
def __init__(self):
self.fields = [
['drawed_times', 0, '已抽次数'],
['total_times', 0, '总次数'],
['single_cost', 0, '单次抽奖消耗(钻石)'],
['double_cost', 0, '双次抽奖消耗(钻石)'],
['!items1', [BigwheelGrid()], '档位1'],
['!items2', [BigwheelGrid()], '档位2'],
]

View File

@ -1948,3 +1948,22 @@ CREATE TABLE `t_box_alloc` (
KEY `idx_createtime` (`createtime`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_middata`
--
DROP TABLE IF EXISTS `t_middata`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_middata` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id',
`type` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'type',
`data` text COMMENT 'data',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `account_id_type` (`account_id`, `type`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -10,7 +10,7 @@ class BaseController {
private $relationDbConn = null;
private $mailDbConn = null;
private $timeOffset = 0;
private $serviceHash = array();
private $moduleHash = array();
function __construct()
{
@ -276,17 +276,61 @@ class BaseController {
return $channel == "0000";
}
public function _getServiceConstant($serviceName, $name)
{
return $this->_internalGetModuleConstant('services', $serviceName, $name);
}
public function _callServiceStatic($serviceName, $funcName, ...$args)
{
if (!array_key_exists($serviceName, $this->serviceHash)) {
require_once('services/' . $serviceName . '.php');
$this->serviceHash[$serviceName] = $this->_getNowTime();
}
$method = new ReflectionMethod('services\\' . $serviceName, $funcName);
return $this->_internalCallModuleStatic('services', $serviceName, $funcName, ... $args);
}
public function _getModelConstant($modelName, $name)
{
return $this->_internalGetModuleConstant('models', $modelName, $name);
}
public function _callModelStatic($modelName, $funcName, ...$args)
{
return $this->_internalCallModuleStatic('models', $modelName, $funcName, ... $args);
}
public function _getMtConstant($modelName, $name)
{
return $this->_internalGetModuleConstant('mt', $modelName, $name);
}
public function _callMtStatic($modelName, $funcName, ...$args)
{
return $this->_internalCallModuleStatic('mt', $modelName, $funcName, ... $args);
}
private function _internalGetModuleConstant($dir, $moduleName, $name)
{
$fullName = $dir . '\\' . $moduleName;
$this->_internalMustBeLoadModule($fullName);
$reflectionConstant = new ReflectionClassConstant($fullName, $name);
return $reflectionConstant->getValue();;
}
private function _internalCallModuleStatic($dir, $moduleName, $funcName, ...$args)
{
$fullName = $dir . '\\' . $moduleName;
$this->_internalMustBeLoadModule($fullName);
$method = new ReflectionMethod($fullName, $funcName);
$ret = $method->invoke(null, ...$args);
return $ret;
}
private function _internalMustBeLoadModule($fullName)
{
if (!array_key_exists($fullName, $this->moduleHash)) {
require_once(str_replace('\\', '/', $fullName) . '.php');
$this->moduleHash[$fullName] = $this->_getNowTime();
}
}
public function _getGameId() {
return 2006;
}

View File

@ -0,0 +1,196 @@
<?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,
"draw_times": 1,
}
}
*/
class BigwheelController extends BaseAuthedController {
const MAX_DRAW_TIMES = 9;
public function info()
{
$key = $this->getMidDataKey();
$data = $this->getAndCreateData($key);
$priceInfo = $this->getPriceInfo($data['drawed_times']);
if (empty($priceInfo)) {
myself()->_rspErr(500, 'server internal error');
return;
}
$info = array();
$this->fillInfo($info, $data, $priceInfo);
myself()->_rspData(array(
'info' => $info
));
}
public function drawS()
{
$drawType = getReqVal('type', 0);
if (!($drawType == 0 || $drawType == 1 || $drawType == 2)) {
myself()->_rspErr(2, 'type param error');
return;
}
$key = $this->getMidDataKey();
$data = $this->getAndCreateData($key);
if ($data['drawed_times'] >= self::MAX_DRAW_TIMES) {
myself()->_rspErr(1, 'The maximum number of lucky draws has been reached');
return;
}
$priceInfo = $this->getPriceInfo($data['drawed_times']);
if (empty($priceInfo)) {
myself()->_rspErr(500, 'server internal error');
return;
}
if ($priceInfo['cost_item_id'] != V_ITEM_DIAMOND) {
myself()->_rspErr(500, 'server internal error');
return;
}
$costItemNum = 0;
if ($drawType == 0) {
$costItemNum = $priceInfo['price_double'] * $priceInfo['discount_double'];
if (empty($costItemNum)) {
myself()->_rspErr(3, 'config error');
return;
}
} else if ($drawType == 1 || $drawType == 2) {
$costItemNum = $priceInfo['price_single'] * $priceInfo['discount_single'];
if (empty($costItemNum)) {
myself()->_rspErr(3, 'config error');
return;
}
} else {
myself()->_rspErr(2, 'type param error');
return;
}
}
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, $priceInfo)
{
$info = array(
'drawed_times' => $data['drawed_times'],
'total_times' => self::MAX_DRAW_TIMES,
'single_cost' => $priceInfo['price_single'] * $priceInfo['discount_single'],
'double_cost' => $priceInfo['price_double'] * $priceInfo['discount_double'],
'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;
}
}
}
private function getPriceInfo($drawedTimes)
{
$costItem = mt\Parameter::getVal('gacha_cost_item', 0);
$gachaPriceSingles = mt\Parameter::getListValue('gacha_price_single');
$gachaDiscountSingles = mt\Parameter::getListValue('gacha_discount_single');
$gachaPriceDoubles = mt\Parameter::getListValue('gacha_price_double');
$gachaDiscountDoubles = mt\Parameter::getListValue('gacha_discount_double');
$gachaPriceBuys = mt\Parameter::getListValue('gacha_price_buy');
$gachaDiscountBuys = mt\Parameter::getListValue('gacha_discount_buy');
if (count($gachaPriceSingles) != count($gachaDiscountSingles) &&
count($gachaPriceDoubles) != count($gachaDiscountDoubles) &&
count($gachaPriceBuys) != count($gachaDiscountBuys) &&
count($gachaDiscountBuys) != self::MAX_DRAW_TIMES) {
return null;
}
if ($drawedTimes < 0) {
return null;
}
if ($drawedTimes > self::MAX_DRAW_TIMES) {
$drawedTimes = self::MAX_DRAW_TIMES - 1;
}
$priceInfo = array(
'cost_item_id' => $costItem,
'price_single' => $gachaPriceSingles[$drawedTimes],
'discount_single' => $gachaDiscountSingles[$drawedTimes],
'price_double' => $gachaPriceDoubles[$drawedTimes],
'discount_double' => $gachaDiscountSingles[$drawedTimes],
'price_buy' => $gachaPriceBuys[$drawedTimes],
'discount_buy' => $gachaDiscountBuys[$drawedTimes],
);
return $priceInfo;
}
}

49
webapp/models/MidData.php Normal file
View File

@ -0,0 +1,49 @@
<?php
namespace models;
use mt;
use phpcommon\SqlHelper;
class MidData extends BaseModel {
const BIG_WHEEL_TYPE = 'offer.reward.missions';
public static function getData($type)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_middata',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
)
);
return $row ? json_decode($row['data'], true) : null;
}
public static function setData($type, $data)
{
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_middata',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type
),
array(
'data' => $data,
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
'data' => $data,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}

33
webapp/mt/Bigwheel.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace mt;
use phpcommon;
class Bigwheel
{
public static function get($id)
{
return getXVal(self::getMetaList(), $id);
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('Bigwheel@Bigwheel.php');
}
return self::$metaList;
}
public static function traverseMeta($cb)
{
foreach (self::getMetaList() as $meta) {
if (!$cb($meta)) {
break;
}
}
}
protected static $metaList;
}