24 changed files with 1497 additions and 11 deletions
@ -0,0 +1,58 @@ |
|||||
|
import request from '@/utils/request' |
||||
|
|
||||
|
// USER_CODE_BEGIN -- class_resources_rel
|
||||
|
/** |
||||
|
* 获取班级和资源列表 |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function getClassResourcesRelList(params: Record<string, any>) { |
||||
|
return request.get(`class_resources_rel/class_resources_rel`, {params}) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取班级和资源详情 |
||||
|
* @param id 班级和资源id |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function getClassResourcesRelInfo(id: number) { |
||||
|
return request.get(`class_resources_rel/class_resources_rel/${id}`); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加班级和资源 |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function addClassResourcesRel(params: Record<string, any>) { |
||||
|
return request.post('class_resources_rel/class_resources_rel', params, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑班级和资源 |
||||
|
* @param id |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function editClassResourcesRel(params: Record<string, any>) { |
||||
|
return request.put(`class_resources_rel/class_resources_rel/${params.id}`, params, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除班级和资源 |
||||
|
* @param id |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function deleteClassResourcesRel(id: number) { |
||||
|
return request.delete(`class_resources_rel/class_resources_rel/${id}`, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
export function getWithClassGradeList(params: Record<string,any>){ |
||||
|
return request.get('class_resources_rel/class_grade_all', {params}) |
||||
|
}export function getWithCustomerResourcesList(params: Record<string,any>){ |
||||
|
return request.get('class_resources_rel/customer_resources_all', {params}) |
||||
|
}export function getWithCampusList(params: Record<string,any>){ |
||||
|
return request.get('class_resources_rel/campus_all', {params}) |
||||
|
} |
||||
|
|
||||
|
// USER_CODE_END -- class_resources_rel
|
||||
@ -0,0 +1,17 @@ |
|||||
|
{ |
||||
|
"classId":"班级", |
||||
|
"classIdPlaceholder":"请输入班级", |
||||
|
"resourceId":"资源", |
||||
|
"resourceIdPlaceholder":"请输入资源", |
||||
|
"campusId":"校区", |
||||
|
"campusIdPlaceholder":"请输入校区", |
||||
|
"sourceType":"数据资源类型", |
||||
|
"sourceTypePlaceholder":"请输入数据资源类型", |
||||
|
"status":"状态", |
||||
|
"statusPlaceholder":"请输入状态", |
||||
|
"addClassResourcesRel":"添加班级和资源", |
||||
|
"updateClassResourcesRel":"编辑班级和资源", |
||||
|
"classResourcesRelDeleteTips":"确定要删除该数据吗?", |
||||
|
"startDate":"请选择开始时间", |
||||
|
"endDate":"请选择结束时间" |
||||
|
} |
||||
@ -0,0 +1,201 @@ |
|||||
|
<template> |
||||
|
<div class="main-container"> |
||||
|
<el-card class="box-card !border-none" shadow="never"> |
||||
|
|
||||
|
<div class="flex justify-between items-center"> |
||||
|
<span class="text-lg">{{pageName}}</span> |
||||
|
<el-button type="primary" @click="addEvent"> |
||||
|
{{ t('addClassResourcesRel') }} |
||||
|
</el-button> |
||||
|
</div> |
||||
|
|
||||
|
<el-card class="box-card !border-none my-[10px] table-search-wrap" shadow="never"> |
||||
|
<el-form :inline="true" :model="classResourcesRelTable.searchParam" ref="searchFormRef"> |
||||
|
|
||||
|
<el-form-item> |
||||
|
<el-button type="primary" @click="loadClassResourcesRelList()">{{ t('search') }}</el-button> |
||||
|
<el-button @click="resetForm(searchFormRef)">{{ t('reset') }}</el-button> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
</el-card> |
||||
|
|
||||
|
<div class="mt-[10px]"> |
||||
|
<el-table :data="classResourcesRelTable.data" size="large" v-loading="classResourcesRelTable.loading"> |
||||
|
<template #empty> |
||||
|
<span>{{ !classResourcesRelTable.loading ? t('emptyData') : '' }}</span> |
||||
|
</template> |
||||
|
<el-table-column prop="class_id_name" :label="t('classId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="resource_id_name" :label="t('resourceId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="campus_id_name" :label="t('campusId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column :label="t('sourceType')" min-width="180" align="center" :show-overflow-tooltip="true"> |
||||
|
<template #default="{ row }"> |
||||
|
<div v-for="(item, index) in source_typeList"> |
||||
|
<div v-if="item.value == row.source_type">{{ item.name }}</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
<el-table-column :label="t('status')" min-width="180" align="center" :show-overflow-tooltip="true"> |
||||
|
<template #default="{ row }"> |
||||
|
<div v-for="(item, index) in statusList"> |
||||
|
<div v-if="item.value == row.status">{{ item.name }}</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
<el-table-column :label="t('operation')" fixed="right" min-width="120"> |
||||
|
<template #default="{ row }"> |
||||
|
<el-button type="primary" link @click="editEvent(row)">{{ t('edit') }}</el-button> |
||||
|
<el-button type="primary" link @click="deleteEvent(row.id)">{{ t('delete') }}</el-button> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
</el-table> |
||||
|
<div class="mt-[16px] flex justify-end"> |
||||
|
<el-pagination v-model:current-page="classResourcesRelTable.page" v-model:page-size="classResourcesRelTable.limit" |
||||
|
layout="total, sizes, prev, pager, next, jumper" :total="classResourcesRelTable.total" |
||||
|
@size-change="loadClassResourcesRelList()" @current-change="loadClassResourcesRelList" /> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<edit ref="editClassResourcesRelDialog" @complete="loadClassResourcesRelList" /> |
||||
|
</el-card> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts" setup> |
||||
|
import { reactive, ref, watch } from 'vue' |
||||
|
import { t } from '@/lang' |
||||
|
import { useDictionary } from '@/app/api/dict' |
||||
|
import { getClassResourcesRelList, deleteClassResourcesRel, getWithClassGradeList, getWithCustomerResourcesList, getWithCampusList } from '@/app/api/class_resources_rel' |
||||
|
import { img } from '@/utils/common' |
||||
|
import { ElMessageBox,FormInstance } from 'element-plus' |
||||
|
import Edit from '@/app/views/class_resources_rel/components/class-resources-rel-edit.vue' |
||||
|
import { useRoute } from 'vue-router' |
||||
|
const route = useRoute() |
||||
|
const pageName = route.meta.title; |
||||
|
|
||||
|
let classResourcesRelTable = reactive({ |
||||
|
page: 1, |
||||
|
limit: 10, |
||||
|
total: 0, |
||||
|
loading: true, |
||||
|
data: [], |
||||
|
searchParam:{ |
||||
|
|
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
const searchFormRef = ref<FormInstance>() |
||||
|
|
||||
|
// 选中数据 |
||||
|
const selectData = ref<any[]>([]) |
||||
|
|
||||
|
// 字典数据 |
||||
|
const source_typeList = ref([] as any[]) |
||||
|
const source_typeDictList = async () => { |
||||
|
source_typeList.value = await (await useDictionary('sj_type')).data.dictionary |
||||
|
} |
||||
|
source_typeDictList(); |
||||
|
const statusList = ref([] as any[]) |
||||
|
const statusDictList = async () => { |
||||
|
statusList.value = await (await useDictionary('student_status')).data.dictionary |
||||
|
} |
||||
|
statusDictList(); |
||||
|
|
||||
|
/** |
||||
|
* 获取班级和资源列表 |
||||
|
*/ |
||||
|
const loadClassResourcesRelList = (page: number = 1) => { |
||||
|
classResourcesRelTable.loading = true |
||||
|
classResourcesRelTable.page = page |
||||
|
|
||||
|
getClassResourcesRelList({ |
||||
|
page: classResourcesRelTable.page, |
||||
|
limit: classResourcesRelTable.limit, |
||||
|
...classResourcesRelTable.searchParam |
||||
|
}).then(res => { |
||||
|
classResourcesRelTable.loading = false |
||||
|
classResourcesRelTable.data = res.data.data |
||||
|
classResourcesRelTable.total = res.data.total |
||||
|
}).catch(() => { |
||||
|
classResourcesRelTable.loading = false |
||||
|
}) |
||||
|
} |
||||
|
loadClassResourcesRelList() |
||||
|
|
||||
|
const editClassResourcesRelDialog: Record<string, any> | null = ref(null) |
||||
|
|
||||
|
/** |
||||
|
* 添加班级和资源 |
||||
|
*/ |
||||
|
const addEvent = () => { |
||||
|
editClassResourcesRelDialog.value.setFormData() |
||||
|
editClassResourcesRelDialog.value.showDialog = true |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑班级和资源 |
||||
|
* @param data |
||||
|
*/ |
||||
|
const editEvent = (data: any) => { |
||||
|
editClassResourcesRelDialog.value.setFormData(data) |
||||
|
editClassResourcesRelDialog.value.showDialog = true |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除班级和资源 |
||||
|
*/ |
||||
|
const deleteEvent = (id: number) => { |
||||
|
ElMessageBox.confirm(t('classResourcesRelDeleteTips'), t('warning'), |
||||
|
{ |
||||
|
confirmButtonText: t('confirm'), |
||||
|
cancelButtonText: t('cancel'), |
||||
|
type: 'warning', |
||||
|
} |
||||
|
).then(() => { |
||||
|
deleteClassResourcesRel(id).then(() => { |
||||
|
loadClassResourcesRelList() |
||||
|
}).catch(() => { |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const classIdList = ref([]) |
||||
|
const setClassIdList = async () => { |
||||
|
classIdList.value = await (await getWithClassGradeList({})).data |
||||
|
} |
||||
|
setClassIdList() |
||||
|
const resourceIdList = ref([]) |
||||
|
const setResourceIdList = async () => { |
||||
|
resourceIdList.value = await (await getWithCustomerResourcesList({})).data |
||||
|
} |
||||
|
setResourceIdList() |
||||
|
const campusIdList = ref([]) |
||||
|
const setCampusIdList = async () => { |
||||
|
campusIdList.value = await (await getWithCampusList({})).data |
||||
|
} |
||||
|
setCampusIdList() |
||||
|
|
||||
|
const resetForm = (formEl: FormInstance | undefined) => { |
||||
|
if (!formEl) return |
||||
|
formEl.resetFields() |
||||
|
loadClassResourcesRelList() |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
/* 多行超出隐藏 */ |
||||
|
.multi-hidden { |
||||
|
word-break: break-all; |
||||
|
text-overflow: ellipsis; |
||||
|
overflow: hidden; |
||||
|
display: -webkit-box; |
||||
|
-webkit-line-clamp: 2; |
||||
|
-webkit-box-orient: vertical; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,251 @@ |
|||||
|
<template> |
||||
|
<el-dialog v-model="showDialog" title="班级分配" width="50%" class="diy-dialog-wrap" :destroy-on-close="true"> |
||||
|
<el-form :model="formData" label-width="120px" ref="formRef" :rules="formRules" class="page-form" v-loading="loading"> |
||||
|
<el-form-item :label="t('campusId')" > |
||||
|
<el-select class="input-width" v-model="formData.campus_id" clearable :placeholder="t('campusIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in campusIdList" |
||||
|
:key="index" |
||||
|
:label="item['campus_name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('classId')" prop="class_id"> |
||||
|
<el-select class="input-width" v-model="formData.class_id" clearable :placeholder="t('classIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in classIdList" |
||||
|
:key="index" |
||||
|
:label="item['class_name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<!-- <el-form-item label="资源" > |
||||
|
<el-select class="input-width" v-model="formData.resource_id" clearable :placeholder="t('resourceIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in resourceIdList" |
||||
|
:key="index" |
||||
|
:label="item['name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> --> |
||||
|
|
||||
|
|
||||
|
|
||||
|
<el-form-item label="数据资源类型" > |
||||
|
<el-select class="input-width" v-model="formData.source_type" clearable placeholder="请选择数据资源类型"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in source_typeList" |
||||
|
:key="index" |
||||
|
:label="item.name" |
||||
|
:value="item.value" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('status')" > |
||||
|
<el-select class="input-width" v-model="formData.status" clearable :placeholder="t('statusPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in statusList" |
||||
|
:key="index" |
||||
|
:label="item.name" |
||||
|
:value="Number(item.value)" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
</el-form> |
||||
|
|
||||
|
<template #footer> |
||||
|
<span class="dialog-footer"> |
||||
|
<el-button @click="showDialog = false">{{ t('cancel') }}</el-button> |
||||
|
<el-button type="primary" :loading="loading" @click="confirm(formRef)">{{ |
||||
|
t('confirm') |
||||
|
}}</el-button> |
||||
|
</span> |
||||
|
</template> |
||||
|
</el-dialog> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts" setup> |
||||
|
import { ref, reactive, computed, watch } from 'vue' |
||||
|
import { useDictionary } from '@/app/api/dict' |
||||
|
import { t } from '@/lang' |
||||
|
import type { FormInstance } from 'element-plus' |
||||
|
import { addClassResourcesRel, editClassResourcesRel, getClassResourcesRelInfo, getWithClassGradeList, getWithCustomerResourcesList, getWithCampusList } from '@/app/api/class_resources_rel' |
||||
|
|
||||
|
let showDialog = ref(false) |
||||
|
const loading = ref(false) |
||||
|
|
||||
|
/** |
||||
|
* 表单数据 |
||||
|
*/ |
||||
|
const initialFormData = { |
||||
|
id: '', |
||||
|
class_id: '', |
||||
|
// resource_id: '', |
||||
|
campus_id: '', |
||||
|
source_type: '', |
||||
|
status: '', |
||||
|
} |
||||
|
const formData: Record<string, any> = reactive({ ...initialFormData }) |
||||
|
|
||||
|
const formRef = ref<FormInstance>() |
||||
|
|
||||
|
// 表单验证规则 |
||||
|
const formRules = computed(() => { |
||||
|
return { |
||||
|
class_id: [ |
||||
|
{ required: true, message: t('classIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
resource_id: [ |
||||
|
{ required: true, message: t('resourceIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
campus_id: [ |
||||
|
{ required: true, message: t('campusIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
source_type: [ |
||||
|
{ required: true, message: t('sourceTypePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
status: [ |
||||
|
{ required: true, message: t('statusPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
const emit = defineEmits(['complete']) |
||||
|
|
||||
|
/** |
||||
|
* 确认 |
||||
|
* @param formEl |
||||
|
*/ |
||||
|
const confirm = async (formEl: FormInstance | undefined) => { |
||||
|
if (loading.value || !formEl) return |
||||
|
let save = formData.id ? editClassResourcesRel : addClassResourcesRel |
||||
|
|
||||
|
await formEl.validate(async (valid) => { |
||||
|
if (valid) { |
||||
|
loading.value = true |
||||
|
|
||||
|
let data = formData |
||||
|
|
||||
|
save(data).then(res => { |
||||
|
loading.value = false |
||||
|
showDialog.value = false |
||||
|
emit('complete') |
||||
|
}).catch(err => { |
||||
|
loading.value = false |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 获取字典数据 |
||||
|
let source_typeList = ref([]) |
||||
|
const source_typeDictList = async () => { |
||||
|
source_typeList.value = await (await useDictionary('sj_type')).data.dictionary |
||||
|
} |
||||
|
source_typeDictList(); |
||||
|
watch(() => source_typeList.value, () => { formData.source_type = source_typeList.value[0].value }) |
||||
|
let statusList = ref([]) |
||||
|
const statusDictList = async () => { |
||||
|
statusList.value = await (await useDictionary('student_status')).data.dictionary |
||||
|
} |
||||
|
statusDictList(); |
||||
|
watch(() => statusList.value, () => { formData.status = statusList.value[0].value }) |
||||
|
|
||||
|
|
||||
|
const classIdList = ref([] as any[]) |
||||
|
const setClassIdList = async () => { |
||||
|
classIdList.value = await (await getWithClassGradeList({})).data |
||||
|
} |
||||
|
setClassIdList() |
||||
|
const resourceIdList = ref([] as any[]) |
||||
|
const setResourceIdList = async () => { |
||||
|
resourceIdList.value = await (await getWithCustomerResourcesList({})).data |
||||
|
} |
||||
|
setResourceIdList() |
||||
|
const campusIdList = ref([] as any[]) |
||||
|
const setCampusIdList = async () => { |
||||
|
campusIdList.value = await (await getWithCampusList({})).data |
||||
|
} |
||||
|
setCampusIdList() |
||||
|
const setFormData = async (row: any = null) => { |
||||
|
Object.assign(formData, initialFormData) |
||||
|
loading.value = true |
||||
|
if(row){ |
||||
|
const data = await (await getClassResourcesRelInfo(row.id)).data |
||||
|
if (data) Object.keys(formData).forEach((key: string) => { |
||||
|
if (data[key] != undefined) formData[key] = data[key] |
||||
|
}) |
||||
|
} |
||||
|
loading.value = false |
||||
|
} |
||||
|
|
||||
|
// 验证手机号格式 |
||||
|
const mobileVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/^1[3-9]\d{9}$/.test(value)) { |
||||
|
callback(new Error(t('generateMobile'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证身份证号 |
||||
|
const idCardVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value)) { |
||||
|
callback(new Error(t('generateIdCard'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证邮箱号 |
||||
|
const emailVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(value)) { |
||||
|
callback(new Error(t('generateEmail'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证请输入整数 |
||||
|
const numberVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (!Number.isInteger(value)) { |
||||
|
callback(new Error(t('generateNumber'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
defineExpose({ |
||||
|
showDialog, |
||||
|
setFormData |
||||
|
}) |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped></style> |
||||
|
<style lang="scss"> |
||||
|
.diy-dialog-wrap .el-form-item__label{ |
||||
|
height: auto !important; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\adminapi\controller\class_resources_rel; |
||||
|
|
||||
|
use core\base\BaseAdminController; |
||||
|
use app\service\admin\class_resources_rel\ClassResourcesRelService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 班级和资源控制器 |
||||
|
* Class ClassResourcesRel |
||||
|
* @package app\adminapi\controller\class_resources_rel |
||||
|
*/ |
||||
|
class ClassResourcesRel extends BaseAdminController |
||||
|
{ |
||||
|
/** |
||||
|
* 获取班级和资源列表 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function lists(){ |
||||
|
$data = $this->request->params([ |
||||
|
|
||||
|
]); |
||||
|
return success((new ClassResourcesRelService())->getPage($data)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 班级和资源详情 |
||||
|
* @param int $id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function info(int $id){ |
||||
|
return success((new ClassResourcesRelService())->getInfo($id)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加班级和资源 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function add(){ |
||||
|
$data = $this->request->params([ |
||||
|
["class_id",0], |
||||
|
["resource_id",0], |
||||
|
["campus_id",0], |
||||
|
["source_type",""], |
||||
|
["status",0], |
||||
|
|
||||
|
]); |
||||
|
$this->validate($data, 'app\validate\class_resources_rel\ClassResourcesRel.add'); |
||||
|
$id = (new ClassResourcesRelService())->add($data); |
||||
|
return success('ADD_SUCCESS', ['id' => $id]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 班级和资源编辑 |
||||
|
* @param $id 班级和资源id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function edit(int $id){ |
||||
|
$data = $this->request->params([ |
||||
|
["class_id",0], |
||||
|
["campus_id",0], |
||||
|
["source_type",""], |
||||
|
["status",0], |
||||
|
|
||||
|
]); |
||||
|
// $this->validate($data, 'app\validate\class_resources_rel\ClassResourcesRel.edit'); |
||||
|
(new ClassResourcesRelService())->edit($id, $data); |
||||
|
return success('EDIT_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 班级和资源删除 |
||||
|
* @param $id 班级和资源id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function del(int $id){ |
||||
|
(new ClassResourcesRelService())->del($id); |
||||
|
return success('DELETE_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function getClassGradeAll(){ |
||||
|
return success(( new ClassResourcesRelService())->getClassGradeAll()); |
||||
|
} |
||||
|
|
||||
|
public function getCustomerResourcesAll(){ |
||||
|
return success(( new ClassResourcesRelService())->getCustomerResourcesAll()); |
||||
|
} |
||||
|
|
||||
|
public function getCampusAll(){ |
||||
|
return success(( new ClassResourcesRelService())->getCampusAll()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
use think\facade\Route; |
||||
|
|
||||
|
use app\adminapi\middleware\AdminCheckRole; |
||||
|
use app\adminapi\middleware\AdminCheckToken; |
||||
|
use app\adminapi\middleware\AdminLog; |
||||
|
// USER_CODE_BEGIN -- class_resources_rel |
||||
|
|
||||
|
Route::group('class_resources_rel', function () { |
||||
|
|
||||
|
//班级和资源列表 |
||||
|
Route::get('class_resources_rel', 'class_resources_rel.ClassResourcesRel/lists'); |
||||
|
//班级和资源详情 |
||||
|
Route::get('class_resources_rel/:id', 'class_resources_rel.ClassResourcesRel/info'); |
||||
|
//添加班级和资源 |
||||
|
Route::post('class_resources_rel', 'class_resources_rel.ClassResourcesRel/add'); |
||||
|
//编辑班级和资源 |
||||
|
Route::put('class_resources_rel/:id', 'class_resources_rel.ClassResourcesRel/edit'); |
||||
|
//删除班级和资源 |
||||
|
Route::delete('class_resources_rel/:id', 'class_resources_rel.ClassResourcesRel/del'); |
||||
|
|
||||
|
Route::get('class_grade_all','class_resources_rel.ClassResourcesRel/getClassGradeAll'); |
||||
|
|
||||
|
Route::get('customer_resources_all','class_resources_rel.ClassResourcesRel/getCustomerResourcesAll'); |
||||
|
|
||||
|
Route::get('campus_all','class_resources_rel.ClassResourcesRel/getCampusAll'); |
||||
|
|
||||
|
})->middleware([ |
||||
|
AdminCheckToken::class, |
||||
|
AdminCheckRole::class, |
||||
|
AdminLog::class |
||||
|
]); |
||||
|
// USER_CODE_END -- class_resources_rel |
||||
@ -0,0 +1,189 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\api\controller\apiController; |
||||
|
|
||||
|
use app\Request; |
||||
|
use app\service\api\apiService\CampusService; |
||||
|
use app\service\api\apiService\ChatService; |
||||
|
use app\service\api\apiService\CommonService; |
||||
|
use core\base\BaseApiService; |
||||
|
|
||||
|
/** |
||||
|
* 聊天控制器相关接口 |
||||
|
* Class Personnel |
||||
|
* @package app\api\controller\apiController |
||||
|
*/ |
||||
|
class Chat extends BaseApiService |
||||
|
{ |
||||
|
|
||||
|
//获取好友关系列表 |
||||
|
public function getChatFriendsList(Request $request) |
||||
|
{ |
||||
|
$personnel_id = $request->param('personnel_id', '');//员工人力资源表id(两个参数2选1) |
||||
|
$customer_resources_id = $request->param('customer_resources_id', '');//学生资源表id(两个参数2选1) |
||||
|
if (empty($personnel_id) && empty($customer_resources_id)) { |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
$where = [ |
||||
|
'personnel_id' => $personnel_id, |
||||
|
'customer_resources_id' => $customer_resources_id, |
||||
|
]; |
||||
|
|
||||
|
$res = (new ChatService())->getChatFriendsPage($where); |
||||
|
|
||||
|
return success($res); |
||||
|
} |
||||
|
|
||||
|
//获取好友关系详情 |
||||
|
public function getChatFriendsInfo(Request $request) |
||||
|
{ |
||||
|
$personnel_id = $request->param('personnel_id','');//员工人力资源表id |
||||
|
$customer_resources_id = $request->param('customer_resources_id','');//学生资源表id |
||||
|
|
||||
|
|
||||
|
if (empty($personnel_id) && empty($customer_resources_id)) { |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
$where = [ |
||||
|
'personnel_id' => $personnel_id, |
||||
|
'customer_resources_id' => $customer_resources_id, |
||||
|
]; |
||||
|
|
||||
|
$res = (new ChatService())->getChatFriendsInfo($where); |
||||
|
|
||||
|
if(!$res['data']){ |
||||
|
//创建好友关系 |
||||
|
$add = (new ChatService())->addChatFriends($where); |
||||
|
if(!$add['code']){ |
||||
|
return fail('创建好友关系失败'); |
||||
|
}else{ |
||||
|
$res = (new ChatService())->getChatFriendsInfo($where); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(!$res['code']){ |
||||
|
return fail($res['msg']); |
||||
|
} |
||||
|
|
||||
|
return success($res['data']); |
||||
|
} |
||||
|
|
||||
|
//创建好友关系 |
||||
|
public function addChatFriends(Request $request) |
||||
|
{ |
||||
|
$personnel_id = $request->param('personnel_id', ''); |
||||
|
$customer_resources_id = $request->param('customer_resources_id', ''); |
||||
|
if (empty($personnel_id) || empty($customer_resources_id)) { |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
$where = [ |
||||
|
'personnel_id' => $personnel_id, |
||||
|
'customer_resources_id' => $customer_resources_id, |
||||
|
]; |
||||
|
|
||||
|
|
||||
|
//检测好友关系是否存在 |
||||
|
$getChatFriendsInfo = (new ChatService())->getChatFriendsInfo($where); |
||||
|
|
||||
|
if ($getChatFriendsInfo['data']) { |
||||
|
return fail('好友关系已存在'); |
||||
|
} |
||||
|
|
||||
|
$addChatFriends = (new ChatService())->addChatFriends($where); |
||||
|
if (!$addChatFriends['code']) { |
||||
|
return fail($addChatFriends['msg']); |
||||
|
} |
||||
|
return success($addChatFriends['data']); |
||||
|
} |
||||
|
|
||||
|
//获取聊天记录 |
||||
|
public function getChatMessagesList(Request $request) |
||||
|
{ |
||||
|
|
||||
|
$friend_id = $request->param('friend_id', '');//关联chat_friends表id |
||||
|
|
||||
|
if (empty($friend_id)) { |
||||
|
return fail('发送者类型不正确'); |
||||
|
} |
||||
|
$where = [ |
||||
|
'friend_id' => $friend_id, |
||||
|
]; |
||||
|
$res = (new ChatService())->getChatMessagesList($where); |
||||
|
return success($res); |
||||
|
} |
||||
|
|
||||
|
//发送聊天内容 |
||||
|
public function sendChatMessages(Request $request) |
||||
|
{ |
||||
|
$from_type = $request->param('from_type', '');//发送者类型|personnel=员工,customer=学生(客户) |
||||
|
|
||||
|
$from_id = $request->param('from_id', '');//发送者ID |
||||
|
|
||||
|
$to_id = $request->param('to_id', '');//接收者ID |
||||
|
|
||||
|
$friend_id = $request->param('friend_id', '');//关联chat_friends表id |
||||
|
|
||||
|
$message_type = $request->param('message_type', '');//消息类型|text=文本,img=图片 |
||||
|
|
||||
|
$content = $request->param('content', '');//文本内容(JSON 格式扩展字段),文本类型=纯文字,图片类型=绝对路径 |
||||
|
|
||||
|
if (!in_array($message_type, ['text', 'img'])) { |
||||
|
return fail('消息类型不正确'); |
||||
|
} |
||||
|
if (!in_array($from_type, ['personnel', 'customer'])) { |
||||
|
return fail('发送者类型不正确'); |
||||
|
} |
||||
|
if (empty($from_id) || empty($to_id) || empty($friend_id) || empty($content)) { |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
$data = [ |
||||
|
'from_type' => $from_type, // 发送者类型:personnel=员工,customer=学生(客户) |
||||
|
'from_id' => $from_id, // 发送者ID(员工/学生),根据from_type判断 |
||||
|
'to_id' => $to_id, // 接收者ID(员工/学生),根据from_type判断 |
||||
|
'friend_id' => $friend_id, // 关联chat_friends表id |
||||
|
'message_type' => $message_type, // 消息类型:text=文本,img=图片 |
||||
|
'content' => $content // 文本内容(JSON格式扩展字段) |
||||
|
]; |
||||
|
|
||||
|
$res = (new ChatService())->sendChatMessages($data); |
||||
|
if(!$res['code']){ |
||||
|
return fail($res['msg']); |
||||
|
} |
||||
|
return success($res['data']); |
||||
|
} |
||||
|
|
||||
|
//修改未读消息数量 |
||||
|
public function editUnreadCount(Request $request){ |
||||
|
$from_type = $request->param('from_type', '');//发送者类型|personnel=员工,customer=学生(客户) |
||||
|
|
||||
|
$from_id = $request->param('from_id', '');//发送者ID |
||||
|
|
||||
|
$friend_id = $request->param('friend_id', '');//关联chat_friends表id |
||||
|
|
||||
|
if (!in_array($from_type, ['personnel', 'customer'])) { |
||||
|
return fail('发送者类型不正确'); |
||||
|
} |
||||
|
if (empty($from_id) || empty($friend_id)) { |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
$res = (new ChatService())->editUnreadCount($from_type,$friend_id); |
||||
|
// if(!$res){ |
||||
|
// return fail('修改失败'); |
||||
|
// } |
||||
|
return success($res); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\model\class_resources_rel; |
||||
|
|
||||
|
use core\base\BaseModel; |
||||
|
use think\model\concern\SoftDelete; |
||||
|
use think\model\relation\HasMany; |
||||
|
use think\model\relation\HasOne; |
||||
|
|
||||
|
use app\model\class_grade\ClassGrade; |
||||
|
|
||||
|
use app\model\customer_resources\CustomerResources; |
||||
|
|
||||
|
use app\model\campus\Campus; |
||||
|
|
||||
|
/** |
||||
|
* 班级和资源模型 |
||||
|
* Class ClassResourcesRel |
||||
|
* @package app\model\class_resources_rel |
||||
|
*/ |
||||
|
class ClassResourcesRel extends BaseModel |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 数据表主键 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $pk = 'id'; |
||||
|
|
||||
|
/** |
||||
|
* 模型名称 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $name = 'class_resources_rel'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public function classGrade(){ |
||||
|
return $this->hasOne(ClassGrade::class, 'id', 'class_id')->joinType('left')->withField('class_name,id')->bind(['class_id_name'=>'class_name']); |
||||
|
} |
||||
|
|
||||
|
public function customerResources(){ |
||||
|
return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); |
||||
|
} |
||||
|
|
||||
|
public function campus(){ |
||||
|
return $this->hasOne(Campus::class, 'id', 'campus_id')->joinType('left')->withField('campus_name,id')->bind(['campus_id_name'=>'campus_name']); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,117 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\admin\class_resources_rel; |
||||
|
|
||||
|
use app\model\class_resources_rel\ClassResourcesRel; |
||||
|
use app\model\class_grade\ClassGrade; |
||||
|
use app\model\customer_resources\CustomerResources; |
||||
|
use app\model\campus\Campus; |
||||
|
|
||||
|
use core\base\BaseAdminService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 班级和资源服务层 |
||||
|
* Class ClassResourcesRelService |
||||
|
* @package app\service\admin\class_resources_rel |
||||
|
*/ |
||||
|
class ClassResourcesRelService extends BaseAdminService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
$this->model = new ClassResourcesRel(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取班级和资源列表 |
||||
|
* @param array $where |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getPage(array $where = []) |
||||
|
{ |
||||
|
$field = 'id,class_id,resource_id,campus_id,source_id,source_type,join_time,out_time,status,create_time,update_time'; |
||||
|
$order = 'id desc'; |
||||
|
|
||||
|
$search_model = $this->model->withSearch([], $where)->with(['classGrade','customerResources','campus'])->field($field)->order($order); |
||||
|
$list = $this->pageQuery($search_model); |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取班级和资源信息 |
||||
|
* @param int $id |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getInfo(int $id) |
||||
|
{ |
||||
|
$field = 'id,class_id,resource_id,campus_id,source_id,source_type,join_time,out_time,status,create_time,update_time'; |
||||
|
|
||||
|
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['classGrade','customerResources','campus'])->findOrEmpty()->toArray(); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加班级和资源 |
||||
|
* @param array $data |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function add(array $data) |
||||
|
{ |
||||
|
$res = $this->model->create($data); |
||||
|
return $res->id; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 班级和资源编辑 |
||||
|
* @param int $id |
||||
|
* @param array $data |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function edit(int $id, array $data) |
||||
|
{ |
||||
|
|
||||
|
$this->model->where([['id', '=', $id]])->update($data); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除班级和资源 |
||||
|
* @param int $id |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function del(int $id) |
||||
|
{ |
||||
|
$model = $this->model->where([['id', '=', $id]])->find(); |
||||
|
$res = $model->delete(); |
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function getClassGradeAll(){ |
||||
|
$classGradeModel = new ClassGrade(); |
||||
|
return $classGradeModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
public function getCustomerResourcesAll(){ |
||||
|
$customerResourcesModel = new CustomerResources(); |
||||
|
return $customerResourcesModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
public function getCampusAll(){ |
||||
|
$campusModel = new Campus(); |
||||
|
return $campusModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,216 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\api\apiService; |
||||
|
|
||||
|
use app\model\campus\Campus; |
||||
|
use app\model\campus_person_role\CampusPersonRole; |
||||
|
use app\model\chat_friends\ChatFriends; |
||||
|
use app\model\chat_messages\ChatMessages; |
||||
|
use app\model\dict\Dict; |
||||
|
use core\base\BaseApiService; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
/** |
||||
|
* 校区服务层 |
||||
|
* Class MemberService |
||||
|
* @package app\service\api\member |
||||
|
*/ |
||||
|
class ChatService extends BaseApiService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
} |
||||
|
|
||||
|
//查询好友关系列表 |
||||
|
public function getChatFriendsPage(array $where) |
||||
|
{ |
||||
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数 |
||||
|
$page = $page_params['page']; |
||||
|
$limit = $page_params['limit']; |
||||
|
|
||||
|
$model = new ChatFriends(); |
||||
|
//判断用没有员工id |
||||
|
if (!empty($where['personnel_id'])) { |
||||
|
$model = $model->where('personnel_id', $where['personnel_id']); |
||||
|
} |
||||
|
|
||||
|
if (!empty($where['customer_resources_id'])) { |
||||
|
$model = $model->where('customer_resources_id', $where['customer_resources_id']); |
||||
|
} |
||||
|
|
||||
|
$data = $model->paginate([ |
||||
|
'list_rows' => $limit, |
||||
|
'page' => $page, |
||||
|
])->toArray(); |
||||
|
|
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
//查询好友关系详情 |
||||
|
public function getChatFriendsInfo(array $where) |
||||
|
{ |
||||
|
$model = new ChatFriends(); |
||||
|
//判断用没有员工id |
||||
|
if (!empty($where['personnel_id'])) { |
||||
|
$model = $model->where('personnel_id', $where['personnel_id']); |
||||
|
} |
||||
|
if (!empty($where['customer_resources_id'])) { |
||||
|
$model = $model->where('customer_resources_id', $where['customer_resources_id']); |
||||
|
} |
||||
|
$data = $model->find(); |
||||
|
|
||||
|
|
||||
|
if ($data) { |
||||
|
$data = $data->toArray(); |
||||
|
$res = [ |
||||
|
'code' => 1, |
||||
|
'msg' => '操作成功', |
||||
|
'data' => $data |
||||
|
]; |
||||
|
return $res; |
||||
|
} else { |
||||
|
$res = [ |
||||
|
'code' => 0, |
||||
|
'msg' => '暂无数据', |
||||
|
'data' => [] |
||||
|
]; |
||||
|
return $res; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//创建好友关系 |
||||
|
public function addChatFriends(array $data) |
||||
|
{ |
||||
|
$data = ChatFriends::create($data); |
||||
|
if($data){ |
||||
|
$res = [ |
||||
|
'code' => 1, |
||||
|
'msg' => '操作成功', |
||||
|
'data' => $data |
||||
|
]; |
||||
|
return $res; |
||||
|
}else{ |
||||
|
$res = [ |
||||
|
'code' => 0, |
||||
|
'msg' => '操作失败', |
||||
|
'data' => [] |
||||
|
]; |
||||
|
return $res; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//发送聊天信息 |
||||
|
public function sendChatMessages(array $data){ |
||||
|
//开启事物操作 |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$add = ChatMessages::create($data); |
||||
|
|
||||
|
if(!empty($data['from_type']) && !empty($data['from_id']) && !empty($data['friend_id'])){ |
||||
|
$to_type = 'personnel'; |
||||
|
if($data['from_type'] == 'personnel'){ |
||||
|
$to_type = 'customer'; |
||||
|
} |
||||
|
$this->addUnreadCount($to_type,$data['friend_id']); |
||||
|
|
||||
|
$this->editUnreadCount($data['from_type'],$data['friend_id']); |
||||
|
} |
||||
|
|
||||
|
if($add){ |
||||
|
Db::commit(); |
||||
|
$res = [ |
||||
|
'code' => 1, |
||||
|
'msg' => '操作成功', |
||||
|
'data' => $add->toArray() |
||||
|
]; |
||||
|
return $res; |
||||
|
}else{ |
||||
|
Db::rollback(); |
||||
|
$res = [ |
||||
|
'code' => 0, |
||||
|
'msg' => '操作失败', |
||||
|
'data' => [] |
||||
|
]; |
||||
|
return $res; |
||||
|
} |
||||
|
}catch (\Exception $exception){ |
||||
|
Db::rollback(); |
||||
|
$res = [ |
||||
|
'code' => 0, |
||||
|
'msg' => '操作失败', |
||||
|
'data' => [] |
||||
|
]; |
||||
|
return $res; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//获取聊天记录 |
||||
|
public function getChatMessagesList(array $where){ |
||||
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数 |
||||
|
$page = $page_params['page']; |
||||
|
$limit = $page_params['limit']; |
||||
|
|
||||
|
$model = new ChatMessages(); |
||||
|
$model = $model->where('friend_id',$where['friend_id']); |
||||
|
|
||||
|
// 按id倒序排列 |
||||
|
$data = $model->order('id', 'desc')->paginate([ |
||||
|
'list_rows' => $limit, |
||||
|
'page' => $page, |
||||
|
])->toArray(); |
||||
|
|
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改未读消息数量 |
||||
|
* @param $from_type 发送者类型|personnel=员工,customer=学生(客户) |
||||
|
* @param $from_id 发送者ID(员工/学生) |
||||
|
* @param $friend_id 关联chat_friends表id |
||||
|
*/ |
||||
|
public function editUnreadCount($from_type ,$friend_id){ |
||||
|
$where = []; |
||||
|
if($from_type == 'personnel'){ |
||||
|
//员工发送的消息->把员工的未读消息数量清空 |
||||
|
$data['unread_count_personnel'] = 0; |
||||
|
}else{ |
||||
|
//学生发送的消息->把学生的未读消息数量清空 |
||||
|
$data['unread_count_customer_resources'] = 0; |
||||
|
} |
||||
|
$model = ChatFriends::where('id',$friend_id); |
||||
|
|
||||
|
$data['updated_at'] = date('Y-m-d H:i:s'); |
||||
|
$model = $model->update($data); |
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 追加接收消息的人未读消息数量+1 |
||||
|
* @param $to_type 接收者类型|personnel=员工,customer=学生(客户) |
||||
|
* @param $to_id 接收者ID(员工/学生) |
||||
|
* @param $friend_id 关联chat_friends表id |
||||
|
*/ |
||||
|
public function addUnreadCount($to_type, $friend_id) |
||||
|
{ |
||||
|
$model = ChatFriends::where('id', $friend_id); |
||||
|
|
||||
|
if ($to_type == 'personnel') { |
||||
|
// 员工接收的消息 -> 员工的未读消息数量+1 |
||||
|
return $model->inc('unread_count_personnel')->update(); |
||||
|
} else { |
||||
|
// 学生接收的消息 -> 学生的未读消息数量+1 |
||||
|
return $model->inc('unread_count_customer_resources')->update(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\validate\class_resources_rel; |
||||
|
use core\base\BaseValidate; |
||||
|
/** |
||||
|
* 班级和资源验证器 |
||||
|
* Class ClassResourcesRel |
||||
|
* @package addon\app\validate\class_resources_rel |
||||
|
*/ |
||||
|
class ClassResourcesRel extends BaseValidate |
||||
|
{ |
||||
|
|
||||
|
protected $rule = [ |
||||
|
'class_id' => 'require', |
||||
|
]; |
||||
|
|
||||
|
protected $message = [ |
||||
|
'class_id.require' => ['common_validate.require', ['class_id']], |
||||
|
]; |
||||
|
|
||||
|
protected $scene = [ |
||||
|
"add" => ['class_id', 'resource_id', 'campus_id', 'source_type', 'status'], |
||||
|
"edit" => ['class_id', 'resource_id', 'campus_id', 'source_type', 'status'] |
||||
|
]; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue