Files
spacestation/agent/admin/controllers/api/receiver/Customer.php
T
2025-09-15 14:20:01 +08:00

208 lines
8.9 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
class Customer extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('receiver/receiver_customers_model', 'customers_model');
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model("biz/biz_model");
$this->load->model('area_model');
$this->load->model('receiver/receiver_yx_model');
$this->load->model('receiver/receiver_xz_model');
$this->load->model('receiver/receiver_call_wechat_model');
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
$this->customers_model->set_db('ssdb');
$this->customer_oplogs_model->set_db('ssdb');
$this->auto_brand_model->set_db('ssdb');
$this->auto_series_model->set_db('ssdb');
$this->biz_model->set_db('ssdb');
$this->area_model->set_db('ssdb');
$this->receiver_yx_model->set_db('ssdb');
$this->receiver_xz_model->set_db('ssdb');
$this->receiver_call_wechat_model->set_db('ssdb');
$this->clues_cfrom_model->set_db('ssdb');
}
public function page_get()
{
$status_arr = $this->customers_model->get_status();
unset($status_arr['-1']);
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$sort_order = 'id desc';
$list = [];
$where = $this->buildWhere($params);
$count = $this->customers_model->count($where);
if ($count) {
$rows = $this->customers_model->select($where, $sort_order, $page, $limit);
//车型
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id'));
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id'));
//获取门店
$biz_id_arr = array_unique(array_column($rows, 'biz_id'));
$biz_id_arr && $biz_rows = $this->biz_model->get_map_by_ids($biz_id_arr, 'id,biz_name,county_id');
foreach ($biz_rows as $v) {
$county_id_arr[] = $v[0]['county_id'];
}
if ($county_id_arr) {
$str_ids = implode(',', $county_id_arr);
$map_area = $this->area_model->map('county_id', '', ["county_id in ({$str_ids})" => null], '', 0, 0, 'county_id,province_name,city_name,county_name');
}
foreach ($rows as $val) {
$area = $map_area[$biz_rows[$val['biz_id']][0]['county_id']][0];
$brand_detail = '';
if ($brands[$val['brand_id']]) {
$brand_detail = $brands[$val['brand_id']][0]['name'];
}
if ($brands[$val['brand_id']]) {
$brand_detail .= '-' . $series[$val['series_id']][0]['name'];
}
$temp = [
'id' => $val['id'],
'mobile' => mobile_asterisk($val['mobile']),
'status_name' => $status_arr[$val['status']],
'biz_poi' => $area ? "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}" : '',
'biz_name' => isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']][0]['biz_name'] : '',
'brand_detail' => $brand_detail,
];
$list[] = $temp;
}
}
$data = ['list' => $list, 'count' => $count];
$this->return_response_list($data);
}
/**
* 详情
* @return void
*/
public function index_get()
{
$id = $this->input->get('id');
$this->load->model('auto/auto_series_model');
$select = '*, (select city_name from lc_area where city_id = lc_receiver_customers.city_id limit 1) as city_name, (select county_name from lc_area where county_id = lc_receiver_customers.county_id limit 1) as county_name';
$row = $this->customers_model->get(array('id' => $id), $select);
if (!$row) {
$this->return_json('客户不存在!');
}
$row_biz = $this->biz_model->get(array('id' => $row['biz_id']));
//用户信息
$mobile_sub = mobile_asterisk($row['mobile']);
if ($row['county_id']) {
$area = $this->area_model->get(array('county_id' => $row['county_id']));
$poi = "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}";
} elseif ($row['city_id']) {
$area = $this->area_model->get(array('city_id' => $row['city_id']));
$poi = "{$area['province_name']}-{$area['city_name']}";
} elseif ($row['province_id']) {
$area = $this->area_model->get(array('province_id' => $row['province_id']));
$poi = "{$area['province_name']}";
}
$brand_detail = '';
if ($row['brand_id']) {
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']]);
$brand && $brand_detail = $brand['name'];
}
if ($row['series_id']) {
$series = $this->auto_series_model->get(['id' => $row['series_id']]);
$series && $brand_detail .= '-' . $series['name'];
}
$of_title = '';
if ($row['of_id']) {
$of = $this->clues_cfrom_model->get(array('id' => $row['of_id']));
$of_title = $of['title'];
if ($row['of2_id']) {
$of = $this->clues_cfrom_model->get(array('id' => $row['of2_id']));
$of_title .= '-' . $of['title'];
}
}
$data = array(
'id' => $row['id'],
'name' => $row['name'],
'level' => $row['level'],
'mobile' => $mobile_sub,
'wx_name' => $this->customers_model->wxgrAry($row['wxgr']),
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
'p_time' => $row['p_time'],
'status' => $row['status'],
'poi' => $poi,
'biz' => $row_biz['biz_name'],
'brand_detail' => $brand_detail,
'of_title' => $of_title,
);
$selectedCar = ['brandId' => $row['brand_id'] ?: '', 'seriesId' => $row['series_id'] ?: '', 'modelId' => ''];
$data['selectedCar'] = $selectedCar;
$statusAry = $this->customers_model->get_status();
unset($statusAry['-1']);
$this->return_response($data);
}
/**
* 操作日志
* @return void
*/
public function opt_get()
{
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$params = $this->input_param();
$id = intval($params['id']);
if (!$id) {
$this->return_json('非法参数!');
}
$where = array('customer_id' => $id);
$count = $this->customer_oplogs_model->count($where);
$list = [];
$rows_log = $this->customer_oplogs_model->select($where, 'id desc', $page, $limit);
foreach ($rows_log as $key => $value) {
list($rec_url, $rec_text) = $this->customer_oplogs_model->getRecordUrl($value['id']);
$imgs = [];
if ($value['imgs']) {
$json_imgs = json_decode($value['imgs'], true);
foreach ($json_imgs as $key1 => $value1) {
$imgs[] = build_qiniu_image_url($value1);
}
}
$list[] = array(
'uname' => $value['uname'],
'log' => $value['log'],
'imgs' => $imgs,
'rec_url' => $rec_url,
'rec_text' => $rec_text,
'type_name' => $this->customer_oplogs_model->typeAry()[$value['type']],
'c_time' => date('Y-m-d H:i', $value['c_time'])
);
}
$data = ['list' => $list, 'count' => $count];
$this->return_response_list($data);
}
private function buildWhere($params)
{
$uid = $_SESSION['id'];
$app_id = self::APP_ID;
$where = [];
$where["rid in (select id from lc_receiver_clues where app_id={$app_id})"] = null;
if ($params['title']) {
$where['mobile LIKE "%' . trim($params['title']) . '%"'] = null;
}
if ($params['dateRange'][0] && $params['dateRange'][1]) {
$where['c_time >='] = strtotime($params['dateRange'][0] . ' 00:00:00');
$where['c_time <='] = strtotime($params['dateRange'][1] . ' 23:59:59');
}
return $where;
}
}