Commit fc18daa6 authored by hujun's avatar hujun

更新绑定关系隐私号码

parent 17c446d3
......@@ -32,18 +32,26 @@ class CellPhone extends Basic
public function bindAXB() {
$params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) {
$expiration = _EXPIRATION; //过期时间
$phone_a = $this->params['phone_a'];//经纪人手机号
$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);
if ($phone_x) {
$this->data = ['phone' => $phone_x];
} else {
$phone_x = $aliYunPhone->getAliYunPhone($phone_b);
$bind = new AliYunPhone();
$phone_x = $bind->getAliYunPhone($phone_b);
//是否还有未绑定的中间号码
if ($phone_x) {
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, $phone_x['phone_x']);
$result = PlsDemo::bindAxb($phone_a, $phone_b, _EXPIRATION, $record, $phone_x['phone_x']);
if ($result->Message == 'OK') {
$bind->where('phone_x',$phone_x['phone_x'])->setField('status',1);
$aliYunPhone->where('phone_x', $phone_x['phone_x'])->setField('status', 1);
Db::table('aliYun_binding_phone')->insert([
'phone_a' => $phone_a,
'phone_b' => $phone_b,
......@@ -53,7 +61,7 @@ class CellPhone extends Basic
'aliYun_phone_id' => $phone_x['id']
]);
$this->msg = 'Binding success.';
$this->data = ['phone'=>$phone_x['phone_x']];
$this->data = ['phone' => $phone_x['phone_x']];
} else {
$this->code = 101;
$this->msg = 'Binding failure.';
......@@ -62,19 +70,45 @@ class CellPhone extends Basic
$this->code = 102;
$this->msg = 'Number pool run out.';
}
}
} else {
$this->code = 101;
$this->msg = 'phone_a or phone_b is null';
}
return $this->response($this->code, $this->msg, $this->data);
}
/**
* 更新绑定关系
*
* @return \think\Response
*/
public function updateBindAXB() {
/* $params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) {
$this->data = PlsDemo::updateSubscription($this->params['phone_a'], $this->params['phone_b'], _EXPIRATION, $params['record']);
$params = $this->request->param();
if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) {
$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
if ($phone_x) {
$phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1);
$subsId = $phone->getSubsId($phone_x,$phone_a,'',1);
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') {
......
......@@ -192,29 +192,35 @@ class PlsDemo
/**
* 更新绑定关系
*
* @return stdClass
* @throws ClientException
* @param $type 0 更新A号码,1更新B号码,2更新时间
* @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();
//必填:号池Key
$request->setPoolKey("FC123456");
$request->setPoolKey(_POOLKEY);
//必填: 您所选择的产品类型,目前支持AXB_170、AXN_170、AXN_95三种产品类型
$request->setProductType("AXB_170");
//必填: 创建绑定关系API接口所返回的订购关系ID
$request->setSubsId("123456");
$request->setSubsId($subsId);
//必填: 创建绑定关系API接口所返回的X号码
$request->setPhoneNoX("170000000");
$request->setPhoneNoX($phone_x);
// todo 以下操作三选一, 目前支持三种类型: updateNoA(修改A号码)、updateNoB(修改B号码)、updateExpire(更新绑定关系有效期)
switch ($type) {
case 0 :
// -------------------------------------------------------------------
// 1. 修改A号码示例:
......@@ -222,27 +228,28 @@ class PlsDemo
$request->setOperateType("updateNoA");
// OperateType为updateNoA时必选: 需要修改的A号码
$request->setPhoneNoA("150000000");
$request->setPhoneNoA($phone_a);break;
// -------------------------------------------------------------------
case 1 :
// 2. 修改B号码示例:
// 必填: 操作类型
// $request->setOperateType("updateNoB");
$request->setOperateType("updateNoB");
// OperateType为updateNoB时必选: 需要修改的B号码
// $request->setPhoneNoB("150000000");
$request->setPhoneNoB($phone_b);break;
// -------------------------------------------------------------------
case 2 :
// 3. 更新绑定关系有效期示例:
// 必填: 操作类型
// $request->setOperateType("updateExpire");
$request->setOperateType("updateExpire");
// OperateType为updateExpire时必选: 需要修改的绑定关系有效期
// $request->setExpiration("2017-09-05 12:00:00");
$request->setExpiration($date);break;
// -------------------------------------------------------------------
}
// 此处可能会抛出异常,注意catch
$response = static::getAcsClient()->getAcsResponse($request);
......
......@@ -70,12 +70,36 @@ class CellPhone extends Basic
return $this->response($this->code, $this->msg, $this->data);
}
/**
* 更新绑定关系
*
* @return \think\Response
*/
public function updateBindAXB() {
/* $params = $this->request->param();
if ($params['phone_a'] || $params['phone_b']) {
$this->data = PlsDemo::updateSubscription($this->params['phone_a'], $this->params['phone_b'], _EXPIRATION, $params['record']);
$params = $this->request->param();
if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) {
$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
if ($phone_x) {
$phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1);
$subsId = $phone->getSubsId($phone_x,$phone_a,'',1);
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') {
......
......@@ -29,7 +29,7 @@ class AliYunPhone extends BaseModel
$where['status'] = 0;
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')
->where([
'phone_b' => $phone,
......
......@@ -18,18 +18,25 @@ class BindingPhone extends BaseModel
*
* @param $phone_x
* @param $phone_a
* @param $phone_b
* @param int $status
* @return bool|mixed
*/
public function getSubsId($phone_x, $phone_a, $status = 0) {
if ($phone_x && $phone_a) {
public function getSubsId($phone_x, $phone_a, $phone_b = '', $status = 0) {
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')
->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');
->where($where)->value('subsId');
} else {
$subsId = false;
}
......@@ -60,4 +67,22 @@ class BindingPhone extends BaseModel
}
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', [
'callCollectList' => [ 'index/CellPhone/callCollectList', [ 'method' => 'get' ] ],//经纪人通话汇总
'bindAXB' => [ 'index/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'index/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
'updateBindAXB' => ['api_broker/CellPhone/updateBindAXB', [ 'method' => 'post' ] ], //更新绑定关系隐私号码
]);
......@@ -241,6 +242,7 @@ Route::group('broker', [
'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
'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