|
@@ -58,14 +58,20 @@ class CustomService
|
|
|
$type = $consultantInfo->type;
|
|
|
$currentTime = time();
|
|
|
$diffNums = self::DIFF_TIME;
|
|
|
- $where = [
|
|
|
- [function($query) use ($diffNums, $currentTime){
|
|
|
- $query->orWhereRaw("check_status IN (-1, 1)")
|
|
|
- ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
|
|
|
- ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
|
|
|
- }]
|
|
|
- ];
|
|
|
+ $where = [];
|
|
|
$whereFollow = [];
|
|
|
+ if (!empty($params['belong_status'])) {
|
|
|
+ //团队权限
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("check_status IN (-1, 1)")
|
|
|
+ ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
|
|
|
+ ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
|
|
|
+ }];
|
|
|
+ }
|
|
|
if ($type == 1) {
|
|
|
//团队下所有的
|
|
|
$deptIds = TeamService::getIds($deptId);
|
|
@@ -95,11 +101,39 @@ class CustomService
|
|
|
//所有团队的
|
|
|
|
|
|
}
|
|
|
- if (!empty($params['custom'])) {
|
|
|
- $keywords = $params['custom'];
|
|
|
- $where[] = [function($query) use ($keywords) {
|
|
|
- $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
|
|
|
- }];
|
|
|
+ if (!empty($params['search_type'])) {
|
|
|
+ $searchType = $params['search_type'];
|
|
|
+ // 1 = 仅搜索客户
|
|
|
+ if ($searchType == 1) {
|
|
|
+ if (!empty($params['custom'])) {
|
|
|
+ $keywords = $params['custom'];
|
|
|
+ $where[] = [function($query) use ($keywords) {
|
|
|
+ $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!empty($params['custom'])) {
|
|
|
+ $keywords = $params['custom'];
|
|
|
+ $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
|
|
|
+ if ($searchType == 2) {
|
|
|
+ $searchKey = 'consultant_id';
|
|
|
+ } else {
|
|
|
+ $searchKey = 'report_consultant_id';
|
|
|
+ }
|
|
|
+ $where[] = [function($query) use ($consultantIds, $searchKey) {
|
|
|
+ $query->orWhereIn($searchKey, $consultantIds);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!empty($params['custom'])) {
|
|
|
+ $keywords = $params['custom'];
|
|
|
+ $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
|
|
|
+ $where[] = [function($query) use ($keywords, $consultantIds) {
|
|
|
+ $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")
|
|
|
+ ->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
|
|
|
+ }];
|
|
|
+ }
|
|
|
}
|
|
|
if (!empty($params['report_status'])) {
|
|
|
if ($params['report_status'] == 1) {
|
|
@@ -587,7 +621,7 @@ class CustomService
|
|
|
if (!empty($consultantId)) {
|
|
|
$whereCustom[] = ['consultant_id', '=', $consultantId];
|
|
|
}
|
|
|
- $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
|
|
|
+ $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
|
|
|
if (!$customList->isEmpty()) {
|
|
|
foreach ($customList as$item) {
|
|
|
$logsInertData[] = [
|
|
@@ -609,10 +643,18 @@ class CustomService
|
|
|
if (empty($logsInertData)) {
|
|
|
return json_fail('移交记录不能为空');
|
|
|
}
|
|
|
+ $diffTime = self::DIFF_TIME;
|
|
|
Db::beginTransaction();
|
|
|
$result = false;
|
|
|
try {
|
|
|
foreach ($customList as $item) {
|
|
|
+ if ($item->check_status == 2 && $item->current_status == 2) {
|
|
|
+ $visitTime = $item->visit_time;
|
|
|
+ $diff = strtotime($visitTime) + $diffTime - time();
|
|
|
+ if ($diff <= 0) {
|
|
|
+ $item->visit_time = time();
|
|
|
+ }
|
|
|
+ }
|
|
|
$item->consultant_id = $currentConsultantId;
|
|
|
$item->dept_id = $currentDeptId;
|
|
|
$item->save();
|