1
This commit is contained in:
parent
aa36eea861
commit
ea722cb84a
@ -4,14 +4,15 @@ 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 models\BcOrder;
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
use models\Transaction;
|
||||
use models\BcOrder;
|
||||
use models\Mall;
|
||||
|
||||
use services\LogService;
|
||||
use services\BlockChainService;
|
||||
@ -21,118 +22,42 @@ class MallController extends BaseAuthedController {
|
||||
public function productList()
|
||||
{
|
||||
$page = getReqVal('page', 1);
|
||||
}
|
||||
$queryData = array();
|
||||
|
||||
public function sell()
|
||||
{
|
||||
$address = $this->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$item_id = getReqVal('item_id', '');
|
||||
if ($item_id != V_ITEM_GOLD) {
|
||||
$this->_rspErr(1, 'only support gold');
|
||||
return;
|
||||
}
|
||||
|
||||
$itemMeta = mt\Item::get($item_id);
|
||||
if (!$itemMeta) {
|
||||
$this->_rspErr(1, 'item_id not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
if ($s_price <= 0) {
|
||||
$this->_rspErr(1, 's_price must > 0');
|
||||
return;
|
||||
}
|
||||
|
||||
$amount = getReqVal('amount', 1);
|
||||
if (empty($amount)) {
|
||||
$this->_rspErr(1, 'amount not found');
|
||||
return;
|
||||
}
|
||||
if (!is_numeric($amount)) {
|
||||
$this->_rspErr(1, 'amount must be number');
|
||||
return;
|
||||
}
|
||||
if ($amount <= 0) {
|
||||
$this->_rspErr(1, 'amount must > 0');
|
||||
return;
|
||||
}
|
||||
|
||||
$conn = myself()->_getSelfMysql();
|
||||
|
||||
// 检查是否有足够的物品
|
||||
$costItems = $this->makeCostItems($item_id, $amount);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
{
|
||||
//埋点
|
||||
$event = [
|
||||
'name' => LogService::MARKET_SELL_GOLD,
|
||||
'val' => $amount
|
||||
];
|
||||
LogService::consumeGold($event);
|
||||
}
|
||||
|
||||
$c_name = $itemMeta['name'];
|
||||
$c_job = 0;
|
||||
$c_lv = 0;
|
||||
$c_quality = $itemMeta['quality'];
|
||||
$c_durability = 0;
|
||||
$c_type = 0;
|
||||
$c_id = $item_id;
|
||||
|
||||
$r = SqlHelper::insert(
|
||||
$conn,
|
||||
't_market_store',
|
||||
array(
|
||||
'token_id' => '',
|
||||
'item_id' => $item_id,
|
||||
'status' => 0,
|
||||
'owner_address' => $address,
|
||||
'token_type' => 0,
|
||||
'amount' => $amount,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
's_price' => $s_price,
|
||||
'c_name' => $c_name,
|
||||
'c_job' => $c_job,
|
||||
'c_lv' => $c_lv,
|
||||
'c_quality' => $c_quality,
|
||||
'c_durability' => $c_durability,
|
||||
'c_type' => $c_type,
|
||||
'c_id' => $c_id,
|
||||
)
|
||||
$out = array(
|
||||
'pagination' => array(),
|
||||
'rows' => array()
|
||||
);
|
||||
if (!$r) {
|
||||
$this->_rspErr(3, "sell failed");
|
||||
return;
|
||||
}
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$order_id = $this->genOrderId($lastId);
|
||||
$test = SqlHelper::update($conn, 't_market_store', array('idx' => $lastId), array('order_id' => $order_id));
|
||||
if (!$test) {
|
||||
$this->_rspErr(6, "sell failed");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_rspOk();
|
||||
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()
|
||||
|
92
webapp/models/Mall.php
Normal file
92
webapp/models/Mall.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace models;
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class Mall extends BaseModel {
|
||||
|
||||
const PENDING_STATE = 0;
|
||||
const BUY_OK_STATE = 1;
|
||||
const CANCEL_STATE = 2;
|
||||
|
||||
public static function find($orderId){
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql(''),
|
||||
't_market',
|
||||
array(
|
||||
'order_id' => $orderId
|
||||
)
|
||||
);
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function add($orderId, $tokenId, $seller, $nftToken,
|
||||
$amount, $currency, $pirce) {
|
||||
self::internalUpdate(
|
||||
$orderId,
|
||||
array(
|
||||
'token_id' => $tokenId,
|
||||
'seller' => $seller,
|
||||
'nft_token' => $nftToken,
|
||||
'amount' => $amount,
|
||||
'currency' => $currency,
|
||||
'price' => $price,
|
||||
'activated' => 1,
|
||||
'selltime' => myself()->_getNowTime(),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
));
|
||||
}
|
||||
|
||||
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(),
|
||||
)
|
||||
);
|
||||
SqlHelper::update
|
||||
(myself()->_getMysql(''),
|
||||
't_market',
|
||||
array(
|
||||
'order_id' => $orderId
|
||||
),
|
||||
$fieldsKv
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user