TopicOrderModel::startTrans();
TopicOrderCommentModel::startTrans();
try {
$topicOrderModel = new TopicOrderModel;
$topicOrderModel -> status = 4;
$topicOrderModel -> save();
TopicOrderModel::commit();
$topicOrderCommentModel= new TopicOrderCommentModel;
$topicOrderCommentModel-> topic_order_id = $findOrder -> id;
$topicOrderCommentModel-> content = input('content');
$topicOrderCommentModel-> pics = input('pics');
$topicOrderCommentModel-> from_user_id = $findOrder -> user_id;
$topicOrderCommentModel-> to_user_id = 'ppp';// 这里提交的数据和数据表的对应的字段类型不一致,会抛出异常
$topicOrderCommentModel-> save();
TopicOrderCommentModel::commit();
} catch(\Exception $error) {
TopicOrderModel::rollback();
TopicOrderCommentModel::rollback();
echo '回滚了';
}
ThinkPHP6多个模型事务的提交和回滚
于 2023-09-03 16:15:33 首次发布