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
2edd23df
Commit
2edd23df
authored
Jul 01, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:tcc 下单 t
parent
a37df770
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
54 deletions
+85
-54
GoodsTccValidate.php
application/library/Validate/GoodsTccValidate.php
+2
-2
Tcc.php
application/modules/Tcc/controllers/Tcc.php
+7
-7
TccService.php
application/services/tcc/TccService.php
+76
-45
No files found.
application/library/Validate/GoodsTccValidate.php
View file @
2edd23df
...
@@ -13,11 +13,11 @@ class GoodsTccValidate extends BaseValidate
...
@@ -13,11 +13,11 @@ class GoodsTccValidate extends BaseValidate
{
{
protected
$rule
=
[
protected
$rule
=
[
't_id'
=>
'require'
,
't_id'
=>
'require'
,
'
goods_id
'
=>
'require'
,
'
keys
'
=>
'require'
,
];
];
protected
$message
=
[
protected
$message
=
[
"t_id"
=>
"tcc事务id不能为空"
,
"t_id"
=>
"tcc事务id不能为空"
,
"
goods_id"
=>
"商品id
不能为空"
,
"
keys"
=>
"商品信息
不能为空"
,
];
];
}
}
\ No newline at end of file
application/modules/Tcc/controllers/Tcc.php
View file @
2edd23df
...
@@ -15,7 +15,7 @@ class TccController extends Base
...
@@ -15,7 +15,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
placeAnOrderTry
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
placeAnOrderTry
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -27,7 +27,7 @@ class TccController extends Base
...
@@ -27,7 +27,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
placeAnOrderConfirm
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
placeAnOrderConfirm
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -39,7 +39,7 @@ class TccController extends Base
...
@@ -39,7 +39,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
placeAnOrderCancel
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
placeAnOrderCancel
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -51,7 +51,7 @@ class TccController extends Base
...
@@ -51,7 +51,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
cancelOrderTry
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
cancelOrderTry
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -63,7 +63,7 @@ class TccController extends Base
...
@@ -63,7 +63,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
cancelOrderConfirm
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
cancelOrderConfirm
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -75,7 +75,7 @@ class TccController extends Base
...
@@ -75,7 +75,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
cancelOrderCancel
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
cancelOrderCancel
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
...
@@ -87,7 +87,7 @@ class TccController extends Base
...
@@ -87,7 +87,7 @@ class TccController extends Base
{
{
(
new
GoodsTccValidate
())
->
validate
();
(
new
GoodsTccValidate
())
->
validate
();
$res
=
TccService
::
tccIsFinish
(
$this
->
params
[
"
goods_sku_id
"
],
$this
->
params
[
"t_id"
]);
$res
=
TccService
::
tccIsFinish
(
$this
->
params
[
"
keys
"
],
$this
->
params
[
"t_id"
]);
$this
->
success
([
"result"
=>
$res
]);
$this
->
success
([
"result"
=>
$res
]);
}
}
}
}
\ No newline at end of file
application/services/tcc/TccService.php
View file @
2edd23df
...
@@ -16,41 +16,67 @@ class TccService
...
@@ -16,41 +16,67 @@ class TccService
/**
/**
* 下单 商品tcc try
* 下单 商品tcc try
* @param $
goodsSkuId
* @param $
keys
* @param $tid
* @param $tid
* @return int
* @return int
*/
*/
public
static
function
placeAnOrderTry
(
$
goodsSkuId
,
$tid
)
public
static
function
placeAnOrderTry
(
$
keys
,
$tid
)
{
{
$tccInfo
=
Tcc
::
getRecordMaster
([
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"status"
=>
Tcc
::
STATUS_TRY
]);
$goodsInfoList
=
json_decode
(
$keys
,
true
);
if
(
empty
(
$goodsInfoList
))
{
return
self
::
TCC_RESULT_FAIL
;
}
$goodsSkuIds
=
$numList
=
[];
foreach
(
$goodsInfoList
as
$item
)
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
return
self
::
TCC_RESULT_FAIL
;
}
$goodsSkuIds
[]
=
$item
[
"goods_sku_id"
];
$numList
[
$item
[
"goods_sku_id"
]]
=
$item
[
"num"
];
}
//有结果返回原来的结果,幂等
//有结果返回原来的结果,幂等
if
(
!
empty
(
$tccInfo
))
{
$tccInfoList
=
Tcc
::
getRecordMaster
([
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuIds
,
"status"
=>
Tcc
::
STATUS_TRY
]);
if
(
$tccInfo
[
0
][
"operator_result"
]
==
Tcc
::
OPERATOR_RESULT_FAIL
)
{
if
(
!
empty
(
$tccInfoList
))
{
foreach
(
$tccInfoList
as
$tccInfo
)
{
if
(
$tccInfo
[
"operator_result"
]
==
Tcc
::
OPERATOR_RESULT_FAIL
)
{
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
else
{
return
self
::
TCC_RESULT_SUCCESS
;
}
}
}
}
return
self
::
TCC_RESULT_SUCCESS
;
}
//如果已经有 confirm 或者 cancel,则直接失败
//如果已经有 confirm 或者 cancel,则直接失败
$cTccInfo
=
Tcc
::
getRecordMaster
([
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"status"
=>
[
Tcc
::
STATUS_CONFIRM
,
Tcc
::
STATUS_CANCEL
],
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
]);
$cTccInfoList
=
Tcc
::
getRecordMaster
([
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuIds
,
"status"
=>
[
Tcc
::
STATUS_CONFIRM
,
Tcc
::
STATUS_CANCEL
],
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
]);
if
(
!
empty
(
$cTccInfo
))
{
if
(
!
empty
(
$cTccInfoList
))
{
foreach
(
$goodsSkuIds
as
$goodsSkuId
)
{
Tcc
::
save
([
Tcc
::
save
([
"t_id"
=>
$tid
,
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"goods_sku_id"
=>
$goodsSkuId
,
"status"
=>
Tcc
::
STATUS_TRY
,
"status"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
]);
}
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$skus
=
GoodsSku
::
getRecords
([
"goods_sku_id"
=>
$goodsSkuIds
]);
if
(
!
empty
(
$skus
))
{
GoodsSku
::
beginTransaction
();
foreach
(
$skus
as
$sku
)
{
$goodsSkuId
=
$sku
[
"goods_sku_id"
];
$sku
=
GoodsSku
::
getRecord
([
"goods_sku_id"
=>
$goodsSkuId
]);
if
(
!
empty
(
$sku
[
"inventory_rest"
])
&&
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
!
empty
(
$sku
[
"inventory_rest"
])
&&
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
empty
(
$numList
[
$goodsSkuId
]))
{
return
self
::
TCC_RESULT_FAIL
;
}
$num
=
$numList
[
$sku
[
"goods_sku_id"
]];
GoodsSku
::
beginTransaction
();
GoodsSku
::
beginTransaction
();
GoodsSku
::
save
([
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
1
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
-
1
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
-
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
],
[
"goods_sku_id"
=>
$goodsSkuId
]);
Tcc
::
save
([
Tcc
::
save
([
...
@@ -59,8 +85,7 @@ class TccService
...
@@ -59,8 +85,7 @@ class TccService
"status"
=>
Tcc
::
STATUS_TRY
,
"status"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_SUCCESS
,
]);
]);
}
else
{
if
(
!
GoodsSku
::
commit
())
{
GoodsSku
::
rollback
();
GoodsSku
::
rollback
();
Tcc
::
save
([
Tcc
::
save
([
...
@@ -71,14 +96,20 @@ class TccService
...
@@ -71,14 +96,20 @@ class TccService
]);
]);
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
}
else
{
}
if
(
!
GoodsSku
::
commit
())
{
GoodsSku
::
rollback
();
foreach
(
$skus
as
$sku
)
{
Tcc
::
save
([
Tcc
::
save
([
"t_id"
=>
$tid
,
"t_id"
=>
$tid
,
"goods_sku_id"
=>
$goodsSkuId
,
"goods_sku_id"
=>
$sku
[
"goods_sku_id"
]
,
"status"
=>
Tcc
::
STATUS_TRY
,
"status"
=>
Tcc
::
STATUS_TRY
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
"operator_result"
=>
Tcc
::
OPERATOR_RESULT_FAIL
,
]);
]);
return
self
::
TCC_RESULT_FAIL
;
}
}
}
}
return
self
::
TCC_RESULT_SUCCESS
;
return
self
::
TCC_RESULT_SUCCESS
;
...
...
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