注意:数据只要涉及多表⼀致性操作,必须要开启数据库事务操作 ThinkPHP5 中模型层中使⽤事务:
try{
komda$this->startTrans();
$this->data($order_data)->isUpdate(false)->save();
$new_order = $this->order_no;
if (!is_numeric($new_order)) throw new \Exception("商品订单添加失败");大家来碴
$this->hasMany('OrdersAccess', 'order_no', 'order_no')->saveAll($data_order);
$this->commit();
辜鸿鸣return ['code' => '1001', 'msg' => '商品订单添加成功', 'data' => ['order_no' => $new_order, 'cart_list' => $data_order]];
国民经济核算论文
}catch (\Exception$e){
$this->rollback();
tebreturn ['code'=>'1008','msg'=>'商品订单添加失败','data'];
}