diff --git a/niucloud/app/model/resource_sharing/ResourceSharing.php b/niucloud/app/model/resource_sharing/ResourceSharing.php index db7f1f9a..92a701ae 100644 --- a/niucloud/app/model/resource_sharing/ResourceSharing.php +++ b/niucloud/app/model/resource_sharing/ResourceSharing.php @@ -42,8 +42,6 @@ class ResourceSharing extends BaseModel - - /** * 搜索器:资源共享共享记录编号 * @param $value diff --git a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php index 15c861f2..d7a1a6a1 100644 --- a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php +++ b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php @@ -64,6 +64,7 @@ class CampusPersonRoleService extends BaseAdminService ->alias("a") ->join(['school_personnel' => 'b'],'a.person_id = b.id','left') ->where($where) + ->where('b.deleted_at', 0) // 只显示未删除的人员 ->with(['campus','personnel','sysRole','departments']) ->field($field)->order($order); diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index ac05971f..c2663674 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -144,11 +144,11 @@ class CustomerResourcesService extends BaseApiService 'resource_id' => $resource_id, 'assignee_type' => 'user', 'assignee_id' => $assignee_id, - 'is_primary' => 1, + 'is_primary' => 0, 'assigned_by' => 0, 'assigned_at' => date("Y-m-d H:i:s"), 'campus_id' => $customer_resources_data['campus'], - 'assigned_source' => 'api' + 'assigned_source' => 'add' ]); } catch (\Exception $e) { // 如果插入失败,记录日志但不影响主流程 @@ -164,7 +164,7 @@ class CustomerResourcesService extends BaseApiService $student_data['user_id'] = $resource_id; // 设置user_id为新添加的客户资源ID $student_data['updated_at'] = $date; $student_data['created_at'] = $date; - + $studentAdd = SchoolStudent::create($student_data); if (!$studentAdd) { Db::rollback(); @@ -720,7 +720,7 @@ class CustomerResourcesService extends BaseApiService // 奖励配置(可以后续移到配置文件中) $rewardConfig = [ 'gift_name' => '转介绍奖励', - 'gift_type' => 'referral_reward', + 'gift_type' => 'referral_reward', 'reward_amount' => 100, // 奖励金额,可配置 ]; @@ -740,7 +740,7 @@ class CustomerResourcesService extends BaseApiService ]; Db::table('shcool_resources_gift')->insert($giftData); - + Log::info("转介绍奖励发放成功:推荐人ID $referral_resource_id,新客户ID $new_resource_id"); } catch (\Exception $e) { @@ -754,36 +754,36 @@ class CustomerResourcesService extends BaseApiService if (empty($data['id'])) { return ['code' => false, 'msg' => '缺少必要参数id']; } - + try { // 更新school_student_courses表中的字段 $update_data = []; - + // 更新主教练ID if (isset($data['main_coach_id'])) { $update_data['main_coach_id'] = $data['main_coach_id']; } - + // 更新助教IDs if (isset($data['assistant_ids'])) { $update_data['assistant_ids'] = $data['assistant_ids']; } - + // 更新教务ID if (isset($data['education_id'])) { $update_data['education_id'] = $data['education_id']; } - + // 如果没有需要更新的数据,直接返回成功 if (empty($update_data)) { return ['code' => true, 'msg' => '更新成功']; } - + // 执行更新操作 $res = \think\facade\Db::name('student_courses') ->where('id', $data['id']) ->update($update_data); - + if ($res !== false) { return ['code' => true, 'msg' => '更新成功']; } else { @@ -803,11 +803,11 @@ class CustomerResourcesService extends BaseApiService { try { $resource_id = $where['resource_id'] ?? 0; - + if (empty($resource_id)) { return ['code' => false, 'msg' => '缺少客户资源ID']; } - + // 查询赠品记录,同时关联查询赠送人信息 $gift_records = Db::table('shcool_resources_gift') ->alias('g') @@ -824,7 +824,7 @@ class CustomerResourcesService extends BaseApiService ->order('g.create_time', 'desc') ->select() ->toArray(); - + // 处理数据格式 $formatted_records = []; foreach ($gift_records as $record) { @@ -846,13 +846,13 @@ class CustomerResourcesService extends BaseApiService 'create_time' => date('Y-m-d H:i:s', $record['create_time']) ]; } - + return [ 'code' => true, 'msg' => '获取成功', 'data' => $formatted_records ]; - + } catch (\Exception $e) { Log::error('获取赠品记录失败:' . $e->getMessage()); return [ @@ -876,7 +876,7 @@ class CustomerResourcesService extends BaseApiService 'activity_reward' => '活动奖励', 'other' => '其他' ]; - + return $type_map[$gift_type] ?? $gift_type; } @@ -892,7 +892,7 @@ class CustomerResourcesService extends BaseApiService 1 => '可使用', 2 => '已使用' ]; - + return $status_map[$gift_status] ?? '未知状态'; } @@ -986,7 +986,7 @@ class CustomerResourcesService extends BaseApiService 'msg' => '操作失败', 'data' => [] ]; - + try { // 构建查询条件 $query = Db::table('school_student') @@ -994,17 +994,17 @@ class CustomerResourcesService extends BaseApiService ->leftJoin('school_student_courses sc', 's.id = sc.student_id') ->where('s.deleted_at', 0) ->where('s.status', 1); // 只查询状态正常的学员 - + // 按姓名搜索 if (!empty($where['name'])) { $query->where('s.name', 'like', "%{$where['name']}%"); } - + // 按手机号搜索 if (!empty($where['phone_number'])) { $query->where('s.contact_phone', 'like', "%{$where['phone_number']}%"); } - + // 获取学员基本信息和课程信息 $students = $query ->field([ @@ -1033,22 +1033,22 @@ class CustomerResourcesService extends BaseApiService ->group('s.id') ->order('s.created_at DESC') ->select(); - + if (!$students) { $res['msg'] = '暂无学员数据'; return $res; } - + // 处理数据格式,计算课程进度 $result = []; foreach ($students as $student) { $totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); $usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); $remainingHours = $totalHours - $usedHours; - + // 判断是否为体验课学员 $isTrialStudent = empty($student['student_course_id']); - + // 判断是否需要续费 $needsRenewal = false; if (!$isTrialStudent) { @@ -1064,7 +1064,7 @@ class CustomerResourcesService extends BaseApiService $needsRenewal = true; } } - + $result[] = [ 'id' => $student['student_id'], 'student_id' => $student['student_id'], @@ -1108,16 +1108,16 @@ class CustomerResourcesService extends BaseApiService 'expiryDate' => $student['end_date'] ]; } - + $res['code'] = 1; $res['msg'] = '操作成功'; $res['data'] = $result; - + } catch (\Exception $e) { Log::error('搜索学员失败:' . $e->getMessage()); $res['msg'] = '搜索学员失败:' . $e->getMessage(); } - + return $res; } @@ -1133,16 +1133,16 @@ class CustomerResourcesService extends BaseApiService 'msg' => '操作失败', 'data' => [] ]; - + try { $resourceId = $where['resource_id'] ?? 0; $studentId = $where['student_id'] ?? 0; - + if (!$resourceId && !$studentId) { $res['msg'] = '缺少必要参数'; return $res; } - + // 构建查询条件 - 不限制status状态 $query = Db::table('school_student') ->alias('s') @@ -1150,7 +1150,7 @@ class CustomerResourcesService extends BaseApiService ->leftJoin('school_customer_resources cr', 's.user_id = cr.id') ->where('s.deleted_at', 0) ->where('s.id', $studentId); - + // 获取学员基本信息和课程信息 $student = $query ->field([ @@ -1180,7 +1180,7 @@ class CustomerResourcesService extends BaseApiService 'sc.course_id' ]) ->find(); - + if (!$student) { $res['msg'] = '学员不存在'; return $res; @@ -1190,10 +1190,10 @@ class CustomerResourcesService extends BaseApiService $totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); $usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); $remainingHours = $totalHours - $usedHours; - + // 判断是否为体验课学员 $isTrialStudent = empty($student['student_course_id']); - + // 判断是否需要续费 $needsRenewal = false; if (!$isTrialStudent) { @@ -1209,7 +1209,7 @@ class CustomerResourcesService extends BaseApiService $needsRenewal = true; } } - + $result = [ 'id' => $student['student_id'], 'student_id' => $student['student_id'], @@ -1254,15 +1254,15 @@ class CustomerResourcesService extends BaseApiService 'usedHours' => $usedHours, 'expiryDate' => $student['end_date'] ]; - + $res['code'] = 1; $res['msg'] = '操作成功'; $res['data'] = $result; - + } catch (\Exception $exception) { $res['msg'] = '获取预设学员信息失败:' . $exception->getMessage(); } - + return $res; } } diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 9d8091a2..3faea316 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -643,18 +643,17 @@ class ResourceSharingService extends BaseApiService $consultant_names = $personnel->whereIn('id', $consultant_ids)->column('name', 'id'); } - // 查询销售老师信息(从资源分配表获取assigned_by=0的记录) + // 查询销售老师信息(从资源分配表获取assigned_source为auto_allocation或api的最新记录) $sales_teachers = []; if (!empty($resource_ids)) { $assignment_model = new \app\model\resource_assignment\ResourceAssignment(); - // 查询每个资源assigned_by=0的最新一条记录 + // 查询每个资源assigned_source为auto_allocation或api的最新一条记录 $sales_assignments = []; foreach ($resource_ids as $resource_id) { $latest_assignment = $assignment_model ->where('resource_id', $resource_id) - ->where('assignee_type', 'user') - ->where('assigned_by', 0) + ->whereIn('assigned_source', ['auto_allocation', 'api']) ->order('assigned_at', 'desc') ->field('assignee_id') ->find(); @@ -678,17 +677,18 @@ class ResourceSharingService extends BaseApiService } } - // 查询市场老师信息(从资源分配表获取assigned_source为auto_allocation或api的最新记录) + // 查询市场老师信息(从资源分配表获取assigned_by=0且assignee_type='user'的记录) $market_teachers = []; if (!empty($resource_ids)) { $assignment_model = new \app\model\resource_assignment\ResourceAssignment(); - // 查询每个资源assigned_source为auto_allocation或api的最新一条记录 + // 查询每个资源assigned_by=0且assignee_type='user'的最新一条记录 $market_assignments = []; foreach ($resource_ids as $resource_id) { $latest_assignment = $assignment_model ->where('resource_id', $resource_id) - ->whereIn('assigned_source', ['auto_allocation', 'api']) + ->where('assignee_type', 'user') + ->where('assigned_by', 0) ->order('assigned_at', 'desc') ->field('assignee_id') ->find(); @@ -1266,18 +1266,17 @@ class ResourceSharingService extends BaseApiService $consultant_names = $personnel->whereIn('id', $consultant_ids)->column('name', 'id'); } - // 查询销售老师信息(从资源分配表获取assigned_by=0的记录) + // 查询销售老师信息(从资源分配表获取assigned_source为auto_allocation或api的最新记录) $sales_teachers = []; if (!empty($resource_ids)) { $assignment_model = new \app\model\resource_assignment\ResourceAssignment(); - // 查询每个资源assigned_by=0的最新一条记录 + // 查询每个资源assigned_source为auto_allocation或api的最新一条记录 $sales_assignments = []; foreach ($resource_ids as $resource_id) { $latest_assignment = $assignment_model ->where('resource_id', $resource_id) - ->where('assignee_type', 'user') - ->where('assigned_by', 0) + ->whereIn('assigned_source', ['auto_allocation', 'api']) ->order('assigned_at', 'desc') ->field('assignee_id') ->find(); @@ -1301,17 +1300,18 @@ class ResourceSharingService extends BaseApiService } } - // 查询市场老师信息(从资源分配表获取assigned_source为auto_allocation或api的最新记录) + // 查询市场老师信息(从资源分配表获取assigned_by=0且assignee_type='user'的记录) $market_teachers = []; if (!empty($resource_ids)) { $assignment_model = new \app\model\resource_assignment\ResourceAssignment(); - // 查询每个资源assigned_source为auto_allocation或api的最新一条记录 + // 查询每个资源assigned_by=0且assignee_type='user'的最新一条记录 $market_assignments = []; foreach ($resource_ids as $resource_id) { $latest_assignment = $assignment_model ->where('resource_id', $resource_id) - ->whereIn('assigned_source', ['auto_allocation', 'api']) + ->where('assignee_type', 'user') + ->where('assigned_by', 0) ->order('assigned_at', 'desc') ->field('assignee_id') ->find(); @@ -1524,7 +1524,7 @@ class ResourceSharingService extends BaseApiService 'resource_id' => $resource_id, 'assignee_type' => $assignee_type, 'assignee_id' => $assignee_id, - 'is_primary' => $is_primary ? 1 : 0, + 'is_primary' => 1, 'assigned_by' => $assigned_by, 'assigned_at' => date('Y-m-d H:i:s'), 'campus_id' => $campus_id, diff --git a/start.sh b/start.sh index 6813db7c..1759bc5f 100755 --- a/start.sh +++ b/start.sh @@ -173,6 +173,26 @@ EOF # 启动服务 start_services() { print_message "启动 ${PROJECT_NAME} 服务..." + + # 检查是否存在冲突的容器并清理 + print_message "检查并清理可能冲突的容器..." + + # 检查并停止冲突的容器 + for container in niucloud_mysql niucloud_redis niucloud_php niucloud_nginx niucloud_composer niucloud_node; do + if docker ps -a --format "table {{.Names}}" | grep -q "^${container}$"; then + print_warning "发现已存在的容器: $container,正在清理..." + docker stop $container 2>/dev/null || true + docker rm $container 2>/dev/null || true + fi + done + + # 清理可能存在的网络 + if docker network ls --format "table {{.Name}}" | grep -q "^zhjwxt_niucloud_network$"; then + print_warning "发现已存在的网络,正在清理..." + docker network rm zhjwxt_niucloud_network 2>/dev/null || true + fi + + # 启动服务 docker-compose up -d } @@ -182,6 +202,31 @@ stop_services() { docker-compose down } +# 强制清理所有容器和网络 +force_cleanup() { + print_message "强制清理所有相关容器和网络..." + + # 停止并删除所有相关容器 + for container in niucloud_mysql niucloud_redis niucloud_php niucloud_nginx niucloud_composer niucloud_node; do + if docker ps -a --format "table {{.Names}}" | grep -q "^${container}$"; then + print_warning "正在删除容器: $container" + docker stop $container 2>/dev/null || true + docker rm $container 2>/dev/null || true + fi + done + + # 删除网络 + if docker network ls --format "table {{.Name}}" | grep -q "^zhjwxt_niucloud_network$"; then + print_warning "正在删除网络: zhjwxt_niucloud_network" + docker network rm zhjwxt_niucloud_network 2>/dev/null || true + fi + + # 删除未使用的网络 + docker network prune -f 2>/dev/null || true + + print_message "清理完成!" +} + # 重启服务 restart_services() { print_message "重启 ${PROJECT_NAME} 服务..." @@ -241,6 +286,7 @@ show_help() { echo " status 查看服务状态" echo " logs 查看所有服务日志" echo " logs <服务名> 查看指定服务日志" + echo " cleanup 强制清理所有容器和网络" echo " init 初始化项目" echo " help 显示此帮助信息" } @@ -265,6 +311,9 @@ main() { logs) view_logs "$2" ;; + cleanup) + force_cleanup + ;; init) init_project ;; diff --git a/uniapp/pages-coach/coach/my/salary.vue b/uniapp/pages-coach/coach/my/salary.vue index a96d65c7..53a2167e 100644 --- a/uniapp/pages-coach/coach/my/salary.vue +++ b/uniapp/pages-coach/coach/my/salary.vue @@ -2,7 +2,7 @@