From a7ca1bdc473c4f8b054c23b6b2d1572a5704d595 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 7 Aug 2023 12:48:31 +0800 Subject: [PATCH] 1 --- webapp/controller/MallController.class.php | 118 ++++----------------- webapp/models/Mall.php | 77 ++++++-------- 2 files changed, 53 insertions(+), 142 deletions(-) diff --git a/webapp/controller/MallController.class.php b/webapp/controller/MallController.class.php index 81eefd7a..89b1bfc8 100644 --- a/webapp/controller/MallController.class.php +++ b/webapp/controller/MallController.class.php @@ -60,117 +60,41 @@ class MallController extends BaseAuthedController { myself()->_rspData($out); } + public function sell() + { + + } + public function cancel() { - $idx = getReqVal('idx', ''); - - $address = $this->_getAddress(); - if (!$address) { - $this->_rspErr(1, 'address not found'); + $goodsUuid = getReqVal('goods_uuid', ''); + $goodsDb = Mall::findByGoodsUuid($goodsUuid); + if (!$goodsDb) { + myself()->_resErr(1, 'goods not found'); return; } - - $goods = $this->getGoodsByIdx($idx); - if (!$goods) { - $this->_rspErr(1, 'goods not found, idx:' . $idx); + if ($goodDb['seller'] != myself()->_getAccountId()) { + myself()->_resErr(1, 'goods not found'); return; } - - if ($goods['owner_address'] != $address) { - $this->_rspErr(1, 'not your goods, idx:' . $idx); - return; - } - - $conn = $this->_getSelfMysql(); - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'idx' => $idx, - ), - array( - 'status' => 1, - 'modifytime' => $this->_getNowTime(), - ) - ); - if ($r) { - $items = array( - array( - 'item_id' => $goods['item_id'], - 'item_num' => $goods['amount'], - ) - ); - $awardService = new services\AwardService(); - $propertyChgService = new services\PropertyChgService(); - $this->_addItems($items, $awardService, $propertyChgService); - - { - //埋点 - $event = [ - 'name' => LogService::MARKET_CANCEL_SELL_GOLD, - 'val' => $goods['amount'] - ]; - LogService::productGold($event); - } - - $this->_rspData( - array( - 'idx' => $idx, - 'property_chg' => $propertyChgService->toDto(), - ) - ); - } else { - $this->_rspErr(1, 'cancel failed'); - } + Mall::cancel($goodsDb['goods_uuid']); + myself()->_rspOk(); } public function modifyPrice() { - $idx = getReqVal('idx', ''); - $s_price = getReqVal('s_price', ''); - if (empty($s_price)) { - $this->_rspErr(1, 's_price not found'); + $goodsUuid = getReqVal('goods_uuid', ''); + $price = getReqVal('price', ''); + $goodsDb = Mall::findByGoodsUuid($goodsUuid); + if (!$goodsDb) { + myself()->_resErr(1, 'goods not found'); return; } - if (!is_numeric($s_price)) { - $this->_rspErr(1, 's_price must be number'); + if ($goodDb['seller'] != myself()->_getAccountId()) { + myself()->_resErr(1, 'goods not found'); return; } - - $address = $this->_getAddress(); - if (!$address) { - $this->_rspErr(1, 'address not found'); - return; - } - - $goods = $this->getGoodsByIdx($idx); - if (!$goods) { - $this->_rspErr(1, 'goods not found, idx:' . $idx); - return; - } - - if ($goods['owner_address'] != $address) { - $this->_rspErr(1, 'not your goods, idx:' . $idx); - return; - } - - $conn = $this->_getSelfMysql(); - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'idx' => $idx, - ), - array( - 's_price' => $s_price, - 'modifytime' => $this->_getNowTime(), - ) - ); - if (!$r) { - $this->_rspErr(1, 'update price failed'); - return; - } - + Mall::modifyPrice($goodsDb['goods_uuid'], $price); $this->_rspOk(); } diff --git a/webapp/models/Mall.php b/webapp/models/Mall.php index 7b9a1890..0287dacc 100644 --- a/webapp/models/Mall.php +++ b/webapp/models/Mall.php @@ -10,10 +10,21 @@ class Mall extends BaseModel { const BUY_OK_STATE = 1; const CANCEL_STATE = 2; - public static function find($orderId){ + public static function findByGoodsUuid($goodsUuid){ $row = SqlHelper::ormSelectOne( myself()->_getMysql(''), - 't_market', + 't_mall', + array( + 'goods_uuid' => $goodsUuid + ) + ); + return $row; + } + + public static function findByOrderId($orderId){ + $row = SqlHelper::ormSelectOne( + myself()->_getMysql(''), + 't_mall', array( 'order_id' => $orderId ) @@ -39,53 +50,29 @@ class Mall extends BaseModel { )); } - public static function updatePrice($orderId, $price) { - self::internalUpdate( - $orderId, - array( - 'update_price' => $price, - 'update_time' => myself()->_getNowTime(), - )); - } - - public static function buyOk($orderId) { - self::internalUpdate( - $orderId, - array( - 'status' => self::BUY_OK_STATE, - )); - } - - public static function cancel($orderId) { - self::internalUpdate( - $orderId, - array( - 'status' => self::CANCEL_STATE, - )); - } - - private static function internalUpdate($orderId, $fieldsKv){ - SqlHelper::upsert - (myself()->_getMysql(''), - 't_market', - array( - 'order_id' => $orderId - ), - array( - ), - array( - 'order_id' => $orderId, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - ) - ); + public static function modifyPrice($goodsUuid, $price) { SqlHelper::update (myself()->_getMysql(''), - 't_market', + 't_mall', array( - 'order_id' => $orderId + 'goods_uuid' => $goodsUuid ), - $fieldsKv + array( + 'price' => $price + ) + ); + } + + public static function cancel($goodsUuid) { + SqlHelper::update + (myself()->_getMysql(''), + 't_mall', + array( + 'goods_uuid' => $goodsUuid + ), + array( + 'status' => self::CANCEL_STATE + ) ); }