39 lines
932 B
PHP
39 lines
932 B
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('mt/Item.php');
|
|
require_once('mt/ChipQuality.php');
|
|
require_once('mt/AttrHelper.php');
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class Goods extends BaseModel {
|
|
|
|
public static function getRemainBuyableNum($goodsMeta)
|
|
{
|
|
self::mustByBuyedNumHash();
|
|
return max(0, $goodsMeta['number_of_props'] - getXVal(self::$buyedNumHash, $goodsMeta['id'], 0));
|
|
}
|
|
|
|
private static function mustByBuyedNumHash()
|
|
{
|
|
if (!is_null(self::$buyedNumHash)) {
|
|
return;
|
|
}
|
|
$rows = myself()->_getMarketMysql()->execQuery
|
|
('SELECT goods_id, count(goods_idx) AS num FROM t_goods WHERE state=1 GROUP BY goods_id;',
|
|
array(
|
|
|
|
));
|
|
self::$buyedNumHash = array();
|
|
foreach ($rows as $row) {
|
|
self::$buyedNumHash[$row['goods_id']] = $row['num'];
|
|
}
|
|
}
|
|
|
|
private static $buyedNumHash;
|
|
|
|
}
|