1206, 'app_key' => 'WX6HDVZX3AYSZDR1739332ZM' ]; public function __construct() { parent::__construct(); $this->log_file = 'call_xz.log'; $this->load->model('receiver/receiver_xz_model'); $this->load->model('receiver/receiver_customers_model', 'customers_model'); $this->load->model('receiver/order/receiver_orders_model', 'orders_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') { //后台 $admin_id = $row['cf_uid']; $this->load->model('sys/sys_admin_model'); $admin = $this->sys_admin_model->get(array('id' => $admin_id)); $addData = array( 'uid' => $admin_id, 'uname' => $admin['username'] ? $admin['username'] : '', 'type' => 2,//类型 0 普通 1短信 2电话 'log' => $row['id'], 'c_time' => time() ); if ($row['cf_title'] == 'clues') {//线索拨打电话回调 $this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs'); $addData['clue_id'] = $row['cf_id']; } else if ($row['cf_title'] == 'customer') {//客户拨打电话回调 $this->load->model('receiver/receiver_customer_oplogs_model', 'mdOplogs'); $addData['customer_id'] = $row['cf_id']; } $this->mdOplogs->add($addData); $xcall = new Xcall($this->admin_config); //解绑 $xcall->SWunbind($data['to'], $data['virtualMobile']); } elseif ($row['cf_id'] && $row['cf_platform'] == 'api') { //狸车宝 $this->config->load('xcall'); $params = [ 'app_id' => $this->config->item('app_id'), 'app_key' => $this->config->item('app_key'), ]; $xcall = new Xcall($params); //解绑 $result = $xcall->AXBUnbind($data['to'], $data['from'], $data['virtualMobile']); //删除redis $cache_key = "XZ_LICHEB_MOBILEA_{$data['from']}_MOBILEB_{$data['to']}_{$row['cf_uid']}"; $redis = &load_cache('redis'); $redis->delete($cache_key); if ($row['cf_title'] == 'order') { //订单 $order = $this->orders_model->get(['id' => $row['cf_id']]); $cust = $this->customers_model->get(['id' => $order['rid']]); } else { //客户 $cust = $this->customers_model->get(['id' => $row['cf_id']]); } $this->load->library('receiver/customers_entity'); $visit = $row['cf_title'] == 'customer' ? 1 : 0; $this->customers_entity->add_log_visit($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2,$visit); } } 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']) { if ($data['id'] == 1206) { $params = $this->admin_config; } else { $this->config->load('xcall'); $params = [ 'app_id' => $this->config->item('app_id'), 'app_key' => $this->config->item('app_key'), ]; } $xcall = new Xcall($params); $result = $xcall->getFile($data['getFileUrl'], $data['mid'], $data['tag']); if ($result['code']) { //上传七牛 $this->load->library('qiniu'); $qiniu = new Qiniu(['type' => 'video']); $filename = $qiniu->getFileName($data['mid'], 'mp3', 'xz_video_'); $q_res = $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); } //执行企业微信机器人 public function dorobot() { $o_id = $this->input->get('id'); if ($o_id) { $this->load->library('qyrobot'); $robot_res = $this->qyrobot->deposit_notify($o_id); var_dump($robot_res); } } //更新订单服务id public function up_srv_ids(){ $this->load->model('receiver/receiver_service_package_model','package_model'); $page = $this->input->get('page'); $size = $this->input->get('size'); !$page && $page = 1; !$size && $size = 20; $where = [ 'pack_id>' => 0, 'srv_ids' => '' ]; $rows = $this->orders_model->select($where,'id asc',$page,$size); if($rows){ foreach($rows as $item){ $pack = $this->package_model->get(['id'=>$item['pack_id']]); $res = false; if($pack){ $updata = [ 'srv_ids' => $pack['srv_ids'] ]; $res = $this->orders_model->update($updata,['id'=>$item['id']]); } $log = "{$item['id']}更新结果:{$res}
"; echo $log; } }else{ echo "finish"; } } }