Commit aced145b authored by liuyuzhen's avatar liuyuzhen

库存修改

parent 08d0088b
......@@ -24,15 +24,15 @@ class RedisLock implements \Lock\ILock{
public function getLock($key, $timeout=self::EXPIRE)
{
$currMicroTime = $this->getMicrotime();
$is_lock = $this->lockRedis->tableSetnx($key, $currMicroTime+200);
$is_lock = $this->lockRedis->tableSetnx($key, $currMicroTime+10);
// 不能获取锁
if(!$is_lock){
//判断锁是否过期
$lock_time = $this->lockRedis->get($key);
$lock_time = $this->lockRedis->tableCacheGet($key);
// 锁已过期,删除锁,重新获取
if($currMicroTime>(float)$lock_time){
$this->releaseLock($key);
$is_lock = $this->lockRedis->setnx($key, $currMicroTime+$timeout);
$is_lock = $this->lockRedis->tableSetnx($key, $currMicroTime+$timeout);
}
}
return $is_lock? true : false;
......
......@@ -80,7 +80,7 @@ class OrderConfirmUtil {
$dbName = \Our\DbNameConst::salveDBConnectName;
$this->memberId = $memberId;
$this->member = \DAO\MemberModel::getInstance()->getInfo($this->memberId);
$this ->address = $this->checkCurrentAddress($currentAddress,$this->memberId);
$this->address = $this->checkCurrentAddress($currentAddress,$this->memberId);
//if($this ->address['addressId'] == )
$this->postData = json_decode($data['param'],true);
if(!$this->postData){
......@@ -974,6 +974,7 @@ class OrderConfirmUtil {
if($pBundlingCacheResult===false){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::blGoodsStorageToCacheFailedForOrder);
}
$pBundlingDao->addChangedPBundlingStorage(array('bl_id'=>$key,'bl_storage'=>$blGoods['blStorage'],'op'=>$op));
}
}
if($goodsCommons&&$goodsList){
......
......@@ -206,6 +206,12 @@ class NameConst {
const xp='xp';
const win='win';
const pBundlingStorageRedisPrefix = 'pBundlingStorage_';
const goodsStorageRedisPrefix = 'goodsStorage_';
const changedPBundlingStoragePrefix = 'changedPBundlingStorage';
const changedGoodsStoragePrefix = 'changedGoodsStorage';
}
?>
\ No newline at end of file
......@@ -209,12 +209,17 @@ class GoodsModel extends \DAO\AbstractModel {
*/
public function opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op = \Our\ApiConst::minus,$updateSaleNumFalg = true){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
if($updateSaleNumFalg){
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
}
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
/*if($updateSaleNumFalg){
}*/
$goodsCommonList = $this->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsList));
foreach($goodsCommonList as $goodsCommonId=>$goodsCommonsTemp){
$isLock = \Lock\RedisLock::getInstance()->getLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
if(!$isLock){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
$newGoodsList = array();
$totalGoodsNum = \Our\ApiConst::zero;
foreach($goodsCommonsTemp as $goodsId=>$temp){
......@@ -226,6 +231,7 @@ class GoodsModel extends \DAO\AbstractModel {
}else if($op == \Our\ApiConst::set){
$temp['goodsStorage'] = $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
}else{
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
$totalGoodsNum += $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
......@@ -236,6 +242,7 @@ class GoodsModel extends \DAO\AbstractModel {
$onlineStorageGoodsKey = \Our\NameConst::onlineStorageGoodsPrefix.$goodsCommonId;
$result = $goodsRedis->tableHMSet($onlineStorageGoodsKey,$newGoodsList,\Our\ApiConst::tenDaySecond);
if(!$result){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
......@@ -260,6 +267,7 @@ class GoodsModel extends \DAO\AbstractModel {
}
}
\DAO\PBundlingModel::getInstance()->deletePBundlingByGoodsCommonId($goodsCommonId);
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
}
return true;
}
......
......@@ -171,26 +171,59 @@ class PBundlingModel extends \DAO\AbstractModel {
return false;
}
/**
* 更新组合销售缓存
* @param $blId
* @param $blStorage
* @param int $op
* @return bool
* @throws \Error\OurExceptionModel
* @throws \Exception
*/
public function updatePBundlingStorageCacheByBlId($blId,$blStorage,$op=\Our\ApiConst::minus){
$isLock = \Lock\RedisLock::getInstance()->getLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
if(!$isLock){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::serverBusy);
}
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$result = $pBundlingRedisDao->getByKeys('gid_'.$blId);
if($result){
$pBundling = $result['result'];
$key = $result['key'];
if($pBundling['bl_storage'])
if($op == \Our\ApiConst::minus){
$pBundling['bl_storage'] = $pBundling['bl_storage']-$blStorage;
if($pBundling['bl_storage']-$blStorage<\Our\ApiConst::zero){
\Error\ErrorModel::throwException(\Our\CodeConfigModel::pBundlingNoStorageForOrder);
}
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']-$blStorage;
}else if($op == \Our\ApiConst::plus){
$pBundling['bl_storage'] = $pBundling['bl_storage']+$blStorage;
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']+$blStorage;
if(!$result){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
return false;
}
$pBundling = $result['result'];
$key = $result['key'];
if($op == \Our\ApiConst::minus){
$pBundling['bl_storage'] = $pBundling['bl_storage']-$blStorage;
if($pBundling['bl_storage']-$blStorage<\Our\ApiConst::zero){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
\Error\ErrorModel::throwException(\Our\CodeConfigModel::pBundlingNoStorageForOrder);
}
return $pBundlingRedisDao->setNoPrefix($key,$pBundling,\Our\ApiConst::oneDaySecond);
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']-$blStorage;
}else if($op == \Our\ApiConst::plus){
$pBundling['bl_storage'] = $pBundling['bl_storage']+$blStorage;
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']+$blStorage;
}
return false;
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
return $pBundlingRedisDao->setNoPrefix($key,$pBundling,\Our\ApiConst::oneDaySecond);
}
/**
* 更新需要更新缓存的链表
* @param $pBundling
*/
public function addChangedPBundlingStorage($pBundling){
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$pBundlingRedisDao->tableLPush(\Our\NameConst::changedGoodsStoragePrefix,$pBundling);
}
/**
* 获取需要更新缓存的链表数据
*/
public function getChangedPbundlingStorage(){
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$pBundlingRedisDao->tableLPop(\Our\NameConst::changedGoodsStoragePrefix);
}
public function deletePBundlingByBlId($blId){
......
......@@ -329,6 +329,7 @@ class CodeConfigModel
const beyongRefundAmount = 300146;
const addOrderFrequently = 300147;
const cancelRefundMoneyError = 300148;
const serverBusy = 300149;
//店铺相关错误码
//商品分类
......@@ -840,6 +841,7 @@ class CodeConfigModel
self::beyongRefundAmount=>'退款金额不能超过可退款金额',
self::addOrderFrequently => '操作太频繁,请稍后重试',
self::cancelRefundMoneyError=>'退款有误,请于商家联系',
self::serverBusy => '服务器繁忙,请稍后重试',
//销售员
self::emptySaleGoodsId => '商品id不能为空',
self::emptySaleGoods => '销售商品不存在',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment