Master.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\master\logic;
  9. use app\core\model\BankPlatform;
  10. use app\core\model\UserAccount;
  11. use app\core\model\UserBank;
  12. use app\core\model\UserRecharge;
  13. use app\core\service\Pay;
  14. use app\core\service\Check;
  15. use app\core\service\SMS;
  16. use app\core\model\Master as Model;
  17. use app\core\model\Cang;
  18. use think\Db;
  19. use tool\Common;
  20. class Master extends Base
  21. {
  22. /**
  23. * @api {post} master/loginByPassword 密码登录
  24. * @apiVersion 1.0.0
  25. * @apiName loginByPassword
  26. * @apiDescription 密码登录
  27. * @apiGroup Master
  28. *
  29. * @apiParam {String} mobile 手机号码
  30. * @apiParam {String} password 密码
  31. * @apiParamExample {json} 发送报文:
  32. {
  33. "mobile": "13136180523",
  34. "password": "111111"
  35. }
  36. *
  37. * @apiSuccessExample {json} 返回json数据(举例):
  38. {
  39. "code": 1,
  40. "msg": "操作成功",
  41. "content": {
  42. "token": "a8ajdsjasdfuufayg8aasdfasdfasd"
  43. }
  44. }
  45. * @apiUse CreateUserError
  46. */
  47. public function loginByPassword() {
  48. $master = Model::get([
  49. 'mobile'=>$this->app['mobile']
  50. ]);
  51. if(!$master) {
  52. return Common::rm(-3, '该管理员不存在');
  53. }
  54. if($master['password'] != $master->createPassword($this->app['password'])) {
  55. return Common::rm(-4, '密码不正确');
  56. }
  57. $master['token'] = $master->createToken();
  58. $master['tokenOverTime'] = $master->createTokenOverTime();
  59. $master['loginTime'] = THINK_START_TIME;
  60. $master['ip'] = $this->request->ip();
  61. $master->save();
  62. $this->master = $master;
  63. $group = Db::name('master_group')->where([
  64. 'masterID'=>$master['masterID']
  65. ])->find();
  66. if(!$group) {
  67. return Common::rm(-5, '没有权限');
  68. }
  69. return Common::rm(1, '操作成功', [
  70. 'token'=>$master['token'],
  71. 'masterInfo'=>[
  72. 'mobile'=>$this->app['mobile'],
  73. 'roleID'=>$group['masterRoleID']
  74. ]
  75. ]);
  76. }
  77. /**
  78. * @api {post} master/logout 退出登录
  79. * @apiVersion 1.0.0
  80. * @apiName logout
  81. * @apiDescription 退出登录
  82. * @apiGroup Master
  83. *
  84. * @apiSuccessExample {json} 返回json数据(举例):
  85. {
  86. "code": 1,
  87. "msg": "操作成功"
  88. }
  89. * @apiUse CreateUserError
  90. */
  91. public function logout() {
  92. Model::update([
  93. 'tokenOverTime'=>0
  94. ],[
  95. 'token'=>$this->master['token']
  96. ]);
  97. return Common::rm(1, '操作成功');
  98. }
  99. public static function checkAuth($master = [], $action = '') {
  100. $group = Db::name('master_group')->where([
  101. 'masterID'=>$master['masterID']
  102. ])->find();
  103. if(!$group) {
  104. return false;
  105. }
  106. if($group['masterRoleID'] == 1) {
  107. return true;
  108. }
  109. $auth = Db::name('master_auth')->where([
  110. 'masterRoleID'=>$group['masterRoleID']
  111. ])->select();
  112. if(!$auth) {
  113. return false;
  114. }
  115. $actionS = array_column($auth, 'action');
  116. if(!in_array($action, $actionS)) {
  117. return false;
  118. }
  119. return true;
  120. }
  121. }