System_user.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. use App\lib\ModelBase;
  5. class System_user extends ModelBase {
  6. protected $table = "system_user";
  7. public $timestamps = false;
  8. //获取管理员列表
  9. function getAdminlist($value = '', $type = 1, $page = 10, $sort = 5, $ads = 'desc', $jointable = '') {
  10. $key = $this->getFeild($type);
  11. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  12. //DB::connection()->enableQueryLog();
  13. // if ($jointable == 'system_root') {
  14. // if (is_array($value) && count($value) > 0) {
  15. // $data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->join($jointable, 'system_user.root_id', $jointable . '.id')->where($value)->orderby($sort, $ads)->paginate($page);
  16. // } else {
  17. // $data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->join($jointable, 'system_user.root_id', $jointable . '.id')->orderby($sort, $ads)->paginate($page);
  18. // }
  19. // }else{
  20. if (empty($value)) {
  21. $data = $this->orderby($sort, $ads)->paginate($page);
  22. } else if (is_array($value)) {
  23. $data = $this->where($value)->orderby($sort, $ads)->paginate($page);
  24. } else {
  25. $data = $this->where($key, $value)->orderby($sort, $ads)->paginate($page);
  26. }
  27. // }
  28. if (!$data) {
  29. return -7010100102; //没有列表数据
  30. }
  31. return $data->toArray();
  32. }
  33. //获取管理员信息
  34. function getAdminInfo($value, $type = 1, $jointable = '', $columnn = '', $columnw = '') {
  35. $key = $this->getFeild($type);
  36. if (empty($jointable)) {
  37. $data = $this->where($key, $value)->first();
  38. } elseif ($jointable == 'system_root') {
  39. $data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->where('system_user.' . $key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
  40. } else {
  41. $data = $this->where($key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
  42. }
  43. if (!$data) {
  44. return -7010100202; //没有管理员信息
  45. }
  46. return $data->toArray();
  47. }
  48. protected function checkSuperAdmin($admin_id){
  49. }
  50. //字段对应值
  51. private function getFeild($num) {
  52. $data = array(
  53. '1' => 'id',
  54. '2' => 'loginname',
  55. '3' => 'root_id',
  56. '4' => 'status',
  57. '5' => 'add_time',
  58. );
  59. return $data[$num];
  60. }
  61. //更新
  62. function updateInfo($data, $id) {
  63. $res = $this->where('id', $id)->update($data);
  64. if (!$res) {
  65. return -7010101202; //更新失败
  66. }
  67. return 1;
  68. }
  69. /**
  70. *登录验证
  71. * [adminUser description]
  72. * @param [type] $account [description]
  73. * @param [type] $pwd [description]
  74. * @return [type] [description]
  75. */
  76. function adminLogin($account, $password, $checktwo = false) {
  77. $account = strtolower($account);
  78. if (empty($account) || empty($password)) {
  79. return -400844; //密码或用户名不能为空
  80. }
  81. if (!$user = $this->where(['loginname' => $account, 'status' => 1])->first()) {
  82. return -400845; //用户不存在
  83. }
  84. $yecp = ($checktwo == true) ? $user->encryption_2 : $user->encryption;
  85. $ypwd = ($checktwo == true) ? $user->password_2 : $user->password;
  86. $newpasswd = md5(md5($yecp . $password));
  87. if ($newpasswd == $ypwd) {
  88. return array('admin_name' => $user->loginname, 'admin_id' => $user->id,'passwd'=>$newpasswd);
  89. }
  90. return -400846; //登录成功
  91. }
  92. /**
  93. * 检查admin信息是否存在
  94. */
  95. protected function checkAdmin($admin){
  96. if(!is_array($admin)){
  97. return 1;
  98. }
  99. $re=$this->where('loginname',$admin['admin_name'])->where('password',$admin['passwd'])->first();
  100. if(!$re){
  101. return -400878;
  102. }
  103. return 1;
  104. }
  105. /**
  106. * 检查同一管理员信息是否存在
  107. */
  108. protected function checkAdminname($name){
  109. $name = trim($name);
  110. $re=$this->where('loginname',$name)->first();
  111. if(!$re){
  112. return 1;
  113. }
  114. return -7090100102;
  115. }
  116. function addAdmin($data) {
  117. $res = $this->insert($data);
  118. if (!$res) {
  119. return -7050001022; //添加失败
  120. }
  121. return 1;
  122. }
  123. //开关
  124. function closeGame($data, $loginname) {
  125. $res = $this->where('loginname', $loginname)->update($data);
  126. if (!$res) {
  127. return -5040000122;
  128. }
  129. return $res;
  130. }
  131. // /**
  132. // * 检查登录密码
  133. // *
  134. // * @param $user
  135. // * @param $password
  136. // * @return bool
  137. // */
  138. // public function checkPassword($user, $password) {
  139. // $accountPassword = $this->where(['id' => $user->id, 'status' => 1])->first();
  140. // $dataPassword = md5(md5($accountPassword->encryption . $password));
  141. // return $dataPassword == $accountPassword->account_password ? true : false;
  142. // }
  143. //权限检测
  144. protected function hasRoot($code){
  145. $admin_id=session('adminInfo.admin_id');
  146. $check=$this->where('id',$admin_id)->where('root_id',0)->first();
  147. if($check){
  148. return 1;
  149. }
  150. $data=$this->join('dc_priv_role','dc_priv_role.role_id',$this->table.'.root_id')
  151. ->join('dc_priv_code','dc_priv_role.priv_id','dc_priv_code.id')
  152. ->where('dc_priv_code.priv_code',$code)
  153. ->where('system_user.id',$admin_id)
  154. ->get();
  155. $data=$data->toArray();
  156. if(count($data)>0){
  157. return 1;
  158. }
  159. return -7030050022;//没有权限
  160. }
  161. function checkActMoney($money){
  162. $admin_id=session('adminInfo.admin_id');
  163. $sql = "SELECT max(settingmoney) as maxmoney FROM system_root WHERE system_root.id in (SELECT role_id FROM dc_role WHERE admin_id={$admin_id})";
  164. $moneydata = DB::select($sql);
  165. if(empty($moneydata)){
  166. return -7030060102; //未获取相应权限,权限错误
  167. }
  168. $limitmoney = current($moneydata)->maxmoney;
  169. if($money>$limitmoney){
  170. return -7030060002; //可操作金额超出限额
  171. }
  172. return 1;
  173. }
  174. //获取权限名称
  175. function getAdminInfoByName($admin_user){
  176. $data=$this->join('system_root',$this->table.'.root_id','system_root.id')
  177. ->where('loginname',$admin_user)
  178. ->first();
  179. if(!$data){
  180. return -3020034722;
  181. }
  182. return $data->toArray();
  183. }
  184. //更新token
  185. function refreshToken($admin_id,$token)
  186. {
  187. $res=$this->where('id',$admin_id)->update(['token'=>$token]);
  188. if(!$res){
  189. return -2050050022;//更新token失败
  190. }
  191. return 1;
  192. }
  193. //检测token
  194. function checkToken($admin_id,$token){
  195. // if(\App\Model\Role::hasRoot('passToken')){
  196. // return 1;
  197. // }
  198. $res=$this->where('id',$admin_id)->where('token',$token)->first();
  199. if(!$res){
  200. return -2050050422;//token
  201. }
  202. return 1;
  203. }
  204. protected function checkOpen($id){
  205. $res=$this->where('id',$id)->where('root_id',1)->first();
  206. if(!$res){
  207. return -20001;
  208. }
  209. return 1;
  210. }
  211. }