You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
367 lines
14 KiB
367 lines
14 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\model\personnel\Personnel;
|
|
use app\Request;
|
|
use app\service\api\apiService\CustomerResourcesService;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 客户资源相关接口
|
|
* Class Personnel
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class CustomerResources extends BaseApiService
|
|
{
|
|
|
|
/**
|
|
* 转换gender枚举值
|
|
* school_customer_resources: male/female/other
|
|
* school_student: 1/2/0
|
|
*/
|
|
private function convertGender($gender)
|
|
{
|
|
switch ($gender) {
|
|
case 'male':
|
|
return 1;
|
|
case 'female':
|
|
return 2;
|
|
case 'other':
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
//获取全部客户资源
|
|
public function getAll(Request $request)
|
|
{
|
|
|
|
$name = $request->param('name', '');//客户姓名
|
|
$phone_number = $request->param('phone_number', '');//客户手机号
|
|
$where = [
|
|
'name' => $name,
|
|
'phone_number' => $phone_number
|
|
];
|
|
$res = (new CustomerResourcesService())->getAll($where);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//客户资源添加
|
|
public function add(Request $request)
|
|
{
|
|
|
|
$date = date('Y-m-d');
|
|
$param = $request->param();
|
|
$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));
|
|
}
|
|
$personnel = new Personnel();
|
|
$role_id = $personnel->alias("a")
|
|
->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left')
|
|
->where(['a.id' => $request->param('staff_id', '')]) // 使用staff_id而不是consultant
|
|
->value('b.role_id');
|
|
|
|
$customer_resources_data = [
|
|
"create_year_month" => date('Y-m'),
|
|
"create_date" => $date,
|
|
"source_channel" => $param['source_channel'] ?? '',
|
|
"source" => $param['source'] ?? '',
|
|
"consultant" => 0, // 设置为0而不是当前登录人
|
|
"name" => $param['name'] ?? '',
|
|
"age" => $param['age'] ?? '', // 添加年龄字段
|
|
"gender" => $param['gender'] ?? 'other',//性别
|
|
"phone_number" => $param['phone_number'] ?? '',
|
|
"demand" => $param['demand'] ?? '',
|
|
"decision_maker" => $param['decision_maker'] ?? 0,
|
|
"initial_intent" => $param['initial_intent'] ?? 'low',//客户初步意向度
|
|
"status" => $param['status'] ?? 'pending',//客户状态
|
|
"purchasing_power" => $param['purchasing_power'],
|
|
"cognitive_idea" => $param['cognitive_idea'],
|
|
"optional_class_time" => $optional_class_time,
|
|
"distance" => $param['distance'],
|
|
// 新资源有2节体验课
|
|
"trial_class_count" => 2,
|
|
"rf_type" => get_role_type($role_id),
|
|
'campus' => $param['campus'] ?? '',
|
|
'referral_resource_id' => $param['referral_resource_id'] ?? 0, // 转介绍推荐人资源ID
|
|
];
|
|
|
|
$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
|
|
"efficacious" => $request->param('efficacious', 1),
|
|
];
|
|
|
|
if (strlen($customer_resources_data['phone_number']) > 12) {
|
|
return fail("联系电话不能超过12位");
|
|
}
|
|
|
|
//验证手机号是否存在
|
|
$info = (new CustomerResourcesService())->getInfo(['phone_number' => $customer_resources_data['phone_number']]);
|
|
if (!empty($info['data']['id'])) {
|
|
return fail("手机号已存在");
|
|
}
|
|
|
|
// 准备school_student表数据
|
|
$student_data = [
|
|
"name" => $param['name'] ?? '',
|
|
"gender" => $this->convertGender($param['gender'] ?? 'other'), // 转换gender枚举值
|
|
"age" => floatval($param['age'] ?? 0), // 转换为decimal
|
|
"birthday" => $param['birthday'] ?? null, // 前端计算的生日
|
|
"campus_id" => $param['campus'] ?? 0,
|
|
"headimg" => '', // 默认空字符串
|
|
"trial_class_count" => 2, // 默认2
|
|
"status" => 1, // 状态设置为1
|
|
"created_person_id" => $request->param('staff_id', 0), // 当前登录人
|
|
];
|
|
|
|
// 获取当前登录人的staff_id
|
|
$staff_id = $request->param('staff_id', 0);
|
|
|
|
$res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data, $student_data, $staff_id, $role_id);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success([]);
|
|
}
|
|
|
|
//客户资源-编辑
|
|
public function edit(Request $request)
|
|
{
|
|
$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 = [
|
|
"campus" => $request->param('campus', ''),
|
|
"source_channel" => $request->param('source_channel', ''),//来源渠道
|
|
"source" => $request->param('source', ''),//来源
|
|
"name" => $request->param('name', ''),//姓名
|
|
"age" => $request->param('age', ''),//年龄
|
|
"gender" => $request->param('gender', 'other'),//性别
|
|
"phone_number" => $request->param('phone_number', ''),//联系电话
|
|
"demand" => $request->param('demand', ''),//需求
|
|
"decision_maker" => $request->param('decision_maker', ''),//决策人
|
|
"initial_intent" => $request->param('initial_intent', 'low'),//客户初步意向度
|
|
"status" => $request->param('status', 'pending'),//客户状态
|
|
"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', ''),//沟通备注
|
|
|
|
"efficacious" => $request->param('efficacious', 1),
|
|
"first_visit_time" => $request->param('first_visit_time', ''),
|
|
"first_visit_status" => $request->param('first_visit_status', ''),
|
|
"second_visit_time" => $request->param('second_visit_time', ''),
|
|
"second_visit_status" => $request->param('second_visit_status', ''),
|
|
"chasing_orders" => $request->param('chasing_orders', ''),
|
|
"consultation_remark" => $request->param('consultation_remark', ''),
|
|
"call_intent" => $request->param('call_intent', '')
|
|
|
|
];
|
|
|
|
|
|
|
|
if (strlen($customer_resources_data['phone_number']) > 12) {
|
|
return fail("联系电话不能超过12位");
|
|
}
|
|
|
|
//如果六要素人员id没有就是当前登录人的员工id
|
|
if (empty($six_speed_data['staff_id'])) {
|
|
$six_speed_data['staff_id'] = $this->member_id;
|
|
}
|
|
|
|
$res = (new CustomerResourcesService())->editData($where, $customer_resources_data, $six_speed_data);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success([]);
|
|
}
|
|
|
|
//客户资源-修改记录列表
|
|
public function getEditLogList(Request $request)
|
|
{
|
|
//前端要传递分页(page,limit)参数
|
|
$customer_resource_id = $request->param('customer_resource_id', '');
|
|
$type = $request->param('type', 'resource');//查询类型|resource=客户资源,six_speed=六要素
|
|
|
|
if (empty($customer_resource_id) || empty($type)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
if (!in_array($type, ['resource', 'six_speed'])) {
|
|
return fail('类型不正确');
|
|
}
|
|
|
|
$where = [
|
|
'customer_resource_id' => $customer_resource_id
|
|
];
|
|
|
|
if ($type == 'resource') {
|
|
//resource=客户资源
|
|
$res = (new CustomerResourcesService())->getCustomerResourceChangesEditLog($where);
|
|
} else {
|
|
$res = (new CustomerResourcesService())->getSixSpeedModificationEditLog($where);
|
|
}
|
|
|
|
return success($res);
|
|
}
|
|
|
|
//修改用户课程的主教、助教、教务
|
|
public function updateUserCourse(Request $request)
|
|
{
|
|
$main_coach_id = $request->param('main_coach_id', '');
|
|
$assistant_ids = $request->param('assistant_ids', '');
|
|
$id = $request->param('id', '');
|
|
$education_id = $request->param('education_id', '');//查询类型|resource=客户资源,six_speed=六要素
|
|
|
|
if (empty($customer_resource_id) || empty($course_id) || empty($staff_id) || empty($type)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
//修改用户课程的主教、助教、教务
|
|
$res = (new CustomerResourcesService())->updateUserCourseInfo([
|
|
'id' => $id,
|
|
'main_coach_id' => $main_coach_id,
|
|
'assistant_ids' => $assistant_ids,
|
|
'education_id' => $education_id
|
|
]);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success([]);
|
|
}
|
|
|
|
//获取客户赠品记录列表
|
|
public function getGiftRecordList(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');
|
|
|
|
if (empty($resource_id)) {
|
|
return fail('缺少客户资源ID');
|
|
}
|
|
|
|
$res = (new CustomerResourcesService())->getGiftRecordList(['resource_id' => $resource_id]);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//获取学生标签信息
|
|
public function getStudentLabel(Request $request)
|
|
{
|
|
$id = $request->param('id', '');
|
|
|
|
if (empty($id)) {
|
|
return fail('缺少标签ID');
|
|
}
|
|
|
|
$res = (new CustomerResourcesService())->getStudentLabel(['label_id' => $id]);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//获取所有学生标签列表
|
|
public function getAllStudentLabels(Request $request)
|
|
{
|
|
$res = (new CustomerResourcesService())->getAllStudentLabels();
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//搜索学员(用于课程安排)
|
|
public function searchStudents(Request $request)
|
|
{
|
|
$name = $request->param('name', '');//学员姓名
|
|
$phone_number = $request->param('phone_number', '');//学员手机号
|
|
$where = [
|
|
'name' => $name,
|
|
'phone_number' => $phone_number
|
|
];
|
|
$res = (new CustomerResourcesService())->searchStudents($where);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//获取预设学员信息(不受状态限制)
|
|
public function getPresetStudentInfo(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');
|
|
$student_id = $request->param('student_id', '');
|
|
|
|
if (empty($resource_id) && empty($student_id)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
$where = [
|
|
'resource_id' => $resource_id,
|
|
'student_id' => $student_id
|
|
];
|
|
$res = (new CustomerResourcesService())->getPresetStudentInfo($where);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
}
|
|
|