public function index(){
Db::startTrans();
try{
self::changeUserMoney();
Db::commit();
exit(‘success’);
}catch (\Exception $exception){
$err = [
‘code’ =>
e
x
c
e
p
t
i
o
n
−
>
g
e
t
C
o
d
e
(
)
,
′
m
s
g
′
=
>
u
r
l
d
e
c
o
d
e
(
exception->getCode(), 'msg' => urldecode(
exception−>getCode(),′msg′=>urldecode(exception->getMessage()),
‘file’ => $exception->getFile(),
‘line’ =>
e
x
c
e
p
t
i
o
n
−
>
g
e
t
L
i
n
e
(
)
]
;
@
f
i
l
e
p
u
t
c
o
n
t
e
n
t
s
(
′
e
r
r
o
r
.
t
x
t
′
,
u
r
l
d
e
c
o
d
e
(
j
s
o
n
e
n
c
o
d
e
(
exception->getLine() ]; @file_put_contents('error.txt', urldecode(json_encode(
exception−>getLine()];@fileputcontents(′error.txt′,urldecode(jsonencode(err)).PHP_EOL ,FILE_APPEND);
throw new Exception($exception->getMessage());
Db::rollback();
}
}
public function changeUserMoney(){
$res=Db::name(‘salesman’)->where(“id”,4)->update([‘status’=>1]);
r
e
s
1
=
D
b
:
:
n
a
m
e
(
′
s
a
l
e
s
m
a
n
′
)
−
>
w
h
e
r
e
(
"
i
d
"
,
4
)
−
>
u
p
d
a
t
e
(
[
′
a
c
c
o
u
n
t
i
d
′
=
>
14
]
)
;
i
f
(
e
m
p
t
y
(
res1=Db::name('salesman')->where("id",4)->update(['account_id'=>14]); if(empty(
res1=Db::name(′salesman′)−>where("id",4)−>update([′accountid′=>14]);if(empty(res)){
throw new Exception(‘1000’);
}
if(empty($res1)){
throw new Exception(‘更新失败1!’);
}
}
事务最终解决方案
最新推荐文章于 2024-07-19 23:47:09 发布