Commit fc18daa6 authored by hujun's avatar hujun

更新绑定关系隐私号码

parent 17c446d3
...@@ -32,49 +32,83 @@ class CellPhone extends Basic ...@@ -32,49 +32,83 @@ class CellPhone extends Basic
public function bindAXB() { public function bindAXB() {
$params = $this->request->param(); $params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) { if ($params['phone_a'] || $params['phone_b']) {
$expiration = _EXPIRATION; //过期时间
$phone_a = $this->params['phone_a'];//经纪人手机号 $phone_a = $this->params['phone_a'];//经纪人手机号
$phone_b = $this->params['phone_b'];//客户手机号 $phone_b = $this->params['phone_b'];//客户手机号
$record = empty($this->params['record'])? true:false; //是否录音 $record = empty($this->params['record']) ? true : false; //是否录音
$aliYunPhone = new AliYunPhone();
$bind = new BindingPhone();
$field = 'phone_x';
$where['a.status'] = 1;
$phone_x = $bind->getPhoneX($field, $where);
$bind = new AliYunPhone();
$phone_x = $bind->getAliYunPhone($phone_b);
//是否还有未绑定的中间号码
if ($phone_x) { if ($phone_x) {
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, $phone_x['phone_x']); $this->data = ['phone' => $phone_x];
if ($result->Message == 'OK') { } else {
$bind->where('phone_x',$phone_x['phone_x'])->setField('status',1); $phone_x = $aliYunPhone->getAliYunPhone($phone_b);
Db::table('aliYun_binding_phone')->insert([
'phone_a' => $phone_a, //是否还有未绑定的中间号码
'phone_b' => $phone_b, if ($phone_x) {
'subsId' => $result->SecretBindDTO->SubsId, $result = PlsDemo::bindAxb($phone_a, $phone_b, _EXPIRATION, $record, $phone_x['phone_x']);
'requestId' => $result->RequestId, if ($result->Message == 'OK') {
'record' => $record, $aliYunPhone->where('phone_x', $phone_x['phone_x'])->setField('status', 1);
'aliYun_phone_id' => $phone_x['id'] Db::table('aliYun_binding_phone')->insert([
]); 'phone_a' => $phone_a,
$this->msg = 'Binding success.'; 'phone_b' => $phone_b,
$this->data = ['phone'=>$phone_x['phone_x']]; 'subsId' => $result->SecretBindDTO->SubsId,
'requestId' => $result->RequestId,
'record' => $record,
'aliYun_phone_id' => $phone_x['id']
]);
$this->msg = 'Binding success.';
$this->data = ['phone' => $phone_x['phone_x']];
} else {
$this->code = 101;
$this->msg = 'Binding failure.';
}
} else { } else {
$this->code = 101; $this->code = 102;
$this->msg = 'Binding failure.'; $this->msg = 'Number pool run out.';
} }
} else {
$this->code = 102;
$this->msg = 'Number pool run out.';
} }
} else { } else {
$this->code = 101; $this->code = 101;
$this->msg = 'phone_a or phone_b is null'; $this->msg = 'phone_a or phone_b is null';
} }
return $this->response($this->code, $this->msg, $this->data); return $this->response($this->code, $this->msg, $this->data);
} }
/**
* 更新绑定关系
*
* @return \think\Response
*/
public function updateBindAXB() { public function updateBindAXB() {
/* $params = $this->request->param(); $params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) { if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) {
$this->data = PlsDemo::updateSubscription($this->params['phone_a'], $this->params['phone_b'], _EXPIRATION, $params['record']); $bind = new BindingPhone();
if ($params['phone_a']) {
$subId = $bind->getSubsId($params['phone_x'], $params['phone_a'], '',1); //跟换B号码
} else {
$subId = $bind->getSubsId($params['phone_x'], '', $params['phone_b'],1); //更好A号码
}
$resutl = PlsDemo::updateSubscription($params['type'], $subId, $this->params['phone_x'], $this->params['phone_a'], $this->params['phone_b'], $params['date']);
if ($resutl->Message == 'OK') {
$this->msg = 'ok';
} else {
$this->code = 101;
$this->msg = 'update bind is error';
}
} else {
$this->code = 101;
$this->msg = 'phone is null';
} }
return $this->response($this->code, $this->msg,$this->data);*/ return $this->response($this->code, $this->msg,$this->data);
} }
/** /**
...@@ -89,7 +123,8 @@ class CellPhone extends Basic ...@@ -89,7 +123,8 @@ class CellPhone extends Basic
if ($phone_x) { if ($phone_x) {
$phone = new BindingPhone(); $phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1); $subsId = $phone->getSubsId($phone_x,$phone_a,'',1);
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x); $result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
......
...@@ -192,57 +192,64 @@ class PlsDemo ...@@ -192,57 +192,64 @@ class PlsDemo
/** /**
* 更新绑定关系 * 更新绑定关系
* *
* @return stdClass * @param $type 0 更新A号码,1更新B号码,2更新时间
* @throws ClientException * @param $subsId
* @param $phone_x
* @param string $phone_a
* @param string $phone_b
* @param string $date
* @return mixed|\SimpleXMLElement
*/ */
public static function updateSubscription() { public static function updateSubscription($type, $subsId, $phone_x, $phone_a = '', $phone_b = '', $date = '') {
//组装请求对象 //组装请求对象
$request = new UpdateSubscriptionRequest(); $request = new UpdateSubscriptionRequest();
//必填:号池Key //必填:号池Key
$request->setPoolKey("FC123456"); $request->setPoolKey(_POOLKEY);
//必填: 您所选择的产品类型,目前支持AXB_170、AXN_170、AXN_95三种产品类型 //必填: 您所选择的产品类型,目前支持AXB_170、AXN_170、AXN_95三种产品类型
$request->setProductType("AXB_170"); $request->setProductType("AXB_170");
//必填: 创建绑定关系API接口所返回的订购关系ID //必填: 创建绑定关系API接口所返回的订购关系ID
$request->setSubsId("123456"); $request->setSubsId($subsId);
//必填: 创建绑定关系API接口所返回的X号码 //必填: 创建绑定关系API接口所返回的X号码
$request->setPhoneNoX("170000000"); $request->setPhoneNoX($phone_x);
// todo 以下操作三选一, 目前支持三种类型: updateNoA(修改A号码)、updateNoB(修改B号码)、updateExpire(更新绑定关系有效期) // todo 以下操作三选一, 目前支持三种类型: updateNoA(修改A号码)、updateNoB(修改B号码)、updateExpire(更新绑定关系有效期)
switch ($type) {
case 0 :
// -------------------------------------------------------------------
// ------------------------------------------------------------------- // 1. 修改A号码示例:
// 必填: 操作类型
// 1. 修改A号码示例: $request->setOperateType("updateNoA");
// 必填: 操作类型
$request->setOperateType("updateNoA");
// OperateType为updateNoA时必选: 需要修改的A号码 // OperateType为updateNoA时必选: 需要修改的A号码
$request->setPhoneNoA("150000000"); $request->setPhoneNoA($phone_a);break;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
case 1 :
// 2. 修改B号码示例:
// 必填: 操作类型
$request->setOperateType("updateNoB");
// 2. 修改B号码示例: // OperateType为updateNoB时必选: 需要修改的B号码
// 必填: 操作类型 $request->setPhoneNoB($phone_b);break;
// $request->setOperateType("updateNoB");
// OperateType为updateNoB时必选: 需要修改的B号码 // -------------------------------------------------------------------
// $request->setPhoneNoB("150000000"); case 2 :
// 3. 更新绑定关系有效期示例:
// 必填: 操作类型
$request->setOperateType("updateExpire");
// ------------------------------------------------------------------- // OperateType为updateExpire时必选: 需要修改的绑定关系有效期
$request->setExpiration($date);break;
// 3. 更新绑定关系有效期示例: // -------------------------------------------------------------------
// 必填: 操作类型 }
// $request->setOperateType("updateExpire");
// OperateType为updateExpire时必选: 需要修改的绑定关系有效期
// $request->setExpiration("2017-09-05 12:00:00");
// -------------------------------------------------------------------
// 此处可能会抛出异常,注意catch // 此处可能会抛出异常,注意catch
$response = static::getAcsClient()->getAcsResponse($request); $response = static::getAcsClient()->getAcsResponse($request);
......
...@@ -70,12 +70,36 @@ class CellPhone extends Basic ...@@ -70,12 +70,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
*/
public function updateBindAXB() { public function updateBindAXB() {
/* $params = $this->request->param(); $params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) { if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) {
$this->data = PlsDemo::updateSubscription($this->params['phone_a'], $this->params['phone_b'], _EXPIRATION, $params['record']); $bind = new BindingPhone();
if ($params['phone_a']) {
$subId = $bind->getSubsId($params['phone_x'], $params['phone_a'], '',1); //跟换B号码
} else {
$subId = $bind->getSubsId($params['phone_x'], '', $params['phone_b'],1); //更好A号码
}
$resutl = PlsDemo::updateSubscription($params['type'], $subId, $this->params['phone_x'], $this->params['phone_a'], $this->params['phone_b'], $params['date']);
if ($resutl->Message == 'OK') {
$this->msg = 'ok';
} else {
$this->code = 101;
$this->msg = 'update bind is error';
}
} else {
$this->code = 101;
$this->msg = 'phone is null';
} }
return $this->response($this->code, $this->msg,$this->data);*/ return $this->response($this->code, $this->msg,$this->data);
} }
/** /**
...@@ -90,7 +114,7 @@ class CellPhone extends Basic ...@@ -90,7 +114,7 @@ class CellPhone extends Basic
if ($phone_x) { if ($phone_x) {
$phone = new BindingPhone(); $phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1); $subsId = $phone->getSubsId($phone_x,$phone_a,'',1);
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x); $result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
......
...@@ -29,7 +29,7 @@ class AliYunPhone extends BaseModel ...@@ -29,7 +29,7 @@ class AliYunPhone extends BaseModel
$where['status'] = 0; $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')->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,
......
...@@ -18,18 +18,25 @@ class BindingPhone extends BaseModel ...@@ -18,18 +18,25 @@ class BindingPhone extends BaseModel
* *
* @param $phone_x * @param $phone_x
* @param $phone_a * @param $phone_a
* @param $phone_b
* @param int $status * @param int $status
* @return bool|mixed * @return bool|mixed
*/ */
public function getSubsId($phone_x, $phone_a, $status = 0) { public function getSubsId($phone_x, $phone_a, $phone_b = '', $status = 0) {
if ($phone_x && $phone_a) { if ($phone_x && ($phone_a || $phone_b)) {
$where['a.status'] = $status;
if ($phone_a) {
$where['phone_a'] = $phone_a;
}
if ($phone_b){
$where['phone_b'] = $phone_b;
}
$subsId = $this->alias('a') $subsId = $this->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($where)->value('subsId');
'a.status'=>$status,
'phone_x'=>$phone_x,
'phone_a'=>$phone_a
])->value('subsId');
} else { } else {
$subsId = false; $subsId = false;
} }
...@@ -60,4 +67,22 @@ class BindingPhone extends BaseModel ...@@ -60,4 +67,22 @@ class BindingPhone extends BaseModel
} }
return $result; return $result;
} }
/**
* 获取phone_x
*
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getPhoneX($field, $where) {
return $this->alias('a')
->field($field)
->join('aliYun_phone b','a.aliYun_phone_id=b.id')
->where($where)
->find();
}
} }
\ No newline at end of file
...@@ -147,6 +147,7 @@ Route::group('index', [ ...@@ -147,6 +147,7 @@ Route::group('index', [
'callCollectList' => [ 'index/CellPhone/callCollectList', [ 'method' => 'get' ] ],//经纪人通话汇总 'callCollectList' => [ 'index/CellPhone/callCollectList', [ 'method' => 'get' ] ],//经纪人通话汇总
'bindAXB' => [ 'index/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码 'bindAXB' => [ 'index/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'index/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系 'agentsUnBind' => [ 'index/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
'updateBindAXB' => ['api_broker/CellPhone/updateBindAXB', [ 'method' => 'post' ] ], //更新绑定关系隐私号码
]); ]);
...@@ -241,6 +242,7 @@ Route::group('broker', [ ...@@ -241,6 +242,7 @@ Route::group('broker', [
'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码 'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系 'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
'getShopList' => ['api_broker/Shop/getShopList', [ 'method' => 'get' ] ], 'getShopList' => ['api_broker/Shop/getShopList', [ 'method' => 'get' ] ],
'updateBindAXB' => ['api_broker/CellPhone/updateBindAXB', [ '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