request->post('cardNo', ''); $items = $this->request->post('items', []); $note = $this->request->post('note', ''); if (empty($cardNo) || !preg_match('/^[A-Z]\d{3}$/', $cardNo)) { return json(['code' => -1, 'data' => null, 'msg' => '号码牌无效']); } if (empty($items)) { return json(['code' => -1, 'data' => null, 'msg' => '购物车为空']); } try { $result = $orderService->submit($cardNo, $items, $note); return json(['code' => 0, 'data' => $result, 'msg' => '下单成功']); } catch (\Exception $e) { return json(['code' => -1, 'data' => null, 'msg' => $e->getMessage()]); } } public function list(OrderService $orderService) { $cardNo = $this->request->get('card_no', ''); if (empty($cardNo)) { return json(['code' => -1, 'data' => null, 'msg' => '缺少号码牌']); } $orders = $orderService->listByCard($cardNo); return json(['code' => 0, 'data' => $orders, 'msg' => 'ok']); } // BUG-01: 增加 cardNo 归属校验 public function remind(OrderService $orderService) { $id = $this->request->param('id', 0); $cardNo = $this->request->param('card_no', ''); if (empty($id) || empty($cardNo)) { return json(['code' => -1, 'data' => null, 'msg' => '参数不完整']); } try { $orderService->remind(intval($id), $cardNo); return json(['code' => 0, 'data' => null, 'msg' => '已催单']); } catch (\Exception $e) { return json(['code' => -1, 'data' => null, 'msg' => $e->getMessage()]); } } }