$Model->startTrans();
$result = 0;
//下面的循环里面的代码,事务提交和回滚都无效
foreach($salesInfoArr as $key => $val){
$result1 += $Model->relation(true)->data($val)->add();
}
$data['saleslist_state'] = 1;
$cond['id'] = $shipmentId;
//下面这行代码事务是有效果的
$result2 = $Notice->where($cond)->data($data)->save();
if($result1 == count($salesInfoArr) && $result2){
$Model->commit();
$this->ajaxReturn(array('label' => 'success','message' =>'保存成功!'));
}else{
$Model->rollback();
$this->ajaxReturn(array('label' => 'fail','message' =>'保存失败!'));
}
最佳答案
