You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
272 lines
9.5 KiB
272 lines
9.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\service_logs\ServiceLogs;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 服务API服务层
|
|
* Class ServiceService
|
|
* @package app\service\api\apiService
|
|
*/
|
|
class ServiceService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->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()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取学员服务记录列表
|
|
* @param int $studentId 学员ID
|
|
* @return array
|
|
*/
|
|
public function getStudentServiceList(int $studentId)
|
|
{
|
|
try {
|
|
// 查询SQL:关联服务基础信息、课程信息、员工信息
|
|
$list = $this->model->alias('sl')
|
|
->join('school_service s', 'sl.service_id = s.id')
|
|
->leftJoin('school_course c', 'sl.course_id = c.id')
|
|
->leftJoin('school_personnel p', 'sl.staff_id = p.id')
|
|
->where('sl.resource_id', $studentId)
|
|
->where('s.deleted_at', 0)
|
|
->field([
|
|
// 服务基础信息
|
|
's.id as service_id',
|
|
's.service_name',
|
|
's.preview_image_url',
|
|
's.description',
|
|
's.service_type',
|
|
's.status as service_status',
|
|
// 服务记录信息
|
|
'sl.id as log_id',
|
|
'sl.status as log_status',
|
|
'sl.score',
|
|
'sl.feedback',
|
|
'sl.service_remark',
|
|
'sl.created_at as service_time',
|
|
'sl.feedback_time',
|
|
'sl.updated_at',
|
|
// 课程信息
|
|
'c.course_name',
|
|
// 员工信息
|
|
'p.name as staff_name'
|
|
])
|
|
->order('sl.created_at desc, sl.status asc')
|
|
->select()
|
|
->toArray();
|
|
|
|
// 处理数据格式,按服务分组
|
|
$serviceMap = [];
|
|
foreach ($list as $item) {
|
|
$serviceId = $item['service_id'];
|
|
|
|
if (!isset($serviceMap[$serviceId])) {
|
|
// 初始化服务信息
|
|
$serviceMap[$serviceId] = [
|
|
'id' => $serviceId,
|
|
'service_name' => $item['service_name'],
|
|
'preview_image_url' => $item['preview_image_url'],
|
|
'description' => $item['description'],
|
|
'service_type' => $item['service_type'],
|
|
'status' => $this->mapServiceStatus($item['service_status']),
|
|
'logs' => [],
|
|
'total_count' => 0,
|
|
'completed_count' => 0
|
|
];
|
|
}
|
|
|
|
// 添加服务记录
|
|
if ($item['log_id']) {
|
|
$log = [
|
|
'id' => $item['log_id'],
|
|
'status' => $item['log_status'],
|
|
'service_content' => $item['service_remark'],
|
|
'service_staff' => $item['staff_name'],
|
|
'service_time' => $item['service_time'] ?: '',
|
|
'duration' => $item['updated_at'] ?: '',
|
|
'customer_feedback' => $item['feedback'],
|
|
'service_rating' => $item['score'] && $item['score'] <= 5 ? $item['score'] : null,
|
|
'remark' => $item['service_remark'],
|
|
'course_name' => $item['course_name'],
|
|
'updated_at' => $item['updated_at'] ?: ''
|
|
];
|
|
|
|
$serviceMap[$serviceId]['logs'][] = $log;
|
|
$serviceMap[$serviceId]['total_count']++;
|
|
|
|
if ($item['log_status'] == 1) {
|
|
$serviceMap[$serviceId]['completed_count']++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ['code' => 1, 'data' => array_values($serviceMap), 'msg' => '获取成功'];
|
|
|
|
} catch (\Exception $e) {
|
|
return ['code' => 0, 'data' => [], 'msg' => '获取失败:' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 映射服务状态
|
|
* @param int $status
|
|
* @return string
|
|
*/
|
|
private function mapServiceStatus($status)
|
|
{
|
|
switch ($status) {
|
|
case 1:
|
|
return 'active';
|
|
case 0:
|
|
return 'expired';
|
|
case 2:
|
|
return 'suspended';
|
|
default:
|
|
return 'expired';
|
|
}
|
|
}
|
|
}
|
|
|