1
This commit is contained in:
parent
76e1076f45
commit
100773ef22
@ -281,6 +281,53 @@ class BlockChainController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
|
||||
public function buyDiamond()
|
||||
{
|
||||
$num = getReqVal('num', 0);
|
||||
if (!is_numeric($num)) {
|
||||
$this->_rspErr(1, "num is invalid, {$num}");
|
||||
return;
|
||||
}
|
||||
if ($num <= 0) {
|
||||
$this->_rspErr(1, "num is invalid, {$num}");
|
||||
return;
|
||||
}
|
||||
|
||||
$price = $this->normalizeWeb3Price($num);
|
||||
$item_id = V_ITEM_DIAMOND;
|
||||
$item_count = $num;
|
||||
|
||||
error_log("buy diamond start " . $num);
|
||||
|
||||
$response = services\BlockChainService::gameItemMallBuy(
|
||||
Transaction::BUY_GOODS_ACTION_TYPE,
|
||||
$price,
|
||||
$item_id,
|
||||
$item_count
|
||||
);
|
||||
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_count,
|
||||
'order_type' => 1,
|
||||
'price' => $num,
|
||||
'ext_data' => json_encode(array(
|
||||
'mode' => SHOP_BUY_MODE_NORMAL,
|
||||
)),
|
||||
));
|
||||
|
||||
$response['item_id'] = $item_id;
|
||||
$response['item_num'] = $item_count;
|
||||
|
||||
error_log("buy diamond, item_id = " . $item_id . " item_count = " . $item_count . " num = " . $num . " price = " . $price . " response = " . json_encode($response));
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
"block_chain" => $response
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static function getWeb3ServiceUrl()
|
||||
{
|
||||
if (SERVER_ENV == _TEST) {
|
||||
|
@ -49,43 +49,6 @@ use services\ShopAddItemService;
|
||||
class ShopController extends BaseAuthedController
|
||||
{
|
||||
|
||||
const TOKEN_TYPE_GOLD = '0';
|
||||
const TOKEN_TYPE_CEG = '1';
|
||||
const TOKEN_TYPE_CEC = '2';
|
||||
const TOKEN_TYPE_BCEG = '3';
|
||||
const TOKEN_TYPE_DIAMOND = '4';
|
||||
|
||||
|
||||
const TOKEN_TYPE_USDT = '11';
|
||||
const TOKEN_TYPE_USDC = '12';
|
||||
const TOKEN_TYPE_BUSD = '13';
|
||||
|
||||
const TOKEN_TYPE_MATIC = '101';
|
||||
const TOKEN_TYPE_BNB = '102';
|
||||
|
||||
//99 = 美元
|
||||
const TOKEN_TYPE_USD = '99';
|
||||
|
||||
//21 = 印尼
|
||||
const TOKEN_TYPE_IDR = '21';
|
||||
//22 = 菲律宾
|
||||
const TOKEN_TYPE_PHP = '22';
|
||||
//23 = 越南
|
||||
const TOKEN_TYPE_VND = '23';
|
||||
//24 = 泰国
|
||||
const TOKEN_TYPE_THB = '24';
|
||||
//25 = 马来西亚
|
||||
const TOKEN_TYPE_MYR = '25';
|
||||
//26 = 日本
|
||||
const TOKEN_TYPE_JPY = '26';
|
||||
//27 = 韩国
|
||||
const TOKEN_TYPE_KRW = '27';
|
||||
|
||||
// 限购类型
|
||||
const DAILY_BUY_LIMIT = 1;
|
||||
const WEEKLY_BUY_LIMIT = 2;
|
||||
const TOTAL_BUY_LIMIT = 3;
|
||||
|
||||
public function getGoodsList()
|
||||
{
|
||||
$shop_id = getReqVal('shop_id', 0);
|
||||
@ -161,180 +124,6 @@ class ShopController extends BaseAuthedController
|
||||
);
|
||||
}
|
||||
|
||||
public function startGoodsDirect()
|
||||
{
|
||||
$id = getReqVal('id', 0);
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 1);
|
||||
|
||||
if ($goods_num <= 0) {
|
||||
$this->_rspErr(1, 'goods_num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$goods = mt\ShopGoods::get($id);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(1, "id is invalid. {$id}");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goods['shop_id'] == 9 && $goods_num > 1) {
|
||||
$this->_rspErr(1, 'goods_num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$conn = myself()->_getSelfMysql();
|
||||
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address is empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array(
|
||||
'address' => $address,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'id' => $id,
|
||||
'item_id' => $goods['goods_id'] ? $goods['goods_id'] : 0,
|
||||
'goods_num' => $goods_num,
|
||||
'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败
|
||||
)
|
||||
);
|
||||
if ($chk) {
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$order_id = $this->genOrderId($lastId);
|
||||
SqlHelper::update(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array(
|
||||
'idx' => $lastId,
|
||||
),
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
$this->_rspData(
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspErr(1, "insert error, id: {$id}, token_type: {$token_type}, goods_num: {$goods_num}");
|
||||
}
|
||||
}
|
||||
|
||||
public function statusGoodsDirect()
|
||||
{
|
||||
$order_id = getReqVal('order_id', '');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array('status', 'id'),
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
if ($row) {
|
||||
$this->_rspData(
|
||||
array(
|
||||
'status' => $row['status'],
|
||||
'item_id' => $row['item_id'],
|
||||
'item_num' => $row['goods_num'],
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspErr(1, "order_id not found, order_id: {$order_id}");
|
||||
}
|
||||
}
|
||||
|
||||
public function startInappPurchase()
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
$this->_rspErr(1, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$id = getReqVal('id', 0);
|
||||
$goods = mt\ShopGoods::get($id);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(2, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
if ($goods['shop_id'] != 9) {
|
||||
$this->_rspErr(3, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$goods_num = getReqVal('goods_num', 1);
|
||||
|
||||
$account_id = $self->_getAccountId();
|
||||
$address = $self->_getAddress();
|
||||
if (empty($address)) {
|
||||
$this->_rspErr(4, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$item_id = $goods['goods_id'];
|
||||
$item_num = $goods['goods_num'] * $goods_num;
|
||||
|
||||
$conn = $self->_getMysql('');
|
||||
|
||||
$chk = SqlHelper::insert($conn, 't_web2_order', array(
|
||||
'status' => 0,
|
||||
'createtime' => $self->_getNowTime(),
|
||||
'account_id' => $account_id,
|
||||
'address' => $address,
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_num,
|
||||
'id' => $id,
|
||||
'goods_num' => $goods_num,
|
||||
'price' => $goods['price'],
|
||||
));
|
||||
|
||||
if (!$chk) {
|
||||
$this->_rspErr(5, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$order_id = $this->genOrderId($lastId);
|
||||
|
||||
$test = SqlHelper::update($conn, 't_web2_order', array('idx' => $lastId), array('order_id' => $order_id));
|
||||
if (!$test) {
|
||||
$this->_rspErr(6, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
$this->_rspData(array(
|
||||
'order_id' => $order_id,
|
||||
));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function statusInappPurchase()
|
||||
{
|
||||
$order_id = getReqVal('order_id', '');
|
||||
$conn = myself()->_getMysql('');
|
||||
$order = SqlHelper::selectOne($conn, 't_web2_order', array('item_id', 'item_num', 'status'), array('order_id' => $order_id));
|
||||
if (!$order) {
|
||||
$this->_rspErr(1, "order not found");
|
||||
return;
|
||||
}
|
||||
$this->_rspData($order);
|
||||
}
|
||||
|
||||
public function buyGoods()
|
||||
{
|
||||
$address = $this->_getAddress();
|
||||
@ -624,51 +413,178 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
}
|
||||
|
||||
public function buyDiamond()
|
||||
public function startGoodsDirect()
|
||||
{
|
||||
$num = getReqVal('num', 0);
|
||||
if (!is_numeric($num)) {
|
||||
$this->_rspErr(1, "num is invalid, {$num}");
|
||||
return;
|
||||
}
|
||||
if ($num <= 0) {
|
||||
$this->_rspErr(1, "num is invalid, {$num}");
|
||||
$id = getReqVal('id', 0);
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 1);
|
||||
|
||||
if ($goods_num <= 0) {
|
||||
$this->_rspErr(1, 'goods_num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$price = $this->normalizeWeb3Price($num);
|
||||
$item_id = V_ITEM_DIAMOND;
|
||||
$item_count = $num;
|
||||
$goods = mt\ShopGoods::get($id);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(1, "id is invalid. {$id}");
|
||||
return;
|
||||
}
|
||||
|
||||
error_log("buy diamond start " . $num);
|
||||
if ($goods['shop_id'] == 9 && $goods_num > 1) {
|
||||
$this->_rspErr(1, 'goods_num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$response = services\BlockChainService::gameItemMallBuy(
|
||||
Transaction::BUY_GOODS_ACTION_TYPE,
|
||||
$price,
|
||||
$item_id,
|
||||
$item_count
|
||||
);
|
||||
$conn = myself()->_getSelfMysql();
|
||||
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_count,
|
||||
'order_type' => 1,
|
||||
'price' => $num,
|
||||
'ext_data' => json_encode(array(
|
||||
'mode' => SHOP_BUY_MODE_NORMAL,
|
||||
)),
|
||||
));
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address is empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$response['item_id'] = $item_id;
|
||||
$response['item_num'] = $item_count;
|
||||
|
||||
error_log("buy diamond, item_id = " . $item_id . " item_count = " . $item_count . " num = " . $num . " price = " . $price . " response = " . json_encode($response));
|
||||
|
||||
$this->_rspData(
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array(
|
||||
"block_chain" => $response
|
||||
'address' => $address,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'id' => $id,
|
||||
'item_id' => $goods['goods_id'] ? $goods['goods_id'] : 0,
|
||||
'goods_num' => $goods_num,
|
||||
'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败
|
||||
)
|
||||
);
|
||||
if ($chk) {
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$order_id = $this->genOrderId($lastId);
|
||||
SqlHelper::update(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array(
|
||||
'idx' => $lastId,
|
||||
),
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
$this->_rspData(
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspErr(1, "insert error, id: {$id}, token_type: {$token_type}, goods_num: {$goods_num}");
|
||||
}
|
||||
}
|
||||
|
||||
public function statusGoodsDirect()
|
||||
{
|
||||
$order_id = getReqVal('order_id', '');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array('status', 'id'),
|
||||
array(
|
||||
'order_id' => $order_id,
|
||||
)
|
||||
);
|
||||
if ($row) {
|
||||
$this->_rspData(
|
||||
array(
|
||||
'status' => $row['status'],
|
||||
'item_id' => $row['item_id'],
|
||||
'item_num' => $row['goods_num'],
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspErr(1, "order_id not found, order_id: {$order_id}");
|
||||
}
|
||||
}
|
||||
|
||||
public function startInappPurchase()
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
$this->_rspErr(1, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$id = getReqVal('id', 0);
|
||||
$goods = mt\ShopGoods::get($id);
|
||||
if (!$goods) {
|
||||
$this->_rspErr(2, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
if ($goods['shop_id'] != 9) {
|
||||
$this->_rspErr(3, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$goods_num = getReqVal('goods_num', 1);
|
||||
|
||||
$account_id = $self->_getAccountId();
|
||||
$address = $self->_getAddress();
|
||||
if (empty($address)) {
|
||||
$this->_rspErr(4, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$item_id = $goods['goods_id'];
|
||||
$item_num = $goods['goods_num'] * $goods_num;
|
||||
|
||||
$conn = $self->_getMysql('');
|
||||
|
||||
$chk = SqlHelper::insert($conn, 't_web2_order', array(
|
||||
'status' => 0,
|
||||
'createtime' => $self->_getNowTime(),
|
||||
'account_id' => $account_id,
|
||||
'address' => $address,
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_num,
|
||||
'id' => $id,
|
||||
'goods_num' => $goods_num,
|
||||
'price' => $goods['price'],
|
||||
));
|
||||
|
||||
if (!$chk) {
|
||||
$this->_rspErr(5, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$order_id = $this->genOrderId($lastId);
|
||||
|
||||
$test = SqlHelper::update($conn, 't_web2_order', array('idx' => $lastId), array('order_id' => $order_id));
|
||||
if (!$test) {
|
||||
$this->_rspErr(6, "start purchase failed");
|
||||
return;
|
||||
}
|
||||
$this->_rspData(array(
|
||||
'order_id' => $order_id,
|
||||
));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function statusInappPurchase()
|
||||
{
|
||||
$order_id = getReqVal('order_id', '');
|
||||
$conn = myself()->_getMysql('');
|
||||
$order = SqlHelper::selectOne($conn, 't_web2_order', array('item_id', 'item_num', 'status'), array('order_id' => $order_id));
|
||||
if (!$order) {
|
||||
$this->_rspErr(1, "order not found");
|
||||
return;
|
||||
}
|
||||
$this->_rspData($order);
|
||||
}
|
||||
|
||||
public function boxPreview()
|
||||
|
@ -6,6 +6,43 @@ use phpcommon;
|
||||
|
||||
class Shop {
|
||||
|
||||
const TOKEN_TYPE_GOLD = '0';
|
||||
const TOKEN_TYPE_CEG = '1';
|
||||
const TOKEN_TYPE_CEC = '2';
|
||||
const TOKEN_TYPE_BCEG = '3';
|
||||
const TOKEN_TYPE_DIAMOND = '4';
|
||||
|
||||
|
||||
const TOKEN_TYPE_USDT = '11';
|
||||
const TOKEN_TYPE_USDC = '12';
|
||||
const TOKEN_TYPE_BUSD = '13';
|
||||
|
||||
const TOKEN_TYPE_MATIC = '101';
|
||||
const TOKEN_TYPE_BNB = '102';
|
||||
|
||||
//99 = 美元
|
||||
const TOKEN_TYPE_USD = '99';
|
||||
|
||||
//21 = 印尼
|
||||
const TOKEN_TYPE_IDR = '21';
|
||||
//22 = 菲律宾
|
||||
const TOKEN_TYPE_PHP = '22';
|
||||
//23 = 越南
|
||||
const TOKEN_TYPE_VND = '23';
|
||||
//24 = 泰国
|
||||
const TOKEN_TYPE_THB = '24';
|
||||
//25 = 马来西亚
|
||||
const TOKEN_TYPE_MYR = '25';
|
||||
//26 = 日本
|
||||
const TOKEN_TYPE_JPY = '26';
|
||||
//27 = 韩国
|
||||
const TOKEN_TYPE_KRW = '27';
|
||||
|
||||
// 限购类型
|
||||
const DAILY_BUY_LIMIT = 1;
|
||||
const WEEKLY_BUY_LIMIT = 2;
|
||||
const TOTAL_BUY_LIMIT = 3;
|
||||
|
||||
const OUTSIDE_SHOP = 100;
|
||||
|
||||
public static function get($id)
|
||||
@ -21,7 +58,7 @@ class Shop {
|
||||
array_push(self::$shopNameList, $meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self::$shopNameList;
|
||||
}
|
||||
|
||||
@ -32,7 +69,7 @@ class Shop {
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
|
||||
protected static $shopNameList;
|
||||
protected static $metaList;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user