|
|
|
@ -11,6 +11,7 @@ |
|
|
|
|
|
|
|
namespace app\api\controller\apiController; |
|
|
|
|
|
|
|
use app\model\personnel\Personnel; |
|
|
|
use app\Request; |
|
|
|
use app\service\api\apiService\CustomerResourcesService; |
|
|
|
use core\base\BaseApiService; |
|
|
|
@ -25,44 +26,50 @@ class CustomerResources extends BaseApiService |
|
|
|
|
|
|
|
|
|
|
|
//获取全部客户资源 |
|
|
|
public function getAll(Request $request){ |
|
|
|
public function getAll(Request $request) |
|
|
|
{ |
|
|
|
|
|
|
|
$name = $request->param('name', '');//客户姓名 |
|
|
|
$phone_number = $request->param('phone_number', '');//客户手机号 |
|
|
|
if(empty($name) && empty($phone_number)){ |
|
|
|
if (empty($name) && empty($phone_number)) { |
|
|
|
return fail("缺少查询参数"); |
|
|
|
} |
|
|
|
|
|
|
|
$where = [ |
|
|
|
'name'=>$name, |
|
|
|
'phone_number'=>$phone_number |
|
|
|
'name' => $name, |
|
|
|
'phone_number' => $phone_number |
|
|
|
]; |
|
|
|
$res = (new CustomerResourcesService())->getAll($where); |
|
|
|
if(!$res['code']){ |
|
|
|
if (!$res['code']) { |
|
|
|
return fail($res['msg']); |
|
|
|
} |
|
|
|
return success($res['data']); |
|
|
|
} |
|
|
|
|
|
|
|
//客户资源添加 |
|
|
|
public function add(Request $request){ |
|
|
|
public function add(Request $request) |
|
|
|
{ |
|
|
|
|
|
|
|
$date = date('Y-m-d'); |
|
|
|
|
|
|
|
$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)); |
|
|
|
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 ($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('Y-m-d'), |
|
|
|
"create_year_month" => date('Y-m'), |
|
|
|
"create_date" => $date, |
|
|
|
"source_channel" => $request->param('source_channel', ''), |
|
|
|
"source" => $request->param('source', ''), |
|
|
|
"consultant" => $request->param('consultant', ''), |
|
|
|
@ -78,6 +85,9 @@ class CustomerResources extends BaseApiService |
|
|
|
"cognitive_idea" => $request->param('cognitive_idea', ''), |
|
|
|
"optional_class_time" => $optional_class_time, |
|
|
|
"distance" => $request->param('distance', ''), |
|
|
|
// 新资源有2节体验课 |
|
|
|
"trial_class_count" => 2, |
|
|
|
"rf_type" => get_role_type($role_id), |
|
|
|
]; |
|
|
|
|
|
|
|
$six_speed_data = [ |
|
|
|
@ -90,61 +100,56 @@ class CustomerResources extends BaseApiService |
|
|
|
"staff_id" => $request->param('staff_id', ''),//人员ID |
|
|
|
]; |
|
|
|
|
|
|
|
foreach($customer_resources_data as $k=>$v){ |
|
|
|
if(!isset($v) || $v === ''){ |
|
|
|
return fail("缺少必填项{$k}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strlen($customer_resources_data['phone_number']) > 12) { |
|
|
|
return fail("联系电话不能超过12位"); |
|
|
|
} |
|
|
|
|
|
|
|
foreach($six_speed_data as $k=>$v){ |
|
|
|
if(!isset($v) || $v === ''){ |
|
|
|
foreach ($six_speed_data as $k => $v) { |
|
|
|
if (!isset($v) || $v === '') { |
|
|
|
return fail("缺少必填项{$k}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//验证手机号是否存在 |
|
|
|
$info = (new CustomerResourcesService())->getInfo(['phone_number'=>$customer_resources_data['phone_number']]); |
|
|
|
if(!empty($info['data']['id'])){ |
|
|
|
$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']){ |
|
|
|
$res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data); |
|
|
|
if (!$res['code']) { |
|
|
|
return fail($res['msg']); |
|
|
|
} |
|
|
|
return success([]); |
|
|
|
} |
|
|
|
|
|
|
|
//客户资源-编辑 |
|
|
|
public function edit(Request $request){ |
|
|
|
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)); |
|
|
|
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 ($optional_class_time) { |
|
|
|
$optional_class_time = date('Y-m-d H:i:s', strtotime($optional_class_time)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(empty($customer_resources_id)){ |
|
|
|
if (empty($customer_resources_id)) { |
|
|
|
return fail("缺少客户id"); |
|
|
|
} |
|
|
|
|
|
|
|
$where=[ |
|
|
|
'id'=>$customer_resources_id |
|
|
|
$where = [ |
|
|
|
'id' => $customer_resources_id |
|
|
|
]; |
|
|
|
|
|
|
|
//客户资源数据 |
|
|
|
@ -179,8 +184,8 @@ class CustomerResources extends BaseApiService |
|
|
|
"second_visit_status" => $request->param('second_visit_status', null),//二访情况 |
|
|
|
]; |
|
|
|
|
|
|
|
foreach($customer_resources_data as $k=>$v){ |
|
|
|
if(!isset($v) || $v === ''){ |
|
|
|
foreach ($customer_resources_data as $k => $v) { |
|
|
|
if (!isset($v) || $v === '') { |
|
|
|
return fail("缺少必填项{$k}"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -190,51 +195,52 @@ class CustomerResources extends BaseApiService |
|
|
|
} |
|
|
|
|
|
|
|
//如果六要素人员id没有就是当前登录人的员工id |
|
|
|
if(empty($six_speed_data['staff_id'])){ |
|
|
|
if (empty($six_speed_data['staff_id'])) { |
|
|
|
$six_speed_data['staff_id'] = $this->member_id; |
|
|
|
} |
|
|
|
|
|
|
|
foreach($six_speed_data as $k=>$v){ |
|
|
|
foreach ($six_speed_data as $k => $v) { |
|
|
|
// 排除 first_visit_status 和 second_visit_status 的必填校验 |
|
|
|
if (in_array($k, ['first_visit_status', 'second_visit_status'])) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if(!isset($v) || $v === ''){ |
|
|
|
if (!isset($v) || $v === '') { |
|
|
|
return fail("缺少必填项{$k}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$res = (new CustomerResourcesService())->editData($where,$customer_resources_data,$six_speed_data); |
|
|
|
if(!$res['code']){ |
|
|
|
$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){ |
|
|
|
public function getEditLogList(Request $request) |
|
|
|
{ |
|
|
|
//前端要传递分页(page,limit)参数 |
|
|
|
$customer_resource_id = $request->param('customer_resource_id',''); |
|
|
|
$type = $request->param('type','resource');//查询类型|resource=客户资源,six_speed=六要素 |
|
|
|
$customer_resource_id = $request->param('customer_resource_id', ''); |
|
|
|
$type = $request->param('type', 'resource');//查询类型|resource=客户资源,six_speed=六要素 |
|
|
|
|
|
|
|
if(empty($customer_resource_id) || empty($type)){ |
|
|
|
if (empty($customer_resource_id) || empty($type)) { |
|
|
|
return fail('缺少必要参数'); |
|
|
|
} |
|
|
|
|
|
|
|
if(!in_array($type,['resource','six_speed'])){ |
|
|
|
if (!in_array($type, ['resource', 'six_speed'])) { |
|
|
|
return fail('类型不正确'); |
|
|
|
} |
|
|
|
|
|
|
|
$where = [ |
|
|
|
'customer_resource_id' =>$customer_resource_id |
|
|
|
'customer_resource_id' => $customer_resource_id |
|
|
|
]; |
|
|
|
|
|
|
|
if($type == 'resource'){ |
|
|
|
if ($type == 'resource') { |
|
|
|
//resource=客户资源 |
|
|
|
$res =(new CustomerResourcesService())->getCustomerResourceChangesEditLog($where); |
|
|
|
}else{ |
|
|
|
$res =(new CustomerResourcesService())->getSixSpeedModificationEditLog($where); |
|
|
|
$res = (new CustomerResourcesService())->getCustomerResourceChangesEditLog($where); |
|
|
|
} else { |
|
|
|
$res = (new CustomerResourcesService())->getSixSpeedModificationEditLog($where); |
|
|
|
} |
|
|
|
|
|
|
|
return success($res); |
|
|
|
|