priceLowBn = phpcommon\bnInit(self::PRICE_LOW); $this->priceHighBn = phpcommon\bnInit(self::PRICE_HIGH); } public function productList() { $page = getReqVal('page', 0); $seller = getReqVal('seller', ''); $queryData = array(); if (!empty($seller)) { $queryData['seller'] = $seller; } $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(price) ' . $orderAsc . ', price ' . $orderAsc; } break; } $out = array( 'pagination' => array(), 'rows' => array() ); SqlHelper::rawQueryPage( myself()->_getMySql(''), 'SELECT * FROM t_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_address', '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}') "; } ), ) ), 'orderBy' => $orderBy, 'handle' => function ($row) use(&$out) { array_push($out['rows'], Mall::toDto($row)); } ), $out['pagination'] ); myself()->_rspData($out); } public function sell() { $address = myself()->_getAddress(); if (!$address) { $this->_rspErr(1, 'address not found'); return; } $itemId = getReqVal('item_id', ''); $amount = intval(getReqVal('amount', ''), 10); $currency = getReqVal('currency', ''); $priceBn = phpcommon\bnInit(getReqVal('price', '')); if ($itemId != V_ITEM_GOLD) { $this->_rspErr(1, 'only support gold'); return; } if ($amount <= 0) { $this->_rspErr(1, 'amount must > 0'); return; } if (!$this->checkPrice($priceBn)) { return; } if (!in_array( $currency, array( BlockChainService::CURRENCY_CEG, BlockChainService::CURRENCY_USDC, BlockChainService::CURRENCY_USDT, ) )) { $this->_rspErr(1, 'paramater error currency'); return; } $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); if ($itemId == V_ITEM_GOLD) { //埋点 $event = [ 'name' => LogService::MARKET_SELL_GOLD, 'val' => $amount ]; LogService::consumeGold($event); } $orderId = OrderId::gen(); Mall::Add( $orderId, $orderId, $itemId, $amount, $currency, phpcommon\bnToStr($priceBn) ); myself()->_rspOk(); } public function cancel() { $goodsUuid = getReqVal('goods_uuid', ''); $goodsDb = Mall::findByGoodsUuid($goodsUuid); if (!$goodsDb) { myself()->_rspErr(1, 'goods not found'); return; } $goodsDto = Mall::toDto($goodsDb); if ($goodsDto['cancel_countdown'] != 0) { myself()->_rspErr(1, 'cant cancel'); return; } $awardService = new AwardService(); $propertyChgService = new PropertyChgService(); switch ($goodsDb['item_id']) { case V_ITEM_GOLD: { $items = array( array( 'item_id' => $goodsDb['item_id'], 'item_num' => $goodsDb['item_num'], ) ); Mall::cancel($goodsDto['goods_uuid']); myself()->_addItems($items, $awardService, $propertyChgService); { //埋点 $event = [ 'name' => LogService::MARKET_CANCEL_SELL_GOLD, 'val' => $goods['amount'] ]; LogService::productGold($event); } } break; default: { myself()->_rspErr(1, 'cant cancel'); return; } break; } myself()->_rspData(array( 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), )); } public function modifyPrice() { $goodsUuid = getReqVal('goods_uuid', ''); $priceBn = phpcommon\bnInit(getReqVal('price', '')); if (!$this->checkPrice($priceBn)) { return; } $goodsDb = Mall::findByGoodsUuid($goodsUuid); if (!$goodsDb) { myself()->_rspErr(1, 'goods not found'); return; } $goodsDto = Mall::toDto($goodsDb); if ($goodsDto['modify_countdown'] != 0) { myself()->_rspErr(1, 'cant modify price'); return; } Mall::modifyPrice($goodsDto['goods_uuid'], phpcommon\bnToStr($priceBn)); myself()->_rspOk(); } private function checkPrice($priceBn) { if ($priceBn === false) { myself()->_rspErr(1, 'price format error1'); return false; } if (phpcommon\bnCmp($this->priceLowBn, $priceBn) > 0) { myself()->_rspErr(1, 'price format error2'); return false; } if (phpcommon\bnCmp($this->priceHighBn, $priceBn) < 0) { myself()->_rspErr(1, 'price format error3'); return false; } return true; } }