|
|
|
@ -102,18 +102,18 @@ class Index extends ApiCommon
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$adminModel = new \app\admin\model\Admin();
|
|
|
|
|
$status = $param['label'] ?: 1; //1合同目标2回款目标
|
|
|
|
|
$userWhere['type']=3;
|
|
|
|
|
$userWhere['status']=$param['label'];
|
|
|
|
|
$userWhere['type'] = 3;
|
|
|
|
|
$userWhere['status'] = $param['label'];
|
|
|
|
|
$userIds = [];
|
|
|
|
|
if ($param['dataType'] == 3 || $param['dataType'] == 4) {
|
|
|
|
|
$param['structure_id'] = $userInfo['structure_id'];
|
|
|
|
|
$userWhere['type']=2;
|
|
|
|
|
$userWhere['type'] = 2;
|
|
|
|
|
}
|
|
|
|
|
$whereArr = $adminModel->getWhere($param, 1, '');
|
|
|
|
|
if($param['user_id']){
|
|
|
|
|
$userWhere['type']=3;
|
|
|
|
|
}elseif ($param['structure_id']){
|
|
|
|
|
$userWhere['type']=2;
|
|
|
|
|
if ($param['user_id']) {
|
|
|
|
|
$userWhere['type'] = 3;
|
|
|
|
|
} elseif ($param['structure_id']) {
|
|
|
|
|
$userWhere['type'] = 2;
|
|
|
|
|
}
|
|
|
|
|
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
|
|
|
|
|
if ($param['dataType'] == 1) {
|
|
|
|
@ -128,12 +128,12 @@ class Index extends ApiCommon
|
|
|
|
|
$end_time = $between_time[1];
|
|
|
|
|
} else {
|
|
|
|
|
//自定义时间
|
|
|
|
|
$start_time = $param['start_time'] ?strtotime($param['start_time'].'00:00:00'): strtotime(date('Y-01-01', time()));
|
|
|
|
|
$end_time = $param['end_time'] ? strtotime($param['end_time'].'23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
|
|
|
|
|
$start_time = $param['start_time'] ? strtotime($param['start_time'] . '00:00:00') : strtotime(date('Y-01-01', time()));
|
|
|
|
|
$end_time = $param['end_time'] ? strtotime($param['end_time'] . '23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
|
|
|
|
|
$between_time = array($start_time, $end_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($param['label']==1){
|
|
|
|
|
if ($param['label'] == 1) {
|
|
|
|
|
//合同金额
|
|
|
|
|
$where_contract = $where;
|
|
|
|
|
$where_contract['order_date'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
|
|
|
|
@ -144,7 +144,7 @@ class Index extends ApiCommon
|
|
|
|
|
->fetchSql()
|
|
|
|
|
->select();
|
|
|
|
|
$contractMoney = queryCache($sql, 200);
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
//回款金额
|
|
|
|
|
$where_receivables = $where;
|
|
|
|
|
$where_receivables['return_time'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
|
|
|
|
@ -214,11 +214,21 @@ class Index extends ApiCommon
|
|
|
|
|
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];;
|
|
|
|
|
$businessModel = new \app\crm\model\Business();
|
|
|
|
|
$param['merge'] = 1;
|
|
|
|
|
if($param['start_time'] && $param['end_time']){
|
|
|
|
|
$param['start_time']=$param['start_time'].' 00:00:00';
|
|
|
|
|
$param['end_time']=$param['end_time'].' 23:59:59';
|
|
|
|
|
if ($param['start_time'] && $param['end_time']) {
|
|
|
|
|
$param['start_time'] = $param['start_time'] . ' 00:00:00';
|
|
|
|
|
$param['end_time'] = $param['end_time'] . ' 23:59:59';
|
|
|
|
|
}
|
|
|
|
|
$list = $businessModel->getFunnel($param);
|
|
|
|
|
$list['list'][] = [
|
|
|
|
|
"name" => "赢单",
|
|
|
|
|
"status_id" => "10000",
|
|
|
|
|
"status_name" => "赢单",
|
|
|
|
|
];
|
|
|
|
|
$list['list'][] = [
|
|
|
|
|
"name" => "输单",
|
|
|
|
|
"status_id" => "10001",
|
|
|
|
|
"status_name" => "输单",
|
|
|
|
|
];
|
|
|
|
|
return resultArray(['data' => $list]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -234,27 +244,27 @@ class Index extends ApiCommon
|
|
|
|
|
//统计条件
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$userWhere['status']=$param['label'];
|
|
|
|
|
$userWhere['status'] = $param['label'];
|
|
|
|
|
if ($param['dataType'] == 3 || $param['dataType'] == 4) {
|
|
|
|
|
$userWhere['type']=2;
|
|
|
|
|
}else{
|
|
|
|
|
$userWhere['type']=3;
|
|
|
|
|
$userWhere['type'] = 2;
|
|
|
|
|
} else {
|
|
|
|
|
$userWhere['type'] = 3;
|
|
|
|
|
}
|
|
|
|
|
if ($param['type']) {
|
|
|
|
|
$last_where_contract = getTimeByType($param['type']);
|
|
|
|
|
$userWhere['year']=date('Y',$last_where_contract[0]);
|
|
|
|
|
$userWhere['year'] = date('Y', $last_where_contract[0]);
|
|
|
|
|
$time = getTimeArray();
|
|
|
|
|
} else {
|
|
|
|
|
//自定义时间
|
|
|
|
|
$param['start_time']=$param['start_time']?$param['start_time'].' 00:00:00':0;
|
|
|
|
|
$param['end_time']=$param['end_time'].' 23:59:59';
|
|
|
|
|
$time = getTimeArray(strtotime($param['start_time']),strtotime($param['end_time']));
|
|
|
|
|
$param['start_time'] = $param['start_time'] ? $param['start_time'] . ' 00:00:00' : 0;
|
|
|
|
|
$param['end_time'] = $param['end_time'] . ' 23:59:59';
|
|
|
|
|
$time = getTimeArray(strtotime($param['start_time']), strtotime($param['end_time']));
|
|
|
|
|
}
|
|
|
|
|
$whereArr = $adminModel->getWhere($param, 1, '');
|
|
|
|
|
if($param['user_id']){
|
|
|
|
|
$userWhere['type']=3;
|
|
|
|
|
}elseif ($param['structure_id']){
|
|
|
|
|
$userWhere['type']=2;
|
|
|
|
|
if ($param['user_id']) {
|
|
|
|
|
$userWhere['type'] = 3;
|
|
|
|
|
} elseif ($param['structure_id']) {
|
|
|
|
|
$userWhere['type'] = 2;
|
|
|
|
|
}
|
|
|
|
|
$userIds = $whereArr['userIds'];
|
|
|
|
|
if (!empty($param['user_id'])) {
|
|
|
|
@ -271,7 +281,7 @@ class Index extends ApiCommon
|
|
|
|
|
$auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
|
|
|
|
|
$between_time = [date('Y-m-d', $whereArr['between_time'][0]), date('Y-m-d', $whereArr['between_time'][1])];
|
|
|
|
|
|
|
|
|
|
if($param['label']==1){
|
|
|
|
|
if ($param['label'] == 1) {
|
|
|
|
|
$field_contract["SUBSTR(`order_date`, 1, " . $ax . ")"] = 'type';
|
|
|
|
|
$field_contract['SUM(`money`)'] = 'sum';
|
|
|
|
|
$achievementData = CrmContractModel::field($field_contract)
|
|
|
|
@ -286,7 +296,7 @@ class Index extends ApiCommon
|
|
|
|
|
$res_contract = queryCache($achievementData, 200);
|
|
|
|
|
|
|
|
|
|
$res_money = array_column($res_contract, null, 'type');
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
$field_receivables["SUBSTR(`return_time`, 1, " . $ax . ")"] = 'type';
|
|
|
|
|
$field_receivables['SUM(`money`)'] = 'sum';
|
|
|
|
|
|
|
|
|
@ -306,23 +316,23 @@ class Index extends ApiCommon
|
|
|
|
|
}
|
|
|
|
|
$list = array();
|
|
|
|
|
$money = '0.00';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($time['list'] as $val) {
|
|
|
|
|
$item = [];
|
|
|
|
|
$item['type'] = date('m-d',strtotime($val['type']));
|
|
|
|
|
$item['type'] = date('m-d', strtotime($val['type']));
|
|
|
|
|
$item['money'] = $res_money[$val['type']]['sum'] ?: 0;
|
|
|
|
|
$money += $item['money'];
|
|
|
|
|
|
|
|
|
|
$achievement=Db::name('crm_achievement')->where($userWhere)->select();
|
|
|
|
|
$data_time=date('m',strtotime($val['type']));
|
|
|
|
|
$num='';
|
|
|
|
|
if($achievement){
|
|
|
|
|
foreach ($achievement as $val){
|
|
|
|
|
$num+=(int)$val[$this->monthName[$data_time]];
|
|
|
|
|
$item['achievement']=$num;
|
|
|
|
|
$achievement = Db::name('crm_achievement')->where($userWhere)->select();
|
|
|
|
|
$data_time = date('m', strtotime($val['type']));
|
|
|
|
|
$num = '';
|
|
|
|
|
if ($achievement) {
|
|
|
|
|
foreach ($achievement as $val) {
|
|
|
|
|
$num += (int)$val[$this->monthName[$data_time]];
|
|
|
|
|
$item['achievement'] = $num;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$item['achievement']=0;
|
|
|
|
|
} else {
|
|
|
|
|
$item['achievement'] = 0;
|
|
|
|
|
}
|
|
|
|
|
$list[] = $item;
|
|
|
|
|
}
|
|
|
|
@ -341,9 +351,9 @@ class Index extends ApiCommon
|
|
|
|
|
{
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$adminModel = new \app\admin\model\Admin();
|
|
|
|
|
if($param['start_time'] && $param['end_time']){
|
|
|
|
|
$param['start_time']=$param['start_time'].'00:00:00';
|
|
|
|
|
$param['end_time']=$param['end_time'].'23:59:59';
|
|
|
|
|
if ($param['start_time'] && $param['end_time']) {
|
|
|
|
|
$param['start_time'] = $param['start_time'] . '00:00:00';
|
|
|
|
|
$param['end_time'] = $param['end_time'] . '23:59:59';
|
|
|
|
|
}
|
|
|
|
|
$whereArr = $adminModel->getWhere($param, '', ''); //统计条件
|
|
|
|
|
$userIds = $whereArr['userIds'];
|
|
|
|
@ -370,7 +380,7 @@ class Index extends ApiCommon
|
|
|
|
|
{
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$adminModel = new \app\admin\model\Admin();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$whereArr = $adminModel->getWhere($param, '', ''); //统计条件
|
|
|
|
|
$userIds = $whereArr['userIds'];
|
|
|
|
|
$where = [];
|
|
|
|
@ -540,14 +550,14 @@ class Index extends ApiCommon
|
|
|
|
|
$label = $param['label'];
|
|
|
|
|
$types = $param['types'];
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$user_id = $param['user_id'] ? : $userInfo['id'];
|
|
|
|
|
if($param['start_time'] && $param['end_time']){
|
|
|
|
|
$param['start_time']=$param['start_time'].' 00:00:00';
|
|
|
|
|
$param['end_time']=$param['end_time'].' 23:59:59';
|
|
|
|
|
$user_id = $param['user_id'] ?: $userInfo['id'];
|
|
|
|
|
if ($param['start_time'] && $param['end_time']) {
|
|
|
|
|
$param['start_time'] = $param['start_time'] . ' 00:00:00';
|
|
|
|
|
$param['end_time'] = $param['end_time'] . ' 23:59:59';
|
|
|
|
|
}
|
|
|
|
|
$whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
|
|
|
|
|
$userIds = $whereArr['userIds'];
|
|
|
|
|
$between_time = $whereArr['between_time'];
|
|
|
|
|
$between_time = $whereArr['between_time'];
|
|
|
|
|
$start_time = $between_time[0];
|
|
|
|
|
$end_time = $between_time[1];
|
|
|
|
|
|
|
|
|
@ -599,8 +609,8 @@ class Index extends ApiCommon
|
|
|
|
|
|
|
|
|
|
if ($c != 'activity') {
|
|
|
|
|
$where['owner_user_id']['value'] = $auth_user_ids;
|
|
|
|
|
if($types=='crm_contract' || $types=='crm_receivables'){
|
|
|
|
|
$where['check_status']=2;
|
|
|
|
|
if ($types == 'crm_contract' || $types == 'crm_receivables') {
|
|
|
|
|
$where['check_status'] = 2;
|
|
|
|
|
}
|
|
|
|
|
$data = $model->getDataList($where);
|
|
|
|
|
} else {
|
|
|
|
@ -613,21 +623,21 @@ class Index extends ApiCommon
|
|
|
|
|
foreach ($typesList as $k => $v) {
|
|
|
|
|
$where1['activity_type'] = $v;
|
|
|
|
|
$dataCount = db('crm_activity')->where($where1)->count();
|
|
|
|
|
if($v==1){
|
|
|
|
|
$arr[$k]['types'] ='crm_leads';
|
|
|
|
|
$arr[$k]['activity_type'] =1;
|
|
|
|
|
}elseif ($v==2){
|
|
|
|
|
$arr[$k]['types'] ='crm_customer';
|
|
|
|
|
$arr[$k]['activity_type'] =2;
|
|
|
|
|
}elseif ($v==3){
|
|
|
|
|
$arr[$k]['types'] ='crm_contacts';
|
|
|
|
|
$arr[$k]['activity_type'] =3;
|
|
|
|
|
}elseif ($v==5){
|
|
|
|
|
$arr[$k]['types'] ='crm_business';
|
|
|
|
|
$arr[$k]['activity_type'] =5;
|
|
|
|
|
}elseif ($v==6){
|
|
|
|
|
$arr[$k]['types'] ='crm_contract';
|
|
|
|
|
$arr[$k]['activity_type'] =6;
|
|
|
|
|
if ($v == 1) {
|
|
|
|
|
$arr[$k]['types'] = 'crm_leads';
|
|
|
|
|
$arr[$k]['activity_type'] = 1;
|
|
|
|
|
} elseif ($v == 2) {
|
|
|
|
|
$arr[$k]['types'] = 'crm_customer';
|
|
|
|
|
$arr[$k]['activity_type'] = 2;
|
|
|
|
|
} elseif ($v == 3) {
|
|
|
|
|
$arr[$k]['types'] = 'crm_contacts';
|
|
|
|
|
$arr[$k]['activity_type'] = 3;
|
|
|
|
|
} elseif ($v == 5) {
|
|
|
|
|
$arr[$k]['types'] = 'crm_business';
|
|
|
|
|
$arr[$k]['activity_type'] = 5;
|
|
|
|
|
} elseif ($v == 6) {
|
|
|
|
|
$arr[$k]['types'] = 'crm_contract';
|
|
|
|
|
$arr[$k]['activity_type'] = 6;
|
|
|
|
|
}
|
|
|
|
|
$arr[$k]['dataCount'] = $dataCount;
|
|
|
|
|
$arr[$k]['create_user_id'] = implode(',', $userIds);
|
|
|
|
@ -673,7 +683,7 @@ class Index extends ApiCommon
|
|
|
|
|
{
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$param['user_id'] = $param['user_id']?:$userInfo['id'];
|
|
|
|
|
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
|
|
|
|
|
$indexModel = new IndexLogic;
|
|
|
|
|
$data = $indexModel->ranking($param);
|
|
|
|
|
return resultArray(['data' => $data]);
|
|
|
|
@ -687,7 +697,7 @@ class Index extends ApiCommon
|
|
|
|
|
{
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$param['user_id'] = $param['user_id']?:$userInfo['id'];
|
|
|
|
|
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
|
|
|
|
|
$indexModel = new IndexLogic;
|
|
|
|
|
$data = $indexModel->queryDataInfo($param);
|
|
|
|
|
return resultArray(['data' => $data]);
|
|
|
|
@ -702,7 +712,11 @@ class Index extends ApiCommon
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
|
|
|
|
|
$indexModel = new IndexLogic;
|
|
|
|
|
if ($param['status_id'] == "10000" || $param['status_id'] == "10001") {
|
|
|
|
|
$data['funnel'] = $param['status_id'];
|
|
|
|
|
}
|
|
|
|
|
$data = $indexModel->businessList($param);
|
|
|
|
|
|
|
|
|
|
return resultArray(['data' => $data]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -754,12 +768,13 @@ class Index extends ApiCommon
|
|
|
|
|
* 跟进详情
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
*/
|
|
|
|
|
public function activityList(){
|
|
|
|
|
public function activityList()
|
|
|
|
|
{
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
$param['id']=$userInfo['id'];
|
|
|
|
|
$indexLogic=new IndexLogic();
|
|
|
|
|
$data=$indexLogic->activityList($param);
|
|
|
|
|
return resultArray(['data'=>$data]);
|
|
|
|
|
$param['id'] = $userInfo['id'];
|
|
|
|
|
$indexLogic = new IndexLogic();
|
|
|
|
|
$data = $indexLogic->activityList($param);
|
|
|
|
|
return resultArray(['data' => $data]);
|
|
|
|
|
}
|
|
|
|
|
}
|