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
12d5051c
Commit
12d5051c
authored
Aug 05, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:tcc try
parent
bf78699f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
1 deletion
+62
-1
Tcc2Service.php
application/services/tcc/Tcc2Service.php
+62
-1
No files found.
application/services/tcc/Tcc2Service.php
View file @
12d5051c
...
...
@@ -4,6 +4,7 @@ namespace App\Services\tcc;
use
App\Exception\custom\GoodsException
;
use
App\Models\goods\mysql\GoodsSku
;
use
App\Models\goods\mysql\PindanGoodsSku
;
use
App\Models\goods\mysql\Tcc
;
use
App\Models\marketing\mysql\Marketing
;
...
...
@@ -47,6 +48,23 @@ class Tcc2Service
return
self
::
TCC_RESULT_SUCCESS
;
}
if
(
$isPindan
)
{
return
self
::
pindanGoodsTry
(
$tid
,
$keys
,
$goodsInfoList
);
}
else
{
return
self
::
generalGoodsTry
(
$tid
,
$keys
,
$goodsInfoList
);
}
}
/**
* 普通商品库存 try
* @param $tid
* @param $keys
* @param $goodsInfoList
* @return bool
* @throws GoodsException
*/
private
static
function
generalGoodsTry
(
$tid
,
$keys
,
$goodsInfoList
)
{
if
(
!
empty
(
$goodsInfoList
))
{
GoodsSku
::
beginTransaction
();
foreach
(
$goodsInfoList
as
$item
)
{
...
...
@@ -84,11 +102,54 @@ class Tcc2Service
return
self
::
TCC_RESULT_SUCCESS
;
}
private
static
function
generalGoodsTry
()
/**
* 拼单商品库存 try
* @param $tid
* @param $keys
* @param $goodsInfoList
* @return bool
* @throws GoodsException
*/
private
static
function
pindanGoodsTry
(
$tid
,
$keys
,
$goodsInfoList
)
{
if
(
!
empty
(
$goodsInfoList
))
{
PindanGoodsSku
::
beginTransaction
();
foreach
(
$goodsInfoList
as
$item
)
{
$goodsSkuId
=
$item
[
"goods_sku_id"
];
$num
=
$item
[
"num"
];
$sku
=
PindanGoodsSku
::
getRecord
([
"goods_sku_id"
=>
$goodsSkuId
]
,
[
"goods_sku_id"
,
"inventory_rest"
,
"inventory_lock"
,
"online_status"
]);
if
(
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
//条件加上乐观锁
$rowCount
=
PindanGoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"inventory_rest"
=>
$sku
[
"inventory_rest"
]
-
$num
,
],
[
"goods_sku_id"
=>
$goodsSkuId
,
"inventory_rest[>=]"
=>
$num
]);
if
(
$rowCount
<=
0
)
{
PindanGoodsSku
::
rollback
();
throw
new
GoodsException
([
"cus"
=>
24
]);
}
}
else
{
PindanGoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
}
Tcc
::
save
([
"tid"
=>
$tid
,
"goods_data"
=>
$keys
,
"status"
=>
Tcc
::
STATUS_T_SUCCESS
,
]);
if
(
!
PindanGoodsSku
::
commit
())
{
PindanGoodsSku
::
rollback
();
return
self
::
TCC_RESULT_FAIL
;
}
}
return
self
::
TCC_RESULT_SUCCESS
;
}
/**
* 下单 商品tcc confirm
* @param $keys
...
...
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