TP事物的写法
Db::startTrans();
try{
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
use think\Db; public function addInfoData($member_id, $type, $money, $invoice_name, $invoice_tel, $email, $taxpayer_number, $id) { Db::startTrans(); try{ $invoice_id = $this->insertGetId($data);//添加 发票记录 $pay_log_model = new PayLog(); $pay_log_res = $pay_log_model->updateDataByWhere([['id', 'IN', $id]], ['invoice_id' => $invoice_id]);//更新 支付订单 if($invoice_id && $pay_log_res){ Db::commit(); return ['code' => 200]; }else{ addlog('/upload/running_log/invoice','invoice', '申请开票失败,$invoice_id:'.$invoice_id.';$pay_log_res:'.$pay_log_res.'开票订单详情:'.json_encode($data)); Db::rollback(); return ['code' => -100, 'msg' => '修改失败']; } } catch (\Exception $e) { addlog('/upload/running_log/invoice','invoice', '申请开票失败,开票订单详情:'.json_encode($data).'----结果:'.$e->getMessage()); Db::rollback(); return ['code' => -100, 'msg' => '修改失败']; } }
-----END
影子是一个会撒谎的精灵,它在虚空中流浪和等待被发现之间;在存在与不存在之间....