169 lines
4.8 KiB
PHP
169 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace services;
|
|
|
|
require_once("mt/ShopGoods.php");
|
|
require_once("mt/Item.php");
|
|
|
|
require_once("models/ShopBuyRecord.php");
|
|
require_once("models/OutAppOrder.php");
|
|
|
|
require_once("services/LogService.php");
|
|
require_once("ShopAddItemService.php");
|
|
|
|
use phpcommon\SqlHelper;
|
|
|
|
use models\ShopBuyRecord;
|
|
use models\OutAppOrder;
|
|
|
|
use services\LogService;
|
|
|
|
/*
|
|
// let repdata = {
|
|
// account_id: string
|
|
// order_id: string
|
|
// status: string
|
|
// id: string
|
|
// txhash: string
|
|
// }
|
|
// 我返回给你这些数据和一个sign字段,
|
|
// sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是
|
|
// PENDING = 0, // 初始状态
|
|
// TRANSFERING = 1, //只有国库模式才会有该状态
|
|
// TRANSFERED = 2, //只有国库模式才会有该状态
|
|
// SUCCESS = 9, // 成功的最终状态
|
|
// TRANSFER_FAIL = 98, // 转账错误
|
|
// FAIL = 99, // 也是错误
|
|
//
|
|
*/
|
|
|
|
class OutAppPurchase {
|
|
|
|
public function process()
|
|
{
|
|
error_log("OutAppPurchase --- " . json_encode($_REQUEST));
|
|
|
|
if (!$this->verifySign()) {
|
|
error_log("verifySign error --- " . json_encode($_REQUEST));
|
|
myself()->_rspErr(1, 'verifySign error');
|
|
return;
|
|
}
|
|
$accountId = getReqVal('account_id', '');
|
|
$status = getReqVal('status', '');
|
|
$id = getReqVal('id', '');
|
|
$txhash = getReqVal('txhash', '');
|
|
$sign = getReqVal('sign', '');
|
|
$orderId = getReqVal('order_id', '');
|
|
|
|
$orderDb = OutAppOrder::find($orderId);
|
|
if (!$orderDb) {
|
|
myself()->_rspErr(2, 'not found order');
|
|
return;
|
|
}
|
|
if ($orderDb['status'] != OutAppOrder::FINISHED_STATE) {
|
|
myself()->_rspErr(0, 'order is finished');
|
|
return;
|
|
}
|
|
OutAppOrder::markFinished($orderDb['order_id']);
|
|
$orderDb = OutAppOrder::find($orderId);
|
|
if (!$orderDb) {
|
|
myself()->_rspErr(2, 'not found order');
|
|
return;
|
|
}
|
|
if ($orderDb['status'] == OutAppOrder::FINISHED_STATE) {
|
|
myself()->_rspErr(0, 'order is finished');
|
|
return;
|
|
}
|
|
$buyStatus = 0; // 1: 成功, 2: 失败
|
|
switch ($status) {
|
|
case "9":
|
|
$buyStatus = 1;
|
|
// 充值成功,开始首充奖励
|
|
$this->beginFirstTupop($address);
|
|
break;
|
|
case "99":
|
|
case "98":
|
|
$buyStatus = 2;
|
|
break;
|
|
default:
|
|
error_log("buyGoodsDirect--- " . $order_id . " --- " . $status);
|
|
$this->_rspErr(1, "status error, status: {$status}");
|
|
break;
|
|
}
|
|
|
|
if ($buyStatus == 2) {
|
|
$this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}");
|
|
return;
|
|
}
|
|
|
|
// 以下是看商品表中是否配置了充值额外奖励
|
|
$goodsMeta = mt\ShopGoods::get($orderDb['goods_id']);
|
|
$goodsNum = $orderDb['goods_num'];
|
|
$bundleSize = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0;
|
|
$itemNum = $goodsNum * $bundleSize;
|
|
$itemId = $goodsMeta['bonus'];
|
|
$meta = mt\Item::get($itemId);
|
|
if ($meta && $itemNum > 0) {
|
|
if ($itemId == V_ITEM_DIAMOND) {
|
|
$event = [
|
|
'name' => LogService::RECHARGE_CEBG_BONUS,
|
|
'val' => $itemNum
|
|
];
|
|
LogService::productDiamondCallback(
|
|
array(
|
|
'account_id' => $orderDb['account_id']
|
|
),
|
|
$event);
|
|
}
|
|
|
|
error_log("buyGoodsDirect---" . $address . "---" . $itemId . "---" . $itemNum);
|
|
|
|
$this->_addGoods($address, array(
|
|
'goods_id' => $itemId,
|
|
'goods_num' => $itemNum,
|
|
'id' => $id,
|
|
));
|
|
}
|
|
|
|
$this->_rspOk();
|
|
}
|
|
|
|
private function beginFirstTupop($address)
|
|
{
|
|
$conn = myself()->_getMysql('');
|
|
|
|
$exist = SqlHelper::selectOne(
|
|
$conn,
|
|
't_first_topup',
|
|
array('address'),
|
|
array('address' => $address)
|
|
);
|
|
if ($exist) {
|
|
return;
|
|
}
|
|
|
|
// 开始首充奖励活动进程
|
|
$chk = SqlHelper::insert(
|
|
$conn,
|
|
't_first_topup',
|
|
array(
|
|
'address' => $address,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'status1' => 0,
|
|
'status2' => 0,
|
|
'status3' => 0,
|
|
)
|
|
);
|
|
if (!$chk) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
private function verifySign()
|
|
{
|
|
|
|
}
|
|
|
|
}
|