From b11441c590c6bfbe0879886aee0e353e0ab08a32 Mon Sep 17 00:00:00 2001 From: lcc <805383944@qq.com> Date: Fri, 15 Aug 2025 13:58:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=AE=89=E5=A4=96=E5=91=BC=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/admin/controllers/pingan/call/Log.php | 78 ++++++++++++++++ .../controllers/pingan/receiver/Clues.php | 19 ++++ .../controllers/pingan/user/UserInfo.php | 23 ++++- agent/admin/libraries/api/CallPhone.php | 92 +++++++++++++++++++ common/libraries/carHome/CallOut.php | 32 +++++-- .../models/receiver/Receiver_call_model.php | 20 ++++ .../receiver/Receiver_clue_oplogs_model.php | 6 +- 7 files changed, 257 insertions(+), 13 deletions(-) create mode 100644 agent/admin/controllers/pingan/call/Log.php create mode 100644 agent/admin/libraries/api/CallPhone.php create mode 100644 common/models/receiver/Receiver_call_model.php diff --git a/agent/admin/controllers/pingan/call/Log.php b/agent/admin/controllers/pingan/call/Log.php new file mode 100644 index 00000000..15ff8f7b --- /dev/null +++ b/agent/admin/controllers/pingan/call/Log.php @@ -0,0 +1,78 @@ +load->model('receiver/receiver_call_model', 'callModel'); + $this->load->model('receiver/receiver_clues_model', 'cluesModel'); + $this->cluesModel->set_db('ssdb'); + $this->callModel->set_db('ssdb'); + } + + public function page_get() + { + $params = $this->input_param(); + $page = $params['page'] ?: 1; + $limit = $params['limit'] ?: 10; + $sort_order = 'id desc'; + $where = $this->buildWhere(); + $count = $this->callModel->count($where); + $list = []; + if ($count) { + $rows = $this->callModel->select($where, $sort_order, $page, $limit); + foreach ($rows as $v) { + $temp = $v; + $temp['customerPhoneNo'] = mobile_asterisk($v['customerPhoneNo']); + $temp['finishTypeCn'] = Receiver_call_model::finishTypeList[$v['finishType']] ?: ''; + $temp['callTypeCn'] = Receiver_call_model::callTypeList[$v['callType']] ?: ''; + $temp['hangupTypeCn'] = Receiver_call_model::hangupTypeList[$v['hangupType']] ?: ''; + $list[] = $temp; + } + } + $data = ['list' => $list, 'count' => $count]; + $this->return_response_list($data); + } + + /** + * 搜索条件 + * @return void + */ + public function search_get() + { + $data = []; + $data['finishTypeList'] = Receiver_call_model::finishTypeList;; + $data['callTypeList'] = Receiver_call_model::callTypeList; + $data['hangupTypeList'] = Receiver_call_model::hangupTypeList; + $this->return_response_list($data); + } + + private function buildWhere() + { + $params = $this->input_param(); + $where = [ + 'cfUid' => $_SESSION['id'] + ]; + $params['orderId'] && $where["orderId like '%{$params['orderId']}%'"] = null; + $params['agentId'] && $where['agentId'] = $params['agentId']; + $params['voiceId'] && $where['voiceId'] = $params['voiceId']; + $params['customerPhoneNo'] && $where['customerPhoneNo'] = $params['customerPhoneNo']; + strlen($params['finishType']) && $where['finishType'] = $params['finishType']; + strlen($params['callType']) && $where['callType'] = $params['callType']; + strlen($params['hangupType']) && $where['hangupType'] = $params['hangupType']; + if ($params['startTime'][0] && $params['startTime'][1]) { + $where['startTime >='] = $params['startTime'][0] . ' 00:00:00'; + $where['startTime <='] = $params['startTime'][1] . ' 23:59:59'; + } + if ($params['endTime'][0] && $params['endTime'][1]) { + $where['endTime >='] = $params['endTime'][0] . ' 00:00:00'; + $where['endTime <='] = $params['endTime'][1] . ' 23:59:59'; + } + return $where; + } +} + diff --git a/agent/admin/controllers/pingan/receiver/Clues.php b/agent/admin/controllers/pingan/receiver/Clues.php index 9aabc124..1cf64751 100644 --- a/agent/admin/controllers/pingan/receiver/Clues.php +++ b/agent/admin/controllers/pingan/receiver/Clues.php @@ -27,6 +27,7 @@ class Clues extends BaseController $this->mdReceiverXz->set_db('ssdb'); $this->mdOplogs->set_db('ssdb'); $this->receiver_enroll_model->set_db('ssdb'); + $this->load->library('api/callPhone'); } public function page_get() @@ -380,5 +381,23 @@ class Clues extends BaseController } $this->return_response(); } + + /** + * 拨打电话 + * @return void + */ + public function call_post() + { + $params = $this->input_param(); + if (!$params['id']) { + $this->return_json('参数错误!'); + } + $callPhone = new CallPhone(); + $result = $callPhone->Call(Receiver_call_model::CF_TYPE_CLUE, $params['id'], $_SESSION['id'], $_SESSION['username'], $_SESSION['userCode']); + if (!$result->isSuccess()) { + $this->return_json($result->getMessage()); + } + $this->return_response(); + } } diff --git a/agent/admin/controllers/pingan/user/UserInfo.php b/agent/admin/controllers/pingan/user/UserInfo.php index 59bbf68e..a63f1835 100644 --- a/agent/admin/controllers/pingan/user/UserInfo.php +++ b/agent/admin/controllers/pingan/user/UserInfo.php @@ -32,7 +32,9 @@ class UserInfo extends BaseController 'bankCardNum' => $row['bankCardNum'] ?: '', 'bankName' => $row['bankName'] ?: '', 'cardA' => $row['cardA'] ? changeImg(explode(',', $row['cardA'])) : [], - 'cardB' => $row['cardB'] ? changeImg(explode(',', $row['cardB'])) : [] + 'cardB' => $row['cardB'] ? changeImg(explode(',', $row['cardB'])) : [], + 'mobile' => $row['mobile'], + 'cti' => $row['cti'] ]; $this->return_response($data); } @@ -56,4 +58,23 @@ class UserInfo extends BaseController } $this->return_response(); } + + /** + * 修改手机号 + * @return void + */ + public function mobile_put() + { + $userId = $_SESSION['id']; + $params = $this->input_param(); + $upData = [ + 'mobile' => $params['mobile'] ?: '', + 'cti' => $params['cti'] ?: '' + ]; + $res = $this->userData->update($upData, ['userId' => $userId]); + if (!$res) { + $this->return_json("更新失败"); + } + $this->return_response(); + } } \ No newline at end of file diff --git a/agent/admin/libraries/api/CallPhone.php b/agent/admin/libraries/api/CallPhone.php new file mode 100644 index 00000000..ca60f5f3 --- /dev/null +++ b/agent/admin/libraries/api/CallPhone.php @@ -0,0 +1,92 @@ +ci = &get_instance(); + $this->ci->load->model('agent/pingan/pingan_users_data_model', 'userData'); + $this->ci->load->model('receiver/receiver_clues_model', 'clues_model'); + $this->ci->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs'); + $this->ci->load->model('receiver/receiver_call_model', 'callModel'); + $this->ci->clues_model->set_db('ssdb'); + $this->ci->mdOplogs->set_db('ssdb'); + $this->ci->callModel->set_db('ssdb'); + $this->ci->load->library('carHome/CallOut'); + } + + /** + * @param $cfType int 类型 1线索 + * @param $cfId int 来源id + * @param $cfUid int 用户id + * @param $cfName string 操作用户名 + * @return MyResponse + */ + public function Call($cfType, $cfId, $cfUid, $cfName, $userCode) + { + $this->ci->callModel->db->trans_begin(); + try { + $userData = $this->ci->userData->get(['userId' => $cfUid]); + if (!$userData['mobile']) { + throw new Exception('请先配置分机号'); + } + $agentPhoneNo = $userData['mobile']; + $agentId = $userData['cti']; + $agentUm = $userCode; + $cityId = 350200; + if ($cfType == Receiver_call_model::CF_TYPE_CLUE) { + $clues = $this->ci->clues_model->get(['id' => $cfId]); + if (!$clues) { + throw new Exception('线索不存在'); + } + $orderId = $clues['sid']; + $customerPhoneNo = $clues['mobile']; + $clues['city_id'] && $cityId = $clues['city_id']; + } else { + throw new Exception('来源类型错误'); + } + $requestId = create_order_no($cityId, 'pingan'); + $callOut = new CallOut(); + $callReq = $callOut->call($orderId, $requestId, $agentPhoneNo, $customerPhoneNo, $agentId, $agentUm); + if (!$callReq->isSuccess()) { + throw new Exception($callReq->getMessage()); + } + $callData = [ + 'reqId' => $requestId, + 'orderId' => $orderId, + 'customerPhoneNo' => $customerPhoneNo, + 'agentPhoneNo' => $agentPhoneNo, + 'apiResult' => json_encode($callReq->getData(), JSON_UNESCAPED_UNICODE), + 'cfUid' => $cfUid, + 'cfId' => $cfId, + 'cfType' => $cfType, + 'cfPlatform' => Receiver_call_model::CF_PLATFORM_AGENT_PINGAN, + 'createTime' => time(), + ]; + $callLogId = $this->ci->callModel->add($callData); + if (!is_numeric($callLogId)) { + throw new Exception('添加通话记录失败'); + } + if ($cfType == Receiver_call_model::CF_TYPE_CLUE) { + $optLogId = $this->ci->mdOplogs->add([ + 'clue_id' => $cfId, + 'pingan_user_id' => $cfUid, + 'uname' => $cfName, + 'type' => Receiver_clue_oplogs_model::OP_TYPE_AUTO_CALL, + 'log' => '', + 'c_time' => time() + ]); + if (!is_numeric($optLogId)) { + throw new Exception('添加操作日志失败'); + } + } + $this->ci->callModel->db->trans_commit(); + return new MyRESPONSE(EXIT_SUCCESS, '提交成功'); + } catch (Exception $e) { + $this->ci->callModel->db->trans_rollback(); + return new MyResponse(EXIT_ERROR, "参数错误"); + } + } +} \ No newline at end of file diff --git a/common/libraries/carHome/CallOut.php b/common/libraries/carHome/CallOut.php index dfe2af60..f275baa2 100644 --- a/common/libraries/carHome/CallOut.php +++ b/common/libraries/carHome/CallOut.php @@ -23,6 +23,7 @@ class CallOut // 测试环境: // 汽车之家外呼接口(互联网主线): http://202.105.128.251:18081/bas_car_home_ping_tai/car/v1/call // 汽车之家外呼接口(互联网备线): http://218.18.234.155:18081/bas_car_home_ping_tai/car/v1/call + private $logDir = 'carHome'; public function __construct() { @@ -34,30 +35,41 @@ class CallOut } } - public function call() + public function call($orderId, $requestId, $agentPhoneNo, $customerPhoneNo, $agentId = '', $agentUm = '', $pushUrl = '') { + $logPath = 'call.log'; try { - $agentPhoneNo = '18350451617'; - $customerPhoneNo = '13365081602'; +// $agentPhoneNo = '18350451617'; +// $customerPhoneNo = '13365081602'; + debug_log("加密前手机号:" . json_encode(['agentPhoneNo' => $agentPhoneNo, 'customerPhoneNo' => $customerPhoneNo]), $logPath, $this->logDir); $enAgentPhoneNo = $this->aesEcbPkcs5Encrypt($agentPhoneNo, $this->aesKey); $enCustomerPhoneNo = $this->aesEcbPkcs5Encrypt($customerPhoneNo, $this->aesKey); $params = [ - 'orderId' => md5(time()), //必选 String 订单号 + 'orderId' => $orderId, //必选 String 订单号 'agentPhoneNo' => $enAgentPhoneNo, //必选 String 坐席分机。坐席分机如采用AES加密,汽车之家系统传加密后的号码 'customerPhoneNo' => $enCustomerPhoneNo, //必选 String 客户手机号码。加密规则与坐席分机一致 -// 'agentId' => '', //备选 String 坐席工号(汽车之家上报开通的中兴平台唯一cti号码) -// 'agentUm' => '', //备选 String 坐席Um(汽车之家人员um账号) 'displayedPhoneNo' => '0', //必选 String 外显号码(传“0”和空值均为云中继外显) ]; + $agentId && $params['agentId'] = $agentId; //备选 String 坐席工号(汽车之家上报开通的中兴平台唯一cti号码) + $agentUm && $params['agentUm'] = $agentUm; //备选 String 坐席Um(汽车之家人员um账号) + $pushUrl && $params['pushUrl'] = $pushUrl; //如果有传此字段,那么推送话单数据,就推到这里 $reqParams = [ 'ctiType' => $this->ctiType, - 'requestId' => time(), + 'requestId' => $requestId, 'para' => $params ]; - $req = $this->send($this->baseUrl, $reqParams, self::METHOD_POST); - print_r($req); + debug_log("请求参数:" . json_encode($reqParams, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); + list($req, $header, $httpStatus) = $this->send($this->baseUrl, $reqParams, self::METHOD_POST); + debug_log("响应状态码:" . $httpStatus, $logPath, $this->logDir); + debug_log("响应结果:" . $req, $logPath, $this->logDir); + $reqArr = json_decode($req, true); + if (isset($reqArr['code']) && intval($reqArr['code']) == 200) { + return new Myresponse(EXIT_SUCCESS, '操作成功', $reqArr); + } else { + throw new Exception($reqArr['msg']); + } } catch (\Exception $e) { - + return new MyResponse(EXIT_ERROR, $e->getMessage()); } } diff --git a/common/models/receiver/Receiver_call_model.php b/common/models/receiver/Receiver_call_model.php new file mode 100644 index 00000000..d78d163b --- /dev/null +++ b/common/models/receiver/Receiver_call_model.php @@ -0,0 +1,20 @@ + '通话未完成', 1 => '通话完成', 2 => '通话失败']; + const callTypeList = [0 => '呼入', 1 => '呼出']; + const hangupTypeList = [0 => '客户挂断', 1 => '坐席挂断']; + + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } +} diff --git a/common/models/receiver/Receiver_clue_oplogs_model.php b/common/models/receiver/Receiver_clue_oplogs_model.php index f2d00d03..ccc8fdbf 100644 --- a/common/models/receiver/Receiver_clue_oplogs_model.php +++ b/common/models/receiver/Receiver_clue_oplogs_model.php @@ -6,11 +6,12 @@ * Time: 13:47 */ -defined('BASEPATH') OR exit('No direct script access allowed'); +defined('BASEPATH') or exit('No direct script access allowed'); class Receiver_clue_oplogs_model extends HD_Model { private $table_name = 'lc_receiver_clue_oplogs'; + const OP_TYPE_AUTO_CALL = 4; //汽车之家外呼 public function __construct() { @@ -25,7 +26,8 @@ class Receiver_clue_oplogs_model extends HD_Model */ public function typeAry() { - return array(0 => '小记', 1 => '发短信', 2 => '拨打电话', 3 => '新增', 9 => '系统'); + //4 汽车之家外呼拨打拨打电话 + return array(0 => '小记', 1 => '发短信', 2 => '拨打电话', 3 => '新增', 4 => '拨打电话', 9 => '系统'); } }