<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\Atomic; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\RandomUtil; use ModStart\Core\Util\RedisUtil; class AtomicUtil { public static function produce($bIeOt, $XVADv, $zQeTy = 3600) { if (RedisUtil::isEnable()) { goto mZPRx; Jarn8: RedisUtil::expire($lN0p0, $zQeTy); goto jOxu_; HNGT7: RedisUtil::set($lN0p0, $XVADv); goto Jarn8; mZPRx: $lN0p0 = "Atomic:{$bIeOt}"; goto HNGT7; jOxu_: } else { if (ModelUtil::exists('atomic', array('name' => $bIeOt))) { ModelUtil::update('atomic', array('name' => $bIeOt), array('value' => $XVADv, 'expire' => time() + $zQeTy)); } else { ModelUtil::insert('atomic', array('name' => $bIeOt, 'value' => $XVADv, 'expire' => time() + $zQeTy)); } if (RandomUtil::percent(20)) { ModelUtil::delete('atomic', 'expire', '<', time()); } } } public static function consume($bIeOt) { if (RedisUtil::isEnable()) { goto ZNWlN; cCfNn: if (RedisUtil::decr($lN0p0) >= 0) { return true; } goto QpIyo; ZNWlN: $lN0p0 = "Atomic:{$bIeOt}"; goto cCfNn; QpIyo: return false; goto dUn63; dUn63: } else { goto d6RI0; HWBYj: ModelUtil::transactionCommit(); goto lYclN; wtJhr: $f2T7Z = ModelUtil::getWithLock('atomic', array('name' => $bIeOt)); goto gxB_e; d6RI0: if (RandomUtil::percent(20)) { ModelUtil::delete('atomic', 'expire', '<', time()); } goto Hgrpj; gxB_e: if (empty($f2T7Z)) { ModelUtil::transactionCommit(); return false; } goto xuz3K; Hgrpj: ModelUtil::transactionBegin(); goto wtJhr; xuz3K: if ($f2T7Z['expire'] < time() || $f2T7Z['value'] < 0) { goto rb9YB; mXg86: ModelUtil::transactionCommit(); goto spIH_; spIH_: return false; goto LasRP; rb9YB: ModelUtil::delete('atomic', array('name' => $bIeOt)); goto mXg86; LasRP: } goto Oh4RK; Oh4RK: ModelUtil::update('atomic', array('name' => $bIeOt), array('value' => $f2T7Z['value'] - 1)); goto HWBYj; lYclN: return true; goto toOmH; toOmH: } } public static function remove($bIeOt) { if (RedisUtil::isEnable()) { $lN0p0 = "Atomic:{$bIeOt}"; RedisUtil::delete($lN0p0); } else { ModelUtil::delete('atomic', array('name' => $bIeOt)); } } }