diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index 450ca5ba..daecd478 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -4,6 +4,12 @@ class CallbackController extends BaseController { private $handlers = array( 'gameItemMallBuyOk' => 'GameItemMallBuyOk', + 'eventSellOrder' => 'eventSellOrder', + 'eventBuyOrder' => 'eventBuyOrder', + 'eventCancelOrder' => 'eventCancelOrder', + 'eventPriceUpdateOrder' => 'eventPriceUpdateOrder', + 'buyGoodsDirect' => 'buyGoodsDirect', + 'inappPurchaseDiamonds' => 'inappPurchaseDiamonds', ); public function dispatch() diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index eaeb6afb..123e6919 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -347,7 +347,7 @@ class MarketController extends BaseAuthedController return ''; }; - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $counts = $conn->execQuery( 'SELECT count(idx) as count FROM t_market_store ' . @@ -518,7 +518,7 @@ class MarketController extends BaseAuthedController $signature = getReqVal('signature', ''); $net_id = getReqVal('net_id', ''); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $nftDb = null; @@ -610,7 +610,7 @@ class MarketController extends BaseAuthedController return; } - $conn = $this->_getSelfMysql(''); + $conn = $this->_getSelfMysql(); $r = SqlHelper::update( $conn, 't_market_store', @@ -648,7 +648,7 @@ class MarketController extends BaseAuthedController return; } - $conn = $this->_getSelfMysql(''); + $conn = $this->_getSelfMysql(); $r = SqlHelper::update( $conn, 't_market_store', @@ -717,7 +717,7 @@ class MarketController extends BaseAuthedController $signature = getReqVal('signature', ''); $net_id = getReqVal('net_id', ''); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $nftDb = Nft::findNftByOwner($account, $nft_token); $nftDetail = Nft::toDto($nftDb); @@ -758,7 +758,7 @@ class MarketController extends BaseAuthedController $signature = getReqVal('signature', ''); $net_id = getReqVal('net_id', ''); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\''); $this->_rspOk(); @@ -790,7 +790,7 @@ class MarketController extends BaseAuthedController $start = getReqVal('start', 0); $page_size = getReqVal('page_size', 10); $page_size = max(1, min(100, $page_size)); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $type_filter_fn = function ($f) { if ($f == 0) { @@ -877,7 +877,7 @@ class MarketController extends BaseAuthedController ) ); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); @@ -954,7 +954,7 @@ class MarketController extends BaseAuthedController ) ); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId)); @@ -1010,7 +1010,7 @@ class MarketController extends BaseAuthedController ) ); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); @@ -1057,7 +1057,7 @@ class MarketController extends BaseAuthedController ) ); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); @@ -1132,7 +1132,7 @@ class MarketController extends BaseAuthedController private function attach_market_selling(&$row) { - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $rows = $conn->execQuery( 'SELECT * FROM t_market_store ' . @@ -1159,7 +1159,7 @@ class MarketController extends BaseAuthedController { // error_log('listMySelledNfts ' . $account . ' ' . $type); - $conn = myself()->_getSelfMysql(''); + $conn = myself()->_getSelfMysql(); $rows = $conn->execQuery( 'SELECT * FROM t_market_store ' . @@ -1268,7 +1268,7 @@ class MarketController extends BaseAuthedController private function updateUserInfo($address, $fieldKv) { $r = SqlHelper::update( - myself()->_getSelfMysql(''), + myself()->_getSelfMysql(), 't_user', array( 'address' => $address, @@ -1309,7 +1309,7 @@ class MarketController extends BaseAuthedController // return null; // } - $conn = myself()->_getSelfMysql($address); + $conn = myself()->_getMysql($address); $row = SqlHelper::selectOne( $conn, 't_user', @@ -1328,7 +1328,7 @@ class MarketController extends BaseAuthedController private function getAccountId($address) { $row = SqlHelper::selectOne( - myself()->_getSelfMysql($address), + myself()->_getMysql($address), 't_user', array('account_id'), array( @@ -1352,7 +1352,7 @@ class MarketController extends BaseAuthedController private function getGoodsByIdx($idx) { $row = SqlHelper::selectOne( - myself()->_getSelfMysql(''), + myself()->_getSelfMysql(), 't_market_store', array('item_id', 'amount', 's_price', 'owner_address'), array( @@ -1372,7 +1372,7 @@ class MarketController extends BaseAuthedController private function markOrderBuyStatus($idx) { $r = SqlHelper::update( - myself()->_getSelfMysql(''), + myself()->_getSelfMysql(), 't_market_store', array( 'idx' => $idx, diff --git a/webapp/models/BuyRecord.php b/webapp/models/BuyRecord.php index a0a09073..0de0525f 100644 --- a/webapp/models/BuyRecord.php +++ b/webapp/models/BuyRecord.php @@ -10,7 +10,7 @@ use phpcommon\SqlHelper; class BuyRecord extends BaseModel { - public static function genOrderId($gameId, $funcId, $time, $®) + public static function genOrderId($gameId, $funcId, $time, $buyerAddress) { SqlHelper::insert (myself()->_getMarketMysql(), diff --git a/webapp/services/callback/MarketBuyOrderOk.php b/webapp/services/callback/MarketBuyOrderOk.php new file mode 100644 index 00000000..ae4cc87d --- /dev/null +++ b/webapp/services/callback/MarketBuyOrderOk.php @@ -0,0 +1,75 @@ + $tokenId, + 'orderId' => $orderId, + 'nftToken' => $nftToken, + 'amount' => $amount, + 'seller' => $seller, + 'buyer' => $buyer, + 'erc20' => $erc20, + 'price' => $price, + ), + JSON_PRETTY_PRINT + ) + ); + + $conn = myself()->_getSelfMysql(); + + // 1. check order status + $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId)); + if (empty($chk)) { + $this->_rspErr(1, 'not found order, orderId=' . $orderId); + return; + } + if ($chk['status'] == '0') { + $r = SqlHelper::update( + $conn, + 't_market_store', + array( + 'o_link' => $orderId, + ), + array( + 'status' => 2, + ) + ); + if ($r) { + // 增加交易记录 + $record = array( + 'createtime' => myself()->_getNowTime(), + 'orderid' => $chk['idx'], + 'o_link' => $orderId, + 'seller' => $seller, + 'buyer' => $buyer, + 'tokenid' => $tokenId, + 'amount' => $amount, + 'name' => $chk['c_name'], + 'type' => $chk['token_type'], + ); + $this->addTransactionRecord($record); + $this->_rspOk(); + return; + } + } + $this->_rspErr(1, 'order status error, order=' . $orderId); + } +} diff --git a/webapp/services/callback/MarketCancelOrderOk.php b/webapp/services/callback/MarketCancelOrderOk.php new file mode 100644 index 00000000..8bc36dc2 --- /dev/null +++ b/webapp/services/callback/MarketCancelOrderOk.php @@ -0,0 +1,51 @@ + $orderId, + 'nftToken' => $nftToken, + 'tokenId' => $tokenId, + ), + JSON_PRETTY_PRINT + ) + ); + + $conn = myself()->_getSelfMysql(); + + // 1. check order status + $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); + if (empty($chk)) { + $this->_rspErr(1, 'not found order, orderId=' . $orderId); + return; + } + if ($chk['status'] == '0') { + $r = SqlHelper::update( + $conn, + 't_market_store', + array( + 'o_link' => $orderId, + ), + array( + 'status' => 1, + ) + ); + if ($r) { + $this->_rspOk(); + return; + } + } + $this->_rspErr(1, 'order status error, order=' . $orderId); + } +} diff --git a/webapp/services/callback/MarketPriceUpdateOrderOk.php b/webapp/services/callback/MarketPriceUpdateOrderOk.php new file mode 100644 index 00000000..5ca9a52d --- /dev/null +++ b/webapp/services/callback/MarketPriceUpdateOrderOk.php @@ -0,0 +1,57 @@ + $orderId, + 'nftToken' => $nftToken, + 'tokenId' => $tokenId, + 'priceOld' => $priceOld, + 'price' => $price, + ), + JSON_PRETTY_PRINT + ) + ); + + $conn = myself()->_getSelfMysql(); + + // 1. check order status + $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); + if (empty($chk)) { + $this->_rspErr(1, 'not found order, orderId=' . $orderId); + return; + } + + if ($chk['status'] == '0') { + $r = SqlHelper::update( + $conn, + 't_market_store', + array( + 'o_link' => $orderId, + ), + array( + 's_price' => $price, + ) + ); + if ($r) { + $this->_rspOk(); + return; + } + } + + $this->_rspErr(1, 'price update failed, orderId=' . $orderId); + } +} diff --git a/webapp/services/callback/MarketSellOrderOk.php b/webapp/services/callback/MarketSellOrderOk.php new file mode 100644 index 00000000..21fae73a --- /dev/null +++ b/webapp/services/callback/MarketSellOrderOk.php @@ -0,0 +1,83 @@ + $tokenId, + 'owner' => $owner, + 'nftToken' => $nftToken, + 'amount' => $amount, + 'orderId' => $orderId, + 'currency' => $currency, + 'price' => $price, + ), + JSON_PRETTY_PRINT + ) + ); + + $conn = myself()->_getSelfMysql(); + + // 1. check order status + $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); + if (!empty($chk)) { + $this->_rspErr(1, 'repeat sell order, orderId=' . $orderId); + return; + } + + // 2. insert sell order to t_market_store + $nftDb = Nft::findNftByOwner($owner, $tokenId); + if (empty($nftDb)) { + $nftDb = Nft::getNft($tokenId); + } + $nftDetail = Nft::toDto($nftDb); + $detail = $this->getNftGameData($nftDb); + $r = SqlHelper::insert( + $conn, + 't_market_store', + array( + 'token_id' => $tokenId, + 'o_link' => $orderId, + 'nft_token' => $nftToken, + 'status' => 0, + 'owner_address' => $owner, + 'token_type' => $nftDetail['type'], + 'amount' => $amount, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + 's_currency' => $currency, + 's_price' => $price, + 'c_name' => $nftDetail['info']['name'], + 'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job'] + : (isset($detail['chip_type']) ? $detail['chip_type'] + : (isset($detail['type']) ? $detail['type'] + : 0)), + 'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'], + 'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0, + 'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0), + 'c_type' => isset($detail['type']) ? $detail['type'] : 0, + 'c_id' => $nftDetail['item_id'], + ) + ); + if (!$r) { + $this->_rspErr(2, 'unknown error, orderId=' . $orderId); + } + + $this->_rspOk(); + } +} diff --git a/webapp/services/callback/ShopBuyGoodsDirect.php b/webapp/services/callback/ShopBuyGoodsDirect.php new file mode 100644 index 00000000..20670d51 --- /dev/null +++ b/webapp/services/callback/ShopBuyGoodsDirect.php @@ -0,0 +1,105 @@ + $account_id, + 'id' => $id, + 'order_id' => $order_id, + 'status' => $status, + 'txhash' => $txhash, + ); + + $hash_data = http_build_query($data); + + $signature = hash_hmac('sha256', $hash_data, 'iG4Rpsa)6U31$H#^T85$^^3'); + + if ($signature != $sign) { + $this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}"); + return; + } + + error_log("buyGoodsDirect-------" . $order_id . "---" . $status); + + $conn = myself()->_getMysql(''); + + $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'item_id', 'goods_num', 'status'), array('idx' => $order_id)); + + $id = $order['item_id']; + $goods_num = $order['goods_num']; + $o_status = $order['status']; + + if ($o_status != 0) { + $this->_rspErr(1, "order status error, status: {$o_status}"); + return; + } + + $buyStatus = 0; // 1: 成功, 2: 失败 + switch ($status) { + case "9": + $buyStatus = 1; + break; + case "99": + case "98": + $buyStatus = 2; + break; + } + + SqlHelper::update($conn, 't_shop_buy_order', array('idx' => $order_id), array('status' => $buyStatus)); + + $goods = mt\ShopGoods::get($id); + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_num = $order['goods_num']; + $bundle_size = $goods['bonus_num']; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['bonus']; + $address = $order['address']; + $account_id = $this->getAccountId($address); + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_CEBG_BONUS, + 'val' => $item_num + ]; + LogService::productDiamond(['account_id' => $account_id], $event); + } + + $this->_addGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + + $this->_rspOk(); + } +} diff --git a/webapp/services/callback/ShopInappPurchaseDiamonds.php b/webapp/services/callback/ShopInappPurchaseDiamonds.php new file mode 100644 index 00000000..eb8925b9 --- /dev/null +++ b/webapp/services/callback/ShopInappPurchaseDiamonds.php @@ -0,0 +1,175 @@ +Object.keys(record).sort().map(key => `${key}=${record[key]}`).join('&')).join('&') + + // const sign = hmacsha256(signStr, hashSort) + + // 定义一个空数组,用来存放每个记录的键值对字符串 + $record_strings = array(); + + // 遍历 records 数组,对每个记录进行排序和拼接 + foreach ($records as $record) { + // 对记录的键进行升序排序 + ksort($record); + // 把记录的键值对用等号连接,然后用 & 连接成一个字符串 + $record_string = http_build_query($record); + // 把字符串加入到 record_strings 数组中 + $record_strings[] = $record_string; + } + + // 把 record_strings 数组用 & 连接成一个字符串 + $records_string = implode("&", $record_strings); + + $hash_data = 'channel=' . $channel . '&' . $records_string; + + $signature = hash_hmac('sha256', $hash_data, 'iG4Rpsa)6U31$H#^T85$^^3'); + + if ($signature != $sign) { + $this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}"); + return; + } + + $conn = myself()->_getMysql(''); + // 有三种情况: + // 1. 从商城购买钻石,有订单号 + // 2. 站外充值钻石,没有订单号 + // 3. appstore 退款,没有订单号 + + for ($i = 0; $i < count($records); $i++) { + $record = $records[$i]; + + $product_id = $record['productId']; + $order_id = $record['gameOrderId']; + $out_order_id = $record['orderId']; + $status = $record['status']; + + switch ($status) { + case 9: { + $status = 1; + if (empty($order_id)) { + if (empty($product_id)) { + $this->_rspErr(2, "product_id is empty"); + return; + } + + // $goods = mt\ShopGoods::getByProductId($product_id); + + return; + } + + $order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 0)); + error_log('process order ' . json_encode($order)); + if (!$order) { + $this->_rspErr(3, "order not found, order_id: {$order_id}"); + return; + } + + SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status, 'channel' => $channel, 'out_order_id' => $out_order_id)); + + $id = $order['id']; + $goods = mt\ShopGoods::get($id); + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_num = $order['goods_num']; + $bundle_size = $goods['goods_num']; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['goods_id']; + $address = $order['address']; + $account_id = $this->getAccountId($address); + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_DIAMOND, + 'val' => $item_num + ]; + LogService::productDiamond(['account_id' => $account_id], $event); + } + + $this->_addGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + } + break; + case 96: + $status = 3; + if (empty($order_id)) { + if (empty($product_id)) { + $this->_rspErr(2, "product_id is empty"); + return; + } + // $goods = mt\ShopGoods::getByProductId($product_id); + + return; + } + // 退款 + $order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 1)); + if (!$order) { + $this->_rspErr(3, "order not found, order_id: {$order_id}"); + return; + } + SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status)); + + $id = $order['id']; + $goods = mt\ShopGoods::get($id); + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_num = $order['goods_num']; + $bundle_size = $goods['goods_num']; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['goods_id']; + $address = $order['address']; + $account_id = $this->getAccountId($address); + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_DIAMOND, + 'val' => -$item_num + ]; + LogService::productDiamond(['account_id' => $account_id], $event); + } + + $this->_decGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + break; + default: + $status = 0; + break; + } + } + + $this->_rspOk(); + } +}