diff --git a/admin/controllers/receiver/Clues.php b/admin/controllers/receiver/Clues.php index 40adff1e..846102d0 100644 --- a/admin/controllers/receiver/Clues.php +++ b/admin/controllers/receiver/Clues.php @@ -1,12 +1,14 @@ '客户手机号', 'name' => '客户姓名'); protected $log_dir; - public function __construct(){ + public function __construct() + { parent::__construct(); $this->load->model('receiver/receiver_clues_model', 'clues_model'); $this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model'); @@ -14,15 +16,20 @@ class Clues extends HD_Controller{ $this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs'); $this->load->model('app/licheb/app_licheb_users_model'); $this->load->model("biz/biz_model"); + $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + $this->load->model('auto/auto_series_model', 'mdAutoSeries'); + $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); $this->log_dir = 'receiver_clues'; } //首页信息 - public function index(){ + public function index() + { $this->lists(); } - public function lists($where = array()){ + public function lists($where = array()) + { $status_arr = $this->clues_model->get_status(); $params = $this->input->get(); @@ -48,16 +55,16 @@ class Clues extends HD_Controller{ $count = $this->clues_model->count($where); $lists = []; - if($count){ + if ($count) { $fileds = 'id,name,mobile,cf_id,status_id,c_time,admin_id,status'; - $rows = $this->clues_model->select($where,'id desc',$page,$size,$fileds); + $rows = $this->clues_model->select($where, 'id desc', $page, $size, $fileds); //获取来源 - $cf_id_arr = array_unique(array_column($rows,'cf_id')); - $cf_rows = $this->clues_cfrom_model->get_map_by_ids($cf_id_arr,'id,title'); + $cf_id_arr = array_unique(array_column($rows, 'cf_id')); + $cf_rows = $this->clues_cfrom_model->get_map_by_ids($cf_id_arr, 'id,title'); //获取销售员 - $admin_id_arr = array_unique(array_column($rows,'admin_id')); - $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr,'id,uname'); - foreach($rows as $key => $val){ + $admin_id_arr = array_unique(array_column($rows, 'admin_id')); + $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr, 'id,uname'); + foreach ($rows as $key => $val) { $val['cf_title'] = isset($cf_rows[$val['cf_id']]) ? $cf_rows[$val['cf_id']][0]['title'] : ''; $val['status_name'] = $status_arr[$val['status']]; $val['admin_name'] = isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : ''; @@ -80,7 +87,7 @@ class Clues extends HD_Controller{ if (!$id) { return $this->show_json(SYS_CODE_FAIL, '非法参数!'); } - $statusList = $logsList = $intention = array(); + $statusList = $logsList = $intention = $autoList = array(); $re = $this->clues_model->get(array('id' => $id)); if (!$re || empty($re)) { return $this->show_json(SYS_CODE_FAIL, '线索不存在!'); @@ -107,8 +114,6 @@ class Clues extends HD_Controller{ } $info_show['logsList'] = $logsList; //意向信息 - $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); - $this->load->model('auto/auto_series_model', 'mdAutoSeries'); $re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name'); $re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name'); $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : array(); @@ -117,6 +122,18 @@ class Clues extends HD_Controller{ $intention['v_name'] = '车型:' . ($jsondata['car']['version']['title'] ? $jsondata['car']['version']['title'] : ''); $intention['cor_name'] = '车身颜色:' . ($jsondata['car']['color']['title'] ? $jsondata['car']['color']['title'] : ''); $info_show['intention'] = $intention; + + $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); + if ($re['brand_id']) { + $autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $re['brand_id']), 'id desc', 0, 0, 'id,name'); + } + $dataInfo['v_id'] = intval($jsondata['car']['version']['id']); + $dataInfo['cor_id'] = intval($jsondata['car']['color']['id']); + if ($re['s_id']) { + $autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); + $autoList[4] = $this->mdAutoAttr->select(array('type' => 0, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); + } + $info_show['autoList'] = $autoList; $this->data['info'] = $dataInfo; $this->data['info_show'] = $info_show; $this->data['_title'] = '线索详情'; @@ -166,14 +183,15 @@ class Clues extends HD_Controller{ } //添加单条数据 - public function add(){ + public function add() + { $info = $this->input->post('info'); - if(!$info['name']){ + if (!$info['name']) { return $this->show_json(SYS_CODE_FAIL, '请填写姓名'); } - if(! mobile_valid($info['mobile'])){ + if (!mobile_valid($info['mobile'])) { return $this->show_json(SYS_CODE_FAIL, '手机号码不准确'); } @@ -184,7 +202,7 @@ class Clues extends HD_Controller{ 'c_time' => time(), ); $ret = $this->clues_model->add($add); - if(!$ret){ + if (!$ret) { debug_log("[error]# add fail; " . $this->clues_model->db->last_query(), __FUNCTION__, $this->log_dir); return $this->show_json(SYS_CODE_FAIL, '添加失败'); } @@ -258,7 +276,6 @@ class Clues extends HD_Controller{ public function edit() { $info = $this->input->post('info'); - $opt_type = $this->input->post('opt_type'); if (!$info) { return $this->show_json(SYS_CODE_FAIL, '非法参数!'); } @@ -266,36 +283,108 @@ class Clues extends HD_Controller{ if (!$re || empty($re)) { return $this->show_json(SYS_CODE_FAIL, '线索不存在!'); } + $msg = '修改成功'; + $code = SYS_CODE_SUCCESS; if ($info['editType'] == 1) { $status_name = $this->clues_model->get_status()[$re['status']]; $status_name_up = $this->clues_model->get_status()[$info['status']]; $log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')'; + $ret = $this->clues_model->update(array('status' => $info['status']), array('id' => $info['id'])); + if (!$ret) { + $code = SYS_CODE_FAIL; + $msg = '修改状态失败'; + } else { + $msg = '修改状态成功'; + $this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => $log)); + } + } else if ($info['editType'] == 2) { + if ($info['name'] == $re['name']) { + return $this->show_json(SYS_CODE_FAIL, '客户姓名未修改!'); + } + $log = '更新客户姓名(' . $re['name'] . ')为(' . $info['name'] . ')'; + $ret = $this->clues_model->update(array('name' => $info['name']), array('id' => $info['id'])); + if (!$ret) { + $code = SYS_CODE_FAIL; + $msg = '修改用户信息失败'; + } else { + $msg = '修改用户信息成功'; + $this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => $log)); + } + } else if ($info['editType'] == 3) { + if (!$info['brand_id']) { + return $this->show_json(SYS_CODE_FAIL, '请选择品牌'); + } + $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : array(); + $jsondata['car']['version']['id'] = intval($info['v_id']); + $jsondata['car']['color']['id'] = intval($info['cor_id']); + $ret = $this->clues_model->update(array('brand_id' => $info['brand_id'], + 's_id' => $info['s_id'], 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)), array('id' => $info['id'])); + if (!$ret) { + $code = SYS_CODE_FAIL; + $msg = '修改意向信息失败'; + } else { + $msg = '修改意向信息成功'; + if ($info['brand_id']) { + $re_b = $this->mdAutoBrand->get(array('id' => $info['brand_id']), 'name'); + $log = $re_b['name']; + if ($info['s_id']) { + $re_s = $this->mdAutoSeries->get(array('id' => $info['s_id']), 'name'); + $log .= '-' . $re_s['name']; + } + if ($info['v_id']) { + $re_v = $this->mdAutoAttr->get(array('id' => $info['v_id']), 'title'); + $log .= '-' . $re_v['title']; + } + if ($info['cor_id']) { + $re_cor = $this->mdAutoAttr->get(array('id' => $info['cor_id']), 'title'); + $log .= '-' . $re_cor['title']; + } + $this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => '更新意向信息为(' . $log . ')')); + } + } + } + return $this->show_json($code, $msg); + } + + /** + * 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( - 'clue_id' => $info['id'], + 'clue_id' => $ary['clue_id'], 'uid' => $this->uid, 'uname' => $this->username, - 'type' => 0, - 'log' => $log, + 'type' => intval($ary['type']), + 'log' => $ary['log'], 'c_time' => time() ); - $this->mdOplogs->add($addData); + $id = $this->mdOplogs->add($addData); } - $this->clues_model->update(array('status' => $info['status']), array('id' => $info['id'])); - return $this->show_json(SYS_CODE_SUCCESS, '成功修改状态!'); + return $id; } //删除单条数据 - public function del(){ + public function del() + { } //批量操作(默认修改状态) - public function batch(){ + public function batch() + { } //导出数据列表 - public function export(){ + public function export() + { } @@ -306,7 +395,7 @@ class Clues extends HD_Controller{ $where = [ 'status' => 1, ]; - $bizList = $this->biz_model->select($where,'','','','id,biz_name'); + $bizList = $this->biz_model->select($where, '', '', '', 'id,biz_name'); $this->data['bizList'] = $bizList; $this->data['ids'] = $ids; return $this->show_view('receiver/clues/get_adviser'); @@ -316,8 +405,8 @@ class Clues extends HD_Controller{ { $biz_id = $this->input->post('biz_id'); $ids = $this->input->post('ids'); - $ids_arr = explode(',',$ids); - $biz = $this->biz_model->get(['id'=>$biz_id]); + $ids_arr = explode(',', $ids); + $biz = $this->biz_model->get(['id' => $biz_id]); if (!$biz) { return $this->show_json(SYS_CODE_FAIL, '请选择分配门店!'); } @@ -327,13 +416,13 @@ class Clues extends HD_Controller{ $where = [ "id in ($ids)" => null ]; - $clues_rows = $this->clues_model->map('id','',$where); - foreach($ids_arr as $val){ + $clues_rows = $this->clues_model->map('id', '', $where); + foreach ($ids_arr as $val) { $clues_row = $clues_rows[$val][0]; //判断是否已分配 - $cus_row = $this->customers_model->get(['rid'=>$val,'status != 3'=>null]); - if($clues_row && !$cus_row){ - $jsondata = json_decode($clues_row['jsondata'],true); + $cus_row = $this->customers_model->get(['rid' => $val, 'status != 3' => null]); + if ($clues_row && !$cus_row) { + $jsondata = json_decode($clues_row['jsondata'], true); $add_data = [ 'rid' => $val, 'name' => $clues_row['name'], @@ -346,19 +435,19 @@ class Clues extends HD_Controller{ 'p_time' => date('Y-m-d H:i:s'), 'c_time' => time() ]; - if($jsondata['car']){ + if ($jsondata['car']) { isset($jsondata['car']['version']) && $add_data['v_id'] = $jsondata['car']['version']['id']; - $add_data['car_json'] = json_encode($jsondata['car'],JSON_UNESCAPED_UNICODE); + $add_data['car_json'] = json_encode($jsondata['car'], JSON_UNESCAPED_UNICODE); unset($jsondata['car']); } - $jsondata && $add_data['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE); + $jsondata && $add_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); $customers_id = $this->customers_model->add($add_data); - if($customers_id){ - $this->clues_model->update(['status'=>1],['id'=>$val]); + if ($customers_id) { + $this->clues_model->update(['status' => 1], ['id' => $val]); $this->load->library('receiver/clues_entity'); - $this->clues_entity->add_log($val,$this->uid,$this->username,"分配给【{$biz['biz_name']}】商家"); + $this->clues_entity->add_log($val, $this->uid, $this->username, "分配给【{$biz['biz_name']}】商家"); $this->load->library('receiver/customers_entity'); - $this->customers_entity->add_log($customers_id,$this->uid,$this->username,"平台分配",0,'admin'); + $this->customers_entity->add_log($customers_id, $this->uid, $this->username, "平台分配", 0, 'admin'); } } } @@ -368,8 +457,61 @@ class Clues extends HD_Controller{ //晓致绑定手机号 public function get_xbind() { - $id = $this->input->get_post('id'); - $mobile = '18350451617'; + $params = $this->input->get(); + $id = intval($params['id']); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $re = $this->clues_model->get(array('id' => $id)); + if (!$re['mobile']) { + return $this->show_json(SYS_CODE_FAIL, '客户不存在!'); + } + $mobile = $re['mobile']; + $cache = &load_cache('redis'); + $cache_key = "xz_admin_phone"; + $xz_admin_phone = $cache->get($cache_key); +// $xz_admins_numbers = array(); +// $xz_admins_numbers['admins'][$this->uid] = '18916751561'; +// $xz_admins_numbers['numbers']['18916751561'] = $this->uid; +// $cache->save($cache_key, $xz_admins_numbers); +// echo json_encode($xz_admin_phone,JSON_UNESCAPED_UNICODE); +// exit; + $middleNumber = ''; + if ($xz_admin_phone) { + $middleNumber = $xz_admin_phone['admins'][$this->uid]; + } + if (!$middleNumber) { + return $this->show_json(SYS_CODE_FAIL, '还未分配号码不可使用'); + } + $this->load->helper('order'); + $seq_id = create_order_no(); + require_once COMMPATH . 'third_party/Xcall/Xcall.php'; + $xcall = new Xcall(); + $result = $xcall->SWbind($mobile, $seq_id, $middleNumber); + if ($result['t_code'] == '-26') {//已经绑定解绑 + $s_res = $xcall->Searchbind($middleNumber); + $bined_mobile = $s_res['data']['value'];//已绑定手机号 + if ($bined_mobile) { + $xcall->SWunbind($bined_mobile, $middleNumber);//解绑 + $result = $xcall->SWbind($mobile, $seq_id, $middleNumber); + } + } + if ($result['code']) { + $this->data['middlenumber'] = $result['data']['virtualMobile']; + $this->load->model('receiver/receiver_xz_model', 'mdReceiverXz'); + $add_data = [ + 'call_id' => $seq_id, + 'display_number' => $result['data']['virtualMobile'], + 'cf_id' => $id, + 'cf_uid' => $this->uid, + 'cf_title' => 'clues', + 'cf_platform' => 'admin', + 'c_time' => time() + ]; + $this->mdReceiverXz->add($add_data); + } else { + return $this->show_json(SYS_CODE_FAIL, $result['msg']); + } $this->data['mobile_sub'] = substr_replace($mobile, '*****', 0, 5); $this->data['id'] = $id; $this->show_view('receiver/clues/edit_xbind'); @@ -395,20 +537,21 @@ class Clues extends HD_Controller{ * @param $lists * @return int */ - private function add_batch($lists){ + private function add_batch($lists) + { $done = 0; $adds = array(); $where = array('status' => 1); $select = 'id, title'; $map_cfrom = $this->clues_cfrom_model->map('title', 'id', $where, '', 0, 0, $select); - $fails= array(); - foreach($lists as $k => $v){ - if(!$v['name']){ + $fails = array(); + foreach ($lists as $k => $v) { + if (!$v['name']) { $fails[] = array('data' => $v, 'msg' => 'name is null'); continue; } - if(!mobile_valid($v['mobile'])){ + if (!mobile_valid($v['mobile'])) { $fails[] = array('data' => $v, 'msg' => 'mobile valid fail'); continue; } @@ -424,9 +567,9 @@ class Clues extends HD_Controller{ $fails && debug_log('[warning]# fails=' . json_encode($fails), __FUNCTION__, $this->log_dir); - if($adds){ + if ($adds) { $ret = $this->clues_model->add_batch($adds); - if(!$ret){ + if (!$ret) { debug_log("[error] add_batch fail; " . $this->clues_model->db->last_query(), __FUNCTION__, $this->log_dir); $done = 0; } diff --git a/admin/views/receiver/clues/edit.php b/admin/views/receiver/clues/edit.php index a513f12e..76030e00 100644 --- a/admin/views/receiver/clues/edit.php +++ b/admin/views/receiver/clues/edit.php @@ -42,7 +42,7 @@
保存状态 + @click="saveEdit()">修改状态
@@ -54,7 +54,7 @@ 用户信息 - + @@ -62,16 +62,27 @@ @@ -81,7 +92,7 @@
保存用户信息 + @click="saveEdit()">修改用户信息
@@ -115,15 +126,68 @@ 意向信息 + + +
- 客户姓名:{{info.name}} +
+
客户姓名:
+
- 业主电话:{{infoShow.mobile_sub}} +
+
业主电话:
+ {{infoShow.mobile_sub}} +
- 渠道来源:{{infoShow.cfrom_title}} +
+
渠道来源:
+ {{infoShow.cfrom_title}} +
- 加入时间:{{infoShow.c_time}} +
+
加入时间:
+ {{infoShow.c_time}} +
- - - - + + + + + + +
{{infoShow.intention.brand_name}}{{infoShow.intention.s_name}}{{infoShow.intention.v_name}}{{infoShow.intention.cor_name}} +
+
品牌:
+ +
+
+
+
车系:
+
+
+
+
车型:
+
+
+
+
车身色:
+
+
+
+ +
+
@@ -197,7 +261,7 @@ el: '#vue-edit', data: { info: {}, - infoShow: {"intention":{}}, + infoShow: {"intention": {}, 'autoList': []}, goods: {"imgs_url": [], "imgs": [], "log": ''}, }, mounted: function () { @@ -223,16 +287,68 @@ $("#status_id").removeAttr("disabled"); vm.info.editType = 1; } - } else if (index == 2) { - if (vm.info.editType == 2) { + } else { + if (vm.info.editType == index) { vm.info.editType = 0; } else { - vm.info.editType = 2; + vm.info.editType = index; } - } else { - vm.info.editType = 0; } }, + autoList: function (type) { + var vm = this; + var pid = 0; + if (type == 2) { + if (vm.info.brand_id == 0) { + vm.info.brand_id = 0; + vm.info.s_id = 0; + vm.info.v_id = 0; + vm.info.cor_id = 0; + vm.infoShow['autoList'][2] = []; + vm.infoShow['autoList'][3] = []; + vm.infoShow['autoList'][4] = []; + return; + } + pid = vm.info.brand_id; + } else if (type == 3) { + if (vm.info.s_id == 0) { + vm.info.s_id = 0; + vm.info.v_id = 0; + vm.info.cor_id = 0; + vm.infoShow['autoList'][3] = []; + vm.infoShow['autoList'][4] = []; + return; + } + pid = vm.info.s_id; + } + $.ajax({ + url: '/common/auto', + type: 'get', + dataType: 'json', + data: { + type: type, + pid: pid, + tp: 1, + }, + success: function (data) { + if (data.data) { + if (type == 2) { + vm.info.s_id = 0; + vm.info.v_id = 0; + vm.info.cor_id = 0; + vm.infoShow['autoList'][2] = data.data; + vm.infoShow['autoList'][3] = []; + vm.infoShow['autoList'][4] = []; + } else if (type == 3) { + vm.info.v_id = 0; + vm.info.cor_id = 0; + vm.infoShow['autoList'][3] = data.data[3]; + vm.infoShow['autoList'][4] = data.data[4]; + } + } + }, + }); + }, getStatus2: function () { //二级分类 var vm = this; @@ -333,6 +449,24 @@