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
22746e4e
Commit
22746e4e
authored
Jul 21, 2021
by
jianghaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' of
https://gitlab.yidian-inc.com/bp/goods
into test
parents
f732afc5
4fad3f94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
57 deletions
+102
-57
GoodsException.php
application/exception/custom/GoodsException.php
+2
-0
TccService.php
application/services/tcc/TccService.php
+100
-57
No files found.
application/exception/custom/GoodsException.php
View file @
22746e4e
...
...
@@ -42,5 +42,7 @@ class GoodsException extends BaseException
28
=>
'上架状态不能编辑,需先下架,再做编辑操作'
,
29
=>
'发布商品的生活号不存在'
,
30
=>
'当前商品已过期'
,
31
=>
'当前商品锁定库存不足'
,
32
=>
'当前商品已下单数量不足'
,
];
}
\ No newline at end of file
application/services/tcc/TccService.php
View file @
22746e4e
...
...
@@ -78,15 +78,21 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_rest"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
-
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_rest[>=]"
=>
$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"
=>
24
]);
}
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
...
...
@@ -161,14 +167,14 @@ class TccService
}
//在confirm时候必须已经有try,如果没有就直接返回fail
$
c
TccInfoList
=
Tcc
::
getRecordMaster
([
$
t
TccInfoList
=
Tcc
::
getRecordMaster
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuIds
,
"type"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
]);
if
(
empty
(
$
cTccInfoList
)
||
count
(
$c
TccInfoList
)
!=
count
(
$goodsSkuIds
))
{
if
(
empty
(
$
tTccInfoList
)
||
count
(
$t
TccInfoList
)
!=
count
(
$goodsSkuIds
))
{
foreach
(
$goodsSkuIds
as
$goodsSkuId
)
{
Tcc
::
save
([
"tid"
=>
$tid
,
...
...
@@ -203,15 +209,21 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
+
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$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"
=>
31
]);
}
Tcc
::
save
([
"tid"
=>
$tid
,
...
...
@@ -286,23 +298,24 @@ class TccService
return
self
::
TCC_RESULT_SUCCESS
;
}
//在cancel时候必须已经有try,如果没有就直接返回fail
$cTccInfoList
=
Tcc
::
getRecordMaster
([
//允许空cancel(没有try情况)
//在cancel时候必须已经有try,如果没有就直接返回success
$tTccInfoList
=
Tcc
::
getRecordMaster
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuIds
,
"type"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
]);
if
(
empty
(
$
cTccInfoList
)
||
count
(
$c
TccInfoList
)
!=
count
(
$goodsSkuIds
))
{
if
(
empty
(
$
tTccInfoList
)
||
count
(
$t
TccInfoList
)
!=
count
(
$goodsSkuIds
))
{
foreach
(
$goodsSkuIds
as
$goodsSkuId
)
{
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CANCEL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
FAIL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
SUCCESS
,
]);
}
return
self
::
TCC_RESULT_
FAIL
;
return
self
::
TCC_RESULT_
SUCCESS
;
}
//如果已经 confirm 成功, 则失败
$cTccInfoList
=
Tcc
::
getRecordMaster
([
...
...
@@ -328,16 +341,21 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"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
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
...
...
@@ -435,15 +453,21 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"total_amount_order"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$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
([
"tid"
=>
$tid
,
...
...
@@ -562,30 +586,42 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
if
(
$type
==
self
::
TYPE_CANCEL_ORDER
)
{
$params
=
[
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$num
,
];
}
if
(
$type
==
self
::
TYPE_BACK_ORDER
)
{
if
(
$sku
[
"total_amount_sold"
]
<
$num
)
{
$rowCount
=
GoodsSku
::
save
(
$params
,
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_lock[>=]"
=>
$num
]);
if
(
$rowCount
<=
0
)
{
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
=
[
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
+
$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
([
"tid"
=>
$tid
,
...
...
@@ -660,7 +696,8 @@ class TccService
return
self
::
TCC_RESULT_SUCCESS
;
}
//在cancel时候必须已经有try,如果没有就直接返回fail
//允许空cancel(没有try情况)
//在cancel时候必须已经有try,如果没有就直接返回success
$cTccInfoList
=
Tcc
::
getRecordMaster
([
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuIds
,
...
...
@@ -673,11 +710,12 @@ class TccService
"tid"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"type"
=>
Tcc
::
STATUS_CANCEL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
FAIL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_
SUCCESS
,
]);
}
return
self
::
TCC_RESULT_
FAIL
;
return
self
::
TCC_RESULT_
SUCCESS
;
}
//如果已经 confirm 成功, 则失败
$cTccInfoList
=
Tcc
::
getRecordMaster
([
"tid"
=>
$tid
,
...
...
@@ -702,15 +740,20 @@ class TccService
}
$num
=
$numList
[
$goodsSkuId
];
if
(
$sku
[
"inventory_lock"
]
<
$num
)
{
GoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
GoodsSku
::
save
([
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
-
$num
,
"total_amount_order"
=>
$sku
[
"total_amount_order"
]
+
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"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
([
"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