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
ab2a7568
Commit
ab2a7568
authored
Jan 07, 2019
by
liuyuzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改库存更新方式
parent
dfe6af5c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
5 deletions
+146
-5
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+7
-2
GoodsCommonService.php
application/models/Business/Goods/GoodsCommonService.php
+41
-0
Goods.php
application/models/DAO/Goods.php
+51
-1
GoodsCommon.php
application/models/DAO/GoodsCommon.php
+22
-0
PBundling.php
application/models/DAO/PBundling.php
+25
-2
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
ab2a7568
...
@@ -913,7 +913,8 @@ class OrderConfirmUtil {
...
@@ -913,7 +913,8 @@ class OrderConfirmUtil {
\Our\RedisHelper
::
delCachedFunction
(
\Redis\Db4\PBundlingRedisModel
::
getInstance
(),
array
(
&
$pbundlingInstance
,
'getList'
),
array
(),
array
(
$storeId
));
\Our\RedisHelper
::
delCachedFunction
(
\Redis\Db4\PBundlingRedisModel
::
getInstance
(),
array
(
&
$pbundlingInstance
,
'getList'
),
array
(),
array
(
$storeId
));
}
}
}
}
$this
->
updateGoodsStorageToDBAndCache
(
$goodsCommonIds
,
$goodsIds
,
$blIds
,
$goodsNewList
,
$op
,
$updateSaleNumFlag
);
//$this->updateGoodsStorageToDBAndCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList,$op,$updateSaleNumFlag);
$this
->
updateGoodsStorageToCache
(
$goodsCommonIds
,
$goodsIds
,
$blIds
,
$goodsNewList
,
$op
,
$updateSaleNumFlag
);
return
true
;
return
true
;
}
}
...
@@ -953,6 +954,9 @@ class OrderConfirmUtil {
...
@@ -953,6 +954,9 @@ class OrderConfirmUtil {
return
true
;
return
true
;
}
}
/**
/**
* 更新库存信息到缓存
* 更新库存信息到缓存
* @param $goodsCommons
* @param $goodsCommons
...
@@ -974,7 +978,7 @@ class OrderConfirmUtil {
...
@@ -974,7 +978,7 @@ class OrderConfirmUtil {
if
(
$pBundlingCacheResult
===
false
){
if
(
$pBundlingCacheResult
===
false
){
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
blGoodsStorageToCacheFailedForOrder
);
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
blGoodsStorageToCacheFailedForOrder
);
}
}
$pBundlingDao
->
addChangedPBundlingStorage
(
array
(
'bl_id'
=>
$key
,
'bl_storage'
=>
$blGoods
[
'blStorage'
],
'op'
=>
$op
));
$pBundlingDao
->
addChangedPBundlingStorage
(
serialize
(
array
(
'bl_id'
=>
$key
,
'bl_storage'
=>
$blGoods
[
'blStorage'
],
'op'
=>
$op
)
));
}
}
}
}
if
(
$goodsCommons
&&
$goodsList
){
if
(
$goodsCommons
&&
$goodsList
){
...
@@ -983,6 +987,7 @@ class OrderConfirmUtil {
...
@@ -983,6 +987,7 @@ class OrderConfirmUtil {
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
goodsStorageToCacheFailedForOrder
);
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
goodsStorageToCacheFailedForOrder
);
}
}
}
}
\Our\Common
::
redisPublish
(
'\Business\Goods\GoodsCommonServiceModel'
,
'updateAllStorageForPublish'
,
array
());
return
true
;
return
true
;
}
}
/**
/**
...
...
application/models/Business/Goods/GoodsCommonService.php
View file @
ab2a7568
...
@@ -1463,6 +1463,47 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
...
@@ -1463,6 +1463,47 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
/**
* 更新从缓存链表中更新商品库存
* @return bool
*/
public
function
updateGoodsStorageByRedisList
(){
$goodsModel
=
\DAO\GoodsModel
::
getInstance
();
for
(
$i
=
0
;
$i
<
2000
;
$i
++
){
$goodsStr
=
$goodsModel
->
getChangedGoodsStorage
();
\Our\Log
::
getInstance
()
->
write
(
$goodsStr
,
'/data/log/apptest'
);
if
(
$goodsStr
){
$goods
=
unserialize
(
$goodsStr
);
$goodsModel
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$goodsModel
->
db
->
doTransaction
();
$goodsUpdateResult
=
$goodsModel
->
updateStorageByRedis
(
$goods
);
if
(
!
$goodsUpdateResult
){
$goodsModel
->
db
->
doRollback
();
}
$goodsCommonUpdateResult
=
\DAO\GoodsCommonModel
::
getInstance
()
->
updateStorageByRedis
(
$goods
);
if
(
!
$goodsCommonUpdateResult
){
$goodsModel
->
db
->
doRollback
();
}
$goodsModel
->
db
->
doCommit
();
}
else
{
break
;
}
}
return
true
;
}
/**
* 更新所有商品库存
* @return bool
*/
public
function
updateAllStorageForPublish
(){
\Our\Log
::
getInstance
()
->
write
(
'1执行失败'
,
'/data/log/apptest'
);
$this
->
updateGoodsStorageByRedisList
();
\Our\Log
::
getInstance
()
->
write
(
'2执行失败'
,
'/data/log/apptest'
);
\DAO\PBundlingModel
::
getInstance
()
->
updateStorageByRedisList
();
return
true
;
}
private
static
$_instance
=
null
;
private
static
$_instance
=
null
;
...
...
application/models/DAO/Goods.php
View file @
ab2a7568
...
@@ -39,7 +39,7 @@ class GoodsModel extends \DAO\AbstractModel {
...
@@ -39,7 +39,7 @@ class GoodsModel extends \DAO\AbstractModel {
* @return mixed
* @return mixed
*/
*/
public
function
updateStorage
(
$goodsId
,
$num
,
$op
)
{
public
function
updateStorage
(
$goodsId
,
$num
,
$op
)
{
$this
->
setDb
();
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$whereSql
=
'goods_id='
.
$goodsId
;
$whereSql
=
'goods_id='
.
$goodsId
;
if
(
$op
==
1
){
//调整库存
if
(
$op
==
1
){
//调整库存
$updateSql
=
'goods_storage = goods_storage'
.
(
$num
<
0
?
'-'
.
(
-
$num
)
:
'+'
.
$num
);
$updateSql
=
'goods_storage = goods_storage'
.
(
$num
<
0
?
'-'
.
(
-
$num
)
:
'+'
.
$num
);
...
@@ -51,6 +51,26 @@ class GoodsModel extends \DAO\AbstractModel {
...
@@ -51,6 +51,26 @@ class GoodsModel extends \DAO\AbstractModel {
return
$this
->
db
->
update
(
$this
->
_tableName
)
->
query
(
$updateAllSql
);
return
$this
->
db
->
update
(
$this
->
_tableName
)
->
query
(
$updateAllSql
);
}
}
public
function
updateStorageByRedis
(
$goods
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$sql
=
'UPDATE '
.
$this
->
_tableName
.
' set goods_edittime = '
.
TIMESTAMP
.
',goods_storage = '
;
if
(
$goods
[
'op'
]
==
\Our\ApiConst
::
set
){
$sql
.=
$goods
[
'goods_storage'
]
;
}
else
{
$sql
.=
'goods_storage '
.
\Our\ArrayConst
::
ops
[
$goods
[
'op'
]]
.
$goods
[
'goods_storage'
]
;
/*if($goods['sale_num']){
$sql .= ' sale'
}*/
}
$sql
.=
' where goods_id = '
.
$goods
[
'goods_id'
];
\Our\Log
::
getInstance
()
->
write
(
$sql
.
' 执行失败'
,
'/data/log/apptest'
);
$result
=
$this
->
db
->
update
(
$this
->
_tableName
)
->
query
(
$sql
);
if
(
$result
===
false
){
\Our\Log
::
getInstance
()
->
write
(
$sql
.
' 执行失败'
);
}
return
$result
;
}
/**
/**
*
*
* 分页获取商品列表
* 分页获取商品列表
...
@@ -201,6 +221,25 @@ class GoodsModel extends \DAO\AbstractModel {
...
@@ -201,6 +221,25 @@ class GoodsModel extends \DAO\AbstractModel {
}
}
}*/
}*/
/**
* 更新需要更新缓存的链表
* @param $pBundling
*/
public
function
addChangedGoodsStorage
(
$pBundling
){
$goodsRedisDao
=
\Redis\Db4\GoodsRedisModel
::
getInstance
();
$goodsRedisDao
->
tableLPush
(
\Our\NameConst
::
changedGoodsStoragePrefix
,
$pBundling
);
}
/**
* 获取需要更新缓存的链表数据
*/
public
function
getChangedGoodsStorage
(){
$goodsRedisDao
=
\Redis\Db4\GoodsRedisModel
::
getInstance
();
return
$goodsRedisDao
->
tableLPop
(
\Our\NameConst
::
changedGoodsStoragePrefix
);
}
/**
/**
* 更新商品库存缓存以及更新销量
* 更新商品库存缓存以及更新销量
* @param $goodsList 商品列表
* @param $goodsList 商品列表
...
@@ -235,8 +274,19 @@ class GoodsModel extends \DAO\AbstractModel {
...
@@ -235,8 +274,19 @@ class GoodsModel extends \DAO\AbstractModel {
return
false
;
return
false
;
}
}
$totalGoodsNum
+=
$goodsList
[
$goodsCommonId
][
$goodsId
][
'goodsNum'
];
$totalGoodsNum
+=
$goodsList
[
$goodsCommonId
][
$goodsId
][
'goodsNum'
];
$updateGoods
=
array
(
'goods_id'
=>
$goodsId
,
'goods_commonid'
=>
$goodsCommonId
,
'goods_storage'
=>
$goodsList
[
$goodsCommonId
][
$goodsId
][
'goodsNum'
],
'op'
=>
$op
);
if
(
$updateSaleNumFalg
&&
$op
!=
\Our\ApiConst
::
set
){
$updateGoods
[
'sale_num'
]
=
$goodsList
[
$goodsCommonId
][
$goodsId
][
'goodsNum'
];
}
$this
->
addChangedGoodsStorage
(
serialize
(
$updateGoods
));
}
}
$newGoodsList
[
$goodsId
]
=
serialize
(
$temp
);
$newGoodsList
[
$goodsId
]
=
serialize
(
$temp
);
}
}
if
(
$newGoodsList
){
if
(
$newGoodsList
){
$onlineStorageGoodsKey
=
\Our\NameConst
::
onlineStorageGoodsPrefix
.
$goodsCommonId
;
$onlineStorageGoodsKey
=
\Our\NameConst
::
onlineStorageGoodsPrefix
.
$goodsCommonId
;
...
...
application/models/DAO/GoodsCommon.php
View file @
ab2a7568
...
@@ -257,6 +257,28 @@ class GoodsCommonModel extends \DAO\AbstractModel {
...
@@ -257,6 +257,28 @@ class GoodsCommonModel extends \DAO\AbstractModel {
}
}
public
function
updateStorageByRedis
(
$goods
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$sql
=
'UPDATE '
.
$this
->
_tableName
.
' set goods_edittime = '
.
TIMESTAMP
.
',goods_storage = '
;
if
(
$goods
[
'op'
]
==
\Our\ApiConst
::
set
){
$sql
.=
$goods
[
'goods_storage'
]
;
}
else
{
$sql
.=
'goods_storage '
.
\Our\ArrayConst
::
ops
[
$goods
[
'op'
]]
.
$goods
[
'goods_storage'
]
;
if
(
$goods
[
'sale_num'
]){
$sql
.=
' , sale_num = sale_num '
.
(
$goods
[
'op'
]
==
\Our\ApiConst
::
plus
?
'-'
:
'+'
)
.
' '
.
$goods
[
'sale_num'
];
}
}
$sql
.=
' where goods_commonid = '
.
$goods
[
'goods_commonid'
];
\Our\Log
::
getInstance
()
->
write
(
$sql
.
' 执行失败'
,
'/data/log/apptest'
);
$result
=
$this
->
db
->
update
(
$this
->
_tableName
)
->
query
(
$sql
);
if
(
$result
===
false
){
\Our\Log
::
getInstance
()
->
write
(
$sql
.
' 执行失败'
);
}
return
$result
;
}
public
function
updateGoodsStorage
(
$dataList
,
$op
=
\Our\ApiConst
::
minus
,
$updateSaleNumFlag
=
false
){
public
function
updateGoodsStorage
(
$dataList
,
$op
=
\Our\ApiConst
::
minus
,
$updateSaleNumFlag
=
false
){
$datas
=
array_values
(
$dataList
);
$datas
=
array_values
(
$dataList
);
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
...
...
application/models/DAO/PBundling.php
View file @
ab2a7568
...
@@ -215,7 +215,7 @@ class PBundlingModel extends \DAO\AbstractModel {
...
@@ -215,7 +215,7 @@ class PBundlingModel extends \DAO\AbstractModel {
*/
*/
public
function
addChangedPBundlingStorage
(
$pBundling
){
public
function
addChangedPBundlingStorage
(
$pBundling
){
$pBundlingRedisDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingRedisDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingRedisDao
->
tableLPush
(
\Our\NameConst
::
changed
Goods
StoragePrefix
,
$pBundling
);
$pBundlingRedisDao
->
tableLPush
(
\Our\NameConst
::
changed
PBundling
StoragePrefix
,
$pBundling
);
}
}
/**
/**
...
@@ -223,9 +223,32 @@ class PBundlingModel extends \DAO\AbstractModel {
...
@@ -223,9 +223,32 @@ class PBundlingModel extends \DAO\AbstractModel {
*/
*/
public
function
getChangedPbundlingStorage
(){
public
function
getChangedPbundlingStorage
(){
$pBundlingRedisDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingRedisDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingRedisDao
->
tableLPop
(
\Our\NameConst
::
changedGoods
StoragePrefix
);
return
$pBundlingRedisDao
->
tableLPop
(
\Our\NameConst
::
changedPBundling
StoragePrefix
);
}
}
public
function
updateStorageByRedisList
(){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
for
(
$i
=
0
;
$i
<
2000
;
$i
++
){
$pbundlingStr
=
$this
->
getChangedPbundlingStorage
();
if
(
!
$pbundlingStr
){
break
;
}
$pbundling
=
unserialize
(
$pbundlingStr
);
if
(
$pbundling
[
'op'
]
!=
\Our\ApiConst
::
set
){
$sql
=
\Our\Common
::
format
(
"UPDATE
{
$this
->
_tableName
}
set bl_storage = bl_storage
{
2
}
{
0
}
where bl_id =
{
1
}
"
,
$pbundling
[
'bl_storage'
],
$pbundling
[
'bl_id'
],
\Our\ArrayConst
::
ops
[
$pbundling
[
'op'
]]);
}
else
{
$sql
=
\Our\Common
::
format
(
"UPDATE
{
$this
->
_tableName
}
set bl_storage =
{
0
}
where bl_id =
{
1
}
"
,
$pbundling
[
'bl_storage'
],
$pbundling
[
'bl_id'
]);
}
$one
=
$this
->
db
->
update
(
$this
->
_tableName
)
->
query
(
$sql
);
if
(
$one
===
false
){
\Our\Log
::
getInstance
()
->
write
(
$sql
.
' 执行失败'
);
}
}
return
true
;
}
public
function
deletePBundlingByBlId
(
$blId
){
public
function
deletePBundlingByBlId
(
$blId
){
$pBundlingDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingDao
=
\Redis\Db4\PBundlingRedisModel
::
getInstance
();
$pBundlingDao
->
tableDelAll
(
$pBundlingDao
->
tableKeys
(
'gid_'
.
$blId
));
$pBundlingDao
->
tableDelAll
(
$pBundlingDao
->
tableKeys
(
'gid_'
.
$blId
));
...
...
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