game2006api/webapp/controller/MallController.class.php
aozhiwei ea722cb84a 1
2023-08-07 12:39:12 +08:00

178 lines
4.7 KiB
PHP

<?php
require_once('mt/Item.php');
require_once('mt/Parameter.php');
require_once('models/BcOrder.php');
require_once('models/Mall.php');
require_once('services/BlockChainService.php');
require_once('services/LogService.php');
use phpcommon\SqlHelper;
use models\BcOrder;
use models\Mall;
use services\LogService;
use services\BlockChainService;
class MallController extends BaseAuthedController {
public function productList()
{
$page = getReqVal('page', 1);
$queryData = array();
$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' => 10,
'filter' => array(
'data' => $queryData,
'fields' => array(
)
),
//'orderBy' => $orderBy,
'handle' => function ($row) {
array_push($out['rows'],
array(
'goods_uuid' => $row['goods_uuid'],
'seller' => $row['seller'],
'item_id' => $row['item_id'],
'item_num' => $row['item_num'],
'currency' => $row['currency'],
'price' => $row['price'],
));
}
),
$out['pagination']
);
myself()->_rspData($out);
}
public function cancel()
{
$idx = getReqVal('idx', '');
$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(
'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');
}
}
public function modifyPrice()
{
$idx = getReqVal('idx', '');
$s_price = getReqVal('s_price', '');
if (empty($s_price)) {
$this->_rspErr(1, 's_price not found');
return;
}
if (!is_numeric($s_price)) {
$this->_rspErr(1, 's_price must be number');
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;
}
$this->_rspOk();
}
}