TP 트랜잭션 작성

3428 단어

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' => ' '];
        }
    }

좋은 웹페이지 즐겨찾기