Platform.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. namespace app\index\model;
  3. use\think\Model;
  4. use think\Session;
  5. use think\cache\driver\Redis;
  6. use think\Loader;
  7. use think\Cache;
  8. class Platform extends Model
  9. {
  10. /**
  11. * 获取平台列表
  12. */
  13. public function platformList()
  14. {
  15. // 获取平台列表.
  16. $platformWhere['platform_status'] = 1;
  17. $getPlatform = $this
  18. ->field('platform_name, platform_code, platform_id, platform_remark, platform_url, platform_img')
  19. ->where($platformWhere)
  20. ->select();
  21. return [
  22. 'code' => 1,
  23. 'msg' => lang('MP01001'),
  24. 'data' => ['list' => $getPlatform],
  25. ];
  26. }//end platformList()
  27. /**
  28. * 获取已注册平台列表
  29. */
  30. public function myPlatform()
  31. {
  32. $userToken = input('get.userToken');
  33. // 获取用户信息.
  34. $getUserInfo = model('user')->currentUser($userToken);
  35. $getUserInfo = $getUserInfo['data'];
  36. // 获取平台列表.
  37. $platformWhere['platform_status'] = 1;
  38. $platformWhere['user_identity'] = $getUserInfo['user_identity'];
  39. $getPlatform = $this
  40. ->field('platform_user, platform_code, a.platform_id, platform_remark, platform_name, platform_img')
  41. ->alias('a')
  42. ->join('user_platform b', 'a.platform_id = b.platform_id')
  43. ->where($platformWhere)
  44. ->select();
  45. // 循环添加验证码.
  46. foreach ($getPlatform as $k => $v) {
  47. $newCode = rand(100000, 999999);
  48. $codeData = [
  49. 'code' => $newCode,
  50. 'time' => time(),
  51. ];
  52. $codeKey = $v['platform_user'].'-'.$v['platform_code'];
  53. $data = [
  54. 'code_key' => $codeKey,
  55. 'code_time' => $codeData['time'],
  56. ];
  57. $addCode = model('Code')->addCode($data);
  58. $getPlatform[$k]['safetyCode'] = $newCode;
  59. }
  60. return [
  61. 'code' => 1,
  62. 'msg' => lang('MP01001'),
  63. 'data' => ['list' => $getPlatform],
  64. ];
  65. }//end myPlatform()
  66. /**
  67. * 安全验证
  68. */
  69. public function securityVerify()
  70. {
  71. $code = -2;
  72. $verifyCode = input('get.verifyCode');
  73. $platformCode = input('get.platformCode');
  74. $platformUser = input('get.userName');
  75. if(empty($verifyCode)){
  76. return [
  77. 'code' => $code,
  78. 'msg' => lang('EP01007'),
  79. 'data' => [],
  80. ];
  81. }
  82. if(empty($platformCode)){
  83. return [
  84. 'code' => $code,
  85. 'msg' => lang('EP01008'),
  86. 'data' => [],
  87. ];
  88. }
  89. if(empty($platformUser)){
  90. return [
  91. 'code' => $code,
  92. 'msg' => lang('EP01009'),
  93. 'data' => [],
  94. ];
  95. }
  96. $safetyCodeKey = $platformUser.'-'.$platformCode;
  97. $safetyCodeKey = model('Code')->selectCode($safetyCodeKey);
  98. $safetyCodeKey = $safetyCodeKey['data'];
  99. // 验证.
  100. $nowTime = strtotime(date('Y-m-d H:i:s').'-1 min');
  101. if (!$safetyCodeKey || $safetyCodeKey['code_time'] < $nowTime) {
  102. return [
  103. 'code' => $code,
  104. 'msg' => lang('EP01003'),
  105. 'data' => [],
  106. ];
  107. }
  108. return [
  109. 'code' => 1,
  110. 'msg' => lang('MP01002'),
  111. 'data' => [],
  112. ];
  113. }//end securityVerify()
  114. /**
  115. * 获取平台验证码
  116. */
  117. public function platformToken($getData)
  118. {
  119. $code = -2;
  120. $userToken = input('get.userToken');
  121. $userInfoWhere['user_token'] = $userToken;
  122. // 获取用户信息.
  123. $getUserInfo = model('user')->currentUser($userToken);
  124. $getUserInfo = $getUserInfo['data'];
  125. $platformId = $getData['platformId'];
  126. // 验证传参.
  127. $data = ['platformId' => $platformId];
  128. $validate = Loader::validate('Platform');
  129. if (!$validate->scene('platformToken')->check($data)) {
  130. return [
  131. 'code' => $code,
  132. 'msg' => $validate->getError(),
  133. 'data' => [],
  134. ];
  135. }
  136. // 获取平台信息.
  137. $platformWhere['platform_status'] = 1;
  138. $platformWhere['platform_id'] = $platformId;
  139. $getPlatform = $this
  140. ->field('platform_code')
  141. ->where($platformWhere)
  142. ->find();
  143. // 加密.
  144. if(empty($getPlatform)){
  145. return [
  146. 'code' => $code,
  147. 'msg' => lang('EP01006'),
  148. 'data' => [],
  149. ];
  150. }
  151. $token = randomPassword();
  152. $data = [
  153. 'user_identity' => $getUserInfo['user_identity'],
  154. 'platform_id' => $platformId,
  155. 'platform_code' => $getPlatform['platform_code'],
  156. 'platform_code_time' => time(),
  157. ];
  158. $addCode = model('PlatformUser')->addPlatformUser($data);
  159. return [
  160. 'code' => 1,
  161. 'msg' => lang('MC01005'),
  162. 'data' => [
  163. 'verifySystem' => $token,
  164. 'verifySystemId' => $platformId,
  165. ],
  166. ];
  167. }//end platformToken()
  168. /**
  169. * 验证
  170. */
  171. public function verifyPlatform()
  172. {
  173. $code = -2;
  174. $backSystem = input('get.backSystem');
  175. $platformCode = input('get.platformCode');
  176. $platformUser = input('get.userName');
  177. if(empty($backSystem)){
  178. return [
  179. 'code' => $code,
  180. 'msg' => lang('EP01007'),
  181. 'data' => [],
  182. ];
  183. }
  184. if(empty($platformCode)){
  185. return [
  186. 'code' => $code,
  187. 'msg' => lang('EP01008'),
  188. 'data' => [],
  189. ];
  190. }
  191. if(empty($platformUser)){
  192. return [
  193. 'code' => $code,
  194. 'msg' => lang('EP01009'),
  195. 'data' => [],
  196. ];
  197. }
  198. // 验证.
  199. $platformWhere['platform_code'] = $platformCode;
  200. $platformCode = model('PlatformUser')->selectPlatformUser($platformWhere);
  201. $platformCode = $platformCode['data'];
  202. $nowTime = strtotime(date('Y-m-d H:i:s').'-5 min');
  203. if (!$platformCode || $platformCode['platform_code_time'] < $nowTime) {
  204. return [
  205. 'code' => $code,
  206. 'msg' => lang('EP01002'),
  207. 'data' => [],
  208. ];
  209. }
  210. // 获取平台信息.
  211. $platformWhere['platform_status'] = 1;
  212. $platformWhere['platform_code'] = $platformCode;
  213. $getPlatform = $this
  214. ->field('platform_id')
  215. ->where($platformWhere)
  216. ->find();
  217. if (empty($getPlatform) === true) {
  218. return [
  219. 'code' => $code,
  220. 'msg' => lang('EP01003'),
  221. 'data' => [],
  222. ];
  223. }
  224. // 删除验证token.
  225. model('PlatformUser')->delPlatformUser($platformWhere);
  226. // 验证成功则加入数据.
  227. $addUserPlatform = model('UserPlatform')->addUserPlatform($platformCode['user_identity'], $getPlatform['platform_id'], $platformUser);
  228. return $addUserPlatform;
  229. }//end verifyPlatform()
  230. }