liche update for admin customer control

This commit is contained in:
xxb
2021-07-27 10:28:34 +08:00
committed by lccsw
parent bdaaf44fbb
commit 4b3b283f74
3 changed files with 838 additions and 0 deletions
+288
View File
@@ -0,0 +1,288 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by PhpStorm.
* User: xuxb
* Date: 2021/7/26
* Time: 11:20
*/
class Customer extends HD_Controller{
private $searchTpAry = array('mobile' => '客户手机号', 'name' => '客户姓名');
protected $log_dir;
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('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
$this->log_dir = 'receiver_'. get_class($this);
}
public function index(){
return $this->lists();
}
public function lists(){
$status_arr = $this->customers_model->get_status();
unset($status_arr['-1']);
$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']);
if ($c_time[0]) {
$where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
}
if ($c_time[1]) {
$where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
}
}
strlen($params['status']) && $where["status"] = $params['status'];
$count = $this->customers_model->count($where);
$lists = [];
if($count){
$fileds = 'id,name,mobile,cf_title,c_time,admin_id,status';
$rows = $this->customers_model->select($where,'id desc',$page,$size,$fileds);
//获取销售员
$admin_id_arr = array_unique(array_column($rows,'admin_id'));
$admin_id_arr && $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr,'id,uname');
foreach($rows as $key => $val){
$lists[] = array(
'id' => $val['id'],
'name' => $val['name'],
'mobile' => $val['mobile'] ? substr_replace($val['mobile'], '****', 3, 4) : '',
'cf_title' => $val['cf_title'],
'status_name' => $status_arr[$val['status']],
'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '',
'c_time' => $val['c_time'] > 0 ? date('Y-m-d H:i:s', $val['c_time']) : '',
);
}
}
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['searchTpAry'] = $this->searchTpAry;
$this->data['params'] = $params;
$this->data['status_arr'] = $status_arr;
$this->data['_title'] = '客户列表';
return $this->show_view('receiver/customer/lists', true);
}
public function get(){
$id = $this->input->get('id');
$this->load->model("biz/biz_model");
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$row = $this->customers_model->get(array('id' => $id));
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
}
$if_driver = 1 == $row['if_driver'] ? '是':'否';
$is_top = 1 == $row['is_top'] ? '是':'否';
$car_json = json_decode($row['car_json'], true);
$side = $car_json['version']['title'] ? $car_json['version']['title'] : '';
$color = $car_json['color']['title'] ? $car_json['color']['title'] : '';
$row_biz = $this->biz_model->get(array('id' => $row['biz_id']));
$row_brand = $this->auto_brand_model->get(array('id' => $row['brand_id']), 'name');
$row_seriy = $this->auto_series_model->get(array('id' => $row['s_id']), 'name');
//获取销售员
$row_admin = $this->app_licheb_users_model->get(array('id' => $row['admin_id']),'id,uname');
//操作日志
$rows_log = $this->customer_oplogs_model->select(array('customer_id' => $id), 'c_time desc', 0, 0);
//用户信息
$info = array(
'id' => $row['id'],
'name' => $row['name'],
'mobile' => substr_replace($row['mobile'], '****', 3, 4),
'cf_title' => $row['cf_title'],
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
'status' => $row['status'],
);
//到店信息
$toshop = array(
array(
array('title' => '门店', 'value' => $row_biz['biz_name']),
array('title' => '试驾', 'value' => $if_driver),
array('title' => '到店次数', 'value' => $row['a_num']),
array('title' => '试驾次数', 'value' => $row['t_num']),
),
array(
array('title' => '品牌', 'value' => $row_brand['name']),
array('title' => '车系', 'value' => $row_seriy['name']),
array('title' => '车型', 'value' => $side),
array('title' => '颜色', 'value' => $color),
),
array(
array('title' => '分配时间', 'value' => $row['p_time']),
array('title' => '最后联系', 'value' => $row['cont_time']),
array('title' => '预计购买', 'value' => $row['buy_time']),
),
array(
array('title' => '置顶', 'value' => $is_top),
array('title' => '销售员', 'value' => $row_admin['uname']),
),
);
//操作日志
$logs = array();
foreach ($rows_log as $key => $value) {
$logs[] = array(
'uname' => $value['uname'],
'log' => $value['log'],
'type_name' => '小记',
'c_time' => date('Y-m-d H:i', $value['c_time'])
);
}
//状态值,-1不显示
$statusAry = $this->customers_model->get_status();
unset($statusAry['-1']);
$this->data['statusAry'] = $statusAry;
$this->data['info'] = $info;
$this->data['toshop'] = $toshop;
$this->data['logs'] = $logs;
$this->data['_title'] = '客户详情';
return $this->show_view('receiver/customer/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(
'customer_id' => $params['id'],
'uid' => $this->uid,
'uname' => $this->username,
'type' => intval($params['type']),
'log' => $params['log'],
'c_time' => time()
);
$id = $this->customer_oplogs_model->add($addData);
if ($id) {
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
} else {
debug_log("[error]" . $this->customer_oplogs_model->db->last_query(), __FUNCTION__, $this->log_dir);
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->customers_model->get(array('id' => $info['id']));
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '客户信息不存在!');
}
$msg = '修改成功';
$code = SYS_CODE_SUCCESS;
if ($info['editType'] == 1) {
//更新状态
$statuAry = $this->customers_model->get_status();
$status_name = $statuAry[$row['status']];
$status_name_up = $statuAry[$info['status']];
$log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')';
$ret = $this->customers_model->update(array('status' => $info['status']), array('id' => $info['id']));
if (!$ret) {
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
$code = SYS_CODE_FAIL;
$msg = '修改状态失败';
} else {
$msg = '修改状态成功';
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
}
} else if ($info['editType'] == 2) {
//更新客户信息
if ($info['name'] == $row['name']) {
return $this->show_json(SYS_CODE_FAIL, '客户姓名未修改!');
}
$log = '更新客户姓名(' . $row['name'] . ')为(' . $info['name'] . ')';
$ret = $this->customers_model->update(array('name' => $info['name']), array('id' => $info['id']));
if (!$ret) {
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
$code = SYS_CODE_FAIL;
$msg = '修改用户信息失败';
} else {
$msg = '修改用户信息成功';
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
}
}
return $this->show_json($code, $msg);
}
public function del(){
// TODO: Implement del() method.
}
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(
'customer_id' => $ary['customer_id'],
'uid' => $this->uid,
'uname' => $this->username,
'type' => intval($ary['type']),
'log' => $ary['log'],
'c_time' => time()
);
$id = $this->customer_oplogs_model->add($addData);
}
return $id;
}
}
+387
View File
@@ -0,0 +1,387 @@
<div class="am-form am-form-horizontal" style="width: 98%;padding-top: 10px">
<div id="vue-edit">
<div class="am-g">
<div class="col-sm-12" style="margin-bottom: 20px;">
<div class="col-sm-2">
<div class="my-panel">
<div class="text-center">
状态
</div>
<div class="text-center" style="padding-top: 5px;">
<select id="status" v-model="info.status">
<template v-for="(v,i) in statusAry">
<option :value="i">{{v}}</option>
</template>
</select>
</div>
</div>
</div>
<div class="am-form-inline" style="padding-right: 10px;padding-top: 12px;">
<div class="text-right">
<div class="am-form-group ml10">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-default"
@click="editType(1)" v-if="edit_index==1">取消编辑</a>
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-default"
@click="editType(1)" v-else>编辑状态</a>
</div>
<div class="am-form-group ml10" v-if="edit_index==1">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">修改状态</a>
</div>
</div>
</div>
</div>
</div>
<div class="am-u-lg-12">
<div class="am-panel am-panel-default">
<div class="am-panel-hd">
<span href="javascript:void(0)" style="font-size: 20px">
用户信息
</span>
<span style="float:right;margin-top:5px;">
<a href="javascript:" @click="editType(2)"><i class="fa fa-edit"></i></a>
</span>
</div>
<div class="am-panel-bd am-g">
<table width="100%" style="margin:10px 10px 10px 20px;">
<tr>
<td class="table-td">
<div class="input-group">
<div class="input-group-addon">客户姓名:</div>
<input id="info_name" type="text" v-model="info.name" placeholder="请输入客户姓名">
</div>
</td>
<td class="table-td">
客户电话:{{info.mobile}}
</td>
<td class="table-td">
渠道来源:{{info.cf_title}}
</td>
<td class="table-td">
加入时间:{{info.c_time}}
</td>
</tr>
<tr>
<td>
<div class="am-form-inline" style="padding-right: 30px;padding-top: 10px;">
<div class="text-left pt10">
<div class="am-form-group ml10">
<a v-if="edit_index==2" href="javascript:void(0)"
class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">修改用户信息</a>
</div>
</div>
</div>
</td>
<!--<td colspan="3">
<div class="am-form-inline" style="padding-right: 40px;padding-top: 10px;">
<div class="text-right pt10">
<div class="am-form-group ml10">
<a data-modal="/common/show_sms?id=<?= $info['id'] ?>&mobile=<?= $info['mobile'] ?>&type=1"
data-title="发送短信"
class="am-btn am-btn-sm am-btn-success">短信</a>
</div>
<div class="am-form-group ml10">
<a href="javascript:void(0);"
data-modal="/receiver/clues/get_xbind?id=<?= $info['id'] ?>"
class="am-btn am-btn-sm am-btn-success" data-title="获取手机号">
拨打电话
</a>
</div>
</div>
</div>
</td>-->
</tr>
</table>
</div>
</div>
</div>
<div class="am-u-lg-12">
<div class="am-panel am-panel-default">
<div class="am-panel-hd">
<span href="javascript:void(0)" style="font-size: 20px">
到店信息
</span>
</div>
<div class="am-panel-bd am-g">
<table width="100%"
style="margin:10px 10px 10px 20px;">
<tr v-for="(tr, i) in toshop">
<td class="table-td" v-for="(td, j) in tr"><span class="mr5">{{td.title}}:</span>{{td.value}}</td>
</tr>
</table>
</div>
</div>
</div>
<div class="am-u-lg-12">
<div class="am-panel am-panel-default">
<div class="am-panel-hd">
<span href="javascript:void(0)" style="font-size: 20px">
操作日志
</span>
<span style="float:right;margin-top:5px">
<a href="javascript:void(0)" @click="logModal()">新增小记</a>
</span>
</div>
<div class="am-panel-bd">
<div class="am-tabs" data-am-tabs>
<div class="am-tab-panel am-active">
<table class="am-table">
<thead>
<tr>
<th width="15%"><span>操作人员</span></th>
<th width=""><span>内容</span></th>
<th width="13%"><span>类型</span></th>
<th width="15%"><span>操作时间</span></th>
</tr>
</thead>
<tbody>
<?php foreach ($logs as $key => $val) { ?>
<tr>
<td style="vertical-align:middle;word-wrap:break-word"><?= $val['uname'] ?></td>
<td style="vertical-align:middle;word-wrap:break-word">
<? if ($val['rec_url']) { ?>
<audio controls="controls">
<source src="<?= $val['rec_url'] ?>"/>
</audio>
<? } else if ($val['rec_text']) { ?>
<?= $val['rec_text'] ?>
<? } else { ?>
<?= $val['log'] ?>
<? } ?>
</td>
<td style="vertical-align:middle;word-wrap:break-word"><?= $val['type_name'] ?></td>
<td style="vertical-align:middle;word-wrap:break-word;"><?= $val['c_time'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="log-modal" style="display: none;">
<div style="padding-top: 20px;">
<div class="am-form-group">
<label class="am-para-label label-width">内容:</label>
<div class="am-para-input" style="width: 80%">
<textarea name="log" rows="5" placeholder="请输入内容" v-model="goods.log"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var vue_obj;
$(document).ready(function () {
vue_obj = new Vue({
el: '#vue-edit',
data: {
edit_index:0,
info: {},
statusAry:[],
toshop:[],
logs:[],
goods: {"imgs_url": [], "imgs": [], "log": ''}
},
mounted: function () {
var that = this;
that.info = <?=json_encode($info)?>;
that.statusAry = <?=json_encode($statusAry)?>;
that.toshop = <?=json_encode($toshop)?>;
that.logs = <?=json_encode($logs)?>;
},
computed: {},
created: function () {
},
updated: function () {
},
methods: {
editType: function (index) {
var vm = this;
if (vm.edit_index == index) {
vm.edit_index = 0;
} else {
vm.edit_index = index;
}
},
logModal: function () {
var vm = this;
layer.open({
type: 1,
area: ['50%'], //宽高
content: $('#log-modal'),
title: '新增小记',
shade: false,
btn: ['保存', '取消'],
yes: function (index) {
$.ajax({
url: '/receiver/customer/add_log',
type: 'post',
dataType: 'json',
data: {
act_type: 1, id: <?= $info['id'] ?>, type: 0, log: vm.goods.log, imgs: vm.goods.imgs
},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
layer.closeAll('loading');
},
});
}
});
},
saveEdit: function () {
var vm = this;
vm.info.editType = vm.edit_index;
$.ajax({
url: '/receiver/customer/edit',
type: 'post',
dataType: 'json',
data: {
info: vm.info
},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
loading = false;
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
loading = false;
layer.closeAll('loading');
},
});
},
}
});
});
</script>
<style type="text/css">
.input-group {
width: 100%;
padding-right: 30px;
}
.input-group-addon {
padding: 0px 10px 0px 0px;
font-size: 1.6rem;
font-weight: normal;
line-height: 0px;
color: #333;
text-align: right;
background-color: #fff;
border: 0px solid #fff;
border-radius: 0px;
width: 120px;
}
.table-td {
width: 20%;
padding-top: 15px;
line-height: 37px;
font-size: 1.6rem;
}
.my-ul ul li {
padding: 10px;
}
.my-panel {
padding: 10px;
border: 1px solid #ddd;
height: 90px;
}
.auto-content {
width: min-content;
min-width: 50%;
}
.btn-group .disabled {
background-color: #eee;
opacity: 1;
}
.photo-upload {
position: relative;
font-size: 0;
}
.photo-upload:after {
content: "";
display: table;
clear: both;
}
.photo-upload-item {
position: relative;
float: left;
margin-right: 10px;
margin-bottom: 10px;
font-size: 12px; /*display:inline-block;width:120px;*/
}
.photo-upload-item > img {
}
.photo-upload-item-check,
.photo-upload-item-remove {
opacity: 0;
position: absolute;
top: -8px;
right: -8px;
width: 24px;
height: 24px;
line-height: 24px;
border: 1px solid #fff;
background-color: #eee;
border-radius: 50%;
text-align: center;
cursor: pointer;
}
.photo-upload-item:hover .photo-upload-item-remove {
opacity: 1;
transition: all .4s ease
}
.photo-upload-item-check {
opacity: 1;
background-color: #36f;
color: #fff;
}
</style>
<link rel="stylesheet" type="text/css" href="/static/css/appitem/font-awesome.min.css?v=1581252500">
+163
View File
@@ -0,0 +1,163 @@
<link rel="stylesheet" type="text/css" href="/static/css/font-awesome.min.css?v=1581252500">
<div class="bs-example bs-example-tabs" data-example-id="togglable-tabs" style="font-size:15px;">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="<?= !strlen($params['status']) ? 'active' : '' ?>">
<a href="javascript:void (0);" data-open="/receiver/clues">全部</a>
</li>
<? foreach ($status_arr as $key => $val) { ?>
<li role="presentation"
class="<?= strlen($params['status']) && $params['status'] == $key ? 'active' : '' ?>">
<a href="javascript:void (0);" data-open="/receiver/clues?status=<?= $key ?>">
<?= $val ?>
</a>
</li>
<? } ?>
</ul>
</div>
<div class="coms-table-wrap mt10">
<form class="form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/receiver/customer">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">客户搜索:</label>
<div class="am-para-inline w100">
<select name="search_tp" v-model="params.search_tp">
<option :value="i" v-for="(v,i) in searchTpAry">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group fl">
<div class="am-para-inline w260">
<input id="title" name="title" type="text" v-model="params.title"/>
</div>
</div>
<div class="am-form-group fl">
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<label class="am-para-label w100">创建时间:</label>
<div class="am-form-group fl">
<div class="am-para-inline w300">
<input id="id-create-time" name="c_time" type="text" value="<?= $params['c_time'] ?>"
placeholder="创建时间范围" autocomplete="off"/>
</div>
<div class="am-para-inline" style="padding-top: 5px;">
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="today">今天</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="yesterday">昨日</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="7day">最近7天</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="30day">最近30天</a>
</div>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group fl" style="margin-bottom: 0px;">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<div class="am-form-group fr mr10">
<span>共<?= intval($pager['totle']) ?>个客户</span>
</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="3%">ID</th>
<th width="5%"><span>客户姓名</span></th>
<th width="5%"><span>客户电话</span></th>
<th width="8%"><span>客户来源</span></th>
<th width="8%"><span>状态</span></th>
<th width="4%"><span>跟进人</span></th>
<th width="7%"><span>创建时间</span></th>
</tr>
</thead>
<tbody>
<template v-for="(v,i) in lists">
<tr>
<td>{{v.id}}</td>
<td>{{v.name}}</td>
<td>{{v.mobile}}</td>
<td>{{v.cf_title}}</td>
<td>{{v.status_name}}</td>
<td>{{v.admin_name}}</td>
<td>{{v.c_time}}</td>
</tr>
<tr>
<td colspan="7">
<div class="row">
<div class="col-md-4 align-l">
</div>
<div class="col-md-8 align-r" style="padding-right: 30px;">
<a href="javascript:void(0);" :data-open="'/receiver/customer/get?id='+v.id"
class="am-btn am-btn-primary am-btn-xs">查看详情</a>
</div>
</td>
</tr>
</template>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
laydate.render({
elem: '#id-create-time', range: '~'
});
$('.id-day-btn').click(function () {
var type = $(this).data('date'), date = '', d_obj = new Date();
switch (type) {
case 'today':
date = d_obj.Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case 'yesterday':
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case '7day':
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
case '30day':
date = (new Date(d_obj.getTime() - 86400000 * 30)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
}
$('#id-create-time').val(date);
});
});
var vue_obj;
$(function(){
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params:[],
searchTpAry:[],
lists:[]
},
mounted:function() {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.searchTpAry = <?=json_encode($searchTpAry)?>;
vm.lists = <?=json_encode($lists)?>;
},
methods:{
saveEdit:function(){
$("form").submit();
}
},
watch:{}
});
<?php page_script($pager) ?>
});
</script>