This commit is contained in:
songliang 2023-07-13 14:48:03 +08:00
parent 6b8bf69648
commit 31ef1019c3
2 changed files with 31 additions and 89 deletions

View File

@ -347,7 +347,7 @@ class MarketController extends BaseAuthedController
return '';
};
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$counts = $conn->execQuery(
'SELECT count(idx) as count FROM t_market_store ' .
@ -485,11 +485,6 @@ class MarketController extends BaseAuthedController
public function sell()
{
$self = myself();
if (!$self) {
$this->_rspErr(500, 'internal error, no self');
return;
}
$address = $this->_getAddress();
if (!$address) {
$this->_rspErr(1, 'address not found');
@ -523,7 +518,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', '');
$conn = $self->_getMysql('');
$conn = myself()->_getSelfMysql('');
$nftDb = null;
@ -573,8 +568,8 @@ class MarketController extends BaseAuthedController
'owner_address' => $account,
'token_type' => 0,
'amount' => $amount,
'createtime' => $self->_getNowTime(),
'modifytime' => $self->_getNowTime(),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
's_price' => $s_price,
'c_name' => $c_name,
'c_job' => $c_job,
@ -615,7 +610,7 @@ class MarketController extends BaseAuthedController
return;
}
$conn = $this->_getMysql('');
$conn = $this->_getSelfMysql('');
$r = SqlHelper::update(
$conn,
't_market_store',
@ -653,7 +648,7 @@ class MarketController extends BaseAuthedController
return;
}
$conn = $this->_getMysql('');
$conn = $this->_getSelfMysql('');
$r = SqlHelper::update(
$conn,
't_market_store',
@ -722,7 +717,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', '');
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$nftDb = Nft::findNftByOwner($account, $nft_token);
$nftDetail = Nft::toDto($nftDb);
@ -763,7 +758,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', '');
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\'');
$this->_rspOk();
@ -795,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()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$type_filter_fn = function ($f) {
if ($f == 0) {
@ -882,7 +877,7 @@ class MarketController extends BaseAuthedController
)
);
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -959,7 +954,7 @@ class MarketController extends BaseAuthedController
)
);
$conn = myself()->_getMysql('');
$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));
@ -1015,7 +1010,7 @@ class MarketController extends BaseAuthedController
)
);
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -1062,7 +1057,7 @@ class MarketController extends BaseAuthedController
)
);
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -1137,7 +1132,7 @@ class MarketController extends BaseAuthedController
private function attach_market_selling(&$row)
{
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$rows = $conn->execQuery(
'SELECT * FROM t_market_store ' .
@ -1164,7 +1159,7 @@ class MarketController extends BaseAuthedController
{
// error_log('listMySelledNfts ' . $account . ' ' . $type);
$conn = myself()->_getMysql('');
$conn = myself()->_getSelfMysql('');
$rows = $conn->execQuery(
'SELECT * FROM t_market_store ' .
@ -1180,11 +1175,6 @@ class MarketController extends BaseAuthedController
private function addItems($address, $item_id, $amount)
{
$self = myself();
if (!$self) {
return false;
}
$r = $this->addItem($address, $item_id, $amount);
if (!$r) {
return false;
@ -1195,11 +1185,6 @@ class MarketController extends BaseAuthedController
private function decItems($address, $item_id, $amount)
{
$self = myself();
if (!$self) {
return false;
}
$userInfo = $this->getUserInfo($address, array('gold'));
$count = $this->getItemCount($item_id, $userInfo);
if ($count < $amount) {
@ -1216,10 +1201,6 @@ class MarketController extends BaseAuthedController
private function addItem($address, $item_id, $amount)
{
$self = myself();
if (!$self) {
return false;
}
switch ($item_id) {
case V_ITEM_GOLD: {
$r = $this->addGold($address, $amount);
@ -1234,10 +1215,6 @@ class MarketController extends BaseAuthedController
private function decItem($address, $item_id, $amount)
{
$self = myself();
if (!$self) {
return false;
}
switch ($item_id) {
case V_ITEM_GOLD: {
$r = $this->decGold($address, $amount);
@ -1252,11 +1229,6 @@ class MarketController extends BaseAuthedController
private function addGold($address, $amount)
{
$self = myself();
if (!$self) {
return false;
}
$r = $this->updateUserInfo($address, array(
'gold' => function () use ($amount) {
return "gold + ${amount}";
@ -1272,11 +1244,6 @@ class MarketController extends BaseAuthedController
private function decGold($address, $amount)
{
$self = myself();
if (!$self) {
return false;
}
$userInfo = $this->getUserInfo($address, array('gold'));
$count = $this->getItemCount(V_ITEM_GOLD, $userInfo);
if ($count < $amount) {
@ -1300,13 +1267,8 @@ class MarketController extends BaseAuthedController
private function updateUserInfo($address, $fieldKv)
{
$self = myself();
if (!$self) {
return false;
}
$r = SqlHelper::update(
$self->_getMysql(''),
myself()->_getSelfMysql(''),
't_user',
array(
'address' => $address,
@ -1321,11 +1283,6 @@ class MarketController extends BaseAuthedController
}
private function getCostItem($address, $item_id)
{
$self = myself();
if (!$self) {
return null;
}
$userInfo = $this->getUserInfo($address, array('gold'));
$count = $this->getItemCount($item_id, $userInfo);
@ -1347,17 +1304,12 @@ class MarketController extends BaseAuthedController
private function getUserInfo($address, $fields)
{
$self = myself();
if (!$self) {
return null;
}
// $account_id = $this->getAccountId($address);
// if (!$account_id) {
// return null;
// }
$conn = $self->_getMysql($address);
$conn = myself()->_getSelfMysql($address);
$row = SqlHelper::selectOne(
$conn,
't_user',
@ -1375,13 +1327,8 @@ class MarketController extends BaseAuthedController
private function getAccountId($address)
{
$self = myself();
if (!$self) {
return null;
}
$row = SqlHelper::selectOne(
$self->_getMysql($address),
myself()->_getSelfMysql($address),
't_user',
array('account_id'),
array(
@ -1404,13 +1351,8 @@ class MarketController extends BaseAuthedController
private function getGoodsByIdx($idx)
{
$self = myself();
if (!$self) {
return null;
}
$row = SqlHelper::selectOne(
$self->_getMysql(''),
myself()->_getSelfMysql(''),
't_market_store',
array('item_id', 'amount', 's_price', 'owner_address'),
array(
@ -1429,20 +1371,15 @@ class MarketController extends BaseAuthedController
private function markOrderBuyStatus($idx)
{
$self = myself();
if (!$self) {
return false;
}
$r = SqlHelper::update(
$self->_getMysql(''),
myself()->_getSelfMysql(''),
't_market_store',
array(
'idx' => $idx,
),
array(
'status' => 3,
'buytime' => $self->_getNowTime(),
'buytime' => myself()->_getNowTime(),
)
);
if (!$r) {
@ -1451,4 +1388,5 @@ class MarketController extends BaseAuthedController
return true;
}
}

View File

@ -407,11 +407,8 @@ class ShopController extends BaseAuthedController
return;
}
$lastId = $this->lastInsertId($conn);
// gen order id
$order_id_base = date('YmdHis') . "10000000";
$divIdx = ($lastId) % 9999999;
$order_id = phpcommon\bnAdd_s($order_id_base, $divIdx);
$order_id = $this->genOrderId($lastId);
$test = SqlHelper::update($conn, 't_web2_order', array('idx' => $lastId), array('order_id' => $order_id));
if (!$test) {
$this->_rspErr(5, "start purchase failed");
@ -422,6 +419,13 @@ class ShopController extends BaseAuthedController
));
}
private function genOrderId($id) {
$order_id_base = date('YmdHis') . "10000000";
$divIdx = gmp_mod($id, 9999999);
$order_id = phpcommon\bnAdd_s($order_id_base, $divIdx);
return $order_id;
}
public function statusInappPurchase()
{
$order_id = getReqVal('order_id', '');