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.
243 lines
9.5 KiB
243 lines
9.5 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
|
|
{
|
|
|
|
|
|
//获取全部客户资源
|
|
public function getAll(Request $request)
|
|
{
|
|
|
|
$name = $request->param('name', '');//客户姓名
|
|
$phone_number = $request->param('phone_number', '');//客户手机号
|
|
if (empty($name) && empty($phone_number)) {
|
|
return fail("缺少查询参数");
|
|
}
|
|
|
|
$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('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" => $param['consultant'] ?? 0,
|
|
"name" => $param['name'] ?? '',
|
|
"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'] ?? '',
|
|
];
|
|
|
|
$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("手机号已存在");
|
|
}
|
|
|
|
$res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
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', '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', ''),//沟通备注
|
|
"staff_id" => $request->param('staff_id', ''),//人员ID//如果没有就是当前登录人的员工id
|
|
|
|
"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', ''),
|
|
"is_bm" => $request->param('is_bm', 1),
|
|
"consultation_remark" => $request->param('consultation_remark', ''),
|
|
];
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
foreach ($six_speed_data as $k => $v) {
|
|
// 排除 first_visit_status 和 second_visit_status 的必填校验
|
|
if (in_array($k, ['first_visit_status', 'second_visit_status'])) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$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);
|
|
}
|
|
|
|
|
|
}
|
|
|