800 lines
26 KiB
PHP
800 lines
26 KiB
PHP
<?php
|
|
|
|
require_once('phpcommon/bignumber.php');
|
|
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Language.php');
|
|
|
|
require_once('models/InGameMall.php');
|
|
require_once('models/OrderId.php');
|
|
require_once('models/HeroSkin.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Bag.php');
|
|
|
|
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;
|
|
|
|
use models\InGameMall;
|
|
use models\OrderId;
|
|
use models\HeroSkin;
|
|
use models\Chip;
|
|
use models\Bag;
|
|
|
|
use services\LogService;
|
|
use services\BlockChainService;
|
|
use services\AwardService;
|
|
use services\PropertyChgService;
|
|
|
|
/*
|
|
碎片、芯片、宝箱、英雄
|
|
*/
|
|
class InGameMallController extends BaseAuthedController {
|
|
|
|
|
|
|
|
private $mailApiService = null;
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
$this->mailApiService = new \services\MailApiService();
|
|
myself()->_verifySwitch('ingameMall');
|
|
}
|
|
|
|
public function productList()
|
|
{
|
|
$page = getReqVal('page', 0);
|
|
$seller = getReqVal('seller', '');
|
|
$queryData = array();
|
|
if (!empty($seller)) {
|
|
$queryData['seller'] = $seller;
|
|
}
|
|
$type_filter = getReqVal('type_filter', '');
|
|
if (!empty($type_filter)) {
|
|
$queryData['type_filter'] = $type_filter;
|
|
}
|
|
$item_filter = getReqVal('item_filter', '');
|
|
if (!empty($item_filter)) {
|
|
$queryData['item_filter'] = $item_filter;
|
|
}
|
|
$quality_filter = getReqVal('quality_filter', '');
|
|
if (!empty($quality_filter)) {
|
|
$queryData['quality_filter'] = $quality_filter;
|
|
}
|
|
$queryData['price_filter'] = getReqVal('price_filter', '');
|
|
$orderBy = '';
|
|
$orderAsc = 'ASC';
|
|
if (getReqVal('order_asc', '') == 1) {
|
|
$orderAsc = 'DESC';
|
|
}
|
|
switch (getReqVal('order_method', '')) {
|
|
case 1:
|
|
{
|
|
$orderBy = 'ORDER BY createtime ' . $orderAsc;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$orderBy = 'ORDER BY length(unit_price) ' . $orderAsc . ', unit_price ' . $orderAsc;
|
|
}
|
|
break;
|
|
}
|
|
|
|
$out = array(
|
|
'pagination' => array(),
|
|
'rows' => array()
|
|
);
|
|
SqlHelper::rawQueryPage(
|
|
myself()->_getMySql(''),
|
|
'SELECT * FROM t_ingame_mall WHERE status=:status',
|
|
array(
|
|
':status' => InGameMall::PENDING_STATE
|
|
),
|
|
array(
|
|
'page' => $page,
|
|
'perPage' => 8,
|
|
'filter' => array(
|
|
'data' => $queryData,
|
|
'fields' => array(
|
|
array(
|
|
'name' => 'seller',
|
|
'field_name' => 'seller',
|
|
'cond' => '=',
|
|
'ignore_empty' => true,
|
|
),
|
|
array(
|
|
'name' => 'price_filter',
|
|
'field_name' => '',
|
|
'cond' => 'custom',
|
|
'ignore_empty' => true,
|
|
'custom_func' => function () use ($queryData) {
|
|
$priceFilters = $queryData['price_filter'];
|
|
$arrPriceFilter = explode('|', $priceFilters);
|
|
$priceLow = $arrPriceFilter[0];
|
|
$priceHigh = $arrPriceFilter[1];
|
|
return " AND (length(price) >= length('${priceLow}') AND length(price) <= length('${priceHigh}')) "
|
|
. " AND (price >= '${priceLow}' AND price <= '${priceHigh}') ";
|
|
}
|
|
),
|
|
array(
|
|
'name' => 'item_filter',
|
|
'field_name' => '',
|
|
'cond' => 'custom',
|
|
'ignore_empty' => true,
|
|
'custom_func' => function () use ($queryData) {
|
|
$itemFilters = $queryData['item_filter'];
|
|
$arrItemFilters = explode('|', $itemFilters);
|
|
if(count($arrItemFilters) > 1){
|
|
$strWhere = implode(',',$arrItemFilters);
|
|
return "AND item_id IN (${strWhere})";
|
|
}else{
|
|
return "AND item_id = '${itemFilters}'";
|
|
}
|
|
}
|
|
),
|
|
array(
|
|
'name' => 'quality_filter',
|
|
'field_name' => 'order1',
|
|
'cond' => '=',
|
|
'ignore_empty' => true,
|
|
),
|
|
array(
|
|
'name' => 'type_filter',
|
|
'field_name' => '',
|
|
'cond' => 'custom',
|
|
'ignore_empty' => true,
|
|
'custom_func' => function () use ($queryData) {
|
|
$typeFilter = $queryData['type_filter'];
|
|
if ($typeFilter == 1){
|
|
return "AND ((order_type = 1) OR (order_type = 4))";
|
|
}else{
|
|
return "AND (order_type = '${typeFilter}')";
|
|
}
|
|
}
|
|
),
|
|
)
|
|
),
|
|
'orderBy' => $orderBy,
|
|
'handle' => function ($row) use(&$out) {
|
|
switch ($row['order_type']){
|
|
case InGameMall::HERO_SKIN_TYPE :{
|
|
$row['item_info'] = HeroSkin::toDto(HeroSkin::findEx($row['goods_uniid']));
|
|
}
|
|
break;
|
|
case InGameMall::CHIP_TYPE :{
|
|
$row['item_info'] = Chip::toDto(Chip::findEx($row['goods_uniid']));
|
|
}
|
|
break;
|
|
default:{
|
|
$row['item_info'] = array();
|
|
}
|
|
}
|
|
array_push($out['rows'], $row);
|
|
}
|
|
),
|
|
$out['pagination']
|
|
);
|
|
myself()->_rspData($out);
|
|
}
|
|
|
|
public function sellS()
|
|
{
|
|
$goodsUniid = getReqVal('goods_uniid', '');
|
|
$itemId = getReqVal('item_id', '');
|
|
$amount = intval(getReqVal('amount', ''), 10);
|
|
$priceBn = intval(getReqVal('price', ''));
|
|
$itemMeta = \mt\Item::get($itemId);
|
|
$orderField = 0;
|
|
if (!$itemMeta){
|
|
$this->_rspErr(1, 'param item_id error');
|
|
return;
|
|
}
|
|
if ($itemId != V_ITEM_GOLD){
|
|
if (! $this->_isGoodsType($itemMeta['type'])){
|
|
$this->_rspErr(1, 'param item_id error');
|
|
return;
|
|
}
|
|
}
|
|
switch ($itemMeta['type']){
|
|
case \mt\Item::HERO_SKIN_TYPE : {
|
|
$skinDb = HeroSkin::find($goodsUniid);
|
|
if (!$skinDb || $skinDb['used'] == HeroSkin::USED){
|
|
$this->_rspErr(1, 'param goods_unnid error');
|
|
return;
|
|
}
|
|
$orderField = $itemMeta['quality'];
|
|
}
|
|
break;
|
|
case \mt\Item::CHIP_TYPE : {
|
|
$chipDb = Chip::find($goodsUniid);
|
|
if (!$chipDb || !empty($chipDb['token_id']) || $chipDb['item_id']!= $itemId){
|
|
$this->_rspErr(1, 'param goods_unnid error');
|
|
return;
|
|
}
|
|
if ($chipDb['inlay_state'] == 1){
|
|
$this->_rspErr(1, 'Unable to sell goods in use');
|
|
return;
|
|
}
|
|
$orderField = $chipDb['quality'];
|
|
}
|
|
break;
|
|
default : {
|
|
$orderField = $itemMeta['quality'];
|
|
}
|
|
}
|
|
if ($amount <= 0) {
|
|
$this->_rspErr(1, 'amount must > 0');
|
|
return;
|
|
}
|
|
$minPrice = \mt\Parameter::getVal("market_place_min_price",100);
|
|
if (!$this->_isNumber($priceBn) || $priceBn < 0 || $priceBn < $minPrice) {
|
|
$this->_rspErr(1, 'param price error');
|
|
return;
|
|
}
|
|
if ($priceBn > 0xFFFFFFFF) {
|
|
$this->_rspErr(1, 'param price error');
|
|
return;
|
|
}
|
|
$propertyChgService = new PropertyChgService();
|
|
if (\mt\Item::isBagItem($itemMeta['type'],$itemMeta['sub_type']) || $itemId == V_ITEM_GOLD){
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $amount
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService->addBagChg();
|
|
$propertyChgService->addUserChg();
|
|
}elseif ($itemMeta['type'] == \mt\Item::CHIP_TYPE){
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_chip',
|
|
array(
|
|
'idx' => $goodsUniid,
|
|
),
|
|
array(
|
|
'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT
|
|
)
|
|
);
|
|
$propertyChgService->addChip();
|
|
}elseif ($itemMeta['type'] == \mt\Item::HERO_SKIN_TYPE){
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $goodsUniid,
|
|
),
|
|
array(
|
|
'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT
|
|
)
|
|
);
|
|
$propertyChgService->addHeroChg();
|
|
}
|
|
|
|
$orderId = OrderId::gen();
|
|
$orderType = $this->_getGoodsType($itemMeta);
|
|
if ($orderType == InGameMall::GOLD_TYPE){
|
|
$payType = 1;
|
|
}else{
|
|
$payType = 0;
|
|
}
|
|
InGameMall::add(
|
|
$orderId,
|
|
$orderType,
|
|
$goodsUniid,
|
|
$itemId,
|
|
$amount,
|
|
$payType,
|
|
$priceBn,
|
|
$orderField
|
|
);
|
|
myself()->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function buyS(){
|
|
$orderId = getReqVal('order_id', '');
|
|
$goodsDb = InGameMall::findByOrderId($orderId);
|
|
if (!$goodsDb) {
|
|
myself()->_rspErr(1, 'goods not found');
|
|
return;
|
|
}
|
|
if ($goodsDb['status'] != InGameMall::PENDING_STATE){
|
|
myself()->_rspErr(1, 'cannot cancel the goods');
|
|
return;
|
|
}
|
|
if ($goodsDb['price'] < 0){
|
|
myself()->_rspErr(1, ' goods price error');
|
|
return;
|
|
}
|
|
if ($goodsDb['pay_type'] == 1){
|
|
$costItemId = V_ITEM_DIAMOND;
|
|
}else{
|
|
$costItemId = V_ITEM_GOLD;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $costItemId,
|
|
'item_num' => $goodsDb['price']
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$propertyChgService = new PropertyChgService();
|
|
$this->_buyGoods($goodsDb,$propertyChgService);
|
|
myself()->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function _buyGoods($goods,$propertyChgService){
|
|
if (!$goods){
|
|
return;
|
|
}
|
|
if ($goods['pay_type'] == 1){
|
|
$payType = 'diamond';
|
|
$payItemId = V_ITEM_DIAMOND;
|
|
}else{
|
|
$payType = 'gold';
|
|
$payItemId = V_ITEM_GOLD;
|
|
}
|
|
$price = $goods['price'];
|
|
InGameMall::buyOk($goods['order_id'],myself()->_getAccountId());
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $payItemId,
|
|
'item_num' => $price
|
|
)
|
|
);
|
|
$this->_decItems($costItems);
|
|
|
|
switch ($goods['order_type']){
|
|
case InGameMall::HERO_SKIN_TYPE :{
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $goods['goods_uniid'],
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId()
|
|
)
|
|
);
|
|
$propertyChgService->addHeroChg();
|
|
}
|
|
break;
|
|
case InGameMall::CHIP_TYPE:{
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_chip',
|
|
array(
|
|
'idx' => $goods['goods_uniid'],
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId()
|
|
)
|
|
);
|
|
$propertyChgService->addChip();
|
|
}
|
|
break;
|
|
case InGameMall::GOLD_TYPE:{
|
|
myself()->_addVirtualItem($goods['item_id'],$goods['item_num']);
|
|
$propertyChgService->addUserChg();
|
|
}
|
|
break;
|
|
|
|
default : {
|
|
Bag::addItem($goods['item_id'],$goods['item_num']);
|
|
$propertyChgService->addBagChg();
|
|
}
|
|
}
|
|
$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']);
|
|
$itemName = $languageMeta ? $languageMeta['en'] : "The Item";
|
|
$taxRate = \mt\Parameter::getVal("market_place_tax_rate",0.05);
|
|
$taxGold = ceil($price*$taxRate);
|
|
$falGold = $price - $taxGold;
|
|
|
|
|
|
|
|
$mailContent = <<<EOD
|
|
{$itemName} has been successfully sold
|
|
Transaction price: + {$price} {$payType}
|
|
Service fee: - {$taxGold} {$payType}
|
|
After selling {$itemName}, you received {$falGold} {$payType}
|
|
EOD;
|
|
$attachments = array(
|
|
array(
|
|
'itemid' => $payItemId,
|
|
'itemnum' => $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' => $payItemId,
|
|
'item_num' => $falGold
|
|
),
|
|
);
|
|
LogService::burialPointEvent($event1);
|
|
}
|
|
|
|
public function cancelS()
|
|
{
|
|
$orderId = getReqVal('order_id', '');
|
|
$goodsDb = InGameMall::findByOrderId($orderId);
|
|
if (!$goodsDb) {
|
|
myself()->_rspErr(1, 'goods not found');
|
|
return;
|
|
}
|
|
if ($goodsDb['status'] != InGameMall::PENDING_STATE){
|
|
myself()->_rspErr(1, 'cannot cancel the goods');
|
|
return;
|
|
}
|
|
if ($goodsDb['seller'] != myself()->_getAccountId()){
|
|
myself()->_rspErr(1, 'Not the seller');
|
|
return;
|
|
}
|
|
InGameMall::cancel($orderId);
|
|
$awardService = new services\AwardService();
|
|
$propertyChgService = new PropertyChgService();
|
|
switch ($goodsDb['order_type']){
|
|
case InGameMall::HERO_SKIN_TYPE :{
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
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:{
|
|
myself()->_addItems(array(
|
|
array(
|
|
'item_id' => $goodsDb['item_id'],
|
|
'item_num' => $goodsDb['item_num'],
|
|
)
|
|
), $awardService, $propertyChgService);
|
|
}
|
|
break;
|
|
default : {
|
|
Bag::addItem($goodsDb['item_id'],$goodsDb['item_num']);
|
|
$propertyChgService->addBagChg();
|
|
}
|
|
}
|
|
|
|
myself()->_rspData(array(
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function modifyPrice()
|
|
{
|
|
$orderId = getReqVal('order_id', '');
|
|
$priceBn =intval(getReqVal('price', ''));
|
|
$minPrice = \mt\Parameter::getVal("market_place_min_price",100);
|
|
if (!$this->_isNumber($priceBn) || $priceBn < $minPrice) {
|
|
$this->_rspErr(1, 'param price error');
|
|
return;
|
|
}
|
|
if ($priceBn > 0xFFFFFFFF) {
|
|
$this->_rspErr(1, 'param price error');
|
|
return;
|
|
}
|
|
$goodsDb = InGameMall::findByOrderId($orderId);
|
|
if (!$goodsDb) {
|
|
myself()->_rspErr(1, 'goods not found');
|
|
return;
|
|
}
|
|
if ($goodsDb['status'] != InGameMall::PENDING_STATE){
|
|
myself()->_rspErr(1, 'cannot cancel the goods');
|
|
return;
|
|
}
|
|
if ($goodsDb['seller'] != myself()->_getAccountId()){
|
|
myself()->_rspErr(1, 'Not the seller');
|
|
return;
|
|
}
|
|
$unitPrice = $priceBn / $goodsDb['item_num'];
|
|
InGameMall::modifyPrice($orderId, $priceBn,$unitPrice);
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public function sellList(){
|
|
$page = getReqVal('page', 0);
|
|
$orderBy = '';
|
|
$orderAsc = 'ASC';
|
|
if (getReqVal('order_asc', '') == 1) {
|
|
$orderAsc = 'DESC';
|
|
}
|
|
switch (getReqVal('order_method', '')) {
|
|
case 1:
|
|
{
|
|
$orderBy = 'ORDER BY buy_ok_time ' . $orderAsc;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$orderBy = 'ORDER BY length(unit_price) ' . $orderAsc . ', unit_price ' . $orderAsc;
|
|
}
|
|
break;
|
|
}
|
|
|
|
$out = array(
|
|
'pagination' => array(),
|
|
'rows' => array()
|
|
);
|
|
SqlHelper::rawQueryPage(
|
|
myself()->_getMySql(''),
|
|
'SELECT * FROM t_ingame_mall WHERE seller=:seller AND status=:status',
|
|
array(
|
|
':seller' => myself()->_getAccountId(),
|
|
':status' => InGameMall::BUY_OK_STATE,
|
|
),
|
|
array(
|
|
'page' => $page,
|
|
'perPage' => 8,
|
|
'orderBy' => $orderBy,
|
|
'handle' => function ($row) use(&$out) {
|
|
array_push($out['rows'], $row);
|
|
}
|
|
),
|
|
$out['pagination']
|
|
);
|
|
myself()->_rspData($out);
|
|
}
|
|
|
|
|
|
|
|
public function buyList(){
|
|
$page = getReqVal('page', 0);
|
|
$orderBy = '';
|
|
$orderAsc = 'ASC';
|
|
if (getReqVal('order_asc', '') == 1) {
|
|
$orderAsc = 'DESC';
|
|
}
|
|
switch (getReqVal('order_method', '')) {
|
|
case 1:
|
|
{
|
|
$orderBy = 'ORDER BY buy_ok_time ' . $orderAsc;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$orderBy = 'ORDER BY length(unit_price) ' . $orderAsc . ', unit_price ' . $orderAsc;
|
|
}
|
|
break;
|
|
}
|
|
|
|
$out = array(
|
|
'pagination' => array(),
|
|
'rows' => array()
|
|
);
|
|
SqlHelper::rawQueryPage(
|
|
myself()->_getMySql(''),
|
|
'SELECT * FROM t_ingame_mall WHERE buyer=:buyer AND status=:status',
|
|
array(
|
|
':buyer' => myself()->_getAccountId(),
|
|
':status' => InGameMall::BUY_OK_STATE,
|
|
),
|
|
array(
|
|
'page' => $page,
|
|
'perPage' => 8,
|
|
'orderBy' => $orderBy,
|
|
'handle' => function ($row) use(&$out) {
|
|
array_push($out['rows'], $row);
|
|
}
|
|
),
|
|
$out['pagination']
|
|
);
|
|
myself()->_rspData($out);
|
|
}
|
|
|
|
public function shoppingCartList(){
|
|
$orderIds = getReqVal('order_ids', '');
|
|
if (!$orderIds){
|
|
$this->_rspErr(1, 'param is not null');
|
|
return;
|
|
}
|
|
$orderIdArr = explode("|",$orderIds);
|
|
$list = array();
|
|
foreach ($orderIdArr as $orderId){
|
|
$orderDb = InGameMall::findByOrderId($orderId);
|
|
if ($orderDb){
|
|
switch ($orderDb['order_type']){
|
|
case InGameMall::HERO_SKIN_TYPE :{
|
|
$orderDb['item_info'] = HeroSkin::toDto(HeroSkin::findEx($orderDb['goods_uniid']));
|
|
}
|
|
break;
|
|
case InGameMall::CHIP_TYPE :{
|
|
$orderDb['item_info'] = Chip::toDto(Chip::findEx($orderDb['goods_uniid']));
|
|
}
|
|
break;
|
|
default:{
|
|
$orderDb['item_info'] = array();
|
|
}
|
|
}
|
|
array_push($list,$orderDb);
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'list' => $list
|
|
));
|
|
}
|
|
|
|
public function shoppingCartBuyS(){
|
|
$orderIds = getReqVal('order_ids', '');
|
|
if (!$orderIds){
|
|
$this->_rspErr(1, 'param is not null');
|
|
return;
|
|
}
|
|
$orderIdArr = explode("|",$orderIds);
|
|
$goldPrice = 0;
|
|
$diamondPrice = 0;
|
|
foreach ($orderIdArr as $orderId) {
|
|
$goodsDb = InGameMall::findByOrderId($orderId);
|
|
if (!$goodsDb) {
|
|
myself()->_rspErr(1, 'goods not found');
|
|
return;
|
|
}
|
|
if ($goodsDb['status'] != InGameMall::PENDING_STATE){
|
|
myself()->_rspErr(1, 'cannot cancel the goods');
|
|
return;
|
|
}
|
|
if ($goodsDb['pay_type'] == 1){
|
|
$diamondPrice += $goodsDb['price'];
|
|
}else{
|
|
$goldPrice += $goodsDb['price'];
|
|
}
|
|
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $goldPrice
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => $diamondPrice
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$propertyChgService = new PropertyChgService();
|
|
foreach ($orderIdArr as $orderId) {
|
|
$goodsDb = InGameMall::findByOrderId($orderId);
|
|
if ($goodsDb['status'] != InGameMall::PENDING_STATE){
|
|
continue;
|
|
}
|
|
$this->_buyGoods($goodsDb,$propertyChgService);
|
|
}
|
|
myself()->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function _isNumber($number){
|
|
if (is_int($number) && $number > 0){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function _isGoodsType($type){
|
|
if (in_array($type,array(
|
|
\mt\Item::HERO_SKIN_TYPE, //皮肤
|
|
\mt\Item::CHIP_TYPE, //芯片
|
|
\mt\Item::FRAGMENT_TYPE, //碎片
|
|
\mt\Item::BATTLE_REWARD_BOX,//宝箱
|
|
\mt\Item::MATERIAL_TYPE, //材料(芯片合成材料)
|
|
))){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function _getGoodsType($itemMeta){
|
|
if (!$itemMeta){
|
|
return 0;
|
|
}
|
|
if ($itemMeta['id'] == V_ITEM_GOLD){
|
|
return InGameMall::GOLD_TYPE;
|
|
}
|
|
switch ($itemMeta['type']){
|
|
case \mt\Item::HERO_SKIN_TYPE : {
|
|
return InGameMall::HERO_SKIN_TYPE;
|
|
}
|
|
case \mt\Item::CHIP_TYPE : {
|
|
return InGameMall::CHIP_TYPE;
|
|
}
|
|
case \mt\Item::FRAGMENT_TYPE : {
|
|
if ($itemMeta['sub_type'] == \mt\Item::HERO_FRAGMENT_SUBTYPE){
|
|
return InGameMall::HERO_FRAGMENT_TYPE;
|
|
}elseif ($itemMeta['sub_type'] == \mt\Item::SKIN_FRAGMENT_SUBTYPE){
|
|
return InGameMall::SKIN_FRAGMENT_TYPE;
|
|
}else{
|
|
return 0;
|
|
}
|
|
}
|
|
case \mt\Item::BATTLE_REWARD_BOX : {
|
|
return InGameMall::OTHER_TYPE;
|
|
}
|
|
case \mt\Item::MATERIAL_TYPE : {
|
|
return InGameMall::OTHER_TYPE;
|
|
}
|
|
default : {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|