db->beginTransaction(); try { $order = Order::findOne(['store_id' => get_store_id(), 'id' => $this->order_id]); if (empty($order)) { throw new \Exception('订单查询失败,参数错误'); } if (!$order || $order->is_offline != 1) { throw new \Exception('当前订单商品配送方式不是到店自提'); } if ($order->trade_status === Order::ORDER_FLOW_CONFIRM) { throw new \Exception('订单状态错误,不可更改配送点'); } $md = Md::findOne(['store_id' => get_store_id(), 'id' => $this->shop_id, 'is_delete' => 0]); if (empty($md)) { throw new \Exception('当前门店为空'); } $order->md_id = $this->shop_id; if ($order->save()) { $mdProfit = MdProfit::findOne(['order_id' => $order->id, 'is_send' => 0]); $mdProfit->md_id = $order->md_id; if (!$mdProfit->save()) { throw new \Exception(json_encode($mdProfit->errors)); } $t->commit(); return [ 'code' => 0, 'msg' => '修改成功' ]; } else { throw new \Exception('保存失败'); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }