1
This commit is contained in:
parent
7bfe26ff4f
commit
d2fc2fd37d
@ -351,6 +351,69 @@ class BlockChainController extends BaseAuthedController {
|
||||
);
|
||||
}
|
||||
|
||||
public function buyMallProduct()
|
||||
{
|
||||
$address = $this->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$idx = getReqVal('idx', '');
|
||||
$s_price = getReqVal('s_price', '');
|
||||
if (empty($s_price)) {
|
||||
$this->_rspErr(1, 's_price not found');
|
||||
return;
|
||||
}
|
||||
if (!is_numeric($s_price)) {
|
||||
$this->_rspErr(1, 's_price not number');
|
||||
return;
|
||||
}
|
||||
|
||||
$goods = $this->getGoodsByIdx($idx);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(1, 'goods not found, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($s_price != $goods['s_price']) {
|
||||
$this->_rspErr(1, 'price not match, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
$response = services\BlockChainService::gameItemMarketBuy(
|
||||
Transaction::BUY_GOODS_FROM_MARKET_ACTION_TYPE,
|
||||
$goods['owner_address'],
|
||||
$goods['s_price'],
|
||||
$goods['item_id'],
|
||||
$goods['amount']
|
||||
);
|
||||
|
||||
if (!$this->markOrderBuyStatus($idx)) {
|
||||
$this->_rspErr(1, 'buy failed, update order status failed, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
$item_id = $goods['item_id'];
|
||||
$item_count = $goods['amount'];
|
||||
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_count,
|
||||
'order_type' => BcOrder::SPEC_ORDER_TYPE,
|
||||
'price' => $this->Web3PriceLowFormat($goods['s_price']),
|
||||
'ext_data' => json_encode(array(
|
||||
'mode' => BcOrder::MARKET_BUY_MODE_NORMAL,
|
||||
'idx' => $idx,
|
||||
'order_id' => $goods['order_id'],
|
||||
)),
|
||||
));
|
||||
|
||||
$this->_rspData(array(
|
||||
'block_chain' => $response,
|
||||
));
|
||||
}
|
||||
|
||||
private static function getWeb3ServiceUrl()
|
||||
{
|
||||
if (SERVER_ENV == _TEST) {
|
||||
|
@ -130,30 +130,6 @@ class MallController extends BaseAuthedController {
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
private function genOrderId($id)
|
||||
{
|
||||
$order_id_base = date('YmdHis') . "10000000";
|
||||
$divIdx = phpcommon\bnToStr(gmp_mod($id, 9999999));
|
||||
$order_id = phpcommon\bnAdd_s($order_id_base, $divIdx);
|
||||
return $order_id;
|
||||
}
|
||||
private function lastInsertId($conn)
|
||||
{
|
||||
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array());
|
||||
return $row['lastId'];
|
||||
}
|
||||
|
||||
private function makeCostItems($item_id, $num)
|
||||
{
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $num
|
||||
)
|
||||
);
|
||||
return $costItems;
|
||||
}
|
||||
|
||||
public function productOffline()
|
||||
{
|
||||
$idx = getReqVal('idx', '');
|
||||
@ -268,67 +244,4 @@ class MallController extends BaseAuthedController {
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function buyProduct()
|
||||
{
|
||||
$address = $this->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$idx = getReqVal('idx', '');
|
||||
$s_price = getReqVal('s_price', '');
|
||||
if (empty($s_price)) {
|
||||
$this->_rspErr(1, 's_price not found');
|
||||
return;
|
||||
}
|
||||
if (!is_numeric($s_price)) {
|
||||
$this->_rspErr(1, 's_price not number');
|
||||
return;
|
||||
}
|
||||
|
||||
$goods = $this->getGoodsByIdx($idx);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(1, 'goods not found, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($s_price != $goods['s_price']) {
|
||||
$this->_rspErr(1, 'price not match, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
$response = services\BlockChainService::gameItemMarketBuy(
|
||||
Transaction::BUY_GOODS_FROM_MARKET_ACTION_TYPE,
|
||||
$goods['owner_address'],
|
||||
$goods['s_price'],
|
||||
$goods['item_id'],
|
||||
$goods['amount']
|
||||
);
|
||||
|
||||
if (!$this->markOrderBuyStatus($idx)) {
|
||||
$this->_rspErr(1, 'buy failed, update order status failed, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
$item_id = $goods['item_id'];
|
||||
$item_count = $goods['amount'];
|
||||
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_count,
|
||||
'order_type' => BcOrder::SPEC_ORDER_TYPE,
|
||||
'price' => $this->Web3PriceLowFormat($goods['s_price']),
|
||||
'ext_data' => json_encode(array(
|
||||
'mode' => BcOrder::MARKET_BUY_MODE_NORMAL,
|
||||
'idx' => $idx,
|
||||
'order_id' => $goods['order_id'],
|
||||
)),
|
||||
));
|
||||
|
||||
$this->_rspData(array(
|
||||
'block_chain' => $response,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user