一、项目源代码结构
弘大卡友_完整源代码/
driver-app/ # 司机端应用
package.json
pages/ # 页面文件(28个)
home/index.vue
order/hall.vue
order/detail.vue
wallet/index.vue
components/ # 组件库(45个)
order-list.vue
driver-card.vue
map-navigator.vue
server/ # 服务器端
src/main/java/com/hongda/
controller/ # 控制器层(32个)
OrderController.java
DriverController.java
service/ # 业务层(28个)
OrderService.java
OrderServiceImpl.java
二、核心业务逻辑代码示例
2.1 订单服务实现类 (OrderServiceImpl.java)
/**
* 订单服务实现类 - 核心抢单逻辑
* @copyright 汕头市弘大物流有限公司
* @version 1.0
*/
package com.hongda.logistics.service.impl;
import com.hongda.logistics.dao.OrderDao;
import com.hongda.logistics.dao.DriverDao;
import com.hongda.logistics.model.Order;
import com.hongda.logistics.model.Driver;
import com.hongda.logistics.model.OrderStatus;
import com.hongda.logistics.service.OrderService;
import com.hongda.logistics.exception.BusinessException;
import com.hongda.logistics.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderDao orderDao;
@Autowired
private DriverDao driverDao;
@Override
@Transactional(rollbackFor = Exception.class)
public OrderVO grabOrder(Long orderId, Long driverId) {
// 1. 验证订单是否存在且可接单
Order order = orderDao.selectById(orderId);
if (order == null) {
throw new BusinessException("订单不存在");
}
if (!OrderStatus.WAITING.equals(order.getStatus())) {
throw new BusinessException("订单状态不可接单");
}
// 2. 验证司机资质
Driver driver = driverDao.selectById(driverId);
validateDriverQualification(driver, order);
// 3. 执行抢单逻辑
order.setDriverId(driverId);
order.setStatus(OrderStatus.ACCEPTED);
order.setAcceptTime(new Date());
order.setUpdateTime(new Date());
// 4. 更新数据库
int result = orderDao.updateById(order);
if (result <= 0) {
throw new BusinessException("抢单失败,请重试");
}
// 5. 返回结果
return convertToVO(order);
}
private void validateDriverQualification(Driver driver, Order order) {
// 检查司机状态
if (driver.getStatus() != 1) {
throw new BusinessException("司机账号异常");
}
// 检查车辆类型匹配
if (!driver.getVehicleType().equals(order.getRequiredVehicleType())) {
throw new BusinessException("车辆类型不匹配");
}
// 检查信用分
if (driver.getCreditScore() < order.getMinCreditScore()) {
throw new BusinessException("信用分不足");
}
}
}
2.2 前端订单列表组件 (order-list.vue)
<!-- 订单列表组件 -->
<template>
<view class="order-list-container">
<!-- 筛选条件 -->
<view class="filter-section">
<view class="filter-item" @click="showLocationPicker">
<text>{{ filter.startCity || '出发地' }}</text>
<uni-icons type="arrowdown" size="16"></uni-icons>
</view>
<view class="filter-item" @click="showGoodsTypePicker">
<text>{{ filter.goodsType || '货物类型' }}</text>
<uni-icons type="arrowdown" size="16"></uni-icons>
</view>
</view>
<!-- 订单列表 -->
<scroll-view
class="order-scroll-view"
scroll-y
@scrolltolower="loadMore">
<view v-for="(item, index) in orderList" :key="item.id"
class="order-item" @click="goToDetail(item.id)">
<view class="order-header">
<text class="order-no">订单号: {{ item.orderNo }}</text>
<text class="order-status" :class="getStatusClass(item.status)">
{{ formatStatus(item.status) }}
</text>
</view>
<view class="price-info">
<text class="price">¥{{ formatPrice(item.totalFee) }}</text>
<text class="distance">{{ item.distance }}公里</text>
</view>
<view class="action-buttons" v-if="item.status === 'WAITING'">
<button class="btn-grab" @click.stop="grabOrder(item.id)">立即抢单</button>
</view>