...
This commit is contained in:
parent
b4d879504e
commit
51a1f207f2
@ -59,6 +59,9 @@ define('TN_WEEKLY_RECHARGE_UPGRADE_TIMES', 10004);
|
|||||||
define('TN_WEEKLY_SHARE_GAMES', 10005);
|
define('TN_WEEKLY_SHARE_GAMES', 10005);
|
||||||
define('TN_WEEKLY_END', 10005);
|
define('TN_WEEKLY_END', 10005);
|
||||||
|
|
||||||
|
define('SHOP_BUY_MODE_NORMAL', 0);
|
||||||
|
define('SHOP_BUY_MODE_DAILY_SELECTION', 1);
|
||||||
|
|
||||||
const kHAT_Begin = 0;
|
const kHAT_Begin = 0;
|
||||||
const kHAT_Hp = 1;
|
const kHAT_Hp = 1;
|
||||||
const kHAT_HPRecover = 2;
|
const kHAT_HPRecover = 2;
|
||||||
|
@ -17,10 +17,16 @@ require_once('models/Gun.php');
|
|||||||
require_once('models/GunSkin.php');
|
require_once('models/GunSkin.php');
|
||||||
require_once('models/ShopBuyRecord.php');
|
require_once('models/ShopBuyRecord.php');
|
||||||
require_once('models/Chip.php');
|
require_once('models/Chip.php');
|
||||||
|
require_once('models/BcOrder.php');
|
||||||
|
require_once('models/Transaction.php');
|
||||||
|
|
||||||
require_once('services/AwardService.php');
|
require_once('services/AwardService.php');
|
||||||
require_once('services/PropertyChgService.php');
|
require_once('services/PropertyChgService.php');
|
||||||
|
require_once('services/BlockChainService.php');
|
||||||
|
|
||||||
|
require_once('phpcommon/bignumber.php');
|
||||||
|
|
||||||
|
use phpcommon;
|
||||||
use phpcommon\HttpClient;
|
use phpcommon\HttpClient;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use models\User;
|
use models\User;
|
||||||
@ -34,6 +40,8 @@ use models\Chip;
|
|||||||
use mt\Shop;
|
use mt\Shop;
|
||||||
use mt\PayMethod;
|
use mt\PayMethod;
|
||||||
use mt\Dailyselection;
|
use mt\Dailyselection;
|
||||||
|
use models\Transaction;
|
||||||
|
use models\BcOrder;
|
||||||
|
|
||||||
class ShopController extends BaseAuthedController
|
class ShopController extends BaseAuthedController
|
||||||
{
|
{
|
||||||
@ -813,33 +821,73 @@ class ShopController extends BaseAuthedController
|
|||||||
$grid = getReqVal('grid', 0);
|
$grid = getReqVal('grid', 0);
|
||||||
$count = getReqVal('count', 0);
|
$count = getReqVal('count', 0);
|
||||||
|
|
||||||
$address = $this->_getAddress();
|
$conn = $this->_getMysql('');
|
||||||
// $chk = $this->decDailySelectionItem($idx, $grid, $count);
|
|
||||||
// if (!$chk) {
|
|
||||||
// $this->_rspErr(1, 'goods not enough');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
$url = "192.168.100.39:7672/webapp/index.php";
|
$row = SqlHelper::selectOne(
|
||||||
$params = array(
|
$conn,
|
||||||
'c' => 'GameItemMall',
|
't_shop_dailyselection',
|
||||||
'a' => 'buy',
|
array(
|
||||||
'address' => $address,
|
'idx',
|
||||||
'price' => 100,
|
'address',
|
||||||
|
'grid_' . $grid,
|
||||||
|
'count_' . $grid,
|
||||||
|
),
|
||||||
|
array('idx' => $idx)
|
||||||
);
|
);
|
||||||
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
|
||||||
$this->_rspErr(500, 'GameItemMall buy failed');
|
if (!$row) {
|
||||||
|
$this->_rspErr(2, 'idx is invalid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$response = '';
|
|
||||||
error_log($response);
|
if ($row['address'] != $address) {
|
||||||
|
$this->_rspErr(2, 'address is invalid');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['grid_' . $grid] == 0) {
|
||||||
|
$this->_rspErr(2, 'grid is invalid');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['count_' . $grid] < $count) {
|
||||||
|
$this->_rspErr(2, 'count is invalid');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sel_id = $row['grid_' . $grid];
|
||||||
|
|
||||||
|
$goods = mt\Dailyselection::get($sel_id);
|
||||||
|
|
||||||
|
$price = $this->normalizeWeb3Price($goods['price'] * $count);
|
||||||
|
$item_id = $goods['goods_id'];
|
||||||
|
$item_count = $goods['goods_num'] * $count;
|
||||||
|
|
||||||
|
$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,
|
||||||
|
'ext_data' => json_encode(array(
|
||||||
|
'mode' => SHOP_BUY_MODE_DAILY_SELECTION,
|
||||||
|
'idx' => $idx,
|
||||||
|
'grid' => $grid,
|
||||||
|
'count' => $count,
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
|
||||||
$this->_rspData(
|
$this->_rspData(
|
||||||
array(
|
array(
|
||||||
'idx' => $idx,
|
'idx' => $idx,
|
||||||
'grid' => $grid,
|
'grid' => $grid,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'response' => $response,
|
'trans' => $response,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1258,4 +1306,13 @@ class ShopController extends BaseAuthedController
|
|||||||
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array());
|
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array());
|
||||||
return $row['lastId'];
|
return $row['lastId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normalizeWeb3Price($price)
|
||||||
|
{
|
||||||
|
$bn1 = phpcommon\bnInit($price * pow(10, 8));
|
||||||
|
$bn2 = phpcommon\bnInit('1000000000000000000');
|
||||||
|
$price = phpcommon\bnDiv(phpcommon\bnMul($bn1, $bn2), pow(10, 8));
|
||||||
|
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ class Transaction extends BaseModel {
|
|||||||
|
|
||||||
const BUY_EXP_ACTION_TYPE = 101;
|
const BUY_EXP_ACTION_TYPE = 101;
|
||||||
const BUY_PASS_ACTION_TYPE = 102;
|
const BUY_PASS_ACTION_TYPE = 102;
|
||||||
|
const BUY_GOODS_ACTION_TYPE = 103;
|
||||||
|
|
||||||
const BUY_END_ACTION_TYPE = 200;
|
const BUY_END_ACTION_TYPE = 200;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace services;
|
|||||||
require_once('models/Transaction.php');
|
require_once('models/Transaction.php');
|
||||||
|
|
||||||
use models\Transaction;
|
use models\Transaction;
|
||||||
|
use phpcommon;
|
||||||
|
|
||||||
class BlockChainService {
|
class BlockChainService {
|
||||||
|
|
||||||
@ -83,6 +84,7 @@ class BlockChainService {
|
|||||||
|
|
||||||
private static function getWeb3ServiceUrl()
|
private static function getWeb3ServiceUrl()
|
||||||
{
|
{
|
||||||
|
return 'http://192.168.100.39:7672/webapp/index.php';
|
||||||
if (SERVER_ENV == _TEST) {
|
if (SERVER_ENV == _TEST) {
|
||||||
return 'http://127.0.0.1:7672/webapp/index.php';
|
return 'http://127.0.0.1:7672/webapp/index.php';
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,55 @@
|
|||||||
|
|
||||||
namespace services;
|
namespace services;
|
||||||
|
|
||||||
|
define('V_ORDER_TYPE_BUY_SHOP_GOODS', 1);
|
||||||
|
|
||||||
|
use phpcommon\SqlHelper;
|
||||||
|
|
||||||
class BuyShopGoodsCbService
|
class BuyShopGoodsCbService
|
||||||
{
|
{
|
||||||
public function process($order){
|
public function process($order){
|
||||||
|
switch($order['order_type']){
|
||||||
|
case V_ORDER_TYPE_BUY_SHOP_GOODS : {
|
||||||
|
$ext_data = json_decode($order['ext_data'], true);
|
||||||
|
switch($ext_data['mode'])
|
||||||
|
{
|
||||||
|
case SHOP_BUY_MODE_NORMAL:
|
||||||
|
$this->_buyNormal($order, $ext_data);
|
||||||
|
break;
|
||||||
|
case SHOP_BUY_MODE_DAILY_SELECTION:
|
||||||
|
$this->_buyDailySelection($order, $ext_data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default : {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _buyNormal($order, $ext_data){
|
||||||
|
$ext_data = $order['ext_data'];
|
||||||
|
$goods_id = $ext_data['goods_id'];
|
||||||
|
$goods_num = $ext_data['goods_num'];
|
||||||
|
$goodsDb = SqlHelper::ormSelectOne(
|
||||||
|
myself()->_getMysql($order['address']),
|
||||||
|
't_shop_goods',
|
||||||
|
array(
|
||||||
|
'id' => $goods_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$goodsDb['goods_num'] = $goods_num;
|
||||||
|
$this->_addGoods($order['address'],$goodsDb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _buyDailySelection($order, $ext_data){
|
||||||
|
|
||||||
|
$idx = $ext_data['idx'];
|
||||||
|
$grid = $ext_data['grid'];
|
||||||
|
$count = $ext_data['count'];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user