Files
liche/api/controllers/wxapp/licheb/Customers.php
T
2021-07-05 09:56:27 +08:00

90 lines
3.2 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Date: 2020/06/23
* Time: 14:08
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Customers extends Wxapp{
function __construct($inputs, $app_key){
parent::__construct($inputs, $app_key);
$this->login_white = 'all';//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg =array();//授权微信信息
$this->load->model('receiver/receiver_customers_model','customers_model');
}
protected function get(){
$uid = $this->session['uid'];
$group_id = $this->session['group_id'];
if($group_id==3){ //掌柜
$where = [];
}elseif($group_id==2){ //店长
$sub_user = $this->app_user_model->select(['pid'=>$uid],'','','','id');
$ids_arr = array_column($sub_user,'id');
$ids_arr[] = $uid;
$ids = implode(',',$ids_arr);
$where = [
"admin_id in ($ids)" => null
];
}else{ //销售
$where = [
'admin_id' => $uid
];
}
$count = $this->customers_model->count($where);
$lists = [];
if($count){
$fileds = 'id,name,admin_id,mobile,car_json,is_top,cf_id,c_time';
$rows = $this->customers_model->select($where,'is_top desc,id desc',$page,$size,$fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows,'admin_id'));
$admin_ids = implode(',',$admin_arr);
$admins = [];
if($admin_ids){
$where = [
"id in ({$admin_ids})" => null
];
$admins = $this->app_user_model->map('id','',$where,'','','','id,uname');
}
//获取来源
$cf_arr = array_unique(array_column($rows,'cf_id'));
foreach($rows as $key => $val){
$car_json = json_decode($val['car_json'],true);
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
$cfrom = '';;
$other_data = [
'品牌车型' => '东风EX1',
'颜色型号' => $color.'-'.$version,
'建卡时间' => date('Y-m-d',$val['c_time']),
'上次联系' => date('Y-m-d'),
'客户来源' => $cfrom,
'销售顾问' => isset($admins[$val['admin_id']]) ? $admins[$val['admin_id']][0]['uname'] : '',
];
$lists[] = [
'id' => $val['id'],
'name' => $val['name'],
'mobile' => mobile_asterisk($val['mobile']),
'is_top' => $val['is_top'],
'other_data' => $other_data
];
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
}