diff --git a/webapp/controller/MallController.class.php b/webapp/controller/MallController.class.php index aa3653ad..de1bc4bb 100644 --- a/webapp/controller/MallController.class.php +++ b/webapp/controller/MallController.class.php @@ -46,31 +46,7 @@ class MallController extends BaseAuthedController { ), //'orderBy' => $orderBy, 'handle' => function ($row) use(&$out) { - $cancelCd = -1; - $modifyCd = -1; - if ($row['seller'] == myself()->_getAccountId() && - $row['seller_address'] == myself()->_getAddress()) { - $cancelCd = myself()->_getNowTime() - $row['last_buy_time']; - if ($cancelCd > 3600 * 24) { - $cancelCd = 0; - } - $modifyCd = myself()->_getNowTime() - $row['last_modify_price_time']; - if ($modifyCd > 60 * 10) { - $modifyCd = 0; - } - } - array_push($out['rows'], - array( - 'goods_uuid' => $row['goods_uuid'], - 'seller' => $row['seller'], - 'seller_address' => $row['seller_address'], - 'item_id' => $row['item_id'], - 'item_num' => $row['item_num'], - 'currency' => $row['currency'], - 'price' => $row['price'], - 'cancel_countdown' => $cancelCd, - 'modify_countdown' => $modifyCd - )); + array_push($out['rows'], Mall::toDto($row)); } ), $out['pagination'] diff --git a/webapp/models/Mall.php b/webapp/models/Mall.php index 2cd80005..b0705a38 100644 --- a/webapp/models/Mall.php +++ b/webapp/models/Mall.php @@ -10,7 +10,8 @@ class Mall extends BaseModel { const BUY_OK_STATE = 1; const CANCEL_STATE = 2; - public static function findByGoodsUuid($goodsUuid){ + public static function findByGoodsUuid($goodsUuid) + { $row = SqlHelper::ormSelectOne( myself()->_getMysql(''), 't_mall', @@ -21,7 +22,8 @@ class Mall extends BaseModel { return $row; } - public static function findByOrderId($orderId){ + public static function findByOrderId($orderId) + { $row = SqlHelper::ormSelectOne( myself()->_getMysql(''), 't_mall', @@ -33,7 +35,8 @@ class Mall extends BaseModel { } public static function add($orderId, $goodsUuid, $itemId, $itemNum, - $currency, $price) { + $currency, $price) + { SqlHelper::insert (myself()->_getMysql(''), 't_mall', @@ -51,7 +54,8 @@ class Mall extends BaseModel { )); } - public static function modifyPrice($goodsUuid, $price) { + public static function modifyPrice($goodsUuid, $price) + { SqlHelper::update (myself()->_getMysql(''), 't_mall', @@ -64,7 +68,8 @@ class Mall extends BaseModel { ); } - public static function cancel($goodsUuid) { + public static function cancel($goodsUuid) + { SqlHelper::update (myself()->_getMysql(''), 't_mall', @@ -77,4 +82,32 @@ class Mall extends BaseModel { ); } + public static function toDto($row) + { + $cancelCd = -1; + $modifyCd = -1; + if ($row['seller'] == myself()->_getAccountId() && + $row['seller_address'] == myself()->_getAddress()) { + $cancelCd = myself()->_getNowTime() - $row['last_buy_time']; + if ($cancelCd > 3600 * 24) { + $cancelCd = 0; + } + $modifyCd = myself()->_getNowTime() - $row['last_modify_price_time']; + if ($modifyCd > 60 * 10) { + $modifyCd = 0; + } + } + return array( + 'goods_uuid' => $row['goods_uuid'], + 'seller' => $row['seller'], + 'seller_address' => $row['seller_address'], + 'item_id' => $row['item_id'], + 'item_num' => $row['item_num'], + 'currency' => $row['currency'], + 'price' => $row['price'], + 'cancel_countdown' => $cancelCd, + 'modify_countdown' => $modifyCd + ); + } + }