405 lines
16 KiB
PHP
405 lines
16 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:车主
|
|
* Created on: 2022/6/15 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class Owners extends HD_Controller
|
|
{
|
|
private $searchTpAry = array('mobile' => '车主电话', 'name' => '车主姓名', 'car_num' => '车牌号');
|
|
private $searchTimeAry = array('c_time' => '创建时间', 'order_time' => '购车时间', 'ck_time' => '交付时间', 'u_time' => '最后操作时间');
|
|
protected $log_dir;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
|
|
$this->load->model('receiver/receiver_owners_oplogs_model', 'mdOwnersOplogs');
|
|
$this->load->model('receiver/receiver_owners_tag_model', 'mdOwnersTag');
|
|
$this->load->model('receiver/receiver_owners_tagdata_model', 'mdOwnersTagdata');
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->log_dir = 'receiver_' . get_class($this);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$params = $this->input->get();
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$where = array('status>=0' => null);
|
|
if ($params['title']) {
|
|
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
|
|
}
|
|
!$params['search_tp'] && $params['search_tp'] = 'mobile';
|
|
if ($params['c_time']) {
|
|
$c_time = explode(' ~ ', $params['c_time']);
|
|
$c_time[0] && $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
|
|
$c_time[1] && $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
|
|
}
|
|
if ($params['order_time']) {
|
|
$order_time = explode(' ~ ', $params['order_time']);
|
|
$order_time[0] && $where["order_time >="] = $order_time[0] . ' 00:00:00';
|
|
$order_time[1] && $where["order_time <="] = $order_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['ck_time']) {
|
|
$ck_time = explode(' ~ ', $params['ck_time']);
|
|
$ck_time[0] && $where["ck_time >="] = $ck_time[0] . ' 00:00:00';
|
|
$ck_time[1] && $where["ck_time <="] = $ck_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['u_time']) {
|
|
$u_time = explode(' ~ ', $params['u_time']);
|
|
$u_time[0] && $where["u_time >="] = $u_time[0] . ' 00:00:00';
|
|
$u_time[1] && $where["u_time <="] = $u_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['sex']) {
|
|
$where["sex"] = $params['sex'];
|
|
} else {
|
|
$params['sex'] = '';
|
|
}
|
|
if ($params['brand_id']) {
|
|
$where["brand_id"] = $params['brand_id'];
|
|
} else {
|
|
$params['brand_id'] = '';
|
|
}
|
|
if ($params['s_id']) {
|
|
$where["s_id"] = $params['s_id'];
|
|
} else {
|
|
$params['s_id'] = '';
|
|
}
|
|
if ($params['v_id']) {
|
|
$where["v_id"] = $params['v_id'];
|
|
} else {
|
|
$params['v_id'] = '';
|
|
}
|
|
$count = $this->mdOwners->count($where);
|
|
$lists = [];
|
|
if ($count) {
|
|
$this->load->model('auto/auto_brand_model', 'mdBrand');
|
|
$this->load->model('auto/auto_series_model', 'mdSeries');
|
|
$this->load->model('auto/auto_attr_model', 'mdAttr');
|
|
$res = $this->mdOwners->select($where, 'id desc', $page, $size);
|
|
|
|
$str_brand_ids = implode(',', array_unique(array_column($res, 'brand_id')));
|
|
$map_brands = $this->mdBrand->map('id', 'name', ["id in({$str_brand_ids})" => null]);
|
|
$str_s_ids = implode(',', array_unique(array_column($res, 's_id')));
|
|
$map_series = $this->mdSeries->map('id', 'name', ["id in({$str_s_ids})" => null]);
|
|
$str_v_ids = implode(',', array_unique(array_column($res, 'v_id')));
|
|
$map_attrs = $this->mdAttr->map('id', 'title', ["id in({$str_v_ids})" => null]);
|
|
|
|
foreach ($res as $key => $val) {
|
|
if (SUPER_ADMIN == $this->role || $this->role == 35) {
|
|
$mobile_sub = $val['mobile'];
|
|
} else {
|
|
$mobile_sub = $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : '';
|
|
}
|
|
$sex = $car_name = '';
|
|
if ($val['sex']) {
|
|
$sex = $val['sex'] == 1 ? '男' : '女';
|
|
}
|
|
$map_brands[$val['brand_id']] && $car_name = $map_brands[$val['brand_id']];
|
|
$map_series[$val['s_id']] && $car_name = $car_name ? $car_name . '-' . $map_series[$val['s_id']] : $map_series[$val['s_id']];
|
|
$map_attrs[$val['v_id']] && $car_name = $car_name ? $car_name . '-' . $map_attrs[$val['v_id']] : $map_attrs[$val['v_id']];
|
|
$lists[] = array(
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => $val['mobile'],
|
|
'mobile_sub' => $mobile_sub,
|
|
'sex' => $sex,
|
|
'age' => $this->getAgeByBirth($val['birth_day']),
|
|
'car_name' => $car_name,
|
|
'car_num' => $val['car_num'],
|
|
'order_time' => $val['order_time'] != '0000-00-00 00:00:00' ? $val['order_time'] : '',
|
|
'ck_time' => $val['ck_time'] != '0000-00-00 00:00:00' ? $val['ck_time'] : '',
|
|
);
|
|
}
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
$this->data['searchTpAry'] = $this->searchTpAry;
|
|
$this->data['searchTimeAry'] = $this->searchTimeAry;
|
|
$this->data['params'] = $params;
|
|
$this->data['_title'] = '车主列表';
|
|
return $this->show_view('receiver/owners/lists', true);
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$row = $this->mdOwners->get(array('id' => $id));
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车主不存在!');
|
|
}
|
|
//用户信息
|
|
if (SUPER_ADMIN == $this->role || 35 == $this->role) {
|
|
$mobile_sub = $row['mobile'];
|
|
} else {
|
|
$mobile_sub = $row['mobile'] ? substr_replace($row['mobile'], '*****', 0, 5) : '';
|
|
}
|
|
$info = $row;
|
|
$info['mobile'] = $mobile_sub;
|
|
$info['order_time'] = $row['order_time'] != '0000-00-00 00:00:00' ? $row['order_time'] : '';
|
|
$info['ck_time'] = $row['ck_time'] != '0000-00-00 00:00:00' ? $row['ck_time'] : '';
|
|
$info['c_time'] = date('Y-m-d H:i:s', $row['c_time']);
|
|
$info['tag'] = $this->get_tag($row['id']);
|
|
//操作日志
|
|
$rows_log = $this->mdOwnersOplogs->select(['own_id' => $id], 'id desc', 0, 0);
|
|
if($this->input->get('dev')){
|
|
print_r($rows_log);
|
|
echo '-----';
|
|
}
|
|
$logs = [];
|
|
if ($rows_log) {
|
|
foreach ($rows_log as $key => $value) {
|
|
$rec_text = $rec_url = '';
|
|
if ($value['type'] == 2) {
|
|
$rec_row = $this->receiver_xz_model->get(['id' => $value['log']], 'rec_url,duration');
|
|
if ($rec_row['duration']) {
|
|
$rec_row['rec_url'] && $rec_url = $rec_row['rec_url'];
|
|
!$rec_row['rec_url'] && $rec_text = '录音暂未生成';
|
|
} else {
|
|
$rec_text = '未接通';
|
|
}
|
|
}
|
|
$imgs = [];
|
|
if ($value['imgs']) {
|
|
$json_imgs = json_decode($value['imgs'], true);
|
|
foreach ($json_imgs as $key1 => $value1) {
|
|
$imgs[] = build_qiniu_image_url($value1);
|
|
}
|
|
}
|
|
$logs[] = array(
|
|
'uname' => $value['uname'],
|
|
'log' => $value['log'],
|
|
'imgs' => $imgs,
|
|
'rec_url' => $rec_url,
|
|
'rec_text' => $rec_text,
|
|
'type_name' => $this->mdOwnersOplogs->typeAry($value['type']),
|
|
'c_time' => date('Y-m-d H:i', $value['c_time'])
|
|
);
|
|
}
|
|
}
|
|
$this->data['info'] = $info;
|
|
$this->data['logs'] = $logs;
|
|
$this->data['_title'] = '车主户详情';
|
|
return $this->show_view('receiver/owners/get', true);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
// TODO: Implement add() method.
|
|
}
|
|
|
|
/**
|
|
* 新增日志
|
|
* @return bool
|
|
*/
|
|
function add_log()
|
|
{
|
|
$params = $this->input->post();
|
|
if (!$params['id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
|
|
}
|
|
if (!$params['log']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入内容!');
|
|
}
|
|
$addData = array(
|
|
'own_id' => $params['id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($params['type']),
|
|
'log' => $params['log'],
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->mdOwnersOplogs->add($addData);
|
|
if ($id) {
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
} else {
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
* @return bool
|
|
*/
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
if (!$info) {
|
|
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
|
|
}
|
|
$row = $this->mdOwners->get(array('id' => $info['id']));
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车主信息不存在!');
|
|
}
|
|
$msg = '修改成功';
|
|
$code = SYS_CODE_SUCCESS;
|
|
if ($info['editType'] == 1) {
|
|
} else if ($info['editType'] == 2) {
|
|
//更新车主信息
|
|
$ret = $this->mdOwners->update(['name' => $info['name'], 'birth_day' => $info['birth_day'], 'sex' => $info['sex'],
|
|
'brand_id' => $info['brand_id'], 's_id' => $info['s_id'], 'v_id' => $info['v_id'], 'car_num' => $info['car_num'],
|
|
'order_time' => $info['order_time'], 'ck_time' => $info['ck_time']], ['id' => $info['id']]);
|
|
if (!$ret) {
|
|
$code = SYS_CODE_FAIL;
|
|
$msg = '修改车主信息失败';
|
|
} else {
|
|
$msg = '修改车主信息成功';
|
|
$this->addLog(array('own_id' => $info['id'], 'type' => 0, 'log' => '更新车主信息'));
|
|
}
|
|
} else if ($info['editType'] == 3) {
|
|
$id = $info['id'];
|
|
//客户标签
|
|
if (!$info['tag']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户画像不存在!');
|
|
}
|
|
$add_tag = [];
|
|
//查找已加入标签
|
|
$res_td = $this->mdOwnersTagdata->select(['o_id' => $id], 'id desc', 0, 0, 't_id');
|
|
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
|
|
foreach ($info['tag'] as $key => $val) {
|
|
foreach ($val['list'] as $key2 => $val2) {
|
|
if ($val['type'] == 'checkbox') {
|
|
if ($val2['checked'] == 'true') {
|
|
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
|
|
$add_tag[] = ['o_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
|
|
}
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
|
|
$this->mdOwnersTagdata->delete(['o_id' => $id, 't_id' => $val2['id']]);
|
|
}
|
|
}
|
|
} else {
|
|
if ($val['value'] == $val2['id']) {
|
|
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
|
|
$add_tag[] = ['o_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
|
|
}
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
|
|
$this->mdOwnersTagdata->delete(['o_id' => $id, 't_id' => $val2['id']]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($add_tag && count($add_tag)) {
|
|
$this->mdOwnersTagdata->add_batch($add_tag);
|
|
}
|
|
$this->addLog(array('own_id' => $info['id'], 'type' => 0, 'log' => '修改车主画像'));
|
|
}
|
|
return $this->show_json($code, $msg);
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
// TODO: Implement export() method.
|
|
}
|
|
|
|
/**
|
|
* Notes:增加日志
|
|
* Created on: 2021/7/23 10:48
|
|
* Created by: dengbw
|
|
* @param array $ary
|
|
* @return mixed
|
|
*/
|
|
private function addLog($ary = array())
|
|
{
|
|
$id = 0;
|
|
if ($ary['log']) {
|
|
$addData = array(
|
|
'own_id' => $ary['own_id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($ary['type']),
|
|
'log' => $ary['log'],
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->mdOwnersOplogs->add($addData);
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Notes:车主标签
|
|
* Created on: 2022/6/16 14:47
|
|
* Created by: dengbw
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
private function get_tag($id)
|
|
{
|
|
$show = $res_td = [];
|
|
$res = $this->mdOwnersTag->select(['status' => 1, 'pid' => 0], 'sort desc,id desc', 0, 0, 'id,name,type');
|
|
if ($res) {
|
|
$id && $res_td = $this->mdOwnersTagdata->select(['o_id' => $id], 'id desc', 0, 0, 't_id');//查找用户选择
|
|
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
|
|
foreach ($res as $key => $val) {
|
|
$list = [];
|
|
$value = '';
|
|
$res2 = $this->mdOwnersTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
|
|
foreach ($res2 as $key2 => $val2) {
|
|
//检查是否选中标签
|
|
$setValue = ['id' => $val2['id'], 'name' => $val2['name']];
|
|
if ($val['type'] == 'checkbox') {
|
|
$setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {
|
|
$value = $val2['id'];
|
|
}
|
|
}
|
|
$list[] = $setValue;
|
|
}
|
|
$show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'value' => $value, 'list' => $list];
|
|
}
|
|
}
|
|
return $show;
|
|
}
|
|
|
|
/**
|
|
* Notes:根据生日计算年龄,年龄的格式是:2018-01-22
|
|
* Created on: 2022/6/16 14:47
|
|
* Created by: dengbw
|
|
* @param $birthday
|
|
* @return false|int|string
|
|
*/
|
|
private function getAgeByBirth($birthday)
|
|
{
|
|
$birth_year = date('Y', strtotime($birthday));
|
|
$birth_month = date('m', strtotime($birthday));
|
|
$birth_day = date('d', strtotime($birthday));
|
|
if (empty($birth_year) || empty($birth_month) || empty($birth_day)) {
|
|
return 0;
|
|
}
|
|
$current_year = date('Y', time());
|
|
$current_month = date('m', time());
|
|
$current_day = date('d', time());
|
|
if ($birth_year >= $current_year) {
|
|
return 0;
|
|
}
|
|
$age = $current_year - $birth_year - 1;
|
|
if ($current_month > $birth_month) {
|
|
return $age + 1;
|
|
} else if ($current_month == $birth_month && $current_day >= $birth_day) {
|
|
return $age + 1;
|
|
} else {
|
|
return $age;
|
|
}
|
|
}
|
|
|
|
} |