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' => '修改失败'];
        }
    }

 

posted @ 2019-12-06 22:54  在斑马线上散布  阅读(373)  评论(0编辑  收藏  举报
夫人不言,言必有中。这是高级臣僚的一种可贵品质,言辞精炼,直抵要害。