diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index b18c4c24..ccf79f4d 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -686,7 +686,7 @@ class MarketController extends BaseAuthedController $this->_rspErr(1, 'address not found'); return; } - + $idx = getReqVal('idx', ''); $goods = $this->getGoodsByIdx($idx); @@ -719,6 +719,7 @@ class MarketController extends BaseAuthedController 'ext_data' => json_encode(array( 'mode' => MARKET_BUY_MODE_NORMAL, 'idx' => $idx, + 'order_id' => $goods['order_id'], )), )); @@ -1379,7 +1380,7 @@ class MarketController extends BaseAuthedController $row = SqlHelper::selectOne( myself()->_getSelfMysql(), 't_market_store', - array('item_id', 'amount', 's_price', 'owner_address'), + array('order_id', 'item_id', 'amount', 's_price', 'owner_address'), array( 'idx' => $idx, 'status' => 0, diff --git a/webapp/services/callback/BuyShopGoodsCbService.php b/webapp/services/callback/BuyShopGoodsCbService.php index 12c4965f..2431e741 100644 --- a/webapp/services/callback/BuyShopGoodsCbService.php +++ b/webapp/services/callback/BuyShopGoodsCbService.php @@ -59,6 +59,8 @@ class BuyShopGoodsCbService )), )); break; + case MARKET_BUY_MODE_NORMAL: + break; } } break; diff --git a/webapp/services/callback/GameItemMarketBuyOk.php b/webapp/services/callback/GameItemMarketBuyOk.php index f1810d1a..9d2af813 100644 --- a/webapp/services/callback/GameItemMarketBuyOk.php +++ b/webapp/services/callback/GameItemMarketBuyOk.php @@ -3,81 +3,165 @@ namespace services; require_once('phpcommon/bchelper.php'); -require_once ('services/callback/BuyPassCbService.php'); -require_once ('services/callback/BuyShopGoodsCbService.php'); +require_once('services/callback/BuyPassCbService.php'); +require_once('services/callback/BuyShopGoodsCbService.php'); +require_once('ShopAddItemService.php'); use phpcommon\SqlHelper; +use models\ShopBuyRecord; -class GameItemMarketBuyOk { +class GameItemMarketBuyOk +{ - public function process() - { - $address = getReqVal('address', ''); - $orderId = getReqVal('order_id', ''); - - error_log("GameItemMallBuyOk-------------------"); - $orderDb = SqlHelper::ormSelectOne( - myself()->_getMysql($address), - 't_bc_order', - array( - 'order_id' => $orderId - ) - ); - //1:已发货 2:订单不存在 - if (!$orderDb){ - echo json_encode(array( - 'errcode' => 2, - 'errmsg' => "Order does not exist", - )); - die ; + public function process() + { + $itemService = new ShopAddItemService(); + $address = getReqVal('address', ''); + $orderId = getReqVal('order_id', ''); + + error_log("GameItemMallBuyOk-------------------"); + $orderDb = SqlHelper::ormSelectOne( + myself()->_getMysql($address), + 't_bc_order', + array( + 'order_id' => $orderId + ) + ); + //1:已发货 2:订单不存在 + if (!$orderDb) { + echo json_encode(array( + 'errcode' => 2, + 'errmsg' => "Order does not exist", + )); + die; + } + if ($orderDb['status'] == 1) { + echo json_encode(array( + 'errcode' => 1, + 'errmsg' => "Order shipped", + )); + die; + } + // 修改订单状态 + $this->_updateOrderState($address, $orderId); + + $ext_data = json_decode($orderDb['ext_data'], true); + + 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'], + )), + )); } - if ($orderDb['status'] == 1){ - echo json_encode(array( - 'errcode' => 1, - 'errmsg' => "Order shipped", - )); - die; - } -// 修改订单状态 - $this->_updateOrderState($address,$orderId); - -// 小胡 回调的处理 - if ($this->_isVirtualItem($orderDb['item_id'])){ - $passCbService = new BuyPassCbService(); - $passCbService->process($orderDb); - } else { -// 老宋 处理... - $shopGoodsCbService = new BuyShopGoodsCbService(); - $shopGoodsCbService->process($orderDb); - - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => "callback success", - )); + break; } - private function _isVirtualItem($itemId){ - return in_array($itemId, array( - V_ITEM_EXP, - V_ITEM_PASS, - V_ITEM_RESET_CARD, - ) - ); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "callback success", + )); + } + + private function _isVirtualItem($itemId) + { + return in_array( + $itemId, + array( + V_ITEM_EXP, + V_ITEM_PASS, + V_ITEM_RESET_CARD, + ) + ); + } + + private function _updateOrderState($address, $transId) + { + SqlHelper::update( + myself()->_getMysql($address), + 't_bc_order', + array( + 'order_id' => $transId + ), + array( + 'status' => 1, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + + 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']; } - private function _updateOrderState($address,$transId){ - SqlHelper::update - (myself()->_getMysql($address), - 't_bc_order', - array( - 'order_id' => $transId - ), - array( - 'status' => 1, - 'modifytime' => myself()->_getNowTime(), - ) - ); + 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); } + } }