12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\common\model;
- use think\Model;
- class Ptoken extends Model
- {
- // 表名
- protected $table = 'ptoken';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- /**
- * 检查渠道是否授权指定平台,可同时检查多个平台
- * @param $platform_id
- * @param $channel_id
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function checkChannelIsAuth($platform_id,$channel_id){
- if($token = $this->whereIn('platform_id',$platform_id)->where('admin_id',$channel_id)->select()){
- return true;
- }else{
- return false;
- }
- }
- /**
- * 检查指定平台是否授权
- * @param $platform_id
- * @param $admin_id
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function checkPlatformIsAuth($platform_id,$admin_id){
- $is_auth = true;
- $auth_platform = [];
- if(!$platform = model('platform')->whereIn('id',$platform_id)->where(['status'=>'1'])->select()){
- return false;
- }
- if(!$ptoken = $this->where(['admin_id'=>$admin_id])->select()){
- return false;
- }
- foreach($ptoken as $token){
- if(!empty($token['refresh_token'])){
- array_push($auth_platform,$token['platform_id']);
- }
- }
- foreach($platform as $info){
- if(!in_array($info['id'],$auth_platform)){
- $is_auth = false;
- }
- }
- return $is_auth;
- }
- //根据平台获取refresh_token
- public function getToken($platform_id,$admin_id){
- $info = $this->where(['platform_id'=>$platform_id,'admin_id'=>$admin_id])->find();
- if($info){
- $info = $info->toArray();
- return $info['refresh_token'];
- }else{
- return false;
- }
- }
- }
|