This commit is contained in:
songliang 2023-06-09 17:35:25 +08:00
parent 02f2b1d387
commit a1f2f6ae48

View File

@ -79,7 +79,7 @@ class ShopController extends BaseAuthedController
// }
// }
if(getReqVal('a', '') != 'buyGoodsDirect'){
if (getReqVal('a', '') != 'buyGoodsDirect') {
parent::_handlePre();
}
}
@ -295,12 +295,40 @@ class ShopController extends BaseAuthedController
// }
// 我返回给你这些数据和一个sign字段,
// sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3
// PENDING = 0, // 初始状态
// TRANSFERING = 1, //只有国库模式才会有该状态
// TRANSFERED = 2, //只有国库模式才会有该状态
// SUCCESS = 9, // 成功的最终状态
// TRANSFER_FAIL = 98, // 转账错误
// FAIL = 99, // 也是错误
//
$token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0);
$account_id = getReqVal('account_id', '');
$order_id = getReqVal('order_id', '');
$status = getReqVal('status', '');
$id = getReqVal('id', '');
$txhash = getReqVal('txhash', '');
$order_id = 28;
error_log("buyGoodsDirect-------");
$sign = getReqVal('sign', '');
$data = array(
'account_id' => $account_id,
'id' => $id,
'order_id' => $order_id,
'status' => $status,
'txhash' => $txhash,
);
$hash_data = http_build_query($data);
$signature = hash_hmac('sha256', $hash_data, 'iG4Rpsa)6U31$H#^T85$^^3');
if ($signature != $sign) {
$this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}");
return;
}
error_log("buyGoodsDirect-------" . $order_id . "---" . $status);
$conn = myself()->_getMysql('');
@ -308,25 +336,36 @@ class ShopController extends BaseAuthedController
$id = $order['item_id'];
$goods_num = $order['goods_num'];
$status = $order['status'];
$o_status = $order['status'];
$token_type = $order['token_type'];
if ($status != 0) {
$this->_rspErr(1, "order status error, status: {$status}");
if ($o_status != 0) {
$this->_rspErr(1, "order status error, status: {$o_status}");
return;
}
$buyStatus = 1; // 1: 成功, 2: 失败
SqlHelper::update($conn, 't_shop_buy_order', array('idx' => $order_id), array('status' => $buyStatus) );
$buyStatus = 0; // 1: 成功, 2: 失败
switch ($status) {
case "9":
$buyStatus = 1;
break;
case "99":
case "98":
$buyStatus = 2;
break;
}
SqlHelper::update($conn, 't_shop_buy_order', array('idx' => $order_id), array('status' => $buyStatus));
$row = mt\ShopGoods::get($id);
if ($row) {
$desired_token_type = $row['token_type'];
$check_token_type = splitStr1($desired_token_type);
$token_pos = array_search($token_type, $check_token_type, true);
if (!in_array($token_type, $check_token_type)) {
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
return;
}
// $token_pos = array_search($token_type, $check_token_type, true);
// if (!in_array($token_type, $check_token_type)) {
// $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
// return;
// }
if ($goods_num > $row['max_amount']) {
$this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}");
@ -344,11 +383,13 @@ class ShopController extends BaseAuthedController
$awardService = new services\AwardService();
$awardService->addItem($row['goods_id'], $goods_num);
ShopBuyRecord::add($id, $goods_num);
}
$this->_rspOk();
}
public function startGoodsDirect() {
public function startGoodsDirect()
{
$id = getReqVal('id', 0);
$token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0);
@ -376,7 +417,8 @@ class ShopController extends BaseAuthedController
}
}
public function statusGoodsDirect() {
public function statusGoodsDirect()
{
$order_id = getReqVal('order_id', '');
$conn = myself()->_getMysql('');
@ -978,5 +1020,4 @@ class ShopController extends BaseAuthedController
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array());
return $row['lastId'];
}
}