Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
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
bp
goods
Commits
80437d5c
Commit
80437d5c
authored
Jul 21, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:tcc 取消流程优化
parent
1fa5962e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
25 deletions
+49
-25
GoodsException.php
application/exception/custom/GoodsException.php
+1
-0
TccService.php
application/services/tcc/TccService.php
+48
-25
No files found.
application/exception/custom/GoodsException.php
View file @
80437d5c
...
@@ -43,5 +43,6 @@ class GoodsException extends BaseException
...
@@ -43,5 +43,6 @@ class GoodsException extends BaseException
29
=>
'发布商品的生活号不存在'
,
29
=>
'发布商品的生活号不存在'
,
30
=>
'当前商品已过期'
,
30
=>
'当前商品已过期'
,
31
=>
'当前商品锁定库存不足'
,
31
=>
'当前商品锁定库存不足'
,
32
=>
'当前商品已下单数量不足'
,
];
];
}
}
\ No newline at end of file
application/services/tcc/TccService.php
View file @
80437d5c
...
@@ -453,15 +453,21 @@ class TccService
...
@@ -453,15 +453,21 @@ class TccService
}
}
$num
=
$numList
[
$goodsSkuId
];
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"total_amount_order"
]
<
$num
)
{
//条件加上乐观锁
GoodsSku
::
rollback
();
$rowCount
=
GoodsSku
::
save
([
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
-
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
-
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"total_amount_order[>=]"
=>
$num
]);
if
(
$rowCount
<=
0
)
{
GoodsSku
::
rollback
();
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
throw
new
GoodsException
([
"cus"
=>
32
]);
}
Tcc
::
save
([
Tcc
::
save
([
"tid"
=>
$tid
,
"tid"
=>
$tid
,
...
@@ -580,30 +586,42 @@ class TccService
...
@@ -580,30 +586,42 @@ class TccService
}
}
$num
=
$numList
[
$goodsSkuId
];
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
if
(
$type
==
self
::
TYPE_CANCEL_ORDER
)
{
if
(
$type
==
self
::
TYPE_CANCEL_ORDER
)
{
$params
=
[
$params
=
[
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
];
];
}
$rowCount
=
GoodsSku
::
save
(
$params
,
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$num
]);
if
(
$type
==
self
::
TYPE_BACK_ORDER
)
{
if
(
$rowCount
<=
0
)
{
if
(
$sku
[
"total_amount_sold"
]
<
$num
)
{
GoodsSku
::
rollback
();
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CONFIRM
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
throw
new
GoodsException
([
"cus"
=>
31
]);
}
}
}
if
(
$type
==
self
::
TYPE_BACK_ORDER
)
{
$params
=
[
$params
=
[
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
"total_amount_sold"
=>
$sku
[
"total_amount_sold"
]
-
$num
,
"total_amount_sold"
=>
$sku
[
"total_amount_sold"
]
-
$num
,
];
];
$rowCount
=
GoodsSku
::
save
(
$params
,
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$num
,
"total_amount_sold[>=]"
=>
$num
]);
if
(
$rowCount
<=
0
)
{
GoodsSku
::
rollback
();
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CONFIRM
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
throw
new
GoodsException
([
"cus"
=>
32
]);
}
}
}
GoodsSku
::
save
(
$params
,
[
"goods_sku_id"
=>
$goodsSkuId
]);
Tcc
::
save
([
Tcc
::
save
([
"tid"
=>
$tid
,
"tid"
=>
$tid
,
...
@@ -692,7 +710,7 @@ class TccService
...
@@ -692,7 +710,7 @@ class TccService
"tid"
=>
$tid
,
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CANCEL
,
"type"
=>
Tcc
::
STATUS_CANCEL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
FAIL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
SUCCESS
,
]);
]);
}
}
return
self
::
TCC_RESULT_SUCCESS
;
return
self
::
TCC_RESULT_SUCCESS
;
...
@@ -722,15 +740,20 @@ class TccService
...
@@ -722,15 +740,20 @@ class TccService
}
}
$num
=
$numList
[
$goodsSkuId
];
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
$rowCount
=
GoodsSku
::
save
([
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
+
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
+
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$num
]);
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$num
]);
if
(
$rowCount
<=
0
)
{
GoodsSku
::
rollback
();
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CANCEL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
throw
new
GoodsException
([
"cus"
=>
31
]);
}
Tcc
::
save
([
Tcc
::
save
([
"tid"
=>
$tid
,
"tid"
=>
$tid
,
...
...
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