Browse Source

Merge branch 'master' into yuhongzhe

master
王泽彦 10 months ago
parent
commit
9f148c041f
  1. 4
      admin/src/app/lang/zh-cn/course.course.json
  2. 22
      admin/src/app/views/course/components/course-edit.vue
  3. 13
      admin/src/app/views/course/course.vue
  4. 269
      admin/src/app/views/timetables/timetables.vue
  5. 1
      niucloud/app/adminapi/controller/course/Course.php
  6. 75
      niucloud/app/api/controller/apiController/CustomerResources.php
  7. 124
      niucloud/app/api/controller/apiController/Personnel.php
  8. 68
      niucloud/app/api/controller/apiController/ResourceSharing.php
  9. 9
      niucloud/app/api/route/route.php
  10. 108
      niucloud/app/model/course/Course.php
  11. 180
      niucloud/app/model/customer_resources/CustomerResources.php
  12. 56
      niucloud/app/model/six_speed/SixSpeed.php
  13. 37
      niucloud/app/service/api/apiService/CommonService.php
  14. 122
      niucloud/app/service/api/apiService/CustomerResourcesService.php
  15. 72
      niucloud/app/service/api/apiService/PersonnelService.php
  16. 108
      niucloud/app/service/api/apiService/ResourceSharingService.php

4
admin/src/app/lang/zh-cn/course.course.json

@ -9,8 +9,8 @@
"durationPlaceholder": "请输入课程时长", "durationPlaceholder": "请输入课程时长",
"sessionCount": "课时数量", "sessionCount": "课时数量",
"sessionCountPlaceholder": "请输入课时数量", "sessionCountPlaceholder": "请输入课时数量",
"singleSessionCount": "单次逍客数量", "singleSessionCount": "单次消课数量",
"singleSessionCountPlaceholder": "请输入单次逍客数量", "singleSessionCountPlaceholder": "请输入单次消课数量",
"price": "课程价格", "price": "课程价格",
"pricePlaceholder": "请输入课程价格", "pricePlaceholder": "请输入课程价格",
"internalReminder": "内部提醒课时", "internalReminder": "内部提醒课时",

22
admin/src/app/views/course/components/course-edit.vue

@ -24,14 +24,19 @@
</el-form-item> </el-form-item>
<el-form-item :label="t('courseType')" prop="course_type"> <el-form-item :label="t('courseType')" prop="course_type">
<el-input <el-select
class="input-width"
v-model="formData.course_type" v-model="formData.course_type"
clearable
:placeholder="t('courseTypePlaceholder')" :placeholder="t('courseTypePlaceholder')"
class="input-width" >
/> <el-option
v-for="(item, index) in courseTypeList"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item> </el-form-item>
<el-form-item :label="t('duration')" prop="duration"> <el-form-item :label="t('duration')" prop="duration">
<el-input <el-input
v-model="formData.duration" v-model="formData.duration"
@ -193,6 +198,13 @@ const formRules = computed(() => {
const emit = defineEmits(['complete']) const emit = defineEmits(['complete'])
const courseTypeList = ref([])
const getcourseTypeList = async () => {
courseTypeList.value = await (
await useDictionary('course_type')
).data.dictionary
}
getcourseTypeList()
/** /**
* 确认 * 确认
* @param formEl * @param formEl

13
admin/src/app/views/course/course.vue

@ -24,10 +24,17 @@
/> />
</el-form-item> </el-form-item>
<el-form-item :label="t('courseType')" prop="course_type"> <el-form-item :label="t('courseType')" prop="course_type">
<el-input <el-select
v-model="courseTable.searchParam.course_type" v-model="courseTable.searchParam.course_type"
:placeholder="t('courseTypePlaceholder')" :placeholder="t('courseTypePlaceholder')"
/> >
<el-option
v-for="item in courseTypeList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item> </el-form-item>
<el-form-item :label="t('duration')" prop="duration"> <el-form-item :label="t('duration')" prop="duration">
<el-input <el-input
@ -220,7 +227,7 @@ let courseTable = reactive({
remarks: '', remarks: '',
}, },
}) })
const courseTypeList = useDictionary('course_type')
const searchFormRef = ref<FormInstance>() const searchFormRef = ref<FormInstance>()
// //

269
admin/src/app/views/timetables/timetables.vue

@ -1,125 +1,198 @@
<template> <template>
<div class="schedule-container"> <el-card class="box-card !border-none" shadow="never">
<!-- 周视图日历 --> <el-button @click="addDict">添加</el-button>
<FullCalendar <div class="schedule-container">
:options="calendarOptions" <!-- 周一到周日的布局 -->
ref="fullCalendar" <div v-for="(day, index) in days" :key="index" class="day-column">
class="calendar" <div class="day-header">{{ day.date }}</div>
/> <el-table
:data="day.timeSlots"
<!-- 课程详情弹窗 --> border
<el-dialog :span-method="(data) => objectSpanMethod(day.timeSlots, data)"
v-model="dialogVisible" style="width: 100%"
title="课程人员安排" @cell-click="handleCellClick"
width="30%" >
:before-close="handleClose" <!-- 时间列 -->
> <el-table-column
<div v-if="selectedEvent"> prop="timeRange"
<h3>{{ selectedEvent.title }}</h3> label="时间"
<p>时间{{ selectedEvent.time }}</p> width="80"
<h4>参与人员</h4> align="center"
<ul> >
<li v-for="person in selectedEvent.people" :key="person.id"> <template #default="{ row }">
{{ person.name }} - {{ person.role }} <div :style="{ backgroundColor: row.color }">
</li> {{ row.timeRange }}
</ul> </div>
</template>
</el-table-column>
<!-- 教室列 -->
<el-table-column
v-for="(classroom, idx) in day.classrooms"
:key="idx"
:label="`教室${idx + 1}`"
:prop="`classroom${idx + 1}`"
align="center"
>
<template #default="{ row }">
<div v-if="row.course && row.course.classroom === classroom">
<div class="teacher-name">{{ row.course.teacher }}</div>
<div class="student-list">
<el-tag
v-for="student in row.course.students"
:key="student"
size="small"
effect="plain"
>
{{ student }}
</el-tag>
</div>
<div class="classroom-name">
剩余空位{{ row.course.hasnumber }}
</div>
</div>
</template>
</el-table-column>
</el-table>
</div> </div>
</el-dialog>
</div> <!-- 详情弹窗 -->
<el-dialog v-model="dialogVisible" title="课程详情">
<p><strong>教师:</strong> {{ selectedCourse?.teacher }}</p>
<p><strong>学员:</strong> {{ selectedCourse?.students.join(', ') }}</p>
</el-dialog>
</div>
</el-card>
</template> </template>
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import FullCalendar from '@fullcalendar/vue3'
import dayGridPlugin from '@fullcalendar/daygrid' const days = [
import timeGridPlugin from '@fullcalendar/timegrid' //
import interactionPlugin from '@fullcalendar/interaction' //
import zhLocale from '@fullcalendar/core/locales/zh-cn'
//
const courses = ref([
{ {
id: 1, date: '周一',
title: '数学课', timeSlots: [
start: '2025-05-18 08:00:00', {
end: '2025-05-18 09:00:00', timeRange: '9:00-10:00',
people: [ color: '#FFA07A',
{ id: 1, name: '张老师', role: '主讲' }, course: {
{ id: 2, name: '李同学', role: '学生' }, teacher: '',
students: [],
classroom: '教室1',
hasnumber: 5,
},
},
// ...
], ],
classrooms: ['教室1'], //
}, },
{ {
id: 2, date: '周二',
title: '英语课', timeSlots: [
start: '2025-05-18 10:00:00', {
end: '2025-05-18 11:00:00', timeRange: '9:00-10:00',
people: [{ id: 3, name: '王老师', role: '主讲' }], color: '#FFA07A',
course: {
teacher: '张老师',
students: ['小明', '小红'],
classroom: '教室1',
hasnumber: 5,
},
},
{
timeRange: '11:00-12:00',
color: '#712e13',
course: {
teacher: '张老师',
students: ['小明', '小红'],
classroom: '教室2',
hasnumber: 5,
},
},
// ...
],
classrooms: ['教室1', '教室2'], //
}, },
]) ]
//
const dialogVisible = ref(false) const dialogVisible = ref(false)
const selectedEvent = ref(null) const selectedCourse = ref(null)
// FullCalendar //
const calendarOptions = ref({ const objectSpanMethod = (timeSlots, { row, column, rowIndex }) => {
locale: zhLocale, if (column.property === 'timeRange') {
plugins: [ //
dayGridPlugin, const current = timeSlots[rowIndex]
timeGridPlugin,
interactionPlugin, // //
], if (!current || !current.timeRange) return { rowspan: 0, colspan: 0 }
initialView: 'timeGridWeek', //
headerToolbar: { let spanCount = 1
left: 'prev,next today',
center: 'title', //
right: 'timeGridWeek,timeGridDay', // while (timeSlots[rowIndex + spanCount]?.timeRange === current.timeRange) {
}, spanCount++
events: courses.value,
eventClick: (info) => {
selectedEvent.value = {
title: info.event.title,
time: `${info.event.start.toLocaleTimeString()} - ${info.event.end.toLocaleTimeString()}`,
people: info.event.extendedProps.people,
} }
dialogVisible.value = true
},
eventContent: (arg) => {
//
return { html: `<div class="fc-event-title">${arg.event.title}</div>` }
},
allDaySlot: false, //
slotDuration: '01:00', // 1
slotLabelFormat: {
hour: 'numeric',
minute: '2-digit',
omitZeroMinute: false,
meridiem: 'short',
},
})
// //
const handleClose = () => { if (
dialogVisible.value = false spanCount > 1 &&
selectedEvent.value = null rowIndex > 0 &&
timeSlots[rowIndex - 1]?.timeRange === current.timeRange
) {
return { rowspan: 0, colspan: 0 }
}
return { rowspan: spanCount, colspan: 1 }
}
return { rowspan: 1, colspan: 1 }
}
//
const handleCellClick = (row, column, cell, event) => {
console.log(row, column, cell, event)
if (column.property.startsWith('classroom')) {
selectedCourse.value = row.course
dialogVisible.value = true
}
} }
</script> </script>
<style> <style scoped>
.schedule-container { .schedule-container {
padding: 20px; display: flex;
gap: 10px;
}
.day-column {
flex: 1;
min-width: 200px;
}
.day-header {
text-align: center;
font-weight: bold;
padding: 8px;
background-color: #f0f0f0;
}
.teacher-name {
font-weight: bold;
margin-bottom: 5px;
} }
.calendar { .student-list {
margin-bottom: 20px; margin-top: 5px;
} }
.fc-event-title { .el-table__cell {
white-space: normal !important; display: flex;
font-size: 14px; align-items: center;
} }
.fc-timegrid-event { .classroom-name {
cursor: pointer; margin-bottom: 5px;
} }
</style> </style>

1
niucloud/app/adminapi/controller/course/Course.php

@ -105,5 +105,4 @@ class Course extends BaseAdminController
return success('DELETE_SUCCESS'); return success('DELETE_SUCCESS');
} }
} }

75
niucloud/app/api/controller/apiController/CustomerResources.php

@ -77,5 +77,80 @@ class CustomerResources extends BaseApiService
return success([]); return success([]);
} }
//客户资源-编辑
public function edit(Request $request){
$resource_sharing_id = $request->param('resource_sharing_id', '');//资源共享id
$customer_resources_id = $request->param('id', '');//客户资源表id
$promised_visit_time = $request->param('promised_visit_time', '');
if($promised_visit_time){
$promised_visit_time = date('Y-m-d H:i:s',strtotime($promised_visit_time));
}
$optional_class_time = $request->param('optional_class_time', '');
if($optional_class_time){
$optional_class_time = date('Y-m-d H:i:s',strtotime($optional_class_time));
}
if(empty($customer_resources_id)){
return fail("缺少客户id");
}
$where=[
'id'=>$customer_resources_id
];
//客户资源数据
$customer_resources_data = [
"source_channel" => $request->param('source_channel', ''),//来源渠道
"source" => $request->param('source', ''),//来源
"name" => $request->param('name', ''),//姓名
"age" => $request->param('age', ''),//年龄
"gender" => $request->param('gender', ''),//性别
"phone_number" => $request->param('phone_number', ''),//联系电话
"demand" => $request->param('demand', ''),//需求
"decision_maker" => $request->param('decision_maker', ''),//决策人
"initial_intent" => $request->param('initial_intent', ''),//客户初步意向度
"status" => $request->param('status', ''),//客户状态
"purchasing_power" => $request->param('purchasing_power', ''),//购买力
"cognitive_idea" => $request->param('cognitive_idea', ''),//认知理念
"optional_class_time" => $optional_class_time,//可选上课时间
"distance" => $request->param('distance', ''),//距离
];
//六要素相关数据
$six_speed_data = [
"purchase_power" => $request->param('purchasing_power', ''),//需求购买力
"concept_awareness" => $request->param('cognitive_idea', ''),//认知理念
"promised_visit_time" => $promised_visit_time,//承诺到访时间
"preferred_class_time" => $optional_class_time,//可选上课时间
"distance" => $request->param('distance', ''),//距离
"communication" => $request->param('communication', ''),//沟通备注
"staff_id" => $request->param('staff_id', ''),//人员ID
];
foreach($customer_resources_data as $k=>$v){
if(!isset($v) || $v === ''){
return fail("缺少必填项{$k}");
}
}
foreach($six_speed_data as $k=>$v){
if(!isset($v) || $v === ''){
return fail("缺少必填项{$k}");
}
}
$res = (new CustomerResourcesService())->editData($where,$customer_resources_data,$six_speed_data);
if(!$res['code']){
return fail($res['msg']);
}
return success([]);
}
} }

124
niucloud/app/api/controller/apiController/Personnel.php

@ -36,10 +36,10 @@ class Personnel extends BaseApiService
'id'=>$this->member_id, 'id'=>$this->member_id,
]; ];
$res = (new PersonnelService())->info($where); $res = (new PersonnelService())->info($where);
if(!$res){ if(!$res['code']){
return fail('账户信息有误'); return fail($res['msg']);
} }
return success($res); return success($res['data']);
} }
//员工修改 //员工修改
@ -66,114 +66,20 @@ class Personnel extends BaseApiService
return success([]); return success([]);
} }
/** //人力资源-人员表
* 登录 public function getPersonnelAll(Request $request){
* @return Response //获取员工信息
*/ $where = [
public function login() 'account_type' => $request->param('account_type', ''),//账号类型|teacher=老师,market=销售
{ 'personnel_id' => $request->param('personnel_id', ''),//员工id
$data = $this->request->params([ ];
['username', ''], $field = 'id,name';
['password', ''], $res = (new PersonnelService())->getAll($where,$field);
]); if(!$res){
//校验登录注册配置 return fail('账户信息有误');
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::USERNAME);
//参数验证
//验证码验证
$result = (new LoginService())->account($data['username'], $data['password']);
if (!$result) {
//账号密码错误, 重置验证码
return fail('ACCOUNT_OR_PASSWORD_ERROR');
} }
return success($result); return success($res);
}
/**
* 登出
* @return Response
*/
public function logout()
{
(new LoginService)->logout();
return success('MEMBER_LOGOUT');
}
/**
* 创建验证码
* @return Response
*/
public function captcha()
{
return success((new CaptchaService())->create());
}
/**
* 发送手机验证码
* @param $type
* @return Response
* @throws Exception
*/
public function sendMobileCode($type)
{
$data = $this->request->params([
['mobile', ''],
]);
return success((new LoginService())->sendMobileCode($data['mobile'], $type));
}
/**
* 手机号登录
* @return Response
*/
public function mobile()
{
$data = $this->request->params([
['mobile', ''],
['nickname', ''],
['headimg', ''],
['mobile', '']
]);
//校验登录注册配置
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::MOBILE);
return success((new LoginService())->mobile($data));
}
/**
* 重置密码
* @return Response
*/
public function resetPassword()
{
$data = $this->request->params([
['mobile', ''],
['password', '']
]);
//参数验证
$this->validate($data, 'app\validate\member\Member.reset_password');
(new LoginService())->resetPassword($data['mobile'], $data['password']);
return success('PASSWORD_RESET_SUCCESS');
} }
//销售教师人员登陆
public function personnelLogin()
{
$data = $this->request->params([
['phone', ''],
['password', ''],
['login_type', ''],//登陆类型|1=教练,2=销售
]);
//验证码验证
$result = (new LoginService())->loginByPersonnel($data);
if(!$result['user_type']){
if($data['login_type'] == 1){
$msg = '暂无教练权限';
}else{
$msg = '暂无销售权限';
}
return fail($msg);//code|0错误
}
return success($result);//code|1正确
}
} }

68
niucloud/app/api/controller/apiController/ResourceSharing.php

@ -31,12 +31,80 @@ class ResourceSharing extends BaseApiService
$page = $request->param('page','1');// $page = $request->param('page','1');//
$limit = $request->param('limit','10');// $limit = $request->param('limit','10');//
$shared_by = $request->param('shared_by','');//共享人ID $shared_by = $request->param('shared_by','');//共享人ID
$shared_at_str = $request->param('shared_at_str','');//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)]
$shared_at_arr = [];
if(!empty($shared_at_str)){
$shared_at_arr = explode(' ~ ',$shared_at_str);
$shared_at_arr[0] = "{$shared_at_arr[0]} 00:00:00";
$shared_at_arr[1] = "{$shared_at_arr[1]} 23:59:59";
}
$where = [ $where = [
'shared_by'=>$shared_by, 'shared_by'=>$shared_by,
'shared_at_arr'=>$shared_at_arr,
]; ];
$res= (new ResourceSharingService())->getList($where); $res= (new ResourceSharingService())->getList($where);
return success($res); return success($res);
} }
//资源共享-详情
public function info(Request $request)
{
$resource_sharing_id = $request->param('resource_sharing_id','');//资源共享表id
if(!$resource_sharing_id){
return fail('缺少参数');
}
$where = [
'id' => $resource_sharing_id
];
$res = (new ResourceSharingService())->info($where);
if (!$res['code']) {
return fail($res['msg']);
}
return success($res['data']);
}
//把资源分配给指定员工
public function assign(Request $request)
{
$id = $request->param('resource_sharing_id', '');//资源共享表
$shared_by = $request->param('shared_by', '');//共享人ID
if (empty($id) || empty($shared_by)) {
return fail('缺少必要参数');
}
$where = [
'id' => $id,
];
$data = [
'shared_by' => $shared_by
];
$info = (new ResourceSharingService())->info($where);//获取详情
if (!$info['code']) {
return fail($info['msg']);
} else {
if ($info['data']['shared_by'] > 0) {
if ($info['data']['shared_by'] == $shared_by) {
return success('当前资源已分享给该用户');
} else {
return fail('该资源已被分享给其他用户');
}
}
}
$res = (new ResourceSharingService())->editData($where, $data);//更新
if (!$res['code']) {
return fail('操作失败');
}
return success('操作成功');
}
} }

9
niucloud/app/api/route/route.php

@ -202,12 +202,19 @@ Route::group(function () {
Route::get('personnel/info', 'apiController.Personnel/info'); Route::get('personnel/info', 'apiController.Personnel/info');
//员工端-修改 //员工端-修改
Route::post('personnel/edit', 'apiController.Personnel/edit'); Route::post('personnel/edit', 'apiController.Personnel/edit');
//员工端-获取全部人员列表
Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll');
//客户资源-添加 //客户资源-添加
Route::post('customerResources/add', 'apiController.CustomerResources/add'); Route::post('customerResources/add', 'apiController.CustomerResources/add');
//客户资源-编辑
Route::post('customerResources/edit', 'apiController.CustomerResources/edit');
//资源共享-列表 //资源共享-列表
Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); Route::get('resourceSharing/index', 'apiController.ResourceSharing/index');
//资源共享-详情(客户详情)
Route::get('resourceSharing/info', 'apiController.ResourceSharing/info');
//资源共享-分配员工
Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign');

108
niucloud/app/model/course/Course.php

@ -17,9 +17,9 @@ use think\model\relation\HasMany;
use think\model\relation\HasOne; use think\model\relation\HasOne;
/** /**
* 校区模型 * 课程模型
* Class Campus * Class Course
* @package app\model\campus * @package app\model\course
*/ */
class Course extends BaseModel class Course extends BaseModel
{ {
@ -51,38 +51,122 @@ class Course extends BaseModel
protected $defaultSoftDelete = 0; protected $defaultSoftDelete = 0;
/** /**
* 搜索器:校区校区名称 * 搜索器:课程课程编号
* @param $value * @param $value
* @param $data * @param $data
*/ */
public function searchCampusNameAttr($query, $value, $data) public function searchIdAttr($query, $value, $data)
{ {
if ($value) { if ($value) {
$query->where("campus_name", "like", "%".$value."%"); $query->where("id", $value);
} }
} }
/** /**
* 搜索器:校区校区地址 * 搜索器:课程课程名称
* @param $value * @param $value
* @param $data * @param $data
*/ */
public function searchCampusAddressAttr($query, $value, $data) public function searchCourseNameAttr($query, $value, $data)
{ {
if ($value) { if ($value) {
$query->where("campus_address", $value); $query->where("course_name", $value);
} }
} }
/** /**
* 搜索器:校区校区状态 * 搜索器:课程课程类型
* @param $value * @param $value
* @param $data * @param $data
*/ */
public function searchCampusStatusAttr($query, $value, $data) public function searchCourseTypeAttr($query, $value, $data)
{ {
if ($value) { if ($value) {
$query->where("campus_status", $value); $query->where("course_type", $value);
}
}
/**
* 搜索器:课程课程时长
* @param $value
* @param $data
*/
public function searchDurationAttr($query, $value, $data)
{
if ($value) {
$query->where("duration", $value);
}
}
/**
* 搜索器:课程课时数量
* @param $value
* @param $data
*/
public function searchSessionCountAttr($query, $value, $data)
{
if ($value) {
$query->where("session_count", $value);
}
}
/**
* 搜索器:课程单次逍客数量
* @param $value
* @param $data
*/
public function searchSingleSessionCountAttr($query, $value, $data)
{
if ($value) {
$query->where("single_session_count", $value);
}
}
/**
* 搜索器:课程课程价格
* @param $value
* @param $data
*/
public function searchPriceAttr($query, $value, $data)
{
if ($value) {
$query->where("price", $value);
}
}
/**
* 搜索器:课程内部提醒课时
* @param $value
* @param $data
*/
public function searchInternalReminderAttr($query, $value, $data)
{
if ($value) {
$query->where("internal_reminder", $value);
}
}
/**
* 搜索器:课程客户提醒课时
* @param $value
* @param $data
*/
public function searchCustomerReminderAttr($query, $value, $data)
{
if ($value) {
$query->where("customer_reminder", $value);
}
}
/**
* 搜索器:课程课程备注
* @param $value
* @param $data
*/
public function searchRemarksAttr($query, $value, $data)
{
if ($value) {
$query->where("remarks", $value);
} }
} }

180
niucloud/app/model/customer_resources/CustomerResources.php

@ -11,7 +11,9 @@
namespace app\model\customer_resources; namespace app\model\customer_resources;
use app\model\dict\Dict;
use app\model\resource_sharing\ResourceSharing; use app\model\resource_sharing\ResourceSharing;
use app\model\six_speed\SixSpeed;
use core\base\BaseModel; use core\base\BaseModel;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use think\model\relation\HasMany; use think\model\relation\HasMany;
@ -84,6 +86,7 @@ class CustomerResources extends BaseModel
//获取顾问名字
public function personnel(){ public function personnel(){
return $this->hasOne(Personnel::class, 'id', 'consultant')->joinType('left')->withField('name,id')->bind(['consultant_name'=>'name']); return $this->hasOne(Personnel::class, 'id', 'consultant')->joinType('left')->withField('name,id')->bind(['consultant_name'=>'name']);
} }
@ -99,4 +102,181 @@ class CustomerResources extends BaseModel
} }
//一对一关联six_speed模型
public function sixSpeed()
{
return $this->hasOne(SixSpeed::class, 'resource_id', 'id');
}
/**
* 获取客户初步意向度类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getInitialIntentNameAttr($value, $data)
{
$key = 'preliminarycustomerintention';
$val = (String)$data['initial_intent'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取来源渠道类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getSourceChannelNameAttr($value, $data)
{
$key = 'SourceChannel';
$val = (String)$data['source_channel'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
$arr = [
"name" => "线下",
"value" => "0",
"sort" => 0,
"memo" => "",
];
array_unshift($dictionary, $arr);
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取来源类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getSourceNameAttr($value, $data)
{
$key = 'source';
$val = (String)$data['source'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取性别类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getGenderNameAttr($value, $data)
{
$key = 'zy_sex';
$val = (String)$data['gender'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取购买力类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getPurchasingPowerNameAttr($value, $data)
{
$key = 'customer_purchasing_power';
$val = (String)$data['purchasing_power'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取客户状态类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getStatusNameAttr($value, $data)
{
$key = 'kh_status';
$val = (String)$data['status'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
} }

56
niucloud/app/model/six_speed/SixSpeed.php

@ -11,6 +11,7 @@
namespace app\model\six_speed; namespace app\model\six_speed;
use app\model\dict\Dict;
use core\base\BaseModel; use core\base\BaseModel;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use think\model\relation\HasMany; use think\model\relation\HasMany;
@ -67,4 +68,59 @@ class SixSpeed extends BaseModel
return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']);
} }
/**
* 获取需求购买力类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getPurchasePowerNameAttr($value, $data)
{
$key = 'customer_purchasing_power';
$val = (String)$data['purchase_power'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
/**
* 获取认知理念类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getConceptAwarenessNameAttr($value, $data)
{
$key = 'customer_purchasing_power';
$val = (String)$data['concept_awareness'];
if ((!empty($val) || isset($val)) && $val !== '') {
$dict = Dict::where('key',$key)->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] == $val) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
} }

37
niucloud/app/service/api/apiService/CommonService.php

@ -43,4 +43,41 @@ class CommonService extends BaseApiService
} }
/**
* 对比新旧数据改变
* @param array $old_data 旧数据
* @param array $new_data 新数据
* @param array $ignoreFields 忽略验证的字段|默认[]
* @return array
*/
public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at'])
{
$changedFields = [];//改了那些字段
$oldChanges = [];//数据修改前的样子
$newChanges = [];//数据修改后的样子
foreach ($new_data as $key => $value) {
// 如果字段在忽略列表中,则跳过
if (in_array($key, $ignoreFields)) {
continue;
}
if (!isset($old_data[$key]) || $old_data[$key] != $value) {
$changedFields[] = $key;
$oldChanges[$key] = $old_data[$key] ?? null;
$newChanges[$key] = $value;
}
}
return [
'changed_fields' => $changedFields,
'old_values' => $oldChanges,
'new_values' => $newChanges,
'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE),
'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE),
'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE)
];
}
} }

122
niucloud/app/service/api/apiService/CustomerResourcesService.php

@ -11,10 +11,13 @@
namespace app\service\api\apiService; namespace app\service\api\apiService;
use app\model\campus_person_role\CampusPersonRole;
use app\model\customer_resource_changes\CustomerResourceChanges;
use app\model\customer_resources\CustomerResources; use app\model\customer_resources\CustomerResources;
use app\model\personnel\Personnel; use app\model\personnel\Personnel;
use app\model\resource_sharing\ResourceSharing; use app\model\resource_sharing\ResourceSharing;
use app\model\six_speed\SixSpeed; use app\model\six_speed\SixSpeed;
use app\model\six_speed_modification_log\SixSpeedModificationLog;
use core\base\BaseApiService; use core\base\BaseApiService;
use think\facade\Db; use think\facade\Db;
@ -85,4 +88,123 @@ class CustomerResourcesService extends BaseApiService
} }
} }
//客户资源-编辑
public function editData(array $where, array $customer_resources_data, array $six_speed_data)
{
$operator_id = $this->member_id;//当前登录用户的id(日志操作人的id)
$campus_id = 0;//日志操作人校区的id
$campus_id_arr = CampusPersonRole::where('person_id', $operator_id)->column('campus_id');
if (count($campus_id_arr)) {
if (count($campus_id_arr) > 1) {
$campus_id = 0;
} else {
$campus_id = $campus_id_arr[0];
}
}
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '查询条件不能为空';
return $res;
}
$date = date('Y-m-d H:i:s');
$customer_resources_data['updated_at'] = $date;
$six_speed_data['updated_at'] = $date;
//开启事物
Db::startTrans();
try {
$customer_resources = CustomerResources::where('id', $where['id'])->find();
if ($customer_resources) {
$customer_resources = $customer_resources->toArray();
}
$update_1 = CustomerResources::where('id', $where['id'])->update($customer_resources_data);//客户资源表
if (!$update_1) {
Db::rollback();
return $res;
}
//更近客户资源日志表
$compareData = (new CommonService)->compareData($customer_resources, $customer_resources_data);
if ($compareData['changed_fields']) {
$data = [
"customer_resource_id" => $where['id'],//客户资源的ID
"operator_id" => $operator_id,//操作人的ID
"campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0
"modified_fields" => $compareData['changed_fields_json'],//修改的哪些字段
"old_values" => $compareData['old_values_json'],//修改前的值
"new_values" => $compareData['new_values_json'],//修改后的值
];
$id = CustomerResourceChanges::insertGetId($data);
if (!$id) {
Db::rollback();
return $res;
}
}
$six_speed_data['resource_id'] = $where['id'];
//查六要素是否存在
$six_speed = SixSpeed::where('resource_id', $where['id'])->find();
if ($six_speed) {
$six_speed = $six_speed->toArray();
//更新六要素
$sixSpeedUpdate = SixSpeed::where('id', $six_speed['id'])->update($six_speed_data);
if (!$sixSpeedUpdate) {
Db::rollback();
return $res;
}
//更近六要素日志表
$compareData = (new CommonService)->compareData($six_speed, $six_speed_data);
if ($compareData['changed_fields']) {
$data = [
"operator_id" => $operator_id,//操作人的ID
"campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0
"customer_resource_id" => $where['id'],//客户资源的ID
"modified_field" => $compareData['changed_fields_json'],//修改的哪些字段
"old_value" => $compareData['old_values_json'],//修改前的值
"new_value" => $compareData['new_values_json'],//修改后的值
];
$id = SixSpeedModificationLog::insertGetId($data);
if (!$id) {
Db::rollback();
return $res;
}
}
} else {
//创建六要素
$sixSpeedUpdate = SixSpeed::create($six_speed_data);
if (!$sixSpeedUpdate) {
Db::rollback();
return $res;
}
}
Db::commit();
$res = [
'code' => 1,
'msg' => '操作成功'
];
return $res;
} catch (\Exception $exception) {
Db::rollback();
return $res;
}
}
} }

72
niucloud/app/service/api/apiService/PersonnelService.php

@ -38,10 +38,20 @@ class PersonnelService extends BaseApiService
//获取员工信息 //获取员工信息
public function info(array $where,string $field = '*'){ public function info(array $where,string $field = '*'){
$model = $this->model; $model = $this->model;
$res = [
'code'=>0,
'msg'=>'请添加检索条件',
'data'=>[]
];
if(!$where){
return $res;
}
if(!empty($where['id'])){ if(!empty($where['id'])){
$model = $model->where('id',$where['id']); $model = $model->where('id',$where['id']);
} }
$res = $model->field($field)->find();//员工信息 $data = $model->field($field)->find();//员工信息
//查询部门信息 //查询部门信息
$campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray();
@ -63,16 +73,23 @@ class PersonnelService extends BaseApiService
$department_name_str = implode(',',$department_name_arr); $department_name_str = implode(',',$department_name_arr);
if($res){ if($data){
$res = $res->toArray(); $data = $data->toArray();
$res['role']=$role; $data['role']=$role;
$res['role_name_str'] = $role_name_str; $data['role_name_str'] = $role_name_str;
$res['role_key_arr'] = $role_key_arr; $data['role_key_arr'] = $role_key_arr;
$res['department_name_str'] = $department_name_str; $data['department_name_str'] = $department_name_str;
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data;
}else{ }else{
$res = []; $data = [];
$res['code'] = 0;
$res['msg'] = '为找到数据';
$res['data'] = $data;
} }
return $res; return $res;
} }
@ -109,6 +126,45 @@ class PersonnelService extends BaseApiService
} }
//员工信息-获取全部用户
public function getAll(array $where,string $field = '*')
{
if (!$where) {
return [
'code' => 0,
'msg' => '查询条件不能为空'
];
}
$model = $this->model;
//存在员工id的时候
if ((!empty($where['personnel_id']) || isset($where['personnel_id'])) && $where['personnel_id'] !== '') {
//查询这个员工的校区id
$campus_id = CampusPersonRole::where('person_id', $where['personnel_id'])
->distinct(true)
->column('campus_id');
if ($campus_id) {
$person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id)
->distinct(true)
->column('person_id');
if ($person_id_arr) {
//根据校区id获取校区下的全部员工
$model = $model->whereIn('id', $person_id_arr);
}
}
}
if (empty($where['account_type'])) {
$model = $model->where('account_type', $where['account_type']);
}
$res = $model->field($field)
->select()
->toArray();//员工信息
return $res;
}

108
niucloud/app/service/api/apiService/ResourceSharingService.php

@ -12,6 +12,7 @@
namespace app\service\api\apiService; namespace app\service\api\apiService;
use app\model\campus_person_role\CampusPersonRole; use app\model\campus_person_role\CampusPersonRole;
use app\model\order_table\OrderTable;
use app\model\resource_sharing\ResourceSharing; use app\model\resource_sharing\ResourceSharing;
use core\base\BaseApiService; use core\base\BaseApiService;
@ -38,20 +39,32 @@ class ResourceSharingService extends BaseApiService
$person_id = $this->member_id;//当前登录的员工id $person_id = $this->member_id;//当前登录的员工id
//查当前用户的归属校区 //查当前用户的归属校区
$campus_id = CampusPersonRole::where('person_id',$person_id)->value('campus_id'); $campus_id = CampusPersonRole::where('person_id',$person_id)
->distinct(true)
->column('campus_id');
//查当前用户校区下的全部员工id //查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::where('campus_id',$campus_id) ->distinct(true) $person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id)
->distinct(true)
->column('person_id'); ->column('person_id');
$model = $this->model; $model = $this->model;
if (!isset($where['shared_by']) && $where['shared_by'] !== '') {
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->where('shared_by', $where['shared_by']); $model = $model->where('shared_by', $where['shared_by']);
} }
if (!empty($where['shared_at_arr'])) {
$model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]);
}
$model = $model->whereIn('user_id', $person_id_arr); $model = $model->whereIn('user_id', $person_id_arr);
//分页查询 //分页查询
$res = $model->with([ $res = $model->with([
'customerResource'=>function($query){} 'customerResource'=>function($query){
$query->append(['initial_intent_name']);
}
])->paginate([ ])->paginate([
'list_rows' => $limit, 'list_rows' => $limit,
'page' => $page, 'page' => $page,
@ -61,4 +74,91 @@ class ResourceSharingService extends BaseApiService
} }
//查询资源共享详情
public function info(array $where, string $field = '*')
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '缺少查询条件';
return $res;
}
$model = $this->model;
if (!empty($where['id'])) {
$model = $model->where('id', $where['id']);
}
$data = $model->with([
'customerResource'=>function($query){
$query->with([
'sixSpeed'=>function($query_2){
$query_2->append([
'purchase_power_name',//购买力
'concept_awareness_name',//认知理念
]);
},
'personnel'=>function($query_2){}
])->append([
'source_channel_name',//来源渠道
'source_name',//来源
'gender_name',//性别
'purchasing_power_name',//购买力
'cognitive_idea_name',//认知理念
'initial_intent_name',//客户初步意向度
'status_name',//客户状态
]);
}
])->field($field)->find();
if (!empty($data['customerResource'])) {
$data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id'])
->where('order_status', 'paid')
->count();//成交次数
}
if ($data) {
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data->toArray();
} else {
$res['code'] = 0;
$res['msg'] = '未找到数据';
$res['data'] = [];
}
return $res;
}
//更新资源共享表
public function editData(array $where, array $data)
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '查询条件不能为空';
return $res;
}
$model = $this->model;
if ($where['id']) {
$model = $model->where('id', $where['id']);
}
$data = $model->update($data);
if ($data) {
$res = [
'code' => 1,
'msg' => '操作成功',
'data' => []
];
}
return $res;
}
} }

Loading…
Cancel
Save