This commit is contained in:
aozhiwei 2023-08-07 12:48:31 +08:00
parent ea722cb84a
commit a7ca1bdc47
2 changed files with 53 additions and 142 deletions

View File

@ -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();
}

View File

@ -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
)
);
}