model = new ServiceLogs(); } /** * 获取员工服务记录列表 * @param array $where * @return array */ public function getMyServiceLogs(array $where = []) { // 获取当前登录的员工ID $staffId = $this->member_id; $field = 'id,service_id,staff_id,status,service_remark,feedback,score,created_at,updated_at'; $order = 'created_at desc'; $search_model = $this->model ->withSearch(["staff_id"], ['staff_id' => $staffId]) ->with(['service', 'staff']) ->field($field) ->order($order); $list = $this->pageQuery($search_model); // 如果没有数据,为演示目的返回一些测试数据 if (empty($list['data']) && isset($where['demo'])) { $list = [ 'data' => [ [ 'id' => 1, 'service_id' => 1, 'staff_id' => $staffId, 'status' => 0, 'service_remark' => '', 'feedback' => '', 'score' => null, 'created_at' => time(), 'updated_at' => time(), 'service_name' => '体能训练指导服务', 'preview_image_url' => '', 'description' => '专业的体能训练指导,帮助学员提升身体素质', 'service_type' => '训练指导' ], [ 'id' => 2, 'service_id' => 2, 'staff_id' => $staffId, 'status' => 1, 'service_remark' => '学员表现**优秀**,完成了所有训练项目\n• 力量训练:90%完成度\n• 耐力训练:85%完成度\n• 柔韧性训练:95%完成度', 'feedback' => '孩子很喜欢这次训练,教练很专业', 'score' => 95, 'created_at' => time() - 86400, 'updated_at' => time() - 3600, 'service_name' => '技能训练服务', 'preview_image_url' => '', 'description' => '专项技能训练,提升运动技巧', 'service_type' => '技能培训' ] ], 'current_page' => 1, 'last_page' => 1, 'per_page' => 10, 'total' => 2 ]; } return $list; } /** * 获取服务记录详情 * @param int $id * @return array */ public function getServiceLogDetail(int $id) { // 获取当前登录的员工ID $staffId = $this->member_id; $field = 'id,service_id,staff_id,status,service_remark,feedback,score,created_at,updated_at'; $info = $this->model ->with(['service', 'staff']) ->field($field) ->where([ ['id', "=", $id], ['staff_id', "=", $staffId] ]) ->findOrEmpty() ->toArray(); return $info; } /** * 更新服务结果 * @param int $id * @param string $serviceRemark * @return array */ public function updateServiceRemark(int $id, string $serviceRemark) { // 获取当前登录的员工ID $staffId = $this->member_id; // 查找对应的服务记录 $serviceLog = $this->model ->where([ ['id', '=', $id], ['staff_id', '=', $staffId] ]) ->find(); if (!$serviceLog) { return ['code' => 0, 'msg' => '服务记录不存在']; } // 检查状态,只有非完成状态才能修改 if ($serviceLog->status == 1) { return ['code' => 0, 'msg' => '服务已完成,无法修改']; } try { // 更新服务结果 $serviceLog->service_remark = $serviceRemark; $serviceLog->updated_at = time(); $serviceLog->save(); return ['code' => 1, 'msg' => '更新成功']; } catch (\Exception $e) { return ['code' => 0, 'msg' => '更新失败:' . $e->getMessage()]; } } }