admin_clues_726

This commit is contained in:
dengbw
2021-07-26 14:13:18 +08:00
committed by lccsw
parent 34294e0fca
commit d26343da3e
5 changed files with 687 additions and 69 deletions
+195 -52
View File
@@ -1,12 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Clues extends HD_Controller{
class Clues extends HD_Controller
{
private $searchTpAry = array('mobile' => '客户手机号', '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'] = '线索详情';
@@ -124,14 +141,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, '手机号码不准确');
}
@@ -142,7 +160,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, '添加失败');
}
@@ -216,7 +234,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, '非法参数!');
}
@@ -224,36 +241,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()
{
}
@@ -264,7 +353,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');
@@ -274,8 +363,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, '请选择分配门店!');
}
@@ -285,13 +374,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'],
@@ -304,19 +393,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');
}
}
}
@@ -326,8 +415,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');
@@ -353,20 +495,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;
}
@@ -382,9 +525,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;
}
+151 -17
View File
@@ -42,7 +42,7 @@
</div>
<div class="am-form-group ml10" v-if="info.editType==1">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">保存状态</a>
@click="saveEdit()">修改状态</a>
</div>
</div>
</div>
@@ -54,7 +54,7 @@
<span href="javascript:void(0)" style="font-size: 20px">
用户信息
</span>
<span style="float:right;margin-top:5px;display: none">
<span style="float:right;margin-top:5px;">
<a href="javascript:" @click="editType(2)"><i class="fa fa-edit"></i></a>
</span>
</div>
@@ -62,16 +62,27 @@
<table width="100%" style="margin:10px 10px 10px 20px;">
<tr>
<td class="table-td">
客户姓名:{{info.name}}
<div class="input-group">
<div class="input-group-addon">客户姓名:</div>
<input type="text" v-model="info.name" placeholder="请输入客户姓名"></div>
</td>
<td class="table-td">
业主电话:{{infoShow.mobile_sub}}
<div class="input-group">
<div class="input-group-addon">业主电话:</div>
{{infoShow.mobile_sub}}
</div>
</td>
<td class="table-td">
渠道来源:{{infoShow.cfrom_title}}
<div class="input-group">
<div class="input-group-addon">渠道来源:</div>
{{infoShow.cfrom_title}}
</div>
</td>
<td class="table-td">
加入时间:{{infoShow.c_time}}
<div class="input-group">
<div class="input-group-addon">加入时间:</div>
{{infoShow.c_time}}
</div>
</td>
</tr>
<tr>
@@ -81,7 +92,7 @@
<div class="am-form-group ml10">
<a v-if="info.editType==2" href="javascript:void(0)"
class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">保存用户信息</a>
@click="saveEdit()">修改用户信息</a>
</div>
</div>
</div>
@@ -115,15 +126,68 @@
<span href="javascript:void(0)" style="font-size: 20px">
意向信息
</span>
<span style="float:right;margin-top:5px;">
<a href="javascript:" @click="editType(3)"><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">{{infoShow.intention.brand_name}}</td>
<td class="table-td">{{infoShow.intention.s_name}}</td>
<td class="table-td">{{infoShow.intention.v_name}}</td>
<td class="table-td">{{infoShow.intention.cor_name}}</td>
<td class="table-td">
<div class="input-group">
<div class="input-group-addon">品牌:</div>
<select style="width: 120px;" v-model="info.brand_id" @change='autoList(2);'>
<option value="0">选择品牌</option>
<template v-for="(v,i) in infoShow['autoList'][1]">
<option :value="v.id">{{v.name}}</option>
</template>
</select>
</div>
</td>
<td class="table-td">
<div class="input-group">
<div class="input-group-addon">车系:</div>
<select style="width: 120px;" v-model="info.s_id" @change='autoList(3);'>
<option value="0">选择车系</option>
<template v-for="(v,i) in infoShow['autoList'][2]">
<option :value="v.id">{{v.name}}</option>
</template>
</select></div>
</td>
<td class="table-td">
<div class="input-group">
<div class="input-group-addon">车型:</div>
<select style="width: 120px;" v-model="info.v_id">
<option value="0">选择车型</option>
<template v-for="(v,i) in infoShow['autoList'][3]">
<option :value="v.id">{{v.name}}</option>
</template>
</select></div>
</td>
<td class="table-td">
<div class="input-group">
<div class="input-group-addon">车身色:</div>
<select style="width: 120px;" v-model="info.cor_id">
<option value="0">选择车身色</option>
<template v-for="(v,i) in infoShow['autoList'][4]">
<option :value="v.id">{{v.name}}</option>
</template>
</select></div>
</td>
</tr>
<tr v-if="info.editType==3">
<td colspan="4">
<div class="am-form-inline" style="padding-right: 30px;padding-top: 10px;">
<div class="text-left pt10">
<div class="am-form-group ml10">
<a href="javascript:void(0)"
class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">修改意向信息</a>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
@@ -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 @@
</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;
+123
View File
@@ -0,0 +1,123 @@
<?php
/**
* Created by Vim
* User: lcc
* Desc: 晓致拨号回调
* Date: 2021/4/14
* Time: 19:15
*/
class Xzcall extends HD_Controller
{
private $log_file;
public function __construct()
{
parent::__construct();
$this->log_file = 'call_xz.log';
$this->load->model('receiver/receiver_xz_model');
}
public function index()
{
debug_log("start function:" . __FUNCTION__, $this->log_file);
$data = $this->input->post();
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
if ($data && $data['seqId']) {
$row = $this->receiver_xz_model->get(array('call_id' => $data['seqId']));
if ($row) {
$jsondata = json_decode($row['json_data'], true);
$data['uname'] = $jsondata['uname'];
$data['brand_id'] = $jsondata['brand_id'];
$up_data['caller_state'] = $data['status'];
$up_data['status'] = 1;
$data['mid'] && $up_data['mid'] = $data['mid'];
$data['to'] && $up_data['called_num'] = $data['to'];
$data['from'] && $up_data['caller_num'] = $data['from'];
if ($data['callAnswer']) {
$up_data['duration'] = $data['callEnd'] - $data['callAnswer'];
$up_data['answer_time'] = $this->getMsecToMescdate($data['callAnswer']);
}
$data['callStart'] && $up_data['start_time'] = $this->getMsecToMescdate($data['callStart']);
$data['callEnd'] && $up_data['end_time'] = $this->getMsecToMescdate($data['callEnd']);
$up_data['json_data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
if ($row['cf_id'] && $row['cf_platform'] == 'admin' && $row['cf_title'] == 'clues') { //后台线索池拨打电话回调
$admin_id = $row['cf_uid'];
$this->load->model('sys/sys_admin_model');
$admin = $this->sys_admin_model->get(array('id' => $admin_id));
$addData = array(
'clue_id' => $row['cf_id'],
'uid' => $admin_id,
'uname' => $admin['username'] ? $admin['username'] : '',
'type' => 2,//类型 0 普通 1短信 2电话
'log' => $row['id'],
'c_time' => time()
);
$this->mdOplogs->add($addData);
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
$xcall = new Xcall();
//解绑
$xcall->SWunbind($data['to'], $data['virtualMobile']);
}
} else {
debug_log("error: 未找到拨打记录", $this->log_file);
}
}
debug_log("end " . __FUNCTION__, $this->log_file);
echo '{"result":"0","error":""}';
}
//录音推送地址
public function video()
{
$data = $this->input->post();
debug_log("start function:" . __FUNCTION__, $this->log_file);
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
$row = $this->receiver_xz_model->get(array('mid' => $data['mid']));
if ($row) {
$jsondata = json_decode($row['json_data'], true);
if ($data['getFileUrl']) {
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
$xcall = new Xcall();
$result = $xcall->getFile($data['getFileUrl'], $data['mid'], $data['tag']);
if ($result['code']) { //上传七牛
$this->load->library('qiniu');
$filename = $this->qiniu->getFileName($data['mid'], 'mp3', 'xz_video_');
$q_res = $this->qiniu->save($filename, $result['data']);
if (!$q_res) {
debug_log('error:文件上传七牛失败', $this->log_file);
} else {
$up_data['rec_url'] = $q_res['url'];
}
} else {
debug_log('error:' . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
}
}
$jsondata['file_info'] = $data;
$up_data['json_data'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
}
debug_log("end " . __FUNCTION__, $this->log_file);
echo '{"result":"0","error":""}';
}
/**
* 毫秒转日期
*/
private function getMsecToMescdate($msectime)
{
$msectime = $msectime * 0.001;
if (strstr($msectime, '.')) {
sprintf("%01.3f", $msectime);
list($usec, $sec) = explode(".", $msectime);
$sec = str_pad($sec, 3, "0", STR_PAD_RIGHT);
} else {
$usec = $msectime;
$sec = "000";
}
$date = date("Y-m-d H:i:s.x", $usec);
return $mescdate = str_replace('x', $sec, $date);
}
}
@@ -0,0 +1,18 @@
<?php
/**
* Notes:晓致虚拟号通话记录
* Created on: 2021/7/26 13:38
* Created by: dengbw
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Receiver_xz_model extends HD_Model
{
private $table_name = 'lc_receiver_xz';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}
+200
View File
@@ -0,0 +1,200 @@
<?php
/**
* Created by Vim.
* User: lcc
* Date: 2021/4/14
* Time: 15:11
*/
class Xcall{
private $id = '1176';
private $key = 'EM2JG6FUJRXUNMSNL2GLNXXF';
private $api_url = 'http://api.teleii.com/';
private $ci;
private $log_file = 'xcall.log';
public function __construct(){
$this -> ci = & get_instance();
}
/**
* 商务号绑定
* @param $mobile 手机号
* @param $seq_id 唯一请求单号
* @param $middleNumber 虚拟号码
* @param $bindTime 绑定时间
*/
public function SWbind($mobile,$seq_id,$middleNumber,$bindTime=10){
$url=$this->api_url.'bindMobile.do';
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
$seqId=$seq_id; //唯一订单
$virtualMobile=$middleNumber;
//Md5(key+id+seqId+timestamp+fm+tm) 生成签名
$sign_source=$spKey.$spId.$seqId.$timestamp.$mobile.$virtualMobile.$bindTime;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&seqId='.$seqId.'&bindMobile='.$mobile.'&bindTime='.$bindTime.'&virtualMobile='.$virtualMobile.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if(!$data['result']){
return ['code'=>1,'msg'=>'绑定成功','data'=> $data];
}{
debug_log('function:'.__FUNCTION__,$this->log_file);
debug_log('post_data:'.$curlparams,$this->log_file);
debug_log('result:'.$result,$this->log_file);
return ['code'=>0,'msg'=>$data['error'],'t_code' => $data['result']];
}
}
//解除绑定
public function SWunbind($bindmobile,$virtualMobile){
$url=$this->api_url.'unbindMobile.do';
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
//Md5(key+id+timestamp+virtualMobile) 生成签名
$sign_source=$spKey.$spId.$timestamp.$virtualMobile;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&bindMobile='.$bindmobile.'&virtualMobile='.$virtualMobile.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if(!$data['result']){
return ['code'=>1,'msg'=>'解绑成功','data'=> $data];
}{
debug_log('function:'.__FUNCTION__,$this->log_file);
debug_log('post_data:'.$curlparams,$this->log_file);
debug_log('result:'.$result,$this->log_file);
return ['code'=>0,'msg'=>$data['error']];
}
}
//商户模式查找绑定关系
public function Searchbind($middleNumber){
$url=$this->api_url.'searchBindMobile.do';
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
$virtualMobile=$middleNumber;
$bindTime=10;//关系绑定10分钟
//Md5(key+id+timestamp+virtualMobile) 生成签名
$sign_source=$spKey.$spId.$timestamp.$virtualMobile;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&virtualMobile='.$virtualMobile.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if(!$data['result']){
return ['code'=>1,'msg'=>'绑定成功','data'=> $data];
}{
debug_log('function:'.__FUNCTION__,$this->log_file);
debug_log('post_data:'.$curlparams,$this->log_file);
debug_log('result:'.$result,$this->log_file);
return ['code'=>0,'msg'=>$data['error']];
}
}
//绑定关系
public function ABXbind($mobileA, $mobileB,$seq_id, $middleNumber='',$scene=''){
$url=$this->api_url.'autoCallTransferForSp.do';
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
$seqId=$seq_id; //唯一订单
$fm=$mobileA; //主叫号码
$tm=$mobileB; //被叫号码
$virtualMobile=$middleNumber; //虚拟号码.创建新关系时,虚拟号码为空,系统自行分配虚拟号码。
$bindTime=10;//关系绑定10分钟
//Md5(key+id+seqId+timestamp+fm+tm) 生成签名
$sign_source=$spKey.$spId.$seqId.$timestamp.$fm.$tm;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&seqId='.$seqId.'&fm='.$fm.'&tm='.$tm.'&bindTime='.$bindTime.'&virtualMobile='.$virtualMobile.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if(!$data['result']){
return ['code'=>1,'msg'=>'绑定成功','data'=> $data];
}{
debug_log('function:'.__FUNCTION__,$this->log_file);
debug_log('post_data:'.$curlparams,$this->log_file);
debug_log('result:'.$result,$this->log_file);
return ['code'=>0,'msg'=>$data['error']];
}
}
//解绑
public function AXBUnbind($mobileA,$mobileB,$middleNumber){
$url=$this->api_url.'unbindCallTransferForSp.do';
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
$fm=$mobileA;//主叫号码
$tm=$mobileB;//被叫主码
$vm=$middleNumber; //虚拟号码
//Md5(key+id+timestamp+fm+tm+vm) 生成签名
$sign_source=$spKey.$spId.$timestamp.$fm.$tm.$vm;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&vm='.$vm.'&fm='.$fm.'&tm='.$tm.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if(!$data['result']){
return ['code'=>1,'msg'=>'解绑成功'];
}{
debug_log('function:'.__FUNCTION__,$this->log_file);
debug_log('post_data:'.$curlparams,$this->log_file);
debug_log('result:'.$result,$this->log_file);
return ['code'=>0,'msg'=>$data['error']];
}
}
//获取录音文件
public function getFile($url,$mid,$tag){
$spId=$this->id; //teleii平台分配的商户id
$spKey=$this->key; //teleii平台分配的商户key
$timestamp=time().'000'; //毫秒级的时间戳
//Md5(key+id+timestamp+fm+tm+vm) 生成签名
$sign_source=$spKey.$spId.$timestamp.$mid;
$sign=md5($sign_source);
//拼接HTTP请求参数
$curlparams='id='.$spId.'&timestamp='.$timestamp.'&mid='.$mid.'&tag='.$tag.'&sign='.$sign;
//发起HTTP请求
$result=$this->postUrlForCalling($url, $curlparams);
$data = json_decode($result,true);
if($data['result']||!$result){
return ['code'=>0,'msg'=>$data['error']];
}{
return ['code'=>1,'msg'=>'获取成功','data' => $result];
}
}
private function postUrlForCalling($url, $reqParams){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$reqParams);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}