This commit is contained in:
songliang 2023-07-14 13:56:53 +08:00
parent 300d4fcc3c
commit 4435fb0631
3 changed files with 155 additions and 68 deletions

View File

@ -719,6 +719,7 @@ class MarketController extends BaseAuthedController
'ext_data' => json_encode(array( 'ext_data' => json_encode(array(
'mode' => MARKET_BUY_MODE_NORMAL, 'mode' => MARKET_BUY_MODE_NORMAL,
'idx' => $idx, 'idx' => $idx,
'order_id' => $goods['order_id'],
)), )),
)); ));
@ -1379,7 +1380,7 @@ class MarketController extends BaseAuthedController
$row = SqlHelper::selectOne( $row = SqlHelper::selectOne(
myself()->_getSelfMysql(), myself()->_getSelfMysql(),
't_market_store', 't_market_store',
array('item_id', 'amount', 's_price', 'owner_address'), array('order_id', 'item_id', 'amount', 's_price', 'owner_address'),
array( array(
'idx' => $idx, 'idx' => $idx,
'status' => 0, 'status' => 0,

View File

@ -59,6 +59,8 @@ class BuyShopGoodsCbService
)), )),
)); ));
break; break;
case MARKET_BUY_MODE_NORMAL:
break;
} }
} }
break; break;

View File

@ -3,15 +3,19 @@
namespace services; namespace services;
require_once('phpcommon/bchelper.php'); require_once('phpcommon/bchelper.php');
require_once ('services/callback/BuyPassCbService.php'); require_once('services/callback/BuyPassCbService.php');
require_once ('services/callback/BuyShopGoodsCbService.php'); require_once('services/callback/BuyShopGoodsCbService.php');
require_once('ShopAddItemService.php');
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
use models\ShopBuyRecord;
class GameItemMarketBuyOk { class GameItemMarketBuyOk
{
public function process() public function process()
{ {
$itemService = new ShopAddItemService();
$address = getReqVal('address', ''); $address = getReqVal('address', '');
$orderId = getReqVal('order_id', ''); $orderId = getReqVal('order_id', '');
@ -24,41 +28,58 @@ class GameItemMarketBuyOk {
) )
); );
//1已发货 2订单不存在 //1已发货 2订单不存在
if (!$orderDb){ if (!$orderDb) {
echo json_encode(array( echo json_encode(array(
'errcode' => 2, 'errcode' => 2,
'errmsg' => "Order does not exist", 'errmsg' => "Order does not exist",
)); ));
die ; die;
} }
if ($orderDb['status'] == 1){ if ($orderDb['status'] == 1) {
echo json_encode(array( echo json_encode(array(
'errcode' => 1, 'errcode' => 1,
'errmsg' => "Order shipped", 'errmsg' => "Order shipped",
)); ));
die; die;
} }
// 修改订单状态 // 修改订单状态
$this->_updateOrderState($address,$orderId); $this->_updateOrderState($address, $orderId);
// 小胡 回调的处理 $ext_data = json_decode($orderDb['ext_data'], true);
if ($this->_isVirtualItem($orderDb['item_id'])){
$passCbService = new BuyPassCbService();
$passCbService->process($orderDb);
} else {
// 老宋 处理...
$shopGoodsCbService = new BuyShopGoodsCbService();
$shopGoodsCbService->process($orderDb);
switch ($ext_data['mode']) {
case MARKET_BUY_MODE_NORMAL: {
$order = $orderDb;
$itemService->addGameLog($order['address'], "shopBuyNormal", "begin", array(
'param1' => $order['order_id'],
'param2' => json_encode(array(
'item_id' => $order['item_id'],
'item_num' => $order['item_num'],
)),
));
$this->buyFromMarket($order, $ext_data['idx']);
$itemService->addGameLog($order['address'], "shopBuyNormal", "end", array(
'param1' => $order['order_id'],
'param2' => json_encode(array(
'item_id' => $order['item_id'],
'item_num' => $order['item_num'],
)),
));
} }
break;
}
echo json_encode(array( echo json_encode(array(
'errcode' => 0, 'errcode' => 0,
'errmsg' => "callback success", 'errmsg' => "callback success",
)); ));
} }
private function _isVirtualItem($itemId){ private function _isVirtualItem($itemId)
return in_array($itemId, array( {
return in_array(
$itemId,
array(
V_ITEM_EXP, V_ITEM_EXP,
V_ITEM_PASS, V_ITEM_PASS,
V_ITEM_RESET_CARD, V_ITEM_RESET_CARD,
@ -66,9 +87,10 @@ class GameItemMarketBuyOk {
); );
} }
private function _updateOrderState($address,$transId){ private function _updateOrderState($address, $transId)
SqlHelper::update {
(myself()->_getMysql($address), SqlHelper::update(
myself()->_getMysql($address),
't_bc_order', 't_bc_order',
array( array(
'order_id' => $transId 'order_id' => $transId
@ -80,4 +102,66 @@ class GameItemMarketBuyOk {
); );
} }
private function buyFromMarket($order, $idx)
{
$address = $order['address'];
$goods = $this->getMarketGoods($address, $idx);
$this->markMarketGoodsSold($address, $idx);
$this->_addGoods($address, $goods);
}
private function getMarketGoods($address, $idx)
{
$row = SqlHelper::selectOne(
myself()->_getMysql($address),
't_market_store',
array('order_id', 'item_id', 'amount', 's_price', 'owner_address'),
array(
'idx' => $idx
)
);
if (!$row) {
return null;
}
if (!$row['item_id']) {
return null;
}
return $row;
}
private function markMarketGoodsSold($address, $idx)
{
SqlHelper::update(
myself()->_getMysql($address),
't_market_store',
array(
'idx' => $idx
),
array(
'status' => 2,
'modifytime' => myself()->_getNowTime(),
)
);
}
private function _addGoods($address, $goods)
{
$itemService = new ShopAddItemService();
$item_id = $goods['item_id'];
$goods_num = $goods['amount'];
$id = null;
if ($goods['id']) {
$id = $goods['id'];
}
error_log(json_encode($goods));
error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $amount . ' id ' . $id);
$itemService->addItem($address, $item_id, $goods_num);
if ($id) {
ShopBuyRecord::addWithAddress($address, $id, $goods_num);
}
}
} }