| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- namespace app\index\model;
- use\think\Model;
- use think\Session;
- use think\cache\driver\Redis;
- use think\Loader;
- use think\Cache;
- class Platform extends Model
- {
- /**
- * 获取平台列表
- */
- public function platformList()
- {
- // 获取平台列表.
- $platformWhere['platform_status'] = 1;
- $getPlatform = $this
- ->field('platform_name, platform_code, platform_id, platform_remark, platform_url, platform_img')
- ->where($platformWhere)
- ->select();
- return [
- 'code' => 1,
- 'msg' => lang('MP01001'),
- 'data' => ['list' => $getPlatform],
- ];
- }//end platformList()
- /**
- * 获取已注册平台列表
- */
- public function myPlatform()
- {
- $userToken = input('get.userToken');
- // 获取用户信息.
- $getUserInfo = model('user')->currentUser($userToken);
- $getUserInfo = $getUserInfo['data'];
- // 获取平台列表.
- $platformWhere['platform_status'] = 1;
- $platformWhere['user_identity'] = $getUserInfo['user_identity'];
- $getPlatform = $this
- ->field('platform_user, platform_code, a.platform_id, platform_remark, platform_name, platform_img')
- ->alias('a')
- ->join('user_platform b', 'a.platform_id = b.platform_id')
- ->where($platformWhere)
- ->select();
- // 循环添加验证码.
- foreach ($getPlatform as $k => $v) {
- $newCode = rand(100000, 999999);
- $codeData = [
- 'code' => $newCode,
- 'time' => time(),
- ];
- $codeKey = $v['platform_user'].'-'.$v['platform_code'];
- $data = [
- 'code_key' => $codeKey,
- 'code_time' => $codeData['time'],
- ];
- $addCode = model('Code')->addCode($data);
- $getPlatform[$k]['safetyCode'] = $newCode;
- }
- return [
- 'code' => 1,
- 'msg' => lang('MP01001'),
- 'data' => ['list' => $getPlatform],
- ];
- }//end myPlatform()
- /**
- * 安全验证
- */
- public function securityVerify()
- {
- $code = -2;
- $verifyCode = input('get.verifyCode');
- $platformCode = input('get.platformCode');
- $platformUser = input('get.userName');
- if(empty($verifyCode)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01007'),
- 'data' => [],
- ];
- }
- if(empty($platformCode)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01008'),
- 'data' => [],
- ];
- }
- if(empty($platformUser)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01009'),
- 'data' => [],
- ];
- }
- $safetyCodeKey = $platformUser.'-'.$platformCode;
- $safetyCodeKey = model('Code')->selectCode($safetyCodeKey);
- $safetyCodeKey = $safetyCodeKey['data'];
- // 验证.
- $nowTime = strtotime(date('Y-m-d H:i:s').'-1 min');
- if (!$safetyCodeKey || $safetyCodeKey['code_time'] < $nowTime) {
- return [
- 'code' => $code,
- 'msg' => lang('EP01003'),
- 'data' => [],
- ];
- }
- return [
- 'code' => 1,
- 'msg' => lang('MP01002'),
- 'data' => [],
- ];
- }//end securityVerify()
- /**
- * 获取平台验证码
- */
- public function platformToken($getData)
- {
- $code = -2;
- $userToken = input('get.userToken');
- $userInfoWhere['user_token'] = $userToken;
- // 获取用户信息.
- $getUserInfo = model('user')->currentUser($userToken);
- $getUserInfo = $getUserInfo['data'];
- $platformId = $getData['platformId'];
- // 验证传参.
- $data = ['platformId' => $platformId];
- $validate = Loader::validate('Platform');
- if (!$validate->scene('platformToken')->check($data)) {
- return [
- 'code' => $code,
- 'msg' => $validate->getError(),
- 'data' => [],
- ];
- }
- // 获取平台信息.
- $platformWhere['platform_status'] = 1;
- $platformWhere['platform_id'] = $platformId;
- $getPlatform = $this
- ->field('platform_code')
- ->where($platformWhere)
- ->find();
- // 加密.
- if(empty($getPlatform)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01006'),
- 'data' => [],
- ];
- }
- $token = randomPassword();
- $data = [
- 'user_identity' => $getUserInfo['user_identity'],
- 'platform_id' => $platformId,
- 'platform_code' => $getPlatform['platform_code'],
- 'platform_code_time' => time(),
- ];
- $addCode = model('PlatformUser')->addPlatformUser($data);
- return [
- 'code' => 1,
- 'msg' => lang('MC01005'),
- 'data' => [
- 'verifySystem' => $token,
- 'verifySystemId' => $platformId,
- ],
- ];
- }//end platformToken()
- /**
- * 验证
- */
- public function verifyPlatform()
- {
- $code = -2;
- $backSystem = input('get.backSystem');
- $platformCode = input('get.platformCode');
- $platformUser = input('get.userName');
- if(empty($backSystem)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01007'),
- 'data' => [],
- ];
- }
- if(empty($platformCode)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01008'),
- 'data' => [],
- ];
- }
- if(empty($platformUser)){
- return [
- 'code' => $code,
- 'msg' => lang('EP01009'),
- 'data' => [],
- ];
- }
- // 验证.
- $platformWhere['platform_code'] = $platformCode;
- $platformCode = model('PlatformUser')->selectPlatformUser($platformWhere);
- $platformCode = $platformCode['data'];
- $nowTime = strtotime(date('Y-m-d H:i:s').'-5 min');
- if (!$platformCode || $platformCode['platform_code_time'] < $nowTime) {
- return [
- 'code' => $code,
- 'msg' => lang('EP01002'),
- 'data' => [],
- ];
- }
- // 获取平台信息.
- $platformWhere['platform_status'] = 1;
- $platformWhere['platform_code'] = $platformCode;
- $getPlatform = $this
- ->field('platform_id')
- ->where($platformWhere)
- ->find();
- if (empty($getPlatform) === true) {
- return [
- 'code' => $code,
- 'msg' => lang('EP01003'),
- 'data' => [],
- ];
- }
- // 删除验证token.
- model('PlatformUser')->delPlatformUser($platformWhere);
- // 验证成功则加入数据.
- $addUserPlatform = model('UserPlatform')->addUserPlatform($platformCode['user_identity'], $getPlatform['platform_id'], $platformUser);
- return $addUserPlatform;
- }//end verifyPlatform()
- }
|