Commit 8439c732 authored by hujun's avatar hujun

解除绑定关系

parent 0c7fcc15
...@@ -4,10 +4,10 @@ error_reporting(E_ERROR | E_PARSE); ...@@ -4,10 +4,10 @@ error_reporting(E_ERROR | E_PARSE);
define('_MESSAGE_TYPE','SecretReport'); define('_MESSAGE_TYPE','SecretReport');
define('_QUEUE_NAME','Alicom-Queue-1186048444498461-SecretReport'); define('_QUEUE_NAME','Alicom-Queue-1186048444498461-SecretReport');
define('_EXPIRATION',date('Y-m-d H:i:s',time()+518400));//手机号码保留七天 define('_EXPIRATION',date('Y-m-d H:i:s',time()+518400));//手机号码保留七天
define('_POOLKEY','FC100000022056027');
define('_TLSYPoolKey','FC100000022056027');
return [ return [
'jwt_key' => 'tonglian+123', 'jwt_key' => 'tonglian+123',
// 应用模式状态 // 应用模式状态
'app_status' => 'dev-config', 'app_status' => 'dev-config',
'_DefaultPoolKey' => 'FC100000022056027',
'tonglianshangyePoolKey' =>'FC100000027622039'
]; ];
\ No newline at end of file
...@@ -11,8 +11,8 @@ namespace app\api_broker\controller; ...@@ -11,8 +11,8 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
use app\model\AliyunPhone; use app\model\AliYunPhone;
use think\Config; use app\model\BindingPhone;
use think\Db; use think\Db;
class CellPhone extends Basic class CellPhone extends Basic
...@@ -25,7 +25,9 @@ class CellPhone extends Basic ...@@ -25,7 +25,9 @@ class CellPhone extends Basic
* 绑定手机号 * 绑定手机号
* *
* @return \think\Response * @return \think\Response
* @throws \Aliyun\Core\Exception\ClientException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function bindAXB() { public function bindAXB() {
$params = $this->request->param(); $params = $this->request->param();
...@@ -35,22 +37,29 @@ class CellPhone extends Basic ...@@ -35,22 +37,29 @@ class CellPhone extends Basic
$phone_b = $this->params['phone_b'];//客户手机号 $phone_b = $this->params['phone_b'];//客户手机号
$record = empty($this->params['record'])? false:true; //是否录音 $record = empty($this->params['record'])? false:true; //是否录音
$bind = new AliyunPhone(); $bind = new AliYunPhone();
$phone_x = $bind->getAliYunPhone($phone_b); $phone_x = $bind->getAliYunPhone($phone_b);
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, Config::get('_DefaultPoolKey'), $phone_x); //是否还有未绑定的中间号码
if ($phone_x) {
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, $phone_x['phone_x']);
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
Db::table('aliyun_binding_phone')->save([ $bind->where('phone_x',$phone_x['phone_x'])->setField('status',1);
Db::table('aliYun_binding_phone')->insert([
'phone_a' => $phone_a, 'phone_a' => $phone_a,
'phone_b' => $phone_b, 'phone_b' => $phone_b,
'SubsId' => $result->SecretBindDTO->SubsId, 'subsId' => $result->SecretBindDTO->SubsId,
'RequestId' => $result->RequestId, 'requestId' => $result->RequestId,
'record' => $record 'record' => $record,
'aliYun_phone_id' => $phone_x['id']
]); ]);
$this->msg = 'Binding success'; $this->msg = 'Binding success.';
} else { } else {
$this->code = 101; $this->code = 101;
$this->msg = 'Binding failure'; $this->msg = 'Binding failure.';
}
} else {
$this->code = 102;
$this->msg = 'Number pool run out.';
} }
} else { } else {
$this->code = 101; $this->code = 101;
...@@ -67,8 +76,36 @@ class CellPhone extends Basic ...@@ -67,8 +76,36 @@ class CellPhone extends Basic
return $this->response($this->code, $this->msg,$this->data);*/ return $this->response($this->code, $this->msg,$this->data);*/
} }
/**
* 解除绑定关系
*
* @return \think\Response
* @throws \think\exception\DbException
*/
public function agentsUnBind() { public function agentsUnBind() {
PlsDemo::unbindSubscription(); $phone_x = $this->params['phone_x'];
} $phone_a = $this->params['phone_a'];
if ($phone_x) {
$phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1);
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') {
$phone->UnBind($phone_x);
} else {
$this->code = 101;
$this->msg = 'remove binding error';
}
} else {
$this->code = 101;
$this->msg = 'dont\'t have about phone_x info';
}
} else {
$this->code = 101;
$this->msg = 'phone_x is null';
}
$this->params['phone_x'];
return $this->response($this->code, $this->msg);
}
} }
\ No newline at end of file
...@@ -29,7 +29,7 @@ class PlsDemo ...@@ -29,7 +29,7 @@ class PlsDemo
{ {
static $acsClient = null; static $acsClient = null;
static $pool_key = _POOLKEY;
/** /**
* 取得AcsClient * 取得AcsClient
* *
...@@ -80,13 +80,13 @@ class PlsDemo ...@@ -80,13 +80,13 @@ class PlsDemo
* @param string $phoneNoX 中间号码 * @param string $phoneNoX 中间号码
* @return mixed|\SimpleXMLElement * @return mixed|\SimpleXMLElement
*/ */
public static function bindAxb($phoneA, $phoneB, $time, $isRecordingEnabled=false, $poolKey='FC100000022056027', $phoneNoX = '17091955105') { public static function bindAxb($phoneA, $phoneB, $time, $isRecordingEnabled=false, $phoneNoX = '17091955105') {
//组装请求对象-具体描述见控制台-文档部分内容 //组装请求对象-具体描述见控制台-文档部分内容
$request = new BindAxbRequest(); $request = new BindAxbRequest();
//必填:号池Key //必填:号池Key
$request->setPoolKey($poolKey); $request->setPoolKey(self::$pool_key);
//必填:AXB关系中的A号码 //必填:AXB关系中的A号码
$request->setPhoneNoA($phoneA); $request->setPhoneNoA($phoneA);
...@@ -162,8 +162,9 @@ class PlsDemo ...@@ -162,8 +162,9 @@ class PlsDemo
/** /**
* 解绑接口 * 解绑接口
* *
* @return stdClass * @param $subsId
* @throws ClientException * @param $secretNo
* @return mixed|\SimpleXMLElement
*/ */
public static function unbindSubscription($subsId, $secretNo) { public static function unbindSubscription($subsId, $secretNo) {
...@@ -171,7 +172,7 @@ class PlsDemo ...@@ -171,7 +172,7 @@ class PlsDemo
$request = new UnbindSubscriptionRequest(); $request = new UnbindSubscriptionRequest();
//必填:号池Key //必填:号池Key
$request->setPoolKey("FC123456"); $request->setPoolKey(self::$pool_key);
//必填:对应的产品类型 //必填:对应的产品类型
$request->setProductType("AXB_170"); $request->setProductType("AXB_170");
......
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: fuju * User: hu jun
* Date: 2018/1/20 * Date: 2018/1/20
* Time: 17:52 * Time: 17:52
*/ */
...@@ -10,8 +10,11 @@ namespace app\model; ...@@ -10,8 +10,11 @@ namespace app\model;
use think\Db; use think\Db;
class AliyunPhone extends BaseModel class AliYunPhone extends BaseModel
{ {
// 设置当前模型对应的完整数据表名称
protected $table = 'aliYun_phone';
/** /**
* 获取未绑定的手机号码 * 获取未绑定的手机号码
* *
...@@ -22,19 +25,22 @@ class AliyunPhone extends BaseModel ...@@ -22,19 +25,22 @@ class AliyunPhone extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getAliYunPhone($phone = '') { public function getAliYunPhone($phone = '') {
$where['status'] = 1;
$where['status'] = 0;
if ($phone) { if ($phone) {
//查询之前一次绑定关系的号码 //查询之前一次绑定关系的号码
$phone_x = Db::table('aliyun_binding_phone')->field('phone_x')->alias('a') $phone_x = Db::table('aliYun_binding_phone')->field('phone_x')->alias('a')
->join('aliyun_phone b','a.aliyun_phone_id = b.id','left') ->join('aliYun_phone b','a.aliYun_phone_id = b.id','left')
->where([ ->where([
'phone_b' => $phone, 'phone_b' => $phone,
'a.status' => 1 'a.status' => 1
])->value('phone_x'); ])->value('phone_x');
if ($phone_x) {
$where['phone_x'] = $phone_x; $where['phone_x'] = $phone_x;
} }
}
$result = Db::table('aliyun_phone')->field('phone_x')->whereOr($where)->find(); $result = Db::table('aliYun_phone')->field('id,phone_x')->whereOr($where)->find();
return $result; return $result;
} }
} }
\ No newline at end of file
...@@ -12,4 +12,52 @@ class BindingPhone extends BaseModel ...@@ -12,4 +12,52 @@ class BindingPhone extends BaseModel
{ {
// 设置当前模型对应的完整数据表名称 // 设置当前模型对应的完整数据表名称
protected $table = 'aliyun_binding_phone'; protected $table = 'aliyun_binding_phone';
/**
* 通过阿里号码获取subsId
*
* @param $phone_x
* @param $phone_a
* @param int $status
* @return bool|mixed
*/
public function getSubsId($phone_x, $phone_a, $status = 0) {
if ($phone_x && $phone_a) {
$subsId = $this->alias('a')
->join('aliYun_phone b','a.aliYun_phone_id=b.id','left')
->where([
'a.status'=>$status,
'phone_x'=>$phone_x,
'phone_a'=>$phone_a
])->value('subsId');
} else {
$subsId = false;
}
return $subsId;
}
/**
* @param $phone_x
* @return bool|int
* @throws \think\exception\DbException
*/
public function UnBind($phone_x) {
if ($phone_x) {
$phone = new AliYunPhone();
$phone_data = $phone->get(['phone_x'=>$phone_x]);
if ($phone_data->id) {
$phone_data->status = 0;
$phone_data->save();
$result = $this->where([
'aliYun_phone_id'=>$phone_data->id,
'status' => 1
])->setField('status',0);
} else {
$result = false;
}
} else {
$result = false;
}
return $result;
}
} }
\ No newline at end of file
...@@ -228,7 +228,8 @@ Route::group('broker', [ ...@@ -228,7 +228,8 @@ Route::group('broker', [
'add_phone_follow_up' => ['api_broker/broker/add_phone_follow_up',['method'=>'get|post']],//新增-客户电话跟进 'add_phone_follow_up' => ['api_broker/broker/add_phone_follow_up',['method'=>'get|post']],//新增-客户电话跟进
'user_search' => ['api_broker/broker/user_search',['method'=>'get|post']],//客户搜索 'user_search' => ['api_broker/broker/user_search',['method'=>'get|post']],//客户搜索
'agentUserTb' => [ 'api_broker/Client/agentUserTb', [ 'method' => 'get' ] ],//客户列表 'agentUserTb' => [ 'api_broker/Client/agentUserTb', [ 'method' => 'get' ] ],//客户列表
'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//客户列表 'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
]); ]);
......
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