array(), 'rows' => array() ); SqlHelper::rawQueryPage( myself()->_getMySql(''), 'SELECT * FROM t_ingame_mall WHERE status=:status', array( ':status' => Mall::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' => 'item_id', 'cond' => '=', 'ignore_empty' => true, ), array( 'name' => 'type_filter', 'field_name' => 'order_type', 'cond' => '=', 'ignore_empty' => true, ) ) ), 'orderBy' => $orderBy, 'handle' => function ($row) use(&$out) { array_push($out['rows'], $row); } ), $out['pagination'] ); myself()->_rspData($out); } public function sell() { $goodsUniid = getReqVal('goods_uniid', ''); $itemId = getReqVal('item_id', ''); $amount = intval(getReqVal('amount', ''), 10); $priceBn = intval(getReqVal('price', '')); $itemMeta = \mt\Item::get($itemId); if (!$itemMeta){ $this->_rspErr(1, 'param item_id error'); return; } if (! $this->_isGoodsType($itemMeta['type'])){ $this->_rspErr(1, 'param item_id error'); 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; } } 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 ($amount <= 0) { $this->_rspErr(1, 'amount must > 0'); return; } if (!$this->_isNumber($priceBn) || $priceBn < 0) { $this->_rspErr(1, 'param price error'); return; } $propertyChgService = new PropertyChgService(); if (\mt\Item::isBagItem($itemMeta['type'],$itemMeta['sub_type'])){ $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(); }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(), 't_chip', array( 'idx' => $goodsUniid, ), array( 'account_id' => InGameMall::SYSTEM_MALL_ACCOUNT ) ); $propertyChgService->addChip(); } $orderId = OrderId::gen(); $orderType = $this->_getGoodsType($itemMeta['type']); InGameMall::add( $orderId, $orderType, $goodsUniid, $itemId, $amount, $priceBn ); myself()->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function buy(){ $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; } $price = $goodsDb['price']; $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $price ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); SqlHelper::update ($this->_getSelfMysql(), 't_user', array( 'account_id' => $goodsDb['seller'] ), array( 'gold' => function () use($price) { return "gold + ${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; case InGameMall::CHIP_TYPE:{ SqlHelper::update (myself()->_getSelfMysql(), 't_chip', array( 'idx' => $goodsDb['goods_uniid'], ), array( 'account_id' => myself()->_getAccountId() ) ); $propertyChgService->addChip(); } break; default : { Bag::addItem($goodsDb['item_id'],$goodsDb['item_num']); $propertyChgService->addBagChg(); } } InGameMall::buyOk($orderId,myself()->_getAccountId()); myself()->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function cancel() { $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; } $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; case InGameMall::CHIP_TYPE:{ SqlHelper::update (myself()->_getSelfMysql(), 't_chip', array( 'idx' => $goodsDb['goods_uniid'], ), array( 'account_id' => myself()->_getAccountId() ) ); $propertyChgService->addChip(); } break; default : { Bag::addItem($goodsDb['item_id'],$goodsDb['item_num']); $propertyChgService->addBagChg(); } } InGameMall::cancel($orderId); myself()->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function modifyPrice() { $orderId = getReqVal('order_id', ''); $priceBn =intval(getReqVal('price', '')); if (!$this->_isNumber($priceBn)) { $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; } InGameMall::modifyPrice($orderId, $priceBn); myself()->_rspOk(); } 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_TYPE, \mt\Item::CHIP_TYPE, \mt\Item::FRAGMENT_TYPE, \mt\Item::TREASURE_BOX, ))){ return true; }else{ return false; } } private function _getGoodsType($type){ switch ($type){ case \mt\Item::HERO_TYPE : { return InGameMall::HERO_TYPE; } case \mt\Item::CHIP_TYPE : { return InGameMall::CHIP_TYPE; } case \mt\Item::FRAGMENT_TYPE : { return InGameMall::FRAGMENT_TYPE; } case \mt\Item::TREASURE_BOX : { return InGameMall::BOX_TYPE; } default : { return 0; } } } }