diff --git a/webapp/controller/BaseController.class.php b/webapp/controller/BaseController.class.php index 6fae2bfa..6d453e4e 100644 --- a/webapp/controller/BaseController.class.php +++ b/webapp/controller/BaseController.class.php @@ -158,14 +158,14 @@ class BaseController { return $this->mailDbConn; } $mysql_conf = getMailMysqlConfig(); - $this->marketDbConn = new phpcommon\Mysql(array( + $this->mailDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => $mysql_conf['dbname'], )); - return $this->marketDbConn; + return $this->mailDbConn; } public function _getRelationDbMysql() diff --git a/webapp/controller/InGameMallController.class.php b/webapp/controller/InGameMallController.class.php index e72448cc..ca98151f 100644 --- a/webapp/controller/InGameMallController.class.php +++ b/webapp/controller/InGameMallController.class.php @@ -4,6 +4,7 @@ require_once('phpcommon/bignumber.php'); require_once('mt/Item.php'); require_once('mt/Parameter.php'); +require_once('mt/Language.php'); require_once('models/BcOrder.php'); require_once('models/Mall.php'); @@ -17,6 +18,7 @@ require_once('services/BlockChainService.php'); require_once('services/LogService.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); +require_once('services/MailApiService.php'); use phpcommon\SqlHelper; @@ -38,9 +40,13 @@ use services\PropertyChgService; */ class InGameMallController extends BaseAuthedController { + + + private $mailApiService = null; public function _handlePre() { parent::_handlePre(); + $this->mailApiService = new \services\MailApiService(); } public function productList() @@ -196,19 +202,19 @@ class InGameMallController extends BaseAuthedController { return; } switch ($itemMeta['type']){ - case \mt\Item::HERO_TYPE : { - $heroDb = Hero::find($goodsUniid); - if (!$heroDb || !empty($heroDb['token_id']) || $heroDb['hero_id']!= $itemId){ - $this->_rspErr(1, 'param goods_unnid error'); - return; - } - if ($heroDb['seal_type'] != 1){ - $this->_rspErr(1, 'Shelf heroes need to be packaged first'); - return; - } - $orderField = $heroDb['quality']; - } - break; +// case \mt\Item::HERO_TYPE : { +// $heroDb = Hero::find($goodsUniid); +// if (!$heroDb || !empty($heroDb['token_id']) || $heroDb['hero_id']!= $itemId){ +// $this->_rspErr(1, 'param goods_unnid error'); +// return; +// } +// if ($heroDb['seal_type'] != 1){ +// $this->_rspErr(1, 'Shelf heroes need to be packaged first'); +// return; +// } +// $orderField = $heroDb['quality']; +// } +// break; case \mt\Item::CHIP_TYPE : { $chipDb = Chip::find($goodsUniid); if (!$chipDb || !empty($chipDb['token_id']) || $chipDb['item_id']!= $itemId){ @@ -218,18 +224,18 @@ class InGameMallController extends BaseAuthedController { $orderField = $chipDb['quality']; } break; - case \mt\Item::GOLD_SYN :{ - $itemDb = Bag::findByUniId($goodsUniid); - if (!$itemDb || !empty($itemDb['token_id']) || $itemDb['item_id']!= $itemId){ - $this->_rspErr(1, 'param goods_unnid error'); - return; - } - if ($itemDb['item_num'] <= 0 || $amount > 1){ - $this->_rspErr(1, 'amount not enough'); - return; - } - } - break; +// case \mt\Item::GOLD_SYN :{ +// $itemDb = Bag::findByUniId($goodsUniid); +// if (!$itemDb || !empty($itemDb['token_id']) || $itemDb['item_id']!= $itemId){ +// $this->_rspErr(1, 'param goods_unnid error'); +// return; +// } +// if ($itemDb['item_num'] <= 0 || $amount > 1){ +// $this->_rspErr(1, 'amount not enough'); +// return; +// } +// } +// break; case \mt\Item::FRAGMENT_TYPE :{ $orderField = $itemMeta['quality']; } @@ -238,7 +244,8 @@ class InGameMallController extends BaseAuthedController { $this->_rspErr(1, 'amount must > 0'); 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'); return; } @@ -257,18 +264,6 @@ class InGameMallController extends BaseAuthedController { } $this->_decItems($costItems); $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){ SqlHelper::update (myself()->_getSelfMysql(), @@ -281,19 +276,31 @@ class InGameMallController extends BaseAuthedController { ) ); $propertyChgService->addChip(); - }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(); - } + }//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::GOLD_SYN){ +// SqlHelper::update +// (myself()->_getSelfMysql(), +// 't_bag', +// array( +// 'idx' => $goodsUniid, +// ), +// array( +// 'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT +// ) +// ); +// $propertyChgService->addBagChg(); +// } $orderId = OrderId::gen(); $orderType = $this->_getGoodsType($itemMeta); @@ -322,11 +329,10 @@ class InGameMallController extends BaseAuthedController { myself()->_rspErr(1, 'cannot cancel the goods'); return; } - $price = $goodsDb['price']; $costItems = array( array( 'item_id' => V_ITEM_GOLD, - 'item_num' => $price + 'item_num' => $goodsDb['price'] ) ); $lackItem = null; @@ -334,41 +340,34 @@ class InGameMallController extends BaseAuthedController { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); return; } - $this->_decItems($costItems); - SqlHelper::update - ($this->_getSelfMysql(), - 't_user', + $propertyChgService = new PropertyChgService(); + $this->_buyGoods($goodsDb,$propertyChgService); + myself()->_rspData(array( + '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( - 'account_id' => $goodsDb['seller'] - ), - array( - 'gold' => function () use($price) { - return "gold + ${price}"; - } + 'item_id' => V_ITEM_GOLD, + 'item_num' => $price ) ); - $propertyChgService = new PropertyChgService(); - 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; + $this->_decItems($costItems); + + switch ($goods['order_type']){ case InGameMall::CHIP_TYPE:{ SqlHelper::update (myself()->_getSelfMysql(), 't_chip', array( - 'idx' => $goodsDb['goods_uniid'], + 'idx' => $goods['goods_uniid'], ), array( 'account_id' => myself()->_getAccountId() @@ -377,29 +376,64 @@ class InGameMallController extends BaseAuthedController { $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']); + Bag::addItem($goods['item_id'],$goods['item_num']); $propertyChgService->addBagChg(); } } - InGameMall::buyOk($orderId,myself()->_getAccountId()); - myself()->_rspData(array( - 'property_chg' => $propertyChgService->toDto(), - )); + $event = array( + 'ID' => 'Mail', + '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 = << 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() @@ -418,6 +452,7 @@ class InGameMallController extends BaseAuthedController { myself()->_rspErr(1, 'Not the seller'); return; } + InGameMall::cancel($orderId); $propertyChgService = new PropertyChgService(); switch ($goodsDb['order_type']){ case InGameMall::HERO_TYPE :{ @@ -467,7 +502,7 @@ class InGameMallController extends BaseAuthedController { $propertyChgService->addBagChg(); } } - InGameMall::cancel($orderId); + myself()->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); @@ -477,7 +512,8 @@ class InGameMallController extends BaseAuthedController { { $orderId = getReqVal('order_id', ''); $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'); return; } @@ -651,71 +687,13 @@ class InGameMallController extends BaseAuthedController { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); return; } - $this->_decItems($costItems); $propertyChgService = new PropertyChgService(); foreach ($orderIdArr as $orderId) { $goodsDb = InGameMall::findByOrderId($orderId); - SqlHelper::update - ($this->_getSelfMysql(), - '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(); - } + if ($goodsDb['status'] != InGameMall::PENDING_STATE){ + continue; } - InGameMall::buyOk($orderId,myself()->_getAccountId()); + $this->_buyGoods($goodsDb,$propertyChgService); } myself()->_rspData(array( 'property_chg' => $propertyChgService->toDto(), @@ -732,11 +710,11 @@ class InGameMallController extends BaseAuthedController { private function _isGoodsType($type){ if (in_array($type,array( - \mt\Item::HERO_TYPE, +// \mt\Item::HERO_TYPE, \mt\Item::CHIP_TYPE, \mt\Item::FRAGMENT_TYPE, \mt\Item::BATTLE_REWARD_BOX, - \mt\Item::GOLD_SYN, +// \mt\Item::GOLD_SYN, ))){ return true; }else{ @@ -749,9 +727,9 @@ class InGameMallController extends BaseAuthedController { return ; } switch ($itemMeta['type']){ - case \mt\Item::HERO_TYPE : { - return InGameMall::HERO_TYPE; - } +// case \mt\Item::HERO_TYPE : { +// return InGameMall::HERO_TYPE; +// } case \mt\Item::CHIP_TYPE : { return InGameMall::CHIP_TYPE; } @@ -765,9 +743,9 @@ class InGameMallController extends BaseAuthedController { case \mt\Item::BATTLE_REWARD_BOX : { return InGameMall::BOX_TYPE; } - case \mt\Item::GOLD_SYN : { - return InGameMall::GOLD_TYPE; - } +// case \mt\Item::GOLD_SYN : { +// return InGameMall::GOLD_TYPE; +// } default : { return 0; } diff --git a/webapp/mt/Language.php b/webapp/mt/Language.php new file mode 100644 index 00000000..fbb211cb --- /dev/null +++ b/webapp/mt/Language.php @@ -0,0 +1,27 @@ +_getMailMysql(), 't_sys_mail', @@ -66,7 +68,7 @@ class MailApiService extends BaseService { */ public function sendBuyMail($orderId, $to, $subject, $content, $attachments) { - $unikey = self::BUY_UNIKEY_PRE . $oderId; + $unikey = self::BUY_UNIKEY_PRE . $orderId; SqlHelper::upsert (myself()->_getMailMysql(), 't_sys_mail',