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
1ef06216
Commit
1ef06216
authored
Aug 05, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:商品tcc优化
parent
8917c141
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
40 deletions
+23
-40
Tcc2Service.php
application/services/tcc/Tcc2Service.php
+22
-39
Goods.php
daemon/Goods.php
+1
-1
No files found.
application/services/tcc/Tcc2Service.php
View file @
1ef06216
...
@@ -26,13 +26,10 @@ class Tcc2Service
...
@@ -26,13 +26,10 @@ class Tcc2Service
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
=
$numList
=
[];
foreach
(
$goodsInfoList
as
$item
)
{
foreach
(
$goodsInfoList
as
$item
)
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
[]
=
$item
[
"goods_sku_id"
];
$numList
[
$item
[
"goods_sku_id"
]]
=
$item
[
"num"
];
}
}
$tccInfo
=
self
::
getTccRecord
(
$tid
);
$tccInfo
=
self
::
getTccRecord
(
$tid
);
...
@@ -46,19 +43,14 @@ class Tcc2Service
...
@@ -46,19 +43,14 @@ class Tcc2Service
return
self
::
TCC_RESULT_SUCCESS
;
return
self
::
TCC_RESULT_SUCCESS
;
}
}
$skus
=
GoodsSku
::
getRecords
([
"goods_sku_id"
=>
$goodsSkuIds
]
if
(
!
empty
(
$goodsInfoList
))
{
,
[
"goods_sku_id"
,
"inventory_rest"
,
"inventory_lock"
,
"online_status"
]);
if
(
!
empty
(
$skus
))
{
GoodsSku
::
beginTransaction
();
GoodsSku
::
beginTransaction
();
foreach
(
$skus
as
$sku
)
{
foreach
(
$goodsInfoList
as
$item
)
{
$goodsSkuId
=
$sku
[
"goods_sku_id"
];
$goodsSkuId
=
$item
[
"goods_sku_id"
];
$num
=
$item
[
"num"
];
$sku
=
GoodsSku
::
getRecord
([
"goods_sku_id"
=>
$goodsSkuId
]
,
[
"goods_sku_id"
,
"inventory_rest"
,
"inventory_lock"
,
"online_status"
]);
if
(
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
empty
(
$numList
[
$goodsSkuId
]))
{
return
self
::
TCC_RESULT_FAIL
;
}
$num
=
$numList
[
$goodsSkuId
];
//条件加上乐观锁
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
$rowCount
=
GoodsSku
::
save
([
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
"inventory_lock"
=>
$sku
[
"inventory_lock"
]
+
$num
,
...
@@ -92,7 +84,8 @@ class Tcc2Service
...
@@ -92,7 +84,8 @@ class Tcc2Service
* 下单 商品tcc confirm
* 下单 商品tcc confirm
* @param $keys
* @param $keys
* @param $tid
* @param $tid
* @return int
* @return bool
* @throws GoodsException
*/
*/
public
static
function
placeAnOrderConfirm
(
$keys
,
$tid
)
public
static
function
placeAnOrderConfirm
(
$keys
,
$tid
)
{
{
...
@@ -101,13 +94,10 @@ class Tcc2Service
...
@@ -101,13 +94,10 @@ class Tcc2Service
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
=
$numList
=
[];
foreach
(
$goodsInfoList
as
$item
)
{
foreach
(
$goodsInfoList
as
$item
)
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
[]
=
$item
[
"goods_sku_id"
];
$numList
[
$item
[
"goods_sku_id"
]]
=
$item
[
"num"
];
}
}
$tccInfo
=
self
::
getTccRecord
(
$tid
);
$tccInfo
=
self
::
getTccRecord
(
$tid
);
...
@@ -125,17 +115,15 @@ class Tcc2Service
...
@@ -125,17 +115,15 @@ class Tcc2Service
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$skus
=
GoodsSku
::
getRecords
([
"goods_sku_id"
=>
$goodsSkuIds
]
if
(
!
empty
(
$goodsInfoList
))
{
,
[
"goods_sku_id"
,
"total_amount_order"
,
"inventory_lock"
,
"online_status"
]);
if
(
!
empty
(
$skus
))
{
GoodsSku
::
beginTransaction
();
GoodsSku
::
beginTransaction
();
foreach
(
$skus
as
$sku
)
{
foreach
(
$goodsInfoList
as
$item
)
{
$goodsSkuId
=
$sku
[
"goods_sku_id"
];
$goodsSkuId
=
$item
[
"goods_sku_id"
];
$num
=
$item
[
"num"
];
$sku
=
GoodsSku
::
getRecord
([
"goods_sku_id"
=>
$goodsSkuId
]
,
[
"goods_sku_id"
,
"inventory_rest"
,
"total_amount_order"
,
"inventory_lock"
,
"online_status"
]);
if
(
!
empty
(
$sku
[
"inventory_lock"
])
&&
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
!
empty
(
$sku
[
"inventory_lock"
])
&&
$sku
[
"online_status"
]
==
GoodsSku
::
ONLINE_STATUS_ONLINE
)
{
if
(
empty
(
$numList
[
$goodsSkuId
]))
{
return
self
::
TCC_RESULT_FAIL
;
}
$num
=
$numList
[
$goodsSkuId
];
//条件加上乐观锁
//条件加上乐观锁
$rowCount
=
GoodsSku
::
save
([
$rowCount
=
GoodsSku
::
save
([
...
@@ -176,13 +164,10 @@ class Tcc2Service
...
@@ -176,13 +164,10 @@ class Tcc2Service
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
=
$numList
=
[];
foreach
(
$goodsInfoList
as
$item
)
{
foreach
(
$goodsInfoList
as
$item
)
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
if
(
empty
(
$item
[
"goods_sku_id"
])
||
empty
(
$item
[
"num"
]))
{
return
self
::
TCC_RESULT_FAIL
;
return
self
::
TCC_RESULT_FAIL
;
}
}
$goodsSkuIds
[]
=
$item
[
"goods_sku_id"
];
$numList
[
$item
[
"goods_sku_id"
]]
=
$item
[
"num"
];
}
}
$tccInfo
=
self
::
getTccRecord
(
$tid
);
$tccInfo
=
self
::
getTccRecord
(
$tid
);
...
@@ -202,16 +187,13 @@ class Tcc2Service
...
@@ -202,16 +187,13 @@ class Tcc2Service
return
self
::
TCC_RESULT_SUCCESS
;
return
self
::
TCC_RESULT_SUCCESS
;
}
}
$skus
=
GoodsSku
::
getRecords
([
"goods_sku_id"
=>
$goodsSkuIds
]
if
(
!
empty
(
$goodsInfoList
))
{
,
[
"goods_sku_id"
,
"inventory_rest"
,
"inventory_lock"
,
"total_amount_order"
,
"online_status"
]);
if
(
!
empty
(
$skus
))
{
GoodsSku
::
beginTransaction
();
GoodsSku
::
beginTransaction
();
foreach
(
$skus
as
$sku
)
{
foreach
(
$goodsInfoList
as
$item
)
{
$goodsSkuId
=
$sku
[
"goods_sku_id"
];
$goodsSkuId
=
$item
[
"goods_sku_id"
];
if
(
empty
(
$numList
[
$goodsSkuId
]))
{
$num
=
$item
[
"num"
];
return
self
::
TCC_RESULT_FAIL
;
$sku
=
GoodsSku
::
getRecord
([
"goods_sku_id"
=>
$goodsSkuId
]
}
,
[
"goods_sku_id"
,
"inventory_rest"
,
"inventory_lock"
,
"total_amount_order"
,
"online_status"
]);
$num
=
$numList
[
$goodsSkuId
];
//T时候执行C2,条件加上乐观锁
//T时候执行C2,条件加上乐观锁
if
(
$tccInfo
[
"status"
]
==
Tcc
::
STATUS_T_SUCCESS
)
{
if
(
$tccInfo
[
"status"
]
==
Tcc
::
STATUS_T_SUCCESS
)
{
...
@@ -224,6 +206,7 @@ class Tcc2Service
...
@@ -224,6 +206,7 @@ class Tcc2Service
throw
new
GoodsException
([
"cus"
=>
31
]);
throw
new
GoodsException
([
"cus"
=>
31
]);
}
}
}
}
//T时候执行C2,条件加上乐观锁
//T时候执行C2,条件加上乐观锁
if
(
$tccInfo
[
"status"
]
==
Tcc
::
STATUS_C1_SUCCESS
)
{
if
(
$tccInfo
[
"status"
]
==
Tcc
::
STATUS_C1_SUCCESS
)
{
$rowCount
=
GoodsSku
::
save
([
$rowCount
=
GoodsSku
::
save
([
...
...
daemon/Goods.php
View file @
1ef06216
...
@@ -9,7 +9,7 @@ use App\Models\goods\mysql\GoodsSku;
...
@@ -9,7 +9,7 @@ use App\Models\goods\mysql\GoodsSku;
use
App\Services\goods\GoodsService
;
use
App\Services\goods\GoodsService
;
use
Api\PhpUtils\Log\DaemonLog
;
use
Api\PhpUtils\Log\DaemonLog
;
class
Goods
implements
DaemonServiceInterface
class
Goods
implements
DaemonServiceInterface
{
public
function
run
()
public
function
run
()
{
{
sleep
(
2
);
sleep
(
2
);
...
...
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