This commit is contained in:
aozhiwei 2024-08-08 13:46:44 +08:00
parent 861a98d0b9
commit 66c225ab10
8 changed files with 2 additions and 502 deletions

View File

@ -1,71 +0,0 @@
# -*- coding: utf-8 -*-
import _common
class Mall(object):
def __init__(self):
self.apis = [
{
'name': 'productList',
'desc': '商品列表',
'group': 'Mall',
'url': 'webapp/index.php?c=Mall&a=productList',
'params': [
_common.ReqHead(),
['page', 0, '第几页数据'],
['seller', '', '查询指定钱包 为空的化查询所有人'],
['order_method', 0, '排序方式 0:默认排序(当前指向1) 1:上架时间 2:价格'],
['order_asc', 0, '排序方向, 0:从小到大 1:从大到小'],
['price_filter', '', '价格过滤(用|分割)'],
],
'response': [
_common.RspHead(),
['pagination', _common.Pagination(), '分页信息'],
['!rows', [_common.MallGoods()], '商品列表']
]
},
{
'name': 'sell',
'desc': '出售',
'group': 'Mall',
'url': 'webapp/index.php?c=Mall&a=sell',
'params': [
_common.ReqHead(),
['item_id', '', '道具id,目前只能卖CEG'],
['amount', '', '出售数量'],
['currency', '', "选用币种 目前只支持CEG USDC USDT"],
['price', '', '出售价格'],
],
'response': [
_common.RspHead()
]
},
{
'name': 'cancel',
'desc': '下架物品',
'group': 'Mall',
'url': 'webapp/index.php?c=Mall&a=cancel',
'params': [
_common.ReqHead(),
['goods_uuid', '', '商品唯一id'],
],
'response': [
_common.RspHead()
]
},
{
'name': 'modifyPrice',
'desc': '修改价格',
'group': 'Mall',
'url': 'webapp/index.php?c=Mall&a=modifyPrice',
'params':[
_common.ReqHead(),
['goods_uuid', '', '商品唯一id'],
['price', '', '出售价格USDT'],
],
'response': [
_common.RspHead()
]
},
]

View File

@ -39,6 +39,8 @@
* c=Battle 改为 c=BattleData
* 2024/08/06
* 删除 c=Market
* 2024/08/08
* 删除 c=Mall
*
*
*/

View File

@ -1,270 +0,0 @@
<?php
require_once('phpcommon/bignumber.php');
require_once('mt/Item.php');
require_once('mt/Parameter.php');
require_once('models/BcOrder.php');
require_once('models/Mall.php');
require_once('models/OrderId.php');
require_once('services/BlockChainService.php');
require_once('services/LogService.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
use phpcommon\SqlHelper;
use models\BcOrder;
use models\Mall;
use models\OrderId;
use services\LogService;
use services\BlockChainService;
use services\AwardService;
use services\PropertyChgService;
/*
碎片、芯片、宝箱、英雄
*/
class MallController extends BaseAuthedController {
const PRICE_LOW = '1';
const PRICE_HIGH = '111111111111111111111000000000000000000';
public function _handlePre()
{
parent::_handlePre();
$this->priceLowBn = phpcommon\bnInit(self::PRICE_LOW);
$this->priceHighBn = phpcommon\bnInit(self::PRICE_HIGH);
}
public function productList()
{
$page = getReqVal('page', 0);
$seller = getReqVal('seller', '');
$queryData = array();
if (!empty($seller)) {
$queryData['seller'] = $seller;
}
$queryData['price_filter'] = getReqVal('price_filter', '');
$orderBy = '';
$orderAsc = 'ASC';
if (getReqVal('order_asc', '') == 1) {
$orderAsc = 'DESC';
}
switch (getReqVal('order_method', '')) {
case 1:
{
$orderBy = 'ORDER BY createtime ' . $orderAsc;
}
break;
case 2:
{
$orderBy = 'ORDER BY length(price) ' . $orderAsc . ', price ' . $orderAsc;
}
break;
}
$out = array(
'pagination' => array(),
'rows' => array()
);
SqlHelper::rawQueryPage(
myself()->_getMySql(''),
'SELECT * FROM t_mall WHERE status=:status',
array(
':status' => Mall::PENDING_STATE
),
array(
'page' => $page,
'perPage' => 8,
'filter' => array(
'data' => $queryData,
'fields' => array(
array(
'name' => 'seller',
'field_name' => 'seller_address',
'cond' => '=',
'ignore_empty' => true,
),
array(
'name' => 'price_filter',
'field_name' => '',
'cond' => 'custom',
'ignore_empty' => true,
'custom_func' => function () use ($queryData) {
$priceFilters = $queryData['price_filter'];
$arrPriceFilter = explode('|', $priceFilters);
$priceLow = $arrPriceFilter[0];
$priceHigh = $arrPriceFilter[1];
return " AND (length(price) >= length('${priceLow}') AND length(price) <= length('${priceHigh}')) "
. " AND (price >= '${priceLow}' AND price <= '${priceHigh}') ";
}
),
)
),
'orderBy' => $orderBy,
'handle' => function ($row) use(&$out) {
array_push($out['rows'], Mall::toDto($row));
}
),
$out['pagination']
);
myself()->_rspData($out);
}
public function sell()
{
$address = myself()->_getAddress();
if (!$address) {
$this->_rspErr(1, 'address not found');
return;
}
$itemId = getReqVal('item_id', '');
$amount = intval(getReqVal('amount', ''), 10);
$currency = getReqVal('currency', '');
$priceBn = phpcommon\bnInit(getReqVal('price', ''));
if ($itemId != V_ITEM_GOLD) {
$this->_rspErr(1, 'only support gold');
return;
}
if ($amount <= 0) {
$this->_rspErr(1, 'amount must > 0');
return;
}
if (!$this->checkPrice($priceBn)) {
return;
}
if (!in_array(
$currency,
array(
BlockChainService::CURRENCY_CEG,
BlockChainService::CURRENCY_USDC,
BlockChainService::CURRENCY_USDT,
)
)) {
$this->_rspErr(1, 'paramater error currency');
return;
}
$costItems = array(
array(
'item_id' => $itemId,
'item_num' => $amount
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
if ($itemId == V_ITEM_GOLD) {
//埋点
$event = [
'name' => LogService::MARKET_SELL_GOLD,
'val' => $amount
];
LogService::consumeGold($event);
}
$orderId = OrderId::gen();
Mall::Add(
$orderId,
$orderId,
$itemId,
$amount,
$currency,
phpcommon\bnToStr($priceBn)
);
myself()->_rspOk();
}
public function cancel()
{
$goodsUuid = getReqVal('goods_uuid', '');
$goodsDb = Mall::findByGoodsUuid($goodsUuid);
if (!$goodsDb) {
myself()->_rspErr(1, 'goods not found');
return;
}
$goodsDto = Mall::toDto($goodsDb);
if ($goodsDto['cancel_countdown'] != 0) {
myself()->_rspErr(1, 'cant cancel');
return;
}
$awardService = new AwardService();
$propertyChgService = new PropertyChgService();
switch ($goodsDb['item_id']) {
case V_ITEM_GOLD:
{
$items = array(
array(
'item_id' => $goodsDb['item_id'],
'item_num' => $goodsDb['item_num'],
)
);
Mall::cancel($goodsDto['goods_uuid']);
myself()->_addItems($items, $awardService, $propertyChgService);
{
//埋点
$event = [
'name' => LogService::MARKET_CANCEL_SELL_GOLD,
'val' => $goods['amount']
];
LogService::productGold($event);
}
}
break;
default:
{
myself()->_rspErr(1, 'cant cancel');
return;
}
break;
}
myself()->_rspData(array(
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
public function modifyPrice()
{
$goodsUuid = getReqVal('goods_uuid', '');
$priceBn = phpcommon\bnInit(getReqVal('price', ''));
if (!$this->checkPrice($priceBn)) {
return;
}
$goodsDb = Mall::findByGoodsUuid($goodsUuid);
if (!$goodsDb) {
myself()->_rspErr(1, 'goods not found');
return;
}
$goodsDto = Mall::toDto($goodsDb);
if ($goodsDto['modify_countdown'] != 0) {
myself()->_rspErr(1, 'cant modify price');
return;
}
Mall::modifyPrice($goodsDto['goods_uuid'], phpcommon\bnToStr($priceBn));
myself()->_rspOk();
}
private function checkPrice($priceBn)
{
if ($priceBn === false) {
myself()->_rspErr(1, 'price format error1');
return false;
}
if (phpcommon\bnCmp($this->priceLowBn, $priceBn) > 0) {
myself()->_rspErr(1, 'price format error2');
return false;
}
if (phpcommon\bnCmp($this->priceHighBn, $priceBn) < 0) {
myself()->_rspErr(1, 'price format error3');
return false;
}
return true;
}
}

View File

@ -8,10 +8,6 @@ class CallBackService extends BaseService {
'mintNftHero' => 'MintNftHero' ,
'gameItemMallBuyOk' => 'GameItemMallBuyOk',
'gameItemMarketBuyOk' => 'GameItemMarketBuyOk',
'MarketSellOrderOk' => 'MarketSellOrderOk',
'MarketBuyOrderOk' => 'MarketBuyOrderOk',
'MarketCancelOrderOk' => 'MarketCancelOrderOk',
'MarketPriceUpdateOrderOk' => 'MarketPriceUpdateOrderOk',
'inappPurchase' => 'InAppPurchase',
'outappPurchase' => 'OutAppPurchase',
'staked721' => 'Staked721',

View File

@ -1,33 +0,0 @@
<?php
namespace services;
require_once('models/Market.php');
require_once('services/callback/common/SignatureService.php');
use phpcommon\SqlHelper;
use models\Market;
class MarketBuyOrderOk {
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketBuyOrderOk:' . json_encode($_REQUEST));
$netId = getReqVal('net_id', '');
$tokenId = getReqVal('tokenId', '');
$orderId = getReqVal('orderId', '');
$nftToken = getReqVal('nftToken', '');
$amount = getReqVal('amount', 0);
$seller = strtolower(getReqVal('seller', ''));
$buyer = strtolower(getReqVal('buyer', ''));
$erc20 = getReqVal('erc20', '');
$price = getReqVal('price', '');
Market::buyOk($orderId, $netId);
myself()->_rspOk();
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace services;
require_once('models/Market.php');
require_once ('services/callback/common/SignatureService.php');
use phpcommon\SqlHelper;
use models\Market;
class MarketCancelOrderOk {
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketCancelOrderOk:' . json_encode($_REQUEST));
$netId = getReqVal('net_id', '');
$orderId = getReqVal('orderId', '');
$nftToken = getReqVal('nftToken', '');
$tokenId = getReqVal('tokenId', '');
Market::cancel($orderId, $netId);
myself()->_rspOk();
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace services;
require_once('models/Market.php');
require_once('services/callback/common/SignatureService.php');
use phpcommon\SqlHelper;
use models\Market;
class MarketPriceUpdateOrderOk {
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketPriceUpdateOrderOk:' . json_encode($_REQUEST));
$netId = getReqVal('net_id', '');
$orderId = getReqVal('orderId', '');;
$nftToken = getReqVal('nftToken', '');
$tokenId = getReqVal('tokenId', '');
$priceOld = getReqVal('priceOld', '');
$price = getReqVal('price', '');
Market::updatePrice($orderId, $netId, $price);
myself()->_rspOk();
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace services;
require_once('phpcommon/bchelper.php');
require_once('models/Nft.php');
require_once('models/Market.php');
require_once ('services/callback/common/SignatureService.php');
use phpcommon\SqlHelper;
use models\Nft;
use models\Market;
class MarketSellOrderOk {
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketSellOrderOk:' . json_encode($_REQUEST));
$netId = getReqVal('net_id', '');
$tokenId = getReqVal('tokenId', '');
$owner = strtolower(getReqVal('owner', ''));
$nftToken = strtolower(getReqVal('nftToken', ''));
$amount = getReqVal('amount', 0);
$orderId = getReqVal('orderId', '');
$currency = getReqVal('currency', '');
$price = getReqVal('price', '');
$fieldsKv = array();
$nftDb = Nft::getNftByNetCont($tokenId, $netId, $nftToken);
if ($nftDb) {
try {
$nftDetail = Nft::toDto($nftDb);
if ($nftDetail) {
$fieldsKv['c_name'] = $nftDetail['info']['name'];
$fieldsKv['c_job'] = $nftDetail['info']['job'];
$fieldsKv['c_lv'] = $nftDetail['info']['level'];
$fieldsKv['c_quality'] = $nftDetail['info']['quality'];
//$fieldsKv['c_durability'] = $nftDetail['info']['hero_tili'];
$fieldsKv['c_type'] = 1;
}
} catch(Exception $e) {
$fieldsKv = array();
error_log('MarketSellOrderOk error:' . $e);
}
}
Market::add(
$orderId,
$netId,
$tokenId,
$owner,
$nftToken,
$amount,
$currency,
$price,
$fieldsKv
);
myself()->_rspOk();
}
}