System_user.php 6.7 KB

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