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.
240 lines
8.6 KiB
240 lines
8.6 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\customer_resources;
|
|
|
|
use app\model\customer_resource_changes\CustomerResourceChanges;
|
|
use app\model\customer_resources\CustomerResources;
|
|
use app\model\personnel\Personnel;
|
|
use app\model\campus\Campus;
|
|
|
|
use app\model\six_speed\SixSpeed;
|
|
use app\model\six_speed_modification_log\SixSpeedModificationLog;
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 客户资源服务层
|
|
* Class CustomerResourcesService
|
|
* @package app\service\admin\customer_resources
|
|
*/
|
|
class CustomerResourcesService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new CustomerResources();
|
|
}
|
|
|
|
/**
|
|
* 获取客户资源列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,create_year_month,create_date,source,source_channel,consultant,name,age,gender,phone_number,demand,purchasing_power,cognitive_idea,optional_class_time,distance,decision_maker,initial_intent,campus,created_at,updated_at,deleted_at,status';
|
|
$order = 'id desc';
|
|
|
|
$search_model = $this->model->withSearch(["name","phone_number"], $where)->with(['personnel'])->field($field)->order($order);
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取客户资源信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,create_year_month,create_date,source,source_channel,consultant,name,age,gender,phone_number,demand,purchasing_power,cognitive_idea,optional_class_time,distance,decision_maker,initial_intent,campus,created_at,updated_at,deleted_at,status';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['personnel'])->findOrEmpty()->toArray();
|
|
|
|
$sixSpeed = new SixSpeed();
|
|
$data = $sixSpeed->where(['resource_id' => $id])->field("*,distance as distance_tow")->findOrEmpty()->toArray();
|
|
$info = $info+$data;
|
|
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加客户资源
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
$personnel = new Personnel();
|
|
$data['consultant'] = $personnel->where(['sys_user_id' => $this->uid])->value("id");
|
|
if(!$data['consultant']){
|
|
return fail("操作失败");
|
|
}
|
|
$sixSpeed = new SixSpeed();
|
|
|
|
$res = $this->model->create($data);
|
|
|
|
if($data['purchase_power']){
|
|
$six_id = $sixSpeed->where(['resource_id' => $res->id])->value("id");
|
|
$data['staff_id'] = $data['consultant'];
|
|
|
|
$field = [
|
|
'purchase_power' => $data['purchase_power'],
|
|
'concept_awareness' => $data['concept_awareness'],
|
|
'preferred_class_time' => $data['preferred_class_time'],
|
|
'distance' => $data['distance_tow'],
|
|
'communication' => $data['communication'],
|
|
'promised_visit_time' => $data['promised_visit_time'],
|
|
'actual_visit_time' => $data['actual_visit_time'],
|
|
'call_intent' => $data['call_intent'],
|
|
'first_visit_status' => $data['first_visit_status'],
|
|
'second_visit_status' => $data['second_visit_status'],
|
|
'is_closed' => $data['is_closed'],
|
|
'staff_id' => $data['staff_id'],
|
|
'resource_id' => $res->id
|
|
];
|
|
if($six_id){
|
|
$sixSpeed->where(['resource_id' => $res->id])->update($field);
|
|
}else{
|
|
$sixSpeed->insert($field);
|
|
}
|
|
}
|
|
return success("操作成功");
|
|
|
|
}
|
|
|
|
/**
|
|
* 客户资源编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
$personnel = new Personnel();
|
|
$data['consultant'] = $personnel->where(['sys_user_id' => $this->uid])->value("id");
|
|
if(!$data['consultant']){
|
|
return fail("操作失败");
|
|
}
|
|
|
|
// $data['consultant'] = 1;
|
|
$res = $this->model->where([['id', '=', $id]])->findOrEmpty()->toArray();
|
|
|
|
|
|
$this->model->where([['id', '=', $id]])->update([
|
|
'source' => $data['source'],
|
|
'source_channel' => $data['source_channel'],
|
|
'consultant' => $data['consultant'],
|
|
'name' => $data['name'],
|
|
'age' => $data['age'],
|
|
'gender' => $data['gender'],
|
|
'phone_number' => $data['phone_number'],
|
|
'demand' => $data['demand'],
|
|
'purchasing_power' => $data['purchasing_power'],
|
|
'cognitive_idea' => $data['cognitive_idea'],
|
|
'optional_class_time' => $data['optional_class_time'],
|
|
'distance' => $data['distance'],
|
|
'decision_maker' => $data['decision_maker'],
|
|
'initial_intent' => $data['initial_intent'],
|
|
'campus' => $data['campus'],
|
|
'status' => $data['status'],
|
|
'create_year_month' => $data['create_year_month'],
|
|
'create_date' => $data['create_date']
|
|
]);
|
|
|
|
$resources_save = getModifiedFields($res,$data);
|
|
|
|
$customerResourceChanges = new CustomerResourceChanges();
|
|
if($resources_save['is_save']){
|
|
$customerResourceChanges->insert([
|
|
'customer_resource_id' => $id,
|
|
'operator_id' => $data['consultant'],
|
|
'campus_id' => $data['campus'],
|
|
'modified_fields' => $resources_save['modified_fields'],
|
|
'old_values' => $resources_save['old_values'],
|
|
'new_values' => $resources_save['new_values']
|
|
]);
|
|
}
|
|
|
|
|
|
$sixSpeed = new SixSpeed();
|
|
if($data['purchase_power']){
|
|
$sixSpeedModificationLog = new SixSpeedModificationLog();
|
|
$six_id = $sixSpeed->where(['resource_id' => $id])->value("id");
|
|
$data['staff_id'] = $data['consultant'];
|
|
|
|
|
|
|
|
$field = [
|
|
'purchase_power' => $data['purchase_power'],
|
|
'concept_awareness' => $data['concept_awareness'],
|
|
'preferred_class_time' => $data['preferred_class_time'],
|
|
'distance' => $data['distance_tow'],
|
|
'communication' => $data['communication'],
|
|
'promised_visit_time' => $data['promised_visit_time'],
|
|
'actual_visit_time' => $data['actual_visit_time'],
|
|
'call_intent' => $data['call_intent'],
|
|
'first_visit_status' => $data['first_visit_status'],
|
|
'second_visit_status' => $data['second_visit_status'],
|
|
'is_closed' => $data['is_closed'],
|
|
'staff_id' => $data['staff_id'],
|
|
'resource_id' => $id
|
|
];
|
|
if($six_id){
|
|
$six_log = $sixSpeed->where(['resource_id' => $id])->findOrEmpty()->toArray();
|
|
$six_save = getModifiedFields($six_log,$field);
|
|
|
|
if($six_save['is_save']){
|
|
|
|
$sixSpeedModificationLog->insert([
|
|
'customer_resource_id' => $id,
|
|
'operator_id' => $data['consultant'],
|
|
'campus_id' => $data['campus'],
|
|
'modified_field' => $six_save['modified_fields'],
|
|
'old_value' => $six_save['old_values'],
|
|
'new_value' => $six_save['new_values']
|
|
]);
|
|
}
|
|
|
|
$sixSpeed->where(['resource_id' => $id])->update($field);
|
|
}else{
|
|
$sixSpeed->insert($field);
|
|
}
|
|
}
|
|
|
|
return success("操作成功");
|
|
}
|
|
|
|
/**
|
|
* 删除客户资源
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$model = $this->model->where([['id', '=', $id]])->find();
|
|
$res = $model->delete();
|
|
return $res;
|
|
}
|
|
|
|
|
|
public function getPersonnelAll(){
|
|
$personnelModel = new Personnel();
|
|
return $personnelModel->select()->toArray();
|
|
}
|
|
|
|
public function getCampusAll(){
|
|
$campusModel = new Campus();
|
|
return $campusModel->select()->toArray();
|
|
}
|
|
|
|
|
|
}
|
|
|