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

141 lines
5.7 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
class Clues extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('agent/auto_product_model', 'autoProduct');
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
$this->load->model('receiver/receiver_yx_model');
$this->load->model('receiver/receiver_xz_model');
$this->load->model('receiver/receiver_call_wechat_model');
$this->clues_model->set_db('ssdb');
$this->clues_cfrom_model->set_db('ssdb');
$this->auto_brand_model->set_db('ssdb');
$this->auto_series_model->set_db('ssdb');
$this->mdOplogs->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');
}
public function page_get()
{
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$title = $this->input_param('title');
$sort_order = 'id desc';
$statusList = $list = [];
$where = [
'app_id' => self::APP_ID
];
if ($title) {
$where['mobile LIKE "%' . trim($title) . '%"'] = null;
}
if ($params['dateRange'][0] && $params['dateRange'][1]) {
$where['en_time >='] = $params['dateRange'][0] . ' 00:00:00';
$where['en_time <='] = $params['dateRange'][1] . ' 23:59:59';
}
foreach ($this->clues_model->statusAry() as $key => $value) {
$statusList[$key] = $value['name'];
}
$count = $this->clues_model->count($where);
if ($count) {
$rows = $this->clues_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'));
foreach ($rows as $v) {
$cfRow = $this->clues_cfrom_model->get(['id' => $v['cf2_id']]);
$brandName = $brands[$v['brand_id']] ? $brands[$v['brand_id']][0]['name'] : '';
$seriesName = $series[$v['series_id']] ? $series[$v['series_id']][0]['name'] : '';
$cfrom2 = $cfRow['title'] ?: '';
if ($v['cf2_id'] == self::CF2_PRODUCT) {
$product = $this->autoProduct->get(['id' => $v['out_id']]);
if ($product) {
$cfrom2 .= '-' . $product['title'];
}
}
$temp = [
'id' => $v['id'],
'mobile' => mobile_asterisk($v['mobile']),
'statusCn' => $statusList[$v['status']],
'cfrom' => $cfrom2,
'brandSeries' => "$brandName-$seriesName",
'enTime' => $v['en_time']
];
$list[] = $temp;
}
}
$data = ['list' => $list, 'count' => $count, 'statusList' => $statusList];
$this->return_response_list($data);
}
/**
* 详情
* @return void
*/
public function index_get()
{
$params = $this->input_param();
$id = intval($params['id']);
if (!$id) {
$this->return_json('非法参数!');
}
$re = $this->clues_model->get(array('id' => $id));
if (!$re || empty($re)) {
$this->return_json('线索不存在!');
}
$dataInfo = $re;
$dataInfo['mobile'] = mobile_asterisk($dataInfo['mobile']);
$dataInfo['c_time'] = date('Y-m-d H:i', $re['c_time']);
$selectedCar = ['brandId' => $re['brand_id'], 'seriesId' => $re['series_id'], 'modelId' => ''];
$dataInfo['selectedCar'] = $selectedCar;
$dataInfo['provinceCity'] = [substr($re['province_id'], 0, 3), $re['city_id'], $re['county_id']];
$this->return_response($dataInfo);
}
/**
* 操作日志
* @return void
*/
public function opt_get()
{
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$list = [];
$params = $this->input_param();
$id = intval($params['id']);
if (!$id) {
$this->return_json('非法参数!');
}
$where = ['clue_id' => $id];
$count = $this->mdOplogs->count($where);
if ($count) {
$resLogs = $this->mdOplogs->select($where, 'c_time desc', $page, $limit);
foreach ($resLogs as $key => $value) {
$setValue = array();
$setValue['uname'] = $value['uname'];
$setValue['log'] = $value['log'];
$setValue['type_name'] = $this->mdOplogs->typeAry()[$value['type']];
$setValue['c_time'] = date('Y-m-d H:i', $value['c_time']);
list($rec_url, $rec_text) = $this->mdOplogs->getRecordUrl($value['id']);
$setValue['rec_url'] = $rec_url;
$setValue['rec_text'] = $rec_text;
$list[] = $setValue;
}
}
$data = ['list' => $list, 'count' => $count];
$this->return_response_list($data);
}
}