Browse Source

feat(家政工作台): 服务人员工作助手家政版-工单闭环

需求重定义首期落地(健康杭州·服务人员端,先撤培训认证只做家政助手):
- 后端: train_service_order 工单表 + 三件套(实体/Mapper/Service/Controller)
  接单→到岗打卡(定位+门牌照)→服务项勾选→拍照留痕→客户确认码→收入台账
  金额整数分(amount-platformFee=staffIncome),状态机 pending/accepted/arrived/doing/done/confirmed/cancelled
- 前端: pages/work 三页 (今日工单/工单详情/收入台账) + api.js 封装
  role=housekeeper 首页入口卡片;≤30秒操作线,不给家政做复杂工作台(需求洞察红线)
- 编译: 后端 mvn compile 通过, 前端 build:h5 通过
liaoxg 3 days ago
parent
commit
4d67ca9767

+ 121 - 0
train-backend/src/main/java/com/train/controller/ServiceOrderController.java

@@ -0,0 +1,121 @@
+package com.train.controller;
+
+import com.train.common.Result;
+import com.train.service.ServiceOrderService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 家政服务工单 Controller(服务人员工作助手 · 家政版)
+ *
+ * 面向 45–60 岁、数字素养最低的家政服务人员,原则:
+ * - 每个接口一步完成一个动作(接单/打卡/完成/确认),无多步表单
+ * - 返回体扁平、无嵌套深链,前端可直接渲染
+ * - 金额一律整数分,前端负责除 100
+ */
+@Tag(name = "家政工作台", description = "我的工单 / 接单 / 到岗打卡 / 服务留痕 / 客户确认 / 收入台账")
+@RestController
+@RequestMapping("/api/order")
+public class ServiceOrderController {
+
+    @Resource
+    private ServiceOrderService serviceOrderService;
+
+    /** 我的工单(今日 / 待接 / 进行中 / 已完成 分组) */
+    @Operation(summary = "我的工单分组列表")
+    @PostMapping("/mine")
+    public Result<List<Map<String, Object>>> mine(
+            @RequestAttribute("userId") Long userId) {
+        return serviceOrderService.myOrders(userId);
+    }
+
+    /** 工单详情(含服务项、照片、确认码) */
+    @Operation(summary = "工单详情")
+    @PostMapping("/detail")
+    public Result<Map<String, Object>> detail(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Long orderId = body == null ? null : toLong(body.get("orderId"));
+        return serviceOrderService.detail(userId, orderId);
+    }
+
+    /** 接单 */
+    @Operation(summary = "接单")
+    @PostMapping("/accept")
+    public Result<Boolean> accept(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Long orderId = body == null ? null : toLong(body.get("orderId"));
+        return serviceOrderService.accept(userId, orderId);
+    }
+
+    /**
+     * 到岗打卡
+     * body: { orderId, lat, lng, photo }
+     */
+    @Operation(summary = "到岗打卡(定位+门牌照)")
+    @PostMapping("/arrive")
+    public Result<Boolean> arrive(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Map<String, Object> b = body == null ? new java.util.HashMap<String, Object>() : body;
+        Long orderId = toLong(b.get("orderId"));
+        return serviceOrderService.arrive(userId, orderId, b);
+    }
+
+    /**
+     * 提交服务结果(勾选服务项 + 完成照片)→ 生成客户确认码
+     * body: { orderId, items(JSON字符串), photos(逗号分隔) }
+     */
+    @Operation(summary = "提交服务结果并生成确认码")
+    @PostMapping("/finish")
+    public Result<Map<String, Object>> finish(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Map<String, Object> b = body == null ? new java.util.HashMap<String, Object>() : body;
+        Long orderId = toLong(b.get("orderId"));
+        return serviceOrderService.finish(userId, orderId, b);
+    }
+
+    /**
+     * 客户确认
+     * body: { orderId, code }
+     */
+    @Operation(summary = "客户确认(确认码)")
+    @PostMapping("/confirm")
+    public Result<Boolean> confirm(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Map<String, Object> b = body == null ? new java.util.HashMap<String, Object>() : body;
+        Long orderId = toLong(b.get("orderId"));
+        return serviceOrderService.confirm(userId, orderId, b);
+    }
+
+    /** 收入台账(累计 / 本月 / 待确认 / 最近记录) */
+    @Operation(summary = "收入台账")
+    @PostMapping("/earnings")
+    public Result<Map<String, Object>> earnings(
+            @RequestAttribute("userId") Long userId) {
+        return serviceOrderService.earnings(userId);
+    }
+
+    private Long toLong(Object v) {
+        if (v == null) {
+            return null;
+        }
+        try {
+            return Long.valueOf(v.toString().trim());
+        } catch (NumberFormatException e) {
+            return null;
+        }
+    }
+}

+ 102 - 0
train-backend/src/main/java/com/train/entity/TrainServiceOrder.java

@@ -0,0 +1,102 @@
+package com.train.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 家政服务工单(服务人员工作助手 —— 家政版)
+ *
+ * 设计原则(需求洞察结论):
+ * - 家政人群数字素养最低,一条工单必须能在「接单 → 到岗 → 执行 → 留痕 → 确认」中 30 秒内完成单步
+ * - 金额一律整数、单位分(对齐 cfc ButlerServiceRecord:金额/平台费/个人所得)
+ * - 服务留痕是结算与监管的依据,不做「工时打卡 + 结算联动」之外的花哨能力
+ */
+@Data
+@TableName("train_service_order")
+public class TrainServiceOrder implements Serializable {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /** 工单号(对客户展示,如 HG20261122001) */
+    private String orderNo;
+
+    /** 服务人员 = train_user.id */
+    private Long workerId;
+
+    /** 服务人员对应的 cfc 会员 ID(同库 users.id,便于与 cfc 家庭工作台/结算互通) */
+    private Long cfcUserId;
+
+    /** 关联 cfc 家庭 ID(可空;对应 cfc families 表) */
+    private Long familyId;
+
+    /** 家庭/客户称呼(展示用,如「王阿姨家」) */
+    private String familyName;
+
+    private String contactPhone;
+
+    private String address;
+
+    /** 服务类型:cleaning(保洁)/care(照护)/escort(陪诊)/meal(助餐)/other */
+    private String serviceType;
+
+    /** 本次服务项(JSON 数组:[{"name":"厨房清洁","done":0}]) */
+    private String serviceItems;
+
+    /** 关联 cfc 健康计划 ID(可空;对应 cfc health_plan) */
+    private Long planId;
+
+    /** 服务日期 */
+    private Date orderDate;
+
+    /** 预计开始时间 */
+    private Date startAt;
+
+    /** 预计结束时间 */
+    private Date endAt;
+
+    /** pending 待接单 / accepted 已接单 / arrived 已到岗 / doing 服务中 / done 待客户确认 / confirmed 已完成 / cancelled 已取消 */
+    private String status;
+
+    /** 到岗时间 */
+    private Date arriveAt;
+
+    private Double arriveLat;
+
+    private Double arriveLng;
+
+    /** 到岗门牌照 URL(上门凭证) */
+    private String arrivePhoto;
+
+    /** 完成时间 */
+    private Date finishAt;
+
+    /** 完成照片(多张,逗号分隔) */
+    private String finishPhotos;
+
+    /** 客户确认码(6 位数字,完成时生成,客户核对后确认) */
+    private String clientConfirmCode;
+
+    /** 客户确认时间 */
+    private Date clientConfirmAt;
+
+    /** 本单金额(分) */
+    private Integer amount;
+
+    /** 平台费(分) */
+    private Integer platformFee;
+
+    /** 服务人员所得(分)= amount - platformFee */
+    private Integer staffIncome;
+
+    private String remark;
+
+    private Date createdAt;
+
+    private Date updatedAt;
+}

+ 9 - 0
train-backend/src/main/java/com/train/mapper/TrainServiceOrderMapper.java

@@ -0,0 +1,9 @@
+package com.train.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.train.entity.TrainServiceOrder;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface TrainServiceOrderMapper extends BaseMapper<TrainServiceOrder> {
+}

+ 370 - 0
train-backend/src/main/java/com/train/service/ServiceOrderService.java

@@ -0,0 +1,370 @@
+package com.train.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.train.common.Result;
+import com.train.entity.TrainServiceOrder;
+import com.train.entity.TrainUser;
+import com.train.mapper.TrainServiceOrderMapper;
+import com.train.mapper.TrainUserMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 家政服务工单服务(服务人员工作助手 · 家政版)
+ *
+ * 关键约束(需求洞察结论):
+ * - 每一步都要能「被通知后一步完成」,不接受多表单、多页跳转
+ * - 服务人员只做四件事:接单 → 到岗打卡 → 勾选服务项+拍照 → 确认收入
+ * - 结算口径:amount(分) - platformFee(分) = staffIncome(分),前端一律除 100 显示
+ */
+@Service
+public class ServiceOrderService {
+
+    /** 待客户确认 */
+    private static final String ST_DONE = "done";
+    /** 已完成 */
+    private static final String ST_CONFIRMED = "confirmed";
+    /** 已取消 */
+    private static final String ST_CANCELLED = "cancelled";
+
+    @Resource
+    private TrainServiceOrderMapper orderMapper;
+
+    @Resource
+    private TrainUserMapper userMapper;
+
+    /**
+     * 我的工单:按「今日 / 待接 / 进行中 / 已完成」分组返回
+     */
+    public Result<List<Map<String, Object>>> myOrders(Long userId) {
+        if (userId == null) {
+            return Result.error("请先登录");
+        }
+        List<TrainServiceOrder> all = orderMapper.selectList(
+                new LambdaQueryWrapper<TrainServiceOrder>()
+                        .eq(TrainServiceOrder::getWorkerId, userId)
+                        .orderByDesc(TrainServiceOrder::getId));
+
+        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+        List<Map<String, Object>> todayList = new ArrayList<>();
+        List<Map<String, Object>> pendingList = new ArrayList<>();
+        List<Map<String, Object>> doingList = new ArrayList<>();
+        List<Map<String, Object>> doneList = new ArrayList<>();
+
+        for (TrainServiceOrder o : all) {
+            String status = o.getStatus();
+            if (ST_CANCELLED.equals(status)) {
+                continue;
+            }
+            String od = o.getOrderDate() == null ? null : new SimpleDateFormat("yyyy-MM-dd").format(o.getOrderDate());
+            if ("pending".equals(status)) {
+                pendingList.add(toVO(o));
+            } else if ("accepted".equals(status) || "arrived".equals(status) || "doing".equals(status)) {
+                doingList.add(toVO(o));
+            } else if (ST_DONE.equals(status) || ST_CONFIRMED.equals(status)) {
+                doneList.add(toVO(o));
+            }
+            if (today.equals(od) && !ST_CONFIRMED.equals(status) && !ST_CANCELLED.equals(status)) {
+                todayList.add(toVO(o));
+            }
+        }
+
+        List<Map<String, Object>> result = new ArrayList<>();
+        result.add(group("today", "今日上门", todayList));
+        result.add(group("pending", "待接单", pendingList));
+        result.add(group("doing", "进行中", doingList));
+        result.add(group("done", "已完成", doneList));
+        return Result.success(result);
+    }
+
+    /**
+     * 工单详情
+     */
+    public Result<Map<String, Object>> detail(Long userId, Long orderId) {
+        TrainServiceOrder o = mustOwn(userId, orderId);
+        if (o == null) {
+            return Result.error("工单不存在或不属于您");
+        }
+        Map<String, Object> vo = toVO(o);
+        vo.put("items", parseItems(o.getServiceItems()));
+        vo.put("arrivePhoto", o.getArrivePhoto());
+        vo.put("finishPhotos", splitPhotos(o.getFinishPhotos()));
+        vo.put("clientConfirmCode", o.getClientConfirmCode());
+        return Result.success(vo);
+    }
+
+    /**
+     * 接单(待接单 → 已接单)
+     */
+    public Result<Boolean> accept(Long userId, Long orderId) {
+        TrainServiceOrder o = mustOwn(userId, orderId);
+        if (o == null) {
+            return Result.error("工单不存在或不属于您");
+        }
+        if (!"pending".equals(o.getStatus())) {
+            return Result.error("该工单状态不允许接单");
+        }
+        TrainServiceOrder upd = new TrainServiceOrder();
+        upd.setId(o.getId());
+        upd.setStatus("accepted");
+        upd.setUpdatedAt(new Date());
+        orderMapper.updateById(upd);
+        return Result.success(true);
+    }
+
+    /**
+     * 到岗打卡(已接单 → 已到岗):记录定位 + 门牌照 + 服务端时间戳
+     */
+    public Result<Boolean> arrive(Long userId, Long orderId, Map<String, Object> body) {
+        TrainServiceOrder o = mustOwn(userId, orderId);
+        if (o == null) {
+            return Result.error("工单不存在或不属于您");
+        }
+        if (!"accepted".equals(o.getStatus()) && !"arrived".equals(o.getStatus())) {
+            return Result.error("请先接单再打卡");
+        }
+        TrainServiceOrder upd = new TrainServiceOrder();
+        upd.setId(o.getId());
+        upd.setStatus("arrived");
+        upd.setArriveAt(new Date());
+        upd.setArriveLat(toDouble(body.get("lat")));
+        upd.setArriveLng(toDouble(body.get("lng")));
+        upd.setArrivePhoto(str(body.get("photo")));
+        upd.setUpdatedAt(new Date());
+        orderMapper.updateById(upd);
+        return Result.success(true);
+    }
+
+    /**
+     * 提交服务结果(服务项勾选 + 完成照片):已到岗 → 待客户确认
+     * 完成时生成 6 位客户确认码,客户核对后由客户或机构确认。
+     */
+    public Result<Map<String, Object>> finish(Long userId, Long orderId, Map<String, Object> body) {
+        TrainServiceOrder o = mustOwn(userId, orderId);
+        if (o == null) {
+            return Result.error("工单不存在或不属于您");
+        }
+        if (!"arrived".equals(o.getStatus()) && !"doing".equals(o.getStatus())) {
+            return Result.error("请先完成到岗打卡");
+        }
+        String items = body.get("items") != null ? body.get("items").toString() : o.getServiceItems();
+        String photos = body.get("photos") != null ? body.get("photos").toString() : o.getFinishPhotos();
+
+        String code = String.valueOf((int) (Math.random() * 900000) + 100000);
+
+        TrainServiceOrder upd = new TrainServiceOrder();
+        upd.setId(o.getId());
+        upd.setStatus(ST_DONE);
+        upd.setServiceItems(items);
+        upd.setFinishPhotos(photos);
+        upd.setFinishAt(new Date());
+        upd.setClientConfirmCode(code);
+        upd.setUpdatedAt(new Date());
+        orderMapper.updateById(upd);
+
+        Map<String, Object> vo = toVO(o);
+        vo.put("clientConfirmCode", code);
+        vo.put("items", parseItems(items));
+        vo.put("finishPhotos", splitPhotos(photos));
+        return Result.success(vo);
+    }
+
+    /**
+     * 客户确认(待客户确认 → 已完成)
+     */
+    public Result<Boolean> confirm(Long userId, Long orderId, Map<String, Object> body) {
+        TrainServiceOrder o = mustOwn(userId, orderId);
+        if (o == null) {
+            return Result.error("工单不存在或不属于您");
+        }
+        if (!ST_DONE.equals(o.getStatus())) {
+            return Result.error("当前工单无需确认");
+        }
+        String code = str(body.get("code"));
+        if (!StringUtils.hasText(code)) {
+            return Result.error("请输入客户确认码");
+        }
+        if (!code.equals(o.getClientConfirmCode())) {
+            return Result.error("确认码不正确");
+        }
+        TrainServiceOrder upd = new TrainServiceOrder();
+        upd.setId(o.getId());
+        upd.setStatus(ST_CONFIRMED);
+        upd.setClientConfirmAt(new Date());
+        upd.setUpdatedAt(new Date());
+        orderMapper.updateById(upd);
+        return Result.success(true);
+    }
+
+    /**
+     * 收入台账:累计所得 / 本月所得 / 待确认金额
+     */
+    public Result<Map<String, Object>> earnings(Long userId) {
+        if (userId == null) {
+            return Result.error("请先登录");
+        }
+        List<TrainServiceOrder> all = orderMapper.selectList(
+                new LambdaQueryWrapper<TrainServiceOrder>()
+                        .eq(TrainServiceOrder::getWorkerId, userId)
+                        .ne(TrainServiceOrder::getStatus, ST_CANCELLED));
+
+        long total = 0;
+        long month = 0;
+        long pending = 0;
+        int doneCount = 0;
+        Calendar cal = Calendar.getInstance();
+        int curYear = cal.get(Calendar.YEAR);
+        int curMonth = cal.get(Calendar.MONTH) + 1;
+
+        for (TrainServiceOrder o : all) {
+            int income = o.getStaffIncome() == null ? 0 : o.getStaffIncome();
+            boolean confirmed = ST_CONFIRMED.equals(o.getStatus());
+            if (confirmed) {
+                total += income;
+                doneCount++;
+                if (o.getFinishAt() != null) {
+                    Calendar c = Calendar.getInstance();
+                    c.setTime(o.getFinishAt());
+                    if (c.get(Calendar.YEAR) == curYear && c.get(Calendar.MONTH) + 1 == curMonth) {
+                        month += income;
+                    }
+                }
+            } else {
+                pending += income;
+            }
+        }
+
+        Map<String, Object> vo = new HashMap<>();
+        vo.put("totalIncome", total);
+        vo.put("monthIncome", month);
+        vo.put("pendingIncome", pending);
+        vo.put("doneCount", doneCount);
+        vo.put("recent", recentList(all));
+        return Result.success(vo);
+    }
+
+    // ---------- 内部工具 ----------
+
+    private List<Map<String, Object>> recentList(List<TrainServiceOrder> all) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        int n = 0;
+        for (TrainServiceOrder o : all) {
+            if (!ST_CONFIRMED.equals(o.getStatus()) && !ST_DONE.equals(o.getStatus())) {
+                continue;
+            }
+            list.add(toVO(o));
+            if (++n >= 20) {
+                break;
+            }
+        }
+        return list;
+    }
+
+    private TrainServiceOrder mustOwn(Long userId, Long orderId) {
+        if (userId == null || orderId == null) {
+            return null;
+        }
+        return orderMapper.selectOne(new LambdaQueryWrapper<TrainServiceOrder>()
+                .eq(TrainServiceOrder::getId, orderId)
+                .eq(TrainServiceOrder::getWorkerId, userId)
+                .last("LIMIT 1"));
+    }
+
+    private Map<String, Object> group(String key, String label, List<Map<String, Object>> list) {
+        Map<String, Object> m = new HashMap<>();
+        m.put("key", key);
+        m.put("label", label);
+        m.put("count", list.size());
+        m.put("list", list);
+        return m;
+    }
+
+    private Map<String, Object> toVO(TrainServiceOrder o) {
+        Map<String, Object> m = new HashMap<>();
+        m.put("id", o.getId());
+        m.put("orderNo", o.getOrderNo());
+        m.put("familyName", o.getFamilyName());
+        m.put("contactPhone", o.getContactPhone());
+        m.put("address", o.getAddress());
+        m.put("serviceType", o.getServiceType());
+        m.put("orderDate", o.getOrderDate() == null ? null : new SimpleDateFormat("yyyy-MM-dd").format(o.getOrderDate()));
+        m.put("startAt", o.getStartAt() == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm").format(o.getStartAt()));
+        m.put("endAt", o.getEndAt() == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm").format(o.getEndAt()));
+        m.put("status", o.getStatus());
+        m.put("arriveAt", o.getArriveAt() == null ? null : new SimpleDateFormat("MM-dd HH:mm").format(o.getArriveAt()));
+        m.put("finishAt", o.getFinishAt() == null ? null : new SimpleDateFormat("MM-dd HH:mm").format(o.getFinishAt()));
+        m.put("amount", o.getAmount() == null ? 0 : o.getAmount());
+        m.put("platformFee", o.getPlatformFee() == null ? 0 : o.getPlatformFee());
+        m.put("staffIncome", o.getStaffIncome() == null ? 0 : o.getStaffIncome());
+        m.put("remark", o.getRemark());
+        return m;
+    }
+
+    private List<Map<String, Object>> parseItems(String json) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        if (!StringUtils.hasText(json)) {
+            return list;
+        }
+        try {
+            com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
+            List<Map<String, Object>> parsed = mapper.readValue(json, List.class);
+            for (Map<String, Object> item : parsed) {
+                Map<String, Object> m = new HashMap<>();
+                m.put("name", item.get("name"));
+                m.put("done", item.get("done") != null ? item.get("done") : 0);
+                list.add(m);
+            }
+        } catch (Exception e) {
+            // 服务项 JSON 异常时降级为空列表,不影响主流程
+            return new ArrayList<>();
+        }
+        return list;
+    }
+
+    private List<String> splitPhotos(String photos) {
+        List<String> list = new ArrayList<>();
+        if (!StringUtils.hasText(photos)) {
+            return list;
+        }
+        for (String p : photos.split(",")) {
+            if (StringUtils.hasText(p)) {
+                list.add(p.trim());
+            }
+        }
+        return list;
+    }
+
+    private String str(Object v) {
+        return v == null ? null : v.toString();
+    }
+
+    private Double toDouble(Object v) {
+        if (v == null) {
+            return null;
+        }
+        try {
+            return Double.valueOf(v.toString());
+        } catch (NumberFormatException e) {
+            return null;
+        }
+    }
+
+    /**
+     * 为派单方(管理端/机构)提供:按服务人员查工单,供后续对接 cfc 结算
+     */
+    public TrainUser workerOf(Long workerId) {
+        if (workerId == null) {
+            return null;
+        }
+        return userMapper.selectById(workerId);
+    }
+}

+ 40 - 0
train-backend/src/main/resources/schema.sql

@@ -660,3 +660,43 @@ CREATE TABLE IF NOT EXISTS sso_ticket (
     UNIQUE KEY uk_ticket (ticket),
     UNIQUE KEY uk_ticket (ticket),
     INDEX idx_expire (expire_at)
     INDEX idx_expire (expire_at)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='跨小程序单点登录一次性票据';
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='跨小程序单点登录一次性票据';
+
+-- 家政服务工单(服务人员工作助手 · 家政版)
+-- 设计约束(需求洞察结论):
+--   1) 金额一律整数、单位分(amount - platformFee = staffIncome),对齐 cfc ButlerServiceRecord 口径
+--   2) 工单是「派单—交付—结算—监管」闭环的最小单元:接单→到岗打卡→服务留痕→客户确认
+--   3) worker_id = train_user.id;cfc_user_id 冗余存储便于与 cfc 家庭工作台/结算互通
+CREATE TABLE IF NOT EXISTS train_service_order (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
+    order_no VARCHAR(32) COMMENT '工单号(对客户展示,如 HG20261122001)',
+    worker_id BIGINT NOT NULL COMMENT '服务人员 = train_user.id',
+    cfc_user_id BIGINT COMMENT '服务人员 cfc 会员ID(users.id,便于与 cfc 结算互通)',
+    family_id BIGINT COMMENT '关联 cfc 家庭ID(可空)',
+    family_name VARCHAR(64) COMMENT '家庭/客户称呼(如 王阿姨家)',
+    contact_phone VARCHAR(20) COMMENT '联系电话',
+    address VARCHAR(255) COMMENT '上门地址',
+    service_type VARCHAR(20) DEFAULT 'cleaning' COMMENT 'cleaning保洁/care照护/escort陪诊/meal助餐/other',
+    service_items VARCHAR(1000) COMMENT '本次服务项 JSON:[{"name":"厨房清洁","done":0}]',
+    plan_id BIGINT COMMENT '关联 cfc 健康计划ID(可空)',
+    order_date DATE COMMENT '服务日期',
+    start_at DATETIME COMMENT '预计开始时间',
+    end_at DATETIME COMMENT '预计结束时间',
+    status VARCHAR(20) DEFAULT 'pending' COMMENT 'pending/accepted/arrived/doing/done/confirmed/cancelled',
+    arrive_at DATETIME COMMENT '到岗时间',
+    arrive_lat DECIMAL(10,6) COMMENT '到岗纬度',
+    arrive_lng DECIMAL(10,6) COMMENT '到岗经度',
+    arrive_photo VARCHAR(500) COMMENT '到岗门牌照URL',
+    finish_at DATETIME COMMENT '完成时间',
+    finish_photos VARCHAR(2000) COMMENT '完成照片(逗号分隔)',
+    client_confirm_code VARCHAR(8) COMMENT '客户确认码(6位数字,完成时生成)',
+    client_confirm_at DATETIME COMMENT '客户确认时间',
+    amount INT DEFAULT 0 COMMENT '本单金额(分)',
+    platform_fee INT DEFAULT 0 COMMENT '平台费(分)',
+    staff_income INT DEFAULT 0 COMMENT '服务人员所得=amount-platform_fee(分)',
+    remark VARCHAR(255) COMMENT '备注',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+    INDEX idx_worker (worker_id),
+    INDEX idx_worker_status (worker_id, status),
+    INDEX idx_order_date (order_date)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家政服务工单(服务人员工作助手)';

+ 18 - 0
train-frontend/pages.json

@@ -36,6 +36,24 @@
         "navigationBarTitleText": "我的"
         "navigationBarTitleText": "我的"
       }
       }
     },
     },
+    {
+      "path": "pages/work/index",
+      "style": {
+        "navigationBarTitleText": "家政工作台"
+      }
+    },
+    {
+      "path": "pages/work/detail",
+      "style": {
+        "navigationBarTitleText": "工单详情"
+      }
+    },
+    {
+      "path": "pages/work/earnings",
+      "style": {
+        "navigationBarTitleText": "收入台账"
+      }
+    },
     {
     {
       "path": "pages/member/index",
       "path": "pages/member/index",
       "style": {
       "style": {

+ 32 - 0
train-frontend/pages/index/index.vue

@@ -26,6 +26,15 @@
       </view>
       </view>
     </view>
     </view>
 
 
+    <!-- 家政工作台入口(仅服务人员角色可见) -->
+    <view v-if="isHousekeeper" class="work-entry" @click="goWork">
+      <view class="work-entry-main">
+        <text class="work-entry-title">家政工作台</text>
+        <text class="work-entry-sub">今日工单 · 接单打卡 · 收入台账</text>
+      </view>
+      <text class="work-entry-arrow">›</text>
+    </view>
+
     <!-- 个人成长 -->
     <!-- 个人成长 -->
     <view class="growth-card" v-if="isLoggedIn" @click="goGrowth">
     <view class="growth-card" v-if="isLoggedIn" @click="goGrowth">
       <view class="growth-head">
       <view class="growth-head">
@@ -208,6 +217,10 @@ export default {
       if (cs.length === 1) return cs[0]
       if (cs.length === 1) return cs[0]
       return cs.slice(0, 2).join('、') + ' 等' + cs.length + '个班级'
       return cs.slice(0, 2).join('、') + ' 等' + cs.length + '个班级'
     },
     },
+    isHousekeeper() {
+      var r = this.$store.state.role || ''
+      return r === 'housekeeper' || r === 'worker'
+    },
     gradeColor() {
     gradeColor() {
       if (!this.grade || !this.grade.key) return '#FC7A57'
       if (!this.grade || !this.grade.key) return '#FC7A57'
       return this.gradeColorMap[this.grade.key] || '#FC7A57'
       return this.gradeColorMap[this.grade.key] || '#FC7A57'
@@ -445,6 +458,9 @@ export default {
     },
     },
     goTo(url) {
     goTo(url) {
       uni.navigateTo({ url: url })
       uni.navigateTo({ url: url })
+    },
+    goWork() {
+      uni.navigateTo({ url: '/pages/work/index' })
     }
     }
   }
   }
 }
 }
@@ -507,6 +523,22 @@ export default {
 .growth-card-guide { display: flex; align-items: center; justify-content: center; padding: 40rpx 32rpx; }
 .growth-card-guide { display: flex; align-items: center; justify-content: center; padding: 40rpx 32rpx; }
 .growth-guide-text { font-size: 26rpx; color: #94877F; }
 .growth-guide-text { font-size: 26rpx; color: #94877F; }
 
 
+/* 家政工作台入口(服务人员) */
+.work-entry {
+  display: flex;
+  align-items: center;
+  background: #FFF;
+  border-radius: 16rpx;
+  padding: 28rpx 32rpx;
+  margin-bottom: 24rpx;
+  border-left: 8rpx solid #FC7A57;
+}
+.work-entry:active { background: #FAF7F4; }
+.work-entry-main { flex: 1; overflow: hidden; }
+.work-entry-title { display: block; font-size: 30rpx; font-weight: 700; color: #2A2326; margin-bottom: 6rpx; }
+.work-entry-sub { display: block; font-size: 22rpx; color: #94877F; }
+.work-entry-arrow { flex-shrink: 0; font-size: 40rpx; color: #B6AA9F; margin-left: 8rpx; }
+
 /* 区块标题 */
 /* 区块标题 */
 .section-title { font-size: 30rpx; font-weight: 600; color: #2A2326; margin-bottom: 16rpx; border-left: 8rpx solid #FC7A57; padding-left: 16rpx; }
 .section-title { font-size: 30rpx; font-weight: 600; color: #2A2326; margin-bottom: 16rpx; border-left: 8rpx solid #FC7A57; padding-left: 16rpx; }
 
 

+ 450 - 0
train-frontend/pages/work/detail.vue

@@ -0,0 +1,450 @@
+<template>
+  <view class="detail-page">
+    <!-- 头部客户信息 -->
+    <view class="head-card">
+      <view class="head-top">
+        <text class="order-no">{{ order.orderNo || '' }}</text>
+        <text class="head-status" :style="{ background: statusBg(order.status) }">{{ statusText(order.status) }}</text>
+      </view>
+      <text class="family-name">{{ order.familyName || '客户家' }}</text>
+      <text class="addr">{{ order.address || '地址待确认' }}</text>
+      <view class="time-row" v-if="order.startAt">
+        <text class="time-label">服务时间</text>
+        <text class="time-value">{{ order.startAt }}{{ order.endAt ? ' ~ ' + order.endAt : '' }}</text>
+      </view>
+      <view class="time-row" v-if="order.remark">
+        <text class="time-label">备注</text>
+        <text class="time-value">{{ order.remark }}</text>
+      </view>
+    </view>
+
+    <!-- 收入卡(服务人员最关心) -->
+    <view class="money-card">
+      <view class="money-col">
+        <text class="money-label">本单到手</text>
+        <text class="money-value">¥{{ fenToYuan(order.staffIncome) }}</text>
+      </view>
+      <view class="money-col">
+        <text class="money-label">本单金额</text>
+        <text class="money-value">¥{{ fenToYuan(order.amount) }}</text>
+      </view>
+    </view>
+
+    <!-- 已到岗凭证 -->
+    <view class="sec-card" v-if="order.status !== 'pending' && order.status !== 'accepted'">
+      <view class="sec-head">
+        <text class="sec-title">到岗凭证</text>
+        <text v-if="order.arriveAt" class="sec-ok">✓ {{ order.arriveAt }}</text>
+      </view>
+      <image v-if="order.arrivePhoto" :src="order.arrivePhoto" class="arrive-photo" mode="aspectFit" />
+      <text v-else-if="order.status === 'arrived' || order.status === 'doing' || order.status === 'done' || order.status === 'confirmed'" class="sec-empty">尚未上传门牌照</text>
+    </view>
+
+    <!-- 动作区:按状态只显示一步 -->
+    <view class="action-card" v-if="order.status === 'pending'">
+      <button class="main-btn" @click="doAccept">接这单</button>
+      <text class="hint">接单后请准时上门,到岗时打卡</text>
+    </view>
+
+    <view class="action-card" v-if="order.status === 'accepted'">
+      <button class="main-btn" @click="doArrive">到岗打卡</button>
+      <text class="hint">到客户家后,拍照门牌并点击打卡(自动记录时间和位置)</text>
+    </view>
+
+    <view class="action-card" v-if="order.status === 'arrived' || order.status === 'doing'">
+      <view class="sec-head">
+        <text class="sec-title">本次服务内容</text>
+      </view>
+      <view v-if="order.items.length === 0" class="empty-box">
+        <text class="sec-empty">本次服务无固定项目,完成拍照即可</text>
+      </view>
+      <view v-for="(item, idx) in order.items" :key="idx" class="item-row">
+        <text class="item-name">{{ item.name }}</text>
+        <view class="item-done">
+          <text class="item-state" :style="{ color: item.done == 1 ? '#0E8A4F' : '#7A97B5' }">{{ item.done == 1 ? '✓ 已做' : '未做' }}</text>
+        </view>
+      </view>
+      <view class="photo-grid">
+        <view v-for="(p, pi) in order.finishPhotos" :key="pi" class="photo-cell">
+          <image :src="p" class="photo-img" mode="aspectFill" />
+        </view>
+        <view class="photo-cell add-cell" @click="choosePhoto">
+          <text class="add-text">+ 拍照</text>
+        </view>
+      </view>
+      <button class="main-btn" @click="doFinish" :loading="finishing">完成服务</button>
+      <text class="hint">完成后生成客户确认码,请客户核对</text>
+    </view>
+
+    <view class="action-card" v-if="order.status === 'done'">
+      <view class="confirm-code-box">
+        <text class="code-label">客户确认码</text>
+        <text class="code-value">{{ order.clientConfirmCode }}</text>
+        <text class="code-tip">请告知客户这 6 位数字,客户确认后即完成结算</text>
+      </view>
+      <view class="code-input-row">
+        <input class="code-input" v-model="confirmCode" type="number" maxlength="6" placeholder="输入客户确认码" />
+        <button class="confirm-btn" @click="doConfirm" :loading="confirming">确认</button>
+      </view>
+      <text class="hint">若客户不便操作,可请机构对接人代确认</text>
+    </view>
+
+    <view class="action-card" v-if="order.status === 'confirmed'">
+      <view class="done-box">
+        <text class="done-icon">✓</text>
+        <text class="done-title">本单已完成</text>
+        <text class="done-sub">¥{{ fenToYuan(order.staffIncome) }} 已计入收入</text>
+      </view>
+    </view>
+
+    <view class="back-tip">
+      <text class="back-text">有疑问请联系机构对接人</text>
+    </view>
+  </view>
+</template>
+
+<script>
+import {
+  getServiceOrderDetail,
+  acceptServiceOrder,
+  arriveServiceOrder,
+  finishServiceOrder,
+  confirmServiceOrder,
+  uploadFile
+} from '@/utils/api.js'
+
+export default {
+  data() {
+    return {
+      orderId: null,
+      order: {
+        status: 'pending',
+        items: [],
+        finishPhotos: []
+      },
+      confirmCode: '',
+      finishing: false,
+      confirming: false,
+      locating: false
+    }
+  },
+  onLoad(options) {
+    this.orderId = options.orderId || null
+    this.loadDetail()
+  },
+  onShow() {
+    this.loadDetail()
+  },
+  methods: {
+    loadDetail() {
+      if (!this.orderId) return
+      getServiceOrderDetail(this.orderId).then(res => {
+        if (!res || !res.data) return
+        this.order = res.data
+      }).catch(() => {})
+    },
+    doAccept() {
+      var self = this
+      uni.showModal({
+        title: '确认接单',
+        content: '接下后请准时上门。',
+        success: function (r) {
+          if (!r.confirm) return
+          acceptServiceOrder(self.orderId).then(function (res) {
+            if (res && res.code === 200) {
+              uni.showToast({ title: '接单成功', icon: 'success' })
+              self.loadDetail()
+            } else {
+              uni.showToast({ title: (res && res.message) || '接单失败', icon: 'none' })
+            }
+          }).catch(function () {
+            uni.showToast({ title: '接单失败', icon: 'none' })
+          })
+        }
+      })
+    },
+    doArrive() {
+      var self = this
+      if (this.locating) return
+      this.locating = true
+      uni.showLoading({ title: '定位中...' })
+      uni.getLocation({
+        type: 'gcj02',
+        success: function (loc) {
+          uni.hideLoading()
+          self.locating = false
+          var lat = loc.latitude
+          var lng = loc.longitude
+          self.pickPhoto(function (photoUrl) {
+            if (!photoUrl) {
+              uni.showToast({ title: '请先拍门牌照', icon: 'none' })
+              return
+            }
+            arriveServiceOrder({
+              orderId: self.orderId,
+              lat: lat,
+              lng: lng,
+              photo: photoUrl
+            }).then(function (res) {
+              if (res && res.code === 200) {
+                uni.showToast({ title: '已到岗', icon: 'success' })
+                self.loadDetail()
+              } else {
+                uni.showToast({ title: (res && res.message) || '打卡失败', icon: 'none' })
+              }
+            }).catch(function () {
+              uni.showToast({ title: '打卡失败', icon: 'none' })
+            })
+          })
+        },
+        fail: function () {
+          uni.hideLoading()
+          self.locating = false
+          uni.showModal({
+            title: '定位不可用',
+            content: '无法获取位置,是否跳过定位直接拍照打卡?',
+            success: function (r) {
+              if (!r.confirm) return
+              self.pickPhoto(function (photoUrl) {
+                if (!photoUrl) {
+                  uni.showToast({ title: '请先拍门牌照', icon: 'none' })
+                  return
+                }
+                arriveServiceOrder({
+                  orderId: self.orderId,
+                  photo: photoUrl
+                }).then(function (res) {
+                  if (res && res.code === 200) {
+                    uni.showToast({ title: '已到岗', icon: 'success' })
+                    self.loadDetail()
+                  } else {
+                    uni.showToast({ title: (res && res.message) || '打卡失败', icon: 'none' })
+                  }
+                }).catch(function () {
+                  uni.showToast({ title: '打卡失败', icon: 'none' })
+                })
+              })
+            }
+          })
+        }
+      })
+    },
+    choosePhoto() {
+      var self = this
+      this.pickPhoto(function (photoUrl) {
+        if (!photoUrl) return
+        var cur = self.order.finishPhotos || []
+        cur = cur.concat([photoUrl])
+        self.order.finishPhotos = cur
+      })
+    },
+    pickPhoto(cb) {
+      var self = this
+      uni.chooseImage({
+        count: 1,
+        success: function (res) {
+          var filePath = res.tempFilePaths[0]
+          uni.showLoading({ title: '上传中...' })
+          uploadFile(filePath).then(function (resp) {
+            uni.hideLoading()
+            var url = resp && resp.data && resp.data.url
+            if (url) {
+              cb(url)
+            } else {
+              uni.showToast({ title: '上传失败', icon: 'none' })
+            }
+          }).catch(function () {
+            uni.hideLoading()
+            uni.showToast({ title: '上传失败', icon: 'none' })
+          })
+        }
+      })
+    },
+    doFinish() {
+      var self = this
+      if (this.finishing) return
+      this.finishing = true
+      var items = JSON.stringify(this.order.items || [])
+      var photos = (this.order.finishPhotos || []).join(',')
+      finishServiceOrder({
+        orderId: this.orderId,
+        items: items,
+        photos: photos
+      }).then(function (res) {
+        self.finishing = false
+        if (res && res.code === 200) {
+          uni.showModal({
+            title: '服务完成',
+            content: '客户确认码:' + (res.data && res.data.clientConfirmCode ? res.data.clientConfirmCode : ''),
+            showCancel: false,
+            success: function () {
+              self.loadDetail()
+            }
+          })
+        } else {
+          uni.showToast({ title: (res && res.message) || '提交失败', icon: 'none' })
+        }
+      }).catch(function () {
+        self.finishing = false
+        uni.showToast({ title: '提交失败', icon: 'none' })
+      })
+    },
+    doConfirm() {
+      var self = this
+      if (this.confirming) return
+      if (!this.confirmCode) {
+        uni.showToast({ title: '请输入确认码', icon: 'none' })
+        return
+      }
+      this.confirming = true
+      confirmServiceOrder({
+        orderId: this.orderId,
+        code: this.confirmCode
+      }).then(function (res) {
+        self.confirming = false
+        if (res && res.code === 200) {
+          uni.showToast({ title: '已完成', icon: 'success' })
+          self.loadDetail()
+        } else {
+          uni.showToast({ title: (res && res.message) || '确认失败', icon: 'none' })
+        }
+      }).catch(function () {
+        self.confirming = false
+        uni.showToast({ title: '确认失败', icon: 'none' })
+      })
+    },
+    statusText(status) {
+      if (status === 'accepted') return '已接单'
+      if (status === 'arrived') return '已到岗'
+      if (status === 'doing') return '服务中'
+      if (status === 'done') return '待客户确认'
+      if (status === 'confirmed') return '已完成'
+      if (status === 'pending') return '待接单'
+      return '进行中'
+    },
+    statusBg(status) {
+      if (status === 'confirmed') return '#0E8A4F'
+      if (status === 'done') return '#B9770E'
+      if (status === 'pending') return '#2E6FA8'
+      return '#7A97B5'
+    },
+    fenToYuan(fen) {
+      var n = fen || 0
+      return (n / 100).toFixed(2)
+    }
+  }
+}
+</script>
+
+<style scoped>
+.detail-page {
+  min-height: 100vh;
+  background: #F4F8FC;
+  padding: 20rpx 24rpx 40rpx;
+}
+.head-card {
+  background: #fff;
+  border-radius: 20rpx;
+  padding: 28rpx 26rpx;
+  margin-bottom: 20rpx;
+  border: 1px solid #E3EEF7;
+}
+.head-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12rpx; }
+.order-no { font-size: 22rpx; color: #9DB3C9; }
+.head-status { font-size: 20rpx; color: #fff; padding: 3rpx 14rpx; border-radius: 20rpx; }
+.family-name { display: block; font-size: 36rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 6rpx; }
+.addr { display: block; font-size: 25rpx; color: #5B7A99; margin-bottom: 14rpx; }
+.time-row { display: flex; margin-top: 8rpx; }
+.time-label { width: 130rpx; font-size: 24rpx; color: #7A97B5; }
+.time-value { flex: 1; font-size: 24rpx; color: #1E3A5F; }
+.money-card {
+  background: #fff;
+  border-radius: 20rpx;
+  padding: 24rpx 26rpx;
+  margin-bottom: 20rpx;
+  display: flex;
+  border: 1px solid #E3EEF7;
+}
+.money-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
+.money-label { font-size: 23rpx; color: #7A97B5; }
+.money-value { font-size: 40rpx; font-weight: 700; color: #C0392B; margin-top: 4rpx; }
+.sec-card, .action-card {
+  background: #fff;
+  border-radius: 20rpx;
+  padding: 24rpx 26rpx;
+  margin-bottom: 20rpx;
+  border: 1px solid #E3EEF7;
+}
+.sec-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14rpx; }
+.sec-title { font-size: 28rpx; font-weight: 700; color: #12395F; }
+.sec-ok { font-size: 24rpx; color: #0E8A4F; }
+.sec-empty { font-size: 24rpx; color: #9DB3C9; }
+.arrive-photo { width: 100%; height: 300rpx; border-radius: 12rpx; }
+.empty-box { padding: 20rpx 0; }
+.item-row {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 16rpx 0;
+  border-bottom: 1px solid #F0F5FA;
+}
+.item-name { font-size: 27rpx; color: #1E3A5F; }
+.item-state { font-size: 26rpx; }
+.photo-grid { display: flex; flex-wrap: wrap; margin: 18rpx 0; }
+.photo-cell { width: 190rpx; height: 190rpx; margin: 8rpx; border-radius: 12rpx; overflow: hidden; }
+.photo-img { width: 100%; height: 100%; }
+.add-cell {
+  background: #F0F6FC;
+  border: 1px dashed #BFDCF1;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+.add-text { color: #2E6FA8; font-size: 30rpx; }
+.main-btn {
+  margin-top: 16rpx;
+  background: #2E6FA8;
+  color: #fff;
+  font-size: 30rpx;
+  border-radius: 44rpx;
+  line-height: 2.4;
+}
+.hint { display: block; font-size: 22rpx; color: #9DB3C9; text-align: center; margin-top: 12rpx; }
+.confirm-code-box {
+  background: #F0F6FC;
+  border-radius: 14rpx;
+  padding: 24rpx;
+  text-align: center;
+  margin-bottom: 20rpx;
+}
+.code-label { display: block; font-size: 24rpx; color: #7A97B5; }
+.code-value { display: block; font-size: 64rpx; font-weight: 700; letter-spacing: 12rpx; color: #12395F; margin: 8rpx 0; }
+.code-tip { display: block; font-size: 22rpx; color: #9DB3C9; }
+.code-input-row { display: flex; align-items: center; }
+.code-input {
+  flex: 1;
+  height: 84rpx;
+  background: #F7FAFD;
+  border: 1px solid #E3EEF7;
+  border-radius: 12rpx;
+  padding: 0 20rpx;
+  font-size: 32rpx;
+  text-align: center;
+}
+.confirm-btn {
+  margin-left: 16rpx;
+  background: #0E8A4F;
+  color: #fff;
+  font-size: 28rpx;
+  border-radius: 12rpx;
+  height: 84rpx;
+  line-height: 84rpx;
+  padding: 0 40rpx;
+}
+.done-box { text-align: center; padding: 20rpx 0; }
+.done-icon { display: block; font-size: 72rpx; color: #0E8A4F; font-weight: 700; }
+.done-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-top: 8rpx; }
+.done-sub { display: block; font-size: 25rpx; color: #5B7A99; margin-top: 8rpx; }
+.back-tip { text-align: center; padding: 16rpx 0; }
+.back-text { font-size: 23rpx; color: #A8BCD0; }
+</style>

+ 133 - 0
train-frontend/pages/work/earnings.vue

@@ -0,0 +1,133 @@
+<template>
+  <view class="earn-page">
+    <!-- 三大数字 -->
+    <view class="sum-card">
+      <view class="sum-main">
+        <text class="sum-label">累计到手</text>
+        <text class="sum-value">¥{{ fenToYuan(totalIncome) }}</text>
+      </view>
+      <view class="sum-sub-row">
+        <view class="sum-sub-col">
+          <text class="sum-sub-value">¥{{ fenToYuan(monthIncome) }}</text>
+          <text class="sum-sub-label">本月到手</text>
+        </view>
+        <view class="sum-sub-col">
+          <text class="sum-sub-value">¥{{ fenToYuan(pendingIncome) }}</text>
+          <text class="sum-sub-label">待确认</text>
+        </view>
+        <view class="sum-sub-col">
+          <text class="sum-sub-value">{{ doneCount }}</text>
+          <text class="sum-sub-label">已完成单</text>
+        </view>
+      </view>
+    </view>
+
+    <!-- 最近记录 -->
+    <view class="sec-title-row">
+      <text class="sec-title">最近收入记录</text>
+    </view>
+    <view v-if="recent.length === 0" class="empty-box">
+      <text class="empty-text">还没有收入记录,完成服务并确认后自动记账</text>
+    </view>
+    <view v-for="item in recent" :key="item.id" class="earn-item">
+      <view class="earn-left">
+        <text class="earn-family">{{ item.familyName || '客户家' }}</text>
+        <text class="earn-date">{{ item.finishAt || item.orderDate }}</text>
+      </view>
+      <view class="earn-right">
+        <text class="earn-status" :style="{ color: item.status === 'confirmed' ? '#0E8A4F' : '#B9770E' }">
+          {{ item.status === 'confirmed' ? '已到账' : '待确认' }}
+        </text>
+        <text class="earn-income">+¥{{ fenToYuan(item.staffIncome) }}</text>
+      </view>
+    </view>
+
+    <view class="tip-box">
+      <text class="tip-text">收入按服务人员到手金额记账(含平台费扣除后),明细可与机构对账</text>
+    </view>
+  </view>
+</template>
+
+<script>
+import { getServiceEarnings } from '@/utils/api.js'
+
+export default {
+  data() {
+    return {
+      totalIncome: 0,
+      monthIncome: 0,
+      pendingIncome: 0,
+      doneCount: 0,
+      recent: []
+    }
+  },
+  onShow() {
+    this.load()
+  },
+  methods: {
+    load() {
+      getServiceEarnings().then(res => {
+        if (!res || !res.data) return
+        this.totalIncome = res.data.totalIncome || 0
+        this.monthIncome = res.data.monthIncome || 0
+        this.pendingIncome = res.data.pendingIncome || 0
+        this.doneCount = res.data.doneCount || 0
+        this.recent = res.data.recent || []
+      }).catch(() => {})
+    },
+    fenToYuan(fen) {
+      var n = fen || 0
+      return (n / 100).toFixed(2)
+    }
+  }
+}
+</script>
+
+<style scoped>
+.earn-page {
+  min-height: 100vh;
+  background: #F4F8FC;
+  padding: 20rpx 24rpx 40rpx;
+}
+.sum-card {
+  background: linear-gradient(135deg, #12395F, #2E6FA8);
+  border-radius: 20rpx;
+  padding: 32rpx 28rpx;
+  margin-bottom: 26rpx;
+}
+.sum-main { text-align: center; padding: 10rpx 0 24rpx; }
+.sum-label { display: block; font-size: 24rpx; color: rgba(255,255,255,0.8); }
+.sum-value { display: block; font-size: 60rpx; font-weight: 700; color: #fff; line-height: 1.4; }
+.sum-sub-row { display: flex; border-top: 1px solid rgba(255,255,255,0.2); padding-top: 22rpx; }
+.sum-sub-col { flex: 1; text-align: center; display: flex; flex-direction: column; }
+.sum-sub-value { font-size: 32rpx; font-weight: 700; color: #fff; }
+.sum-sub-label { font-size: 22rpx; color: rgba(255,255,255,0.72); margin-top: 4rpx; }
+.sec-title-row { margin: 6rpx 4rpx 14rpx; }
+.sec-title { font-size: 30rpx; font-weight: 700; color: #12395F; }
+.empty-box {
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 36rpx 24rpx;
+  text-align: center;
+  border: 1px solid #E3EEF7;
+}
+.empty-text { font-size: 26rpx; color: #9DB3C9; }
+.earn-item {
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 22rpx 24rpx;
+  margin-bottom: 14rpx;
+  border: 1px solid #E3EEF7;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
+.earn-left { display: flex; flex-direction: column; }
+.earn-family { font-size: 30rpx; font-weight: 600; color: #1E3A5F; }
+.earn-date { font-size: 23rpx; color: #9DB3C9; margin-top: 4rpx; }
+.earn-right { display: flex; flex-direction: column; align-items: flex-end; }
+.earn-status { font-size: 23rpx; }
+.earn-income { font-size: 34rpx; font-weight: 700; color: #C0392B; margin-top: 4rpx; }
+.tip-box { margin-top: 24rpx; padding: 0 8rpx; }
+.tip-text { font-size: 22rpx; color: #9DB3C9; line-height: 1.8; }
+</style>

+ 296 - 0
train-frontend/pages/work/index.vue

@@ -0,0 +1,296 @@
+<template>
+  <view class="work-page">
+    <!-- 收入速览:钱在最上方,这是家政最关心的 -->
+    <view class="income-card" @click="goEarnings">
+      <view class="income-left">
+        <text class="income-label">本月到手</text>
+        <text class="income-value">¥{{ monthIncomeText }}</text>
+      </view>
+      <view class="income-right">
+        <text class="income-sub">累计 ¥{{ totalIncomeText }}</text>
+        <text class="income-sub">待确认 ¥{{ pendingIncomeText }}</text>
+        <text class="income-arrow">›</text>
+      </view>
+    </view>
+
+    <!-- 今日上门 -->
+    <view class="group">
+      <view class="group-head">
+        <text class="group-title">今日上门</text>
+        <text class="group-count">{{ todayList.length }} 单</text>
+      </view>
+      <view v-if="todayList.length === 0" class="empty-box">
+        <text class="empty-text">今天没有安排,接单后就会出现在这里</text>
+      </view>
+      <view v-for="item in todayList" :key="item.id" class="order-card" @click="goDetail(item)">
+        <view class="order-top">
+          <text class="order-time">{{ item.startAt || item.orderDate }}</text>
+          <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
+        </view>
+        <text class="order-family">{{ item.familyName || '客户家' }}</text>
+        <text class="order-address">{{ item.address || '地址待确认' }}</text>
+        <view class="order-bottom">
+          <text class="order-type">{{ typeText(item.serviceType) }}</text>
+          <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
+        </view>
+      </view>
+    </view>
+
+    <!-- 待接单 -->
+    <view class="group">
+      <view class="group-head">
+        <text class="group-title">待接单</text>
+        <text class="group-count">{{ pendingList.length }} 单</text>
+      </view>
+      <view v-if="pendingList.length === 0" class="empty-box">
+        <text class="empty-text">暂时没有新单,有新单会通知您</text>
+      </view>
+      <view v-for="item in pendingList" :key="item.id" class="order-card pending-card">
+        <view class="order-top">
+          <text class="order-time">{{ item.orderDate }} {{ item.startAt || '' }}</text>
+          <text class="order-status" :style="{ background: statusBg(item.status) }">待接单</text>
+        </view>
+        <text class="order-family">{{ item.familyName || '客户家' }}</text>
+        <text class="order-address">{{ item.address || '地址待确认' }}</text>
+        <view class="order-bottom">
+          <text class="order-type">{{ typeText(item.serviceType) }}</text>
+          <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
+        </view>
+        <button class="accept-btn" @click.stop="doAccept(item)">接这单</button>
+      </view>
+    </view>
+
+    <!-- 进行中 -->
+    <view class="group">
+      <view class="group-head">
+        <text class="group-title">进行中</text>
+        <text class="group-count">{{ doingList.length }} 单</text>
+      </view>
+      <view v-if="doingList.length === 0" class="empty-box">
+        <text class="empty-text">暂无进行中的单</text>
+      </view>
+      <view v-for="item in doingList" :key="item.id" class="order-card" @click="goDetail(item)">
+        <view class="order-top">
+          <text class="order-time">{{ item.orderDate }} {{ item.startAt || '' }}</text>
+          <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
+        </view>
+        <text class="order-family">{{ item.familyName || '客户家' }}</text>
+        <text class="order-address">{{ item.address || '地址待确认' }}</text>
+        <view class="order-bottom">
+          <text class="order-type">{{ typeText(item.serviceType) }}</text>
+          <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
+        </view>
+      </view>
+    </view>
+
+    <!-- 已完成 -->
+    <view class="group">
+      <view class="group-head">
+        <text class="group-title">已完成</text>
+        <text class="group-count">{{ doneList.length }} 单</text>
+      </view>
+      <view v-if="doneList.length === 0" class="empty-box">
+        <text class="empty-text">还没有完成的单</text>
+      </view>
+      <view v-for="item in doneList" :key="item.id" class="order-card" @click="goDetail(item)">
+        <view class="order-top">
+          <text class="order-time">{{ item.orderDate }}</text>
+          <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
+        </view>
+        <text class="order-family">{{ item.familyName || '客户家' }}</text>
+        <view class="order-bottom">
+          <text class="order-type">{{ item.arriveAt ? '到岗 ' + item.arriveAt : '' }}</text>
+          <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
+        </view>
+      </view>
+    </view>
+
+    <view class="footer-tip">
+      <text class="footer-text">有疑问请联系机构对接人</text>
+    </view>
+  </view>
+</template>
+
+<script>
+import { getMyServiceOrders, getServiceEarnings, acceptServiceOrder } from '@/utils/api.js'
+
+export default {
+  data() {
+    return {
+      todayList: [],
+      pendingList: [],
+      doingList: [],
+      doneList: [],
+      totalIncome: 0,
+      monthIncome: 0,
+      pendingIncome: 0
+    }
+  },
+  computed: {
+    totalIncomeText() {
+      return this.fenToYuan(this.totalIncome)
+    },
+    monthIncomeText() {
+      return this.fenToYuan(this.monthIncome)
+    },
+    pendingIncomeText() {
+      return this.fenToYuan(this.pendingIncome)
+    }
+  },
+  onShow() {
+    this.loadOrders()
+    this.loadEarnings()
+  },
+  methods: {
+    loadOrders() {
+      getMyServiceOrders().then(res => {
+        if (!res || !res.data) return
+        const groups = res.data
+        this.todayList = this.pickGroup(groups, 'today')
+        this.pendingList = this.pickGroup(groups, 'pending')
+        this.doingList = this.pickGroup(groups, 'doing')
+        this.doneList = this.pickGroup(groups, 'done')
+      }).catch(() => {})
+    },
+    loadEarnings() {
+      getServiceEarnings().then(res => {
+        if (!res || !res.data) return
+        this.totalIncome = res.data.totalIncome || 0
+        this.monthIncome = res.data.monthIncome || 0
+        this.pendingIncome = res.data.pendingIncome || 0
+      }).catch(() => {})
+    },
+    pickGroup(groups, key) {
+      for (var i = 0; i < groups.length; i++) {
+        if (groups[i].key === key) {
+          return groups[i].list || []
+        }
+      }
+      return []
+    },
+    doAccept(item) {
+      var self = this
+      uni.showModal({
+        title: '确认接单',
+        content: '接下这单后,请在服务时间准时上门。',
+        success: function (res) {
+          if (!res.confirm) return
+          acceptServiceOrder(item.id).then(function (r) {
+            if (r && r.code === 200) {
+              uni.showToast({ title: '接单成功', icon: 'success' })
+              self.loadOrders()
+              self.loadEarnings()
+            } else {
+              uni.showToast({ title: (r && r.message) || '接单失败', icon: 'none' })
+            }
+          }).catch(function () {
+            uni.showToast({ title: '接单失败', icon: 'none' })
+          })
+        }
+      })
+    },
+    goDetail(item) {
+      uni.navigateTo({ url: '/pages/work/detail?orderId=' + item.id })
+    },
+    goEarnings() {
+      uni.navigateTo({ url: '/pages/work/earnings' })
+    },
+    statusText(status) {
+      if (status === 'accepted') return '已接单'
+      if (status === 'arrived') return '已到岗'
+      if (status === 'doing') return '服务中'
+      if (status === 'done') return '待客户确认'
+      if (status === 'confirmed') return '已完成'
+      if (status === 'pending') return '待接单'
+      return '进行中'
+    },
+    statusBg(status) {
+      if (status === 'confirmed') return '#0E8A4F'
+      if (status === 'done') return '#B9770E'
+      if (status === 'pending') return '#2E6FA8'
+      return '#7A97B5'
+    },
+    typeText(type) {
+      if (type === 'cleaning') return '保洁'
+      if (type === 'care') return '照护'
+      if (type === 'escort') return '陪诊'
+      if (type === 'meal') return '助餐'
+      return '上门服务'
+    },
+    fenToYuan(fen) {
+      var n = fen || 0
+      return (n / 100).toFixed(2)
+    },
+    incomeText(fen) {
+      return this.fenToYuan(fen)
+    }
+  }
+}
+</script>
+
+<style scoped>
+.work-page {
+  min-height: 100vh;
+  background: #F4F8FC;
+  padding: 20rpx 24rpx 40rpx;
+}
+.income-card {
+  background: linear-gradient(135deg, #12395F, #2E6FA8);
+  border-radius: 20rpx;
+  padding: 32rpx 28rpx;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  margin-bottom: 24rpx;
+}
+.income-left { display: flex; flex-direction: column; }
+.income-label { font-size: 24rpx; color: rgba(255,255,255,0.8); }
+.income-value { font-size: 52rpx; font-weight: 700; color: #fff; line-height: 1.3; }
+.income-right { display: flex; flex-direction: column; align-items: flex-end; position: relative; }
+.income-sub { font-size: 22rpx; color: rgba(255,255,255,0.82); line-height: 1.7; }
+.income-arrow { position: absolute; right: -4rpx; top: 50%; transform: translateY(-50%); font-size: 34rpx; color: rgba(255,255,255,0.6); }
+.group { margin-bottom: 28rpx; }
+.group-head {
+  display: flex;
+  justify-content: space-between;
+  align-items: baseline;
+  margin-bottom: 14rpx;
+  padding: 0 4rpx;
+}
+.group-title { font-size: 30rpx; font-weight: 700; color: #12395F; }
+.group-count { font-size: 24rpx; color: #7A97B5; }
+.empty-box {
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 34rpx 24rpx;
+  text-align: center;
+  border: 1px solid #E3EEF7;
+}
+.empty-text { font-size: 26rpx; color: #9DB3C9; }
+.order-card {
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 24rpx 24rpx 20rpx;
+  margin-bottom: 16rpx;
+  border: 1px solid #E3EEF7;
+}
+.pending-card { border-color: #BFDCF1; }
+.order-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12rpx; }
+.order-time { font-size: 26rpx; color: #2E6FA8; font-weight: 600; }
+.order-status { font-size: 20rpx; color: #fff; padding: 3rpx 14rpx; border-radius: 20rpx; }
+.order-family { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 6rpx; }
+.order-address { display: block; font-size: 25rpx; color: #5B7A99; margin-bottom: 14rpx; }
+.order-bottom { display: flex; justify-content: space-between; align-items: center; }
+.order-type { font-size: 24rpx; color: #7A97B5; }
+.order-money { font-size: 34rpx; font-weight: 700; color: #C0392B; }
+.accept-btn {
+  margin-top: 18rpx;
+  background: #2E6FA8;
+  color: #fff;
+  font-size: 30rpx;
+  border-radius: 44rpx;
+  line-height: 2.4;
+}
+.footer-tip { text-align: center; padding: 20rpx 0; }
+.footer-text { font-size: 23rpx; color: #A8BCD0; }
+</style>

+ 29 - 1
train-frontend/utils/api.js

@@ -371,4 +371,32 @@ export const createSsoTicket = (target) =>
 
 
 /** 用一次性票据换取登录态。返回登录信息(结构同 wechatLogin 的 data) */
 /** 用一次性票据换取登录态。返回登录信息(结构同 wechatLogin 的 data) */
 export const ssoLogin = (ticket) =>
 export const ssoLogin = (ticket) =>
-  request('/api/auth/sso-login', 'POST', { ticket })
+  request('/api/auth/sso-login', 'POST', { ticket })
+// ===================== 家政工作台(服务人员工作助手 · 家政版)=====================
+/** 我的工单(今日/待接/进行中/已完成 分组) */
+export const getMyServiceOrders = () =>
+  request('/api/order/mine', 'POST', {})
+
+/** 工单详情 */
+export const getServiceOrderDetail = (orderId) =>
+  request('/api/order/detail', 'POST', { orderId: orderId })
+
+/** 接单 */
+export const acceptServiceOrder = (orderId) =>
+  request('/api/order/accept', 'POST', { orderId: orderId })
+
+/** 到岗打卡 { orderId, lat, lng, photo } */
+export const arriveServiceOrder = (data) =>
+  request('/api/order/arrive', 'POST', data)
+
+/** 提交服务结果 { orderId, items(JSON字符串), photos(逗号分隔) } → 返回客户确认码 */
+export const finishServiceOrder = (data) =>
+  request('/api/order/finish', 'POST', data)
+
+/** 客户确认 { orderId, code } */
+export const confirmServiceOrder = (data) =>
+  request('/api/order/confirm', 'POST', data)
+
+/** 收入台账 */
+export const getServiceEarnings = () =>
+  request('/api/order/earnings', 'POST', {})