Commit 2f7720df authored by hujun's avatar hujun

拨打电话记录redis

parent f82db868
......@@ -94,7 +94,7 @@ class CellPhone extends Basic
header('Access-Control-Allow-Origin:*');
$call = new CallPhoneService();
$result = $call->agentsUnBind($this->params['phone_a'], $this->params['phone_b'], $this->params['phone_x'], $this->params['user_id']);
$result = $call->agentsUnBindRedis($this->params['phone_a'], $this->params['phone_b'], $this->params['phone_x'], $this->params['user_id'], $this->agentId);
if ($result['status'] == 'success') {
$this->msg = $result['msg'];
......
......@@ -123,13 +123,18 @@ class CallPhoneService
return $result;
}
$bind = new BindingPhone();
$where['a.status'] = 1;
$where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b;
$where['a.type'] = $this->is_privacy;
$phone_x = $this->redis->get('call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b);
$phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
if (empty($phone_x)) {
$bind = new BindingPhone();
$where['a.status'] = 1;
$where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b;
$where['a.type'] = $this->is_privacy;
$phone_x_arr = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
$phone_x = $phone_x_arr['phone_x'];
}
if (!empty($phone_x['phone_x'])) {
$result['status'] = 'success';
......@@ -287,6 +292,98 @@ class CallPhoneService
return $data;
}
/**
* 解除(redis)中绑定关系
*
* @param $phone_a
* @param $phone_b
* @param $phone_x
* @param $user_id
* @param $agent_id
* @return mixed
*/
public function agentsUnBindRedis($phone_a, $phone_b, $phone_x, $user_id, $agent_id)
{
$data['status'] = 'success';
$data['msg'] = '';
if (empty($phone_x)) {
$data['status'] = 'failed';
$data['msg'] = '解除失败,请联系运营人员!';
return $data;
}
if (empty($phone_a)) {
$data['status'] = 'failed';
$data['msg'] = '解除失败,请联系运营人员!';
return $data;
}
$this->phone_a = $phone_a;
$this->phone_x = $phone_x;
if (empty($phone_b)) {
if (!empty($user_id)) {
$this->user_id = $user_id;
$user_data = $this->getUserData();
if (empty($user_data['user_phone'])) {
$data['status'] = 'failed';
$data['msg'] = '没有客户信息,可以忽略。';
return $data;
}
$this->phone_b = $user_data['user_phone'];
}
} else {
$this->phone_b = $phone_b;
}
if (empty($this->phone_b)) {
$data['status'] = 'failed';
$data['msg'] = '解除失败,请联系运营人员!';
return $data;
}
$phone = new BindingPhone();
$call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b;
try {
if ($this->is_privacy == 1) {
/*阿里云*/
$subsId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'subsId');
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/
if ($result->Message == 'OK') {
$this->redis->del($call_key);
} else {
$data['status'] = 'failed';
$data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!';
}
} else {
$data['msg'] = '没有号码绑定关系,请忽略!';
}
} elseif ($this->is_privacy == 2) {
/*容联云*/
$mappingId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'mappingId');
$yun_tong_xun = new RongDemo();
if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
if ($result['statusCode'] == '000000') {
$this->redis->del($call_key);
}
} else {
$data['msg'] = '没有号码绑定关系,请忽略!。';
}
} else {
$data['msg'] = '没有号码绑定关系,请忽略!。';
}
} catch (\Exception $e) {
$data['status'] = 'failed';
$data['msg'] = $e->getMessage();
}
return $data;
}
/**
* @return mixed|\SimpleXMLElement
*/
......
......@@ -199,7 +199,7 @@ class CellPhone extends Basic
}
$call_phone = new CallPhoneService();
$data = $call_phone->agentsUnBind($this->params['phone_a'], $phone_b, $this->params['phone_x'], $user_id);
$data = $call_phone->agentsUnBindRedis($this->params['phone_a'], $phone_b, $this->params['phone_x'], $user_id, $this->userId);
$result['msg'] = '';
if ($data['status'] == 'success') {
$result['code'] = 200;
......
......@@ -68,8 +68,8 @@ class BindingPhone extends BaseModel
$phone_data = $phone->where('phone_x', $phone_x)->find();
if ($phone_data['id']) {
$phone_data['bind_num'] -= 1;
$phone_data->save();
// $phone_data['bind_num'] -= 1;
// $phone_data->save();
$result = $this->where([
'aliYun_phone_id' => $phone_data['id'],
......@@ -143,12 +143,13 @@ class BindingPhone extends BaseModel
*/
public function unBindTable($id, $aliYun_phone_id)
{
$phone = new AliYunPhone();
$phone_data = $phone->field('id,bind_num')->where('id', $aliYun_phone_id)->find();
if ($phone_data['id']) {
$phone_data['bind_num'] -= 1;
$phone_data->save();
}
//由虚拟号码提供
// $phone = new AliYunPhone();
// $phone_data = $phone->field('id,bind_num')->where('id', $aliYun_phone_id)->find();
// if ($phone_data['id']) {
// $phone_data['bind_num'] -= 1;
// $phone_data->save();
// }
$this->update([ 'status' => 0, 'id' => $id ]);
return;
}
......@@ -173,8 +174,8 @@ class BindingPhone extends BaseModel
{
$m_ali_phone = new AliYunPhone();
$phone_id = $m_ali_phone->field('id,bind_num')->where('phone_x', $phone_x)->find();
$phone_id['bind_num'] += 1;
$m_ali_phone->where('id', $phone_id['id'])->update([ 'bind_num' => $phone_id['bind_num'] ]);
// $phone_id['bind_num'] += 1;
// $m_ali_phone->where('id', $phone_id['id'])->update([ 'bind_num' => $phone_id['bind_num'] ]); //由虚拟号码提供商记录
$insert_data['phone_a'] = $phone_a;
$insert_data['phone_b'] = $phone_b;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment