|
|
@@ -28,13 +28,20 @@ class User extends Model |
|
|
|
// $dgx = $Appoint_model->query($dgx); |
|
|
|
// $dgx = (empty($dgx)) ? 0 : $dgx[0]['count']; |
|
|
|
$Collection_model = new \app\admin\model\Collection(); |
|
|
|
$where[] = ['a.status', 'between', [1, 6]]; |
|
|
|
$where[] = ['a.status', 'in', [1, 2, 4, 5, 6]]; |
|
|
|
$where[] = ['a.return_visit', '=', 0]; |
|
|
|
$where[] = ['a.feedback', '=', '']; |
|
|
|
//连表 |
|
|
|
$where[] = ['a.appoint_time', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$dgx2 = $Appoint_model->alias('a')->join($Customer_model->getTable() . ' c', 'a.customer_id = c.id and c.user_id = ' . $userInfo['id'])->join($Collection_model->getTable() . ' t', 'c.id = t.customer_id')->field('a.id')->where($where)->with(['getCollectioOneData'])->select()->toArray(); |
|
|
|
$dgx2 = $Appoint_model->alias('a')->join($Customer_model->getTable() . ' c', 'a.customer_id = c.id and c.user_id = ' . $userInfo['id'])->field('a.id,a.customer_id')->where($where)->select()->toArray();//->join($Collection_model->getTable() . ' t', 'c.id = t.customer_id')->with(['getCollectioOneData']) |
|
|
|
//收款记录,审核不通过也要显示 |
|
|
|
foreach ($dgx2 as $k => $v) { |
|
|
|
if (!empty($v['feedback'])) { |
|
|
|
unset($dgx2[$k]); |
|
|
|
$check = $Collection_model->where('appoint_id', $v['id'])->where('is_examine', 1)->where('customer_id', $v['customer_id'])->value('id'); |
|
|
|
if (!$check) { |
|
|
|
$feedback = $Collection_model->where('appoint_id', $v['id'])->where('customer_id', $v['customer_id'])->value('feedback'); |
|
|
|
if (!empty($feedback)) { |
|
|
|
unset($dgx2[$k]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$dgx = array_values($dgx2); |
|
|
@@ -56,7 +63,7 @@ class User extends Model |
|
|
|
//跟进时间查询,如果是今天的话,就查询 |
|
|
|
// $now_start = strtotime($nowDate . ' 00:00:00'); |
|
|
|
// $now_end = strtotime($nowDate . ' 23:59:59'); |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59'))]]; |
|
|
|
// $whereOr[] = ['followup_setting', 'between', [$now_start, $now_end]]; |
|
|
|
$whereOr[] = ['user_id', '=', $userInfo['id']]; |
|
|
|
$whereOr[] = ['status', '=', 2]; |
|
|
@@ -64,9 +71,10 @@ class User extends Model |
|
|
|
$query->where($whereOr); |
|
|
|
})->count();//待预约 |
|
|
|
$whereOr = []; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59'))]]; |
|
|
|
// $whereOr[] = ['followup_setting', 'between', [$now_start, $now_end]]; |
|
|
|
$whereOr[] = ['status', '=', 5]; |
|
|
|
$whereOr[] = ['user_id', '=', $userInfo['id']]; |
|
|
|
$wcj = $Customer_model->where('status', 5)->where('user_id', $userInfo['id'])->where('followup_time', 0)->whereOr(function ($query) use ($whereOr) { |
|
|
|
$query->where($whereOr); |
|
|
|
})->count();//未成交 |
|
|
@@ -84,7 +92,7 @@ class User extends Model |
|
|
|
// } |
|
|
|
// } |
|
|
|
//本月排行榜 |
|
|
|
$Collection = $Customer_model->alias('t')->rightJoin($Appoint_model->getTable() . ' a', 't.id = a.customer_id')->group('t.user_id')->field('t.user_id,count(1) as count,t.id')->whereBetween('a.create_time', [$month_start, $month_end])->with(['getUserOneData'])->select()->toArray(); |
|
|
|
$Collection = $Customer_model->alias('t')->join($Appoint_model->getTable() . ' a', 't.id = a.customer_id')->group('t.user_id')->field('t.user_id,count(1) as count,t.id')->whereBetween('a.create_time', [$month_start, $month_end])->with(['getUserOneData'])->select()->toArray(); |
|
|
|
$Collection2 = $Customer_model->alias('t')->join($Collection_model->getTable() . ' c', 't.id = c.customer_id')->field('sum(collection_money) as collection_money,sum(refundcollection_money) as refundcollection_money,sum(deal_money) as deal_money,sum(newdeal_money) as newdeal_money,sum(refunddeal_money) as refunddeal_money,t.user_id,c.type')->whereBetween('c.collection_time', [$month_start, $month_end])->group('t.user_id')->select()->toArray(); |
|
|
|
$Collection3 = []; |
|
|
|
foreach ($Collection2 as $k => $v) { |
|
|
@@ -112,7 +120,11 @@ class User extends Model |
|
|
|
if (!empty($Collection[$k]['all_collection_money'])) { |
|
|
|
$Collection[$k]['all_collection_money'] = $Collection[$k]['all_collection_money'] / 100; |
|
|
|
} |
|
|
|
if (empty($v['username'])) { |
|
|
|
unset($Collection[$k]); |
|
|
|
} |
|
|
|
} |
|
|
|
$Collection = array_values($Collection); |
|
|
|
array_multisort(array_column($Collection, 'all_deal_money'), SORT_DESC, $Collection); |
|
|
|
foreach ($Collection as $k => $v) { |
|
|
|
$Collection[$k]['id'] = $k + 1; |
|
|
@@ -171,12 +183,19 @@ class User extends Model |
|
|
|
// $dgx = $Appoint_model->where('is_returnvisit', 1)->where('return_visit', 0)->where('status', 4)->whereBetween('appoint_time', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))])->count(); |
|
|
|
$Collection_model = new \app\admin\model\Collection(); |
|
|
|
$where[] = ['a.status', 'in', [1, 2, 4, 5, 6]]; |
|
|
|
$where[] = ['a.return_visit', '=', 0]; |
|
|
|
$where[] = ['a.feedback', '=', '']; |
|
|
|
//连表 |
|
|
|
$where[] = ['a.appoint_time', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$dgx2 = $Appoint_model->alias('a')->join($Customer_model->getTable() . ' c', 'a.customer_id = c.id')->join($Collection_model->getTable() . ' t', 'c.id = t.customer_id')->field('a.id,a.return_visit')->where($where)->with(['getCollectioOneData'])->select()->toArray(); |
|
|
|
$dgx2 = $Appoint_model->alias('a')->join($Customer_model->getTable() . ' c', 'a.customer_id = c.id')->field('a.id,a.customer_id')->where($where)->select()->toArray();//->join($Collection_model->getTable() . ' t', 'c.id = t.customer_id')->with(['getCollectioOneData']) |
|
|
|
//收款记录,审核不通过也要显示 |
|
|
|
foreach ($dgx2 as $k => $v) { |
|
|
|
if (!empty($v['feedback']) || $v['return_visit'] == 1) { |
|
|
|
unset($dgx2[$k]); |
|
|
|
$check = $Collection_model->where('appoint_id', $v['id'])->where('is_examine', 1)->where('customer_id', $v['customer_id'])->value('id'); |
|
|
|
if (!$check) { |
|
|
|
$feedback = $Collection_model->where('appoint_id', $v['id'])->where('customer_id', $v['customer_id'])->value('feedback'); |
|
|
|
if (!empty($feedback)) { |
|
|
|
unset($dgx2[$k]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$dgx = array_values($dgx2); |
|
|
@@ -203,14 +222,14 @@ class User extends Model |
|
|
|
// $now_start = strtotime($nowDate . ' 00:00:00'); |
|
|
|
// $now_end = strtotime($nowDate . ' 23:59:59'); |
|
|
|
$whereOr = []; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59'))]]; |
|
|
|
// $whereOr[] = ['followup_setting', 'between', [$now_start, $now_end]]; |
|
|
|
$whereOr[] = ['status', '=', 2]; |
|
|
|
$dyy = $Customer_model->where('status', 2)->where('followup_time', 0)->whereOr(function ($query) use ($whereOr) { |
|
|
|
$query->where($whereOr); |
|
|
|
})->count();//待预约 |
|
|
|
$whereOr = []; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')))]]; |
|
|
|
$whereOr[] = ['followup_setting', 'between', [strtotime('2020-01-01'), strtotime(date('Y-m-d 23:59:59'))]]; |
|
|
|
// $whereOr[] = ['followup_setting', 'between', [$now_start, $now_end]]; |
|
|
|
$whereOr[] = ['status', '=', 5]; |
|
|
|
$wcj = $Customer_model->where('status', 5)->where('followup_time', 0)->whereOr(function ($query) use ($whereOr) { |
|
|
@@ -230,7 +249,7 @@ class User extends Model |
|
|
|
// } |
|
|
|
// } |
|
|
|
//本月排行榜 |
|
|
|
$Collection = $Customer_model->alias('t')->rightJoin($Appoint_model->getTable() . ' a', 't.id = a.customer_id')->group('t.user_id')->field('t.user_id,count(1) as count,t.id')->whereBetween('a.create_time', [$month_start, $month_end])->with(['getUserOneData'])->select()->toArray(); |
|
|
|
$Collection = $Customer_model->alias('t')->join($Appoint_model->getTable() . ' a', 't.id = a.customer_id')->group('t.user_id')->field('t.user_id,count(1) as count,t.id')->whereBetween('a.create_time', [$month_start, $month_end])->with(['getUserOneData'])->select()->toArray(); |
|
|
|
$Collection2 = $Customer_model->alias('t')->join($Collection_model->getTable() . ' c', 't.id = c.customer_id')->field('sum(collection_money) as collection_money,sum(refundcollection_money) as refundcollection_money,sum(deal_money) as deal_money,sum(newdeal_money) as newdeal_money,sum(refunddeal_money) as refunddeal_money,t.user_id,c.type')->whereBetween('c.collection_time', [$month_start, $month_end])->group('t.user_id')->select()->toArray(); |
|
|
|
$Collection3 = []; |
|
|
|
foreach ($Collection2 as $k => $v) { |
|
|
@@ -258,7 +277,11 @@ class User extends Model |
|
|
|
if (!empty($Collection[$k]['all_collection_money'])) { |
|
|
|
$Collection[$k]['all_collection_money'] = $Collection[$k]['all_collection_money'] / 100; |
|
|
|
} |
|
|
|
if (empty($v['username'])) { |
|
|
|
unset($Collection[$k]); |
|
|
|
} |
|
|
|
} |
|
|
|
$Collection = array_values($Collection); |
|
|
|
// array_multisort(array_column($Collection, 'all_deal_money'), SORT_DESC, $Collection); |
|
|
|
$Collection = self::sortArrByManyField($Collection, 'all_deal_money', SORT_DESC, 'count', SORT_DESC); |
|
|
|
foreach ($Collection as $k => $v) { |
|
|
@@ -842,7 +865,24 @@ class User extends Model |
|
|
|
$ddcjl = bcdiv($cj, $dd, 2) * 100 . '%';//到店成交率 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (count(explode('.', $cj_money)) == 2) { |
|
|
|
$cj_money_check = explode('.', $cj_money); |
|
|
|
if ($cj_money_check[1] == '0') { |
|
|
|
$cj_money = $cj_money_check[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (count(explode('.', $sk_money)) == 2) { |
|
|
|
$sk_money_check = explode('.', $sk_money); |
|
|
|
if ($sk_money_check[1] == '0') { |
|
|
|
$sk_money = $sk_money_check[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (count(explode('.', $pjkdj)) == 2) { |
|
|
|
$pjkdj_check = explode('.', $pjkdj); |
|
|
|
if ($pjkdj_check[1] == '0') { |
|
|
|
$pjkdj = $pjkdj_check[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
return ['kh' => $kh, 'yy' => $yy, 'ydd' => $ydd, 'dd' => $dd, 'cj' => $cj, 'cj_money' => $cj_money, 'sk_money' => $sk_money, 'tk_money' => $tk_money, 'pjkdj' => $pjkdj, 'xsyyl' => $xsyyl, 'yyddl' => $yyddl, 'ddcjl' => $ddcjl]; |
|
|
|
} |
|
|
|
//$today_kh = $Customer_model->whereBetween('create_time', [$today_start, $today_end])->count();//新增客户数 |