当前位置:Gxlcms > 数据库问题 > MySQL事务

MySQL事务

时间:2021-07-01 10:21:17 帮助过:7人阅读

Db::startTrans();
try{
$order = Db::name(‘charge‘)->where(‘order_no‘, $data[‘out_trade_no‘])->find();
if(!$order){
echo ‘FAIL‘;
exit();
}
if($order[‘status‘]==){
echo ‘FAIL‘;
exit();
}
DB::table(‘charge‘)->where(‘order_no‘, $data[‘out_trade_no‘])->update([‘status‘=>1, ‘update_time‘=>time()
Db::table(‘user‘)->where(‘id‘, $order[‘user_id])->setInc(‘money‘, $order[‘money‘]);
$data = array(
‘uid‘ => $order[‘user_id‘],
‘type‘ => 3,
‘relation‘ => $order[‘id‘],
‘money‘ => $order[‘money‘],
‘info‘ => ‘会员充值‘ . $order[‘money‘] . ‘元‘,
‘create_time‘ => time(),
‘create_ip‘ => request()->ip()
);
Db::name(‘wealthlog‘)->insert($data);
//提交事务
Db::commit();
echo ‘SUCCESS‘;
} catch (\Exception $e) {
//回滚事务
Db::rollback();
echo ‘FAIL‘;
}
---------------------
版权声明:本文为CSDN博主「Wake_me_Up123」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wake_me_up123/article/details/82259557

MySQL事务

标签:try   detail   cat   ==   rollback   use   ESS   where   uid   

人气教程排行