Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
aced145b
Commit
aced145b
authored
Jan 04, 2019
by
liuyuzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
库存修改
parent
08d0088b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
23 deletions
+73
-23
RedisLock.php
application/library/Lock/RedisLock.php
+3
-3
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+2
-1
NameConst.php
application/library/Our/NameConst.php
+6
-0
Goods.php
application/models/DAO/Goods.php
+12
-4
PBundling.php
application/models/DAO/PBundling.php
+48
-15
CodeConfig.php
application/models/Error/CodeConfig.php
+2
-0
No files found.
application/library/Lock/RedisLock.php
View file @
aced145b
...
...
@@ -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
+
20
0
);
$is_lock
=
$this
->
lockRedis
->
tableSetnx
(
$key
,
$currMicroTime
+
1
0
);
// 不能获取锁
if
(
!
$is_lock
){
//判断锁是否过期
$lock_time
=
$this
->
lockRedis
->
g
et
(
$key
);
$lock_time
=
$this
->
lockRedis
->
tableCacheG
et
(
$key
);
// 锁已过期,删除锁,重新获取
if
(
$currMicroTime
>
(
float
)
$lock_time
){
$this
->
releaseLock
(
$key
);
$is_lock
=
$this
->
lockRedis
->
s
etnx
(
$key
,
$currMicroTime
+
$timeout
);
$is_lock
=
$this
->
lockRedis
->
tableS
etnx
(
$key
,
$currMicroTime
+
$timeout
);
}
}
return
$is_lock
?
true
:
false
;
...
...
application/library/Order/OrderConfirmUtil.php
View file @
aced145b
...
...
@@ -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
){
...
...
application/library/Our/NameConst.php
View file @
aced145b
...
...
@@ -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
application/models/DAO/Goods.php
View file @
aced145b
...
...
@@ -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
;
}
...
...
application/models/DAO/PBundling.php
View file @
aced145b
...
...
@@ -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
){
...
...
application/models/Error/CodeConfig.php
View file @
aced145b
...
...
@@ -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
=>
'销售商品不存在'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment