This commit is contained in:
hujiabin 2024-06-05 16:26:41 +08:00
parent 4e8fb7080c
commit b2630b7935
4 changed files with 181 additions and 174 deletions

View File

@ -158,14 +158,14 @@ class BaseController {
return $this->mailDbConn; return $this->mailDbConn;
} }
$mysql_conf = getMailMysqlConfig(); $mysql_conf = getMailMysqlConfig();
$this->marketDbConn = new phpcommon\Mysql(array( $this->mailDbConn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'], 'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'], 'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'], 'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'], 'passwd' => $mysql_conf['passwd'],
'dbname' => $mysql_conf['dbname'], 'dbname' => $mysql_conf['dbname'],
)); ));
return $this->marketDbConn; return $this->mailDbConn;
} }
public function _getRelationDbMysql() public function _getRelationDbMysql()

View File

@ -4,6 +4,7 @@ require_once('phpcommon/bignumber.php');
require_once('mt/Item.php'); require_once('mt/Item.php');
require_once('mt/Parameter.php'); require_once('mt/Parameter.php');
require_once('mt/Language.php');
require_once('models/BcOrder.php'); require_once('models/BcOrder.php');
require_once('models/Mall.php'); require_once('models/Mall.php');
@ -17,6 +18,7 @@ require_once('services/BlockChainService.php');
require_once('services/LogService.php'); require_once('services/LogService.php');
require_once('services/AwardService.php'); require_once('services/AwardService.php');
require_once('services/PropertyChgService.php'); require_once('services/PropertyChgService.php');
require_once('services/MailApiService.php');
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
@ -38,9 +40,13 @@ use services\PropertyChgService;
*/ */
class InGameMallController extends BaseAuthedController { class InGameMallController extends BaseAuthedController {
private $mailApiService = null;
public function _handlePre() public function _handlePre()
{ {
parent::_handlePre(); parent::_handlePre();
$this->mailApiService = new \services\MailApiService();
} }
public function productList() public function productList()
@ -196,19 +202,19 @@ class InGameMallController extends BaseAuthedController {
return; return;
} }
switch ($itemMeta['type']){ switch ($itemMeta['type']){
case \mt\Item::HERO_TYPE : { // case \mt\Item::HERO_TYPE : {
$heroDb = Hero::find($goodsUniid); // $heroDb = Hero::find($goodsUniid);
if (!$heroDb || !empty($heroDb['token_id']) || $heroDb['hero_id']!= $itemId){ // if (!$heroDb || !empty($heroDb['token_id']) || $heroDb['hero_id']!= $itemId){
$this->_rspErr(1, 'param goods_unnid error'); // $this->_rspErr(1, 'param goods_unnid error');
return; // return;
} // }
if ($heroDb['seal_type'] != 1){ // if ($heroDb['seal_type'] != 1){
$this->_rspErr(1, 'Shelf heroes need to be packaged first'); // $this->_rspErr(1, 'Shelf heroes need to be packaged first');
return; // return;
} // }
$orderField = $heroDb['quality']; // $orderField = $heroDb['quality'];
} // }
break; // break;
case \mt\Item::CHIP_TYPE : { case \mt\Item::CHIP_TYPE : {
$chipDb = Chip::find($goodsUniid); $chipDb = Chip::find($goodsUniid);
if (!$chipDb || !empty($chipDb['token_id']) || $chipDb['item_id']!= $itemId){ if (!$chipDb || !empty($chipDb['token_id']) || $chipDb['item_id']!= $itemId){
@ -218,18 +224,18 @@ class InGameMallController extends BaseAuthedController {
$orderField = $chipDb['quality']; $orderField = $chipDb['quality'];
} }
break; break;
case \mt\Item::GOLD_SYN :{ // case \mt\Item::GOLD_SYN :{
$itemDb = Bag::findByUniId($goodsUniid); // $itemDb = Bag::findByUniId($goodsUniid);
if (!$itemDb || !empty($itemDb['token_id']) || $itemDb['item_id']!= $itemId){ // if (!$itemDb || !empty($itemDb['token_id']) || $itemDb['item_id']!= $itemId){
$this->_rspErr(1, 'param goods_unnid error'); // $this->_rspErr(1, 'param goods_unnid error');
return; // return;
} // }
if ($itemDb['item_num'] <= 0 || $amount > 1){ // if ($itemDb['item_num'] <= 0 || $amount > 1){
$this->_rspErr(1, 'amount not enough'); // $this->_rspErr(1, 'amount not enough');
return; // return;
} // }
} // }
break; // break;
case \mt\Item::FRAGMENT_TYPE :{ case \mt\Item::FRAGMENT_TYPE :{
$orderField = $itemMeta['quality']; $orderField = $itemMeta['quality'];
} }
@ -238,7 +244,8 @@ class InGameMallController extends BaseAuthedController {
$this->_rspErr(1, 'amount must > 0'); $this->_rspErr(1, 'amount must > 0');
return; return;
} }
if (!$this->_isNumber($priceBn) || $priceBn < 0) { $minPrice = \mt\Parameter::getVal("market_place_min_price",100);
if (!$this->_isNumber($priceBn) || $priceBn < 0 || $priceBn < $minPrice) {
$this->_rspErr(1, 'param price error'); $this->_rspErr(1, 'param price error');
return; return;
} }
@ -257,18 +264,6 @@ class InGameMallController extends BaseAuthedController {
} }
$this->_decItems($costItems); $this->_decItems($costItems);
$propertyChgService->addBagChg(); $propertyChgService->addBagChg();
}elseif ($itemMeta['type'] == \mt\Item::HERO_TYPE){
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'idx' => $goodsUniid,
),
array(
'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT
)
);
$propertyChgService->addHeroChg();
}elseif ($itemMeta['type'] == \mt\Item::CHIP_TYPE){ }elseif ($itemMeta['type'] == \mt\Item::CHIP_TYPE){
SqlHelper::update SqlHelper::update
(myself()->_getSelfMysql(), (myself()->_getSelfMysql(),
@ -281,19 +276,31 @@ class InGameMallController extends BaseAuthedController {
) )
); );
$propertyChgService->addChip(); $propertyChgService->addChip();
}elseif ($itemMeta['type'] == \mt\Item::GOLD_SYN){ }//elseif ($itemMeta['type'] == \mt\Item::HERO_TYPE){
SqlHelper::update // SqlHelper::update
(myself()->_getSelfMysql(), // (myself()->_getSelfMysql(),
't_bag', // 't_hero',
array( // array(
'idx' => $goodsUniid, // 'idx' => $goodsUniid,
), // ),
array( // array(
'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT // 'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT
) // )
); // );
$propertyChgService->addBagChg(); // $propertyChgService->addHeroChg();
} // }elseif ($itemMeta['type'] == \mt\Item::GOLD_SYN){
// SqlHelper::update
// (myself()->_getSelfMysql(),
// 't_bag',
// array(
// 'idx' => $goodsUniid,
// ),
// array(
// 'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT
// )
// );
// $propertyChgService->addBagChg();
// }
$orderId = OrderId::gen(); $orderId = OrderId::gen();
$orderType = $this->_getGoodsType($itemMeta); $orderType = $this->_getGoodsType($itemMeta);
@ -322,11 +329,10 @@ class InGameMallController extends BaseAuthedController {
myself()->_rspErr(1, 'cannot cancel the goods'); myself()->_rspErr(1, 'cannot cancel the goods');
return; return;
} }
$price = $goodsDb['price'];
$costItems = array( $costItems = array(
array( array(
'item_id' => V_ITEM_GOLD, 'item_id' => V_ITEM_GOLD,
'item_num' => $price 'item_num' => $goodsDb['price']
) )
); );
$lackItem = null; $lackItem = null;
@ -334,41 +340,34 @@ class InGameMallController extends BaseAuthedController {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return; return;
} }
$this->_decItems($costItems); $propertyChgService = new PropertyChgService();
SqlHelper::update $this->_buyGoods($goodsDb,$propertyChgService);
($this->_getSelfMysql(), myself()->_rspData(array(
't_user', 'property_chg' => $propertyChgService->toDto(),
));
}
private function _buyGoods($goods,$propertyChgService){
if (!$goods){
return;
}
$price = $goods['price'];
InGameMall::buyOk($goods['order_id'],myself()->_getAccountId());
$costItems = array(
array( array(
'account_id' => $goodsDb['seller'] 'item_id' => V_ITEM_GOLD,
), 'item_num' => $price
array(
'gold' => function () use($price) {
return "gold + ${price}";
}
) )
); );
$propertyChgService = new PropertyChgService(); $this->_decItems($costItems);
switch ($goodsDb['order_type']){
case InGameMall::HERO_TYPE :{ switch ($goods['order_type']){
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'idx' => $goodsDb['goods_uniid'],
),
array(
'account_id' => myself()->_getAccountId()
)
);
$propertyChgService->addHeroChg();
}
break;
case InGameMall::CHIP_TYPE:{ case InGameMall::CHIP_TYPE:{
SqlHelper::update SqlHelper::update
(myself()->_getSelfMysql(), (myself()->_getSelfMysql(),
't_chip', 't_chip',
array( array(
'idx' => $goodsDb['goods_uniid'], 'idx' => $goods['goods_uniid'],
), ),
array( array(
'account_id' => myself()->_getAccountId() 'account_id' => myself()->_getAccountId()
@ -377,29 +376,64 @@ class InGameMallController extends BaseAuthedController {
$propertyChgService->addChip(); $propertyChgService->addChip();
} }
break; break;
case InGameMall::GOLD_TYPE :{
SqlHelper::update
(myself()->_getSelfMysql(),
't_bag',
array(
'idx' => $goodsDb['goods_uniid'],
),
array(
'account_id' => myself()->_getAccountId()
)
);
$propertyChgService->addBagChg();
}
break;
default : { default : {
Bag::addItem($goodsDb['item_id'],$goodsDb['item_num']); Bag::addItem($goods['item_id'],$goods['item_num']);
$propertyChgService->addBagChg(); $propertyChgService->addBagChg();
} }
} }
InGameMall::buyOk($orderId,myself()->_getAccountId()); $event = array(
myself()->_rspData(array( 'ID' => 'Mail',
'property_chg' => $propertyChgService->toDto(), 'SUB_ID' => 'Market Place',
)); 'SUB_KEY' => 'sell_mail',
'mailId' =>$goods['order_id'],
'seller' =>$goods['seller'],
'buyer' =>myself()->_getAccountId(),
'change' => array(
'item_id' => $goods['item_id'],
'item_num' => $goods['item_num']
),
);
LogService::burialPointEvent($event);
//发邮件给卖家
$itemMeta = \mt\Item::get($goods['item_id']);
$languageMeta = \mt\Language::get($itemMeta['name']);
$taxRate = \mt\Parameter::getVal("market_place_tax_rate",0.05);
$taxGold = ceil($price*$taxRate);
$falGold = $price - $taxGold;
$mailContent = <<<EOD
{$languageMeta['en']} has been successfully sold
Transaction price: + {$price} gold
Service fee: - {$taxGold} gold
After selling {$languageMeta['en']}, you received {$falGold} gold
EOD;
$attachments = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $falGold
)
);
$this->mailApiService->sendSellMail(
$goods['order_id'],
$goods['seller'],
\services\MailApiService::SELL_MAIL_SUBJECT,
$mailContent,
$attachments
);
$event1 = array(
'ID' => 'Mail',
'SUB_ID' => 'Market Place',
'SUB_KEY' => 'income_mail',
'mailId' =>$goods['order_id'],
'seller' =>$goods['seller'],
'buyer' =>myself()->_getAccountId(),
'change' => array(
'item_id' => V_ITEM_GOLD,
'item_num' => $falGold
),
);
LogService::burialPointEvent($event1);
} }
public function cancel() public function cancel()
@ -418,6 +452,7 @@ class InGameMallController extends BaseAuthedController {
myself()->_rspErr(1, 'Not the seller'); myself()->_rspErr(1, 'Not the seller');
return; return;
} }
InGameMall::cancel($orderId);
$propertyChgService = new PropertyChgService(); $propertyChgService = new PropertyChgService();
switch ($goodsDb['order_type']){ switch ($goodsDb['order_type']){
case InGameMall::HERO_TYPE :{ case InGameMall::HERO_TYPE :{
@ -467,7 +502,7 @@ class InGameMallController extends BaseAuthedController {
$propertyChgService->addBagChg(); $propertyChgService->addBagChg();
} }
} }
InGameMall::cancel($orderId);
myself()->_rspData(array( myself()->_rspData(array(
'property_chg' => $propertyChgService->toDto(), 'property_chg' => $propertyChgService->toDto(),
)); ));
@ -477,7 +512,8 @@ class InGameMallController extends BaseAuthedController {
{ {
$orderId = getReqVal('order_id', ''); $orderId = getReqVal('order_id', '');
$priceBn =intval(getReqVal('price', '')); $priceBn =intval(getReqVal('price', ''));
if (!$this->_isNumber($priceBn)) { $minPrice = \mt\Parameter::getVal("market_place_min_price",100);
if (!$this->_isNumber($priceBn) || $priceBn < $minPrice) {
$this->_rspErr(1, 'param price error'); $this->_rspErr(1, 'param price error');
return; return;
} }
@ -651,71 +687,13 @@ class InGameMallController extends BaseAuthedController {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return; return;
} }
$this->_decItems($costItems);
$propertyChgService = new PropertyChgService(); $propertyChgService = new PropertyChgService();
foreach ($orderIdArr as $orderId) { foreach ($orderIdArr as $orderId) {
$goodsDb = InGameMall::findByOrderId($orderId); $goodsDb = InGameMall::findByOrderId($orderId);
SqlHelper::update if ($goodsDb['status'] != InGameMall::PENDING_STATE){
($this->_getSelfMysql(), continue;
't_user',
array(
'account_id' => $goodsDb['seller']
),
array(
'gold' => function () use($price) {
return "gold + ${price}";
}
)
);
switch ($goodsDb['order_type']){
case InGameMall::HERO_TYPE :{
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'idx' => $goodsDb['goods_uniid'],
),
array(
'account_id' => myself()->_getAccountId()
)
);
$propertyChgService->addHeroChg();
}
break;
case InGameMall::CHIP_TYPE:{
SqlHelper::update
(myself()->_getSelfMysql(),
't_chip',
array(
'idx' => $goodsDb['goods_uniid'],
),
array(
'account_id' => myself()->_getAccountId()
)
);
$propertyChgService->addChip();
}
break;
case InGameMall::GOLD_TYPE :{
SqlHelper::update
(myself()->_getSelfMysql(),
't_bag',
array(
'idx' => $goodsDb['goods_uniid'],
),
array(
'account_id' => myself()->_getAccountId()
)
);
$propertyChgService->addBagChg();
}
break;
default : {
Bag::addItem($goodsDb['item_id'],$goodsDb['item_num']);
$propertyChgService->addBagChg();
}
} }
InGameMall::buyOk($orderId,myself()->_getAccountId()); $this->_buyGoods($goodsDb,$propertyChgService);
} }
myself()->_rspData(array( myself()->_rspData(array(
'property_chg' => $propertyChgService->toDto(), 'property_chg' => $propertyChgService->toDto(),
@ -732,11 +710,11 @@ class InGameMallController extends BaseAuthedController {
private function _isGoodsType($type){ private function _isGoodsType($type){
if (in_array($type,array( if (in_array($type,array(
\mt\Item::HERO_TYPE, // \mt\Item::HERO_TYPE,
\mt\Item::CHIP_TYPE, \mt\Item::CHIP_TYPE,
\mt\Item::FRAGMENT_TYPE, \mt\Item::FRAGMENT_TYPE,
\mt\Item::BATTLE_REWARD_BOX, \mt\Item::BATTLE_REWARD_BOX,
\mt\Item::GOLD_SYN, // \mt\Item::GOLD_SYN,
))){ ))){
return true; return true;
}else{ }else{
@ -749,9 +727,9 @@ class InGameMallController extends BaseAuthedController {
return ; return ;
} }
switch ($itemMeta['type']){ switch ($itemMeta['type']){
case \mt\Item::HERO_TYPE : { // case \mt\Item::HERO_TYPE : {
return InGameMall::HERO_TYPE; // return InGameMall::HERO_TYPE;
} // }
case \mt\Item::CHIP_TYPE : { case \mt\Item::CHIP_TYPE : {
return InGameMall::CHIP_TYPE; return InGameMall::CHIP_TYPE;
} }
@ -765,9 +743,9 @@ class InGameMallController extends BaseAuthedController {
case \mt\Item::BATTLE_REWARD_BOX : { case \mt\Item::BATTLE_REWARD_BOX : {
return InGameMall::BOX_TYPE; return InGameMall::BOX_TYPE;
} }
case \mt\Item::GOLD_SYN : { // case \mt\Item::GOLD_SYN : {
return InGameMall::GOLD_TYPE; // return InGameMall::GOLD_TYPE;
} // }
default : { default : {
return 0; return 0;
} }

27
webapp/mt/Language.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace mt;
use phpcommon;
class Language {
public static function get($index)
{
foreach (self::getMetaList() as $meta){
if ($meta['info'] == $index){
return $meta;
}
}
return array();
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('language@language.php');
}
return self::$metaList;
}
protected static $metaList;
}

View File

@ -2,11 +2,13 @@
namespace services; namespace services;
use phpcommon\SqlHelper;
class MailApiService extends BaseService { class MailApiService extends BaseService {
const SELL_UNIKEY_PRE = 'ingame.market.sell:'; const SELL_UNIKEY_PRE = 'ingame.market.sell:';
const BUY_UNIKEY_PRE = 'ingame.market.buy:'; const BUY_UNIKEY_PRE = 'ingame.market.buy:';
const SELL_MAIL_SUBJECT = 'Item successfully sold';
/* /*
orderId订单id orderId订单id
to邮件接受方account_id to邮件接受方account_id
@ -22,7 +24,7 @@ class MailApiService extends BaseService {
*/ */
public function sendSellMail($orderId, $to, $subject, $content, $attachments) public function sendSellMail($orderId, $to, $subject, $content, $attachments)
{ {
$unikey = self::SELL_UNIKEY_PRE . $oderId; $unikey = self::SELL_UNIKEY_PRE . $orderId;
SqlHelper::upsert SqlHelper::upsert
(myself()->_getMailMysql(), (myself()->_getMailMysql(),
't_sys_mail', 't_sys_mail',
@ -66,7 +68,7 @@ class MailApiService extends BaseService {
*/ */
public function sendBuyMail($orderId, $to, $subject, $content, $attachments) public function sendBuyMail($orderId, $to, $subject, $content, $attachments)
{ {
$unikey = self::BUY_UNIKEY_PRE . $oderId; $unikey = self::BUY_UNIKEY_PRE . $orderId;
SqlHelper::upsert SqlHelper::upsert
(myself()->_getMailMysql(), (myself()->_getMailMysql(),
't_sys_mail', 't_sys_mail',