Commit c2b4a40a authored by hujun's avatar hujun

隐私号码修改,增加绑定关系检查。

parent 1a208c54
...@@ -14,7 +14,7 @@ use Aliyun\Api\Dypls\Request\V20170525\UnbindSubscriptionRequest; ...@@ -14,7 +14,7 @@ use Aliyun\Api\Dypls\Request\V20170525\UnbindSubscriptionRequest;
use Aliyun\Api\Dypls\Request\V20170525\UpdateSubscriptionRequest; use Aliyun\Api\Dypls\Request\V20170525\UpdateSubscriptionRequest;
use Aliyun\Api\Dypls\Request\V20170525\QueryRecordFileDownloadUrlRequest; use Aliyun\Api\Dypls\Request\V20170525\QueryRecordFileDownloadUrlRequest;
use Aliyun\Api\Dypls\Request\V20170525\QuerySubscriptionDetailRequest; use Aliyun\Api\Dypls\Request\V20170525\QuerySubscriptionDetailRequest;
use Aliyun\Api\Dypls\Request\V20170525\BindAxnExtensionRequest;use Symfony\Component\Yaml\Tests\DumperTest; use Aliyun\Api\Dypls\Request\V20170525\BindAxnExtensionRequest;
// 加载区域结点配置 // 加载区域结点配置
Config::load(); Config::load();
...@@ -292,22 +292,22 @@ class PlsDemo ...@@ -292,22 +292,22 @@ class PlsDemo
* @return stdClass * @return stdClass
* @throws ClientException * @throws ClientException
*/ */
public static function querySubscriptionDetail() { public static function querySubscriptionDetail($subsId, $secretNo) {
//组装请求对象 //组装请求对象
$request = new QuerySubscriptionDetailRequest(); $request = new QuerySubscriptionDetailRequest();
//必填:号池Key //必填:号池Key
$request->setPoolKey("FC123456"); $request->setPoolKey(self::$pool_key);
//必填: 产品类型,目前一共支持三款产品AXB_170,AXN_170,AXN_95 //必填: 产品类型,目前一共支持三款产品AXB_170,AXN_170,AXN_95
$request->setProductType("AXB_170"); $request->setProductType("AXB_170");
//必填: 绑定关系ID //必填: 绑定关系ID
$request->setSubsId("123456"); $request->setSubsId($subsId);
//必填: 绑定关系对应的X号码 //必填: 绑定关系对应的X号码
$request->setPhoneNoX("170000000"); $request->setPhoneNoX($secretNo);
//hint 此处可能会抛出异常,注意catch //hint 此处可能会抛出异常,注意catch
$response = static::getAcsClient()->getAcsResponse($request); $response = static::getAcsClient()->getAcsResponse($request);
......
...@@ -118,7 +118,7 @@ class CellPhone extends Basic ...@@ -118,7 +118,7 @@ class CellPhone extends Basic
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x); $result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
$phone->UnBind($phone_x); $phone->unBind($phone_x);
} else { } else {
$this->code = 101; $this->code = 101;
$this->msg = 'remove binding error'; $this->msg = 'remove binding error';
......
...@@ -26,29 +26,15 @@ class AliYunPhone extends BaseModel ...@@ -26,29 +26,15 @@ class AliYunPhone extends BaseModel
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getAliYunPhone($phone_a,$phone_b,$type=1) { public function getAliYunPhone($phone_a, $phone_b, $type = 1) {
/* //查找phone_x 与 phone_a绑定的号码 //找到phone_a和phone_b出现在两个字段中
$where_a['b.status'] = 1; $where_bind[] = ['EXP', "(a.phone_a='{$phone_a}' or a.phone_b='{$phone_a}') or (a.phone_a='{$phone_b}' or a.phone_b='{$phone_b}')"];
$where_a['phone_a'] = $phone_a; $where_bind['a.status'] = 1;
$where_a['bind_num'] = ['<=',200]; $where_bind['b.bind_num'] = ['<=',200];
$aliYun_phone_id1 = $this->field('a.id,phone_x')->alias('a') $where_bind['b.type'] = $type;
->join('aliYun_binding_phone b','a.id = b.aliYun_phone_id','left')
->where($where_a)->select();
//查找phone_x 与 phone_b绑定的号码 $m_bind = new BindingPhone();
$where_b['b.status'] = 1; $id_arr = $m_bind->getBindingPhoneList('b.id', $where_bind);
$where_b['phone_b'] = $phone_b;
$where_b['bind_num'] = ['<=',200];
$aliYun_phone_id2 = $this->field('a.id,phone_x')->alias('a')
->join('aliYun_binding_phone b','a.id = b.aliYun_phone_id','left')
->where($where_b)->select();
$id_arr = array_merge($aliYun_phone_id1,$aliYun_phone_id2); //合并phone_a和phone_b已经绑定的号码*/
$where_a['b.status'] = 1;
$where_a['bind_num'] = ['<=',200];
$id_arr = $this->field('a.id,phone_x')->alias('a')
->join('aliYun_binding_phone b','a.id = b.aliYun_phone_id','left')
->where($where_a)->where("(b.phone_a=$phone_a or b.phone_b=$phone_b) and a.type=$type ")->select();
foreach ($id_arr as $k=>$v) { foreach ($id_arr as $k=>$v) {
$id[$k] = $v['id'];//去除phone_a已经绑定的号码 $id[$k] = $v['id'];//去除phone_a已经绑定的号码
...@@ -59,10 +45,10 @@ class AliYunPhone extends BaseModel ...@@ -59,10 +45,10 @@ class AliYunPhone extends BaseModel
$where_phone['type'] = $type; $where_phone['type'] = $type;
if (empty($id)) { if (empty($id)) {
$result = Db::table('aliYun_phone')->field('id,phone_x,area')->where($where_phone)->find(); $result = $this->field('id,phone_x,area')->where($where_phone)->find();
} else { } else {
$where_phone['id'] = ['NOT IN',$id]; $where_phone['id'] = ['NOT IN',$id]; //排除已经绑定的号码
$result = Db::table('aliYun_phone')->field('id,phone_x,area')->where($where_phone)->find(); $result = $this->field('id,phone_x,area')->where($where_phone)->find();
} }
return $result; return $result;
......
...@@ -56,7 +56,7 @@ class BindingPhone extends BaseModel ...@@ -56,7 +56,7 @@ class BindingPhone extends BaseModel
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function UnBind($phone_x, $phone_a = '', $phone_b='',$request_id = '') { public function unBind($phone_x, $phone_a = '', $phone_b='',$request_id = '') {
if ($phone_x) { if ($phone_x) {
$phone = new AliYunPhone(); $phone = new AliYunPhone();
$phone_data = $phone->where('phone_x',$phone_x)->find(); $phone_data = $phone->where('phone_x',$phone_x)->find();
...@@ -99,4 +99,38 @@ class BindingPhone extends BaseModel ...@@ -99,4 +99,38 @@ class BindingPhone extends BaseModel
->find(); ->find();
} }
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBindingPhoneList($field, $where) {
return $this->field($field)->alias('a')
->join('aliYun_phone b','a.aliYun_phone_id = b.id','left')
->where($where)
->select();
}
/**
* 更新绑定号码与阿里云绑定不一致的问题
*
* @param $id
* @param $aliYun_phone_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
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();
}
$this->update(['status' => 0, 'id' => $id]);
return ;
}
} }
\ No newline at end of file
...@@ -341,6 +341,7 @@ Route::group('task', [ ...@@ -341,6 +341,7 @@ Route::group('task', [
'addReport' => [ 'task/PrivacyNumber/addReport', [ 'method' => 'get|post' ] ], //阿里大于隐私号码回调 'addReport' => [ 'task/PrivacyNumber/addReport', [ 'method' => 'get|post' ] ], //阿里大于隐私号码回调
'queryRecordFile' => [ 'task/PrivacyNumber/queryRecordFile', [ 'method' => 'get' ] ], //下载录音 'queryRecordFile' => [ 'task/PrivacyNumber/queryRecordFile', [ 'method' => 'get' ] ], //下载录音
'releaseNumber' => [ 'task/PrivacyNumber/releaseNumber', [ 'method' => 'get' ] ], //释放号码 'releaseNumber' => [ 'task/PrivacyNumber/releaseNumber', [ 'method' => 'get' ] ], //释放号码
'checkBindPhone' => [ 'task/PrivacyNumber/checkBindPhone', [ 'method' => 'get' ] ], //检查绑定关系,去除表中不存在的绑定关系
'updateStatusByTime' => [ 'task/updateShopStatusTask/updateStatusByTime', [ 'method' => 'get' ] ], //修改上下架 'updateStatusByTime' => [ 'task/updateShopStatusTask/updateStatusByTime', [ 'method' => 'get' ] ], //修改上下架
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
namespace app\task\controller; namespace app\task\controller;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
use app\model\AliYunBindingPhone;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport; use app\model\SecretReport;
use app\model\RongBilledInform;
use think\Db; use think\Db;
use think\Log; use think\Log;
use think\Request; use think\Request;
...@@ -129,7 +129,7 @@ class PrivacyNumber ...@@ -129,7 +129,7 @@ class PrivacyNumber
$result = PlsDemo::unbindSubscription($subsId, $v['phone_x']); $result = PlsDemo::unbindSubscription($subsId, $v['phone_x']);
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
$bind->UnBind($v['phone_x'], $v['phone_a'], $v['phone_b'], $result->RequestId); $bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b'], $result->RequestId);
$binding_phone_id[$k] = $v['id']; $binding_phone_id[$k] = $v['id'];
$phone_id[$k] = $v['aliYun_phone_id']; $phone_id[$k] = $v['aliYun_phone_id'];
} }
...@@ -203,4 +203,30 @@ class PrivacyNumber ...@@ -203,4 +203,30 @@ class PrivacyNumber
} }
/**
* 检查绑定关系,去除表中不存在的绑定关系
*
* @throws \Aliyun\Core\Exception\ClientException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function checkBindPhone() {
$m_bind = new BindingPhone();
$where['a.status'] = 1;
$where['a.type'] = 1;
$select_data = $m_bind->getBindingPhoneList('a.id,a.aliYun_phone_id,b.phone_x,a.subsId,a.expiry_date', $where);
foreach ($select_data as $k=>$v) {
$query_status = PlsDemo::querySubscriptionDetail($v['subsId'], $v['phone_x']);
$expiry_date = strtotime($select_data['expiry_date']);
if (($query_status->Code != 'OK') && ($expiry_date < time())) {
$m_bind->unBindTable($v['id'], $v['aliYun_phone_id']);
}
}
return ;
}
} }
\ No newline at end of file
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