User.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Factory\Admin;
  3. use Dever;
  4. class User extends Core
  5. {
  6. # 获取基本信息
  7. public function getData()
  8. {
  9. $id = Dever::input('id');
  10. if ($id) {
  11. $data = Dever::db('factory/member')->find($id);
  12. } else {
  13. $data = false;
  14. }
  15. return $data;
  16. }
  17. # 获取角色
  18. public function getRole()
  19. {
  20. $role = Dever::db('factory/member')->config['role'];
  21. $html = '<input update_type="checked" class="checkbox-checkall update_role_id update_value" type="checkbox" name="temp_update_role_id[]" value="0_update_role_id"/> 全选';
  22. $info = $this->getData();
  23. foreach ($role as $k => $v) {
  24. $checked = '';
  25. if ($info && $info['role_id']) {
  26. $temp = explode(',', $info['role_id']);
  27. if (in_array($k, $temp)) {
  28. $checked = 'checked';
  29. }
  30. }
  31. $html .= '&nbsp;&nbsp;<input update_type="checked" class="autoload checkbox-checkall-0_update_role_id update_role_id update_value validate[required]" type="checkbox" name="update_role_id[]" value="'.$k.'" '.$checked.' /> '.$v.' ';
  32. }
  33. return $html;
  34. }
  35. # 订单列表
  36. public function getList()
  37. {
  38. $data = Dever::db('factory/member')->list(array('factory_id' => $this->id));
  39. $html = '';
  40. if ($data) {
  41. $role = Dever::db('factory/member')->config['role'];
  42. foreach ($data as $k => $v) {
  43. $edit = Dever::url('user_edit?id=' . $v['id'], 'factory');
  44. $temp = explode(',', $v['role_id']);
  45. $v['role_name'] = array();
  46. foreach ($temp as $k1 => $v1) {
  47. if (isset($role[$v1])) {
  48. $v['role_name'][] = $role[$v1];
  49. }
  50. }
  51. $v['role_name'] = implode(',', $v['role_name']);
  52. $cdate = date('Y-m-d H:i', $v['cdate']);
  53. $button = '<a href="javascript:;" onclick="fastEdit($(this), \''.$edit.'\', \'编辑\', \'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">编辑</button></a>';
  54. if ($v['state'] == 1) {
  55. $state = 2;
  56. } else {
  57. $state = 1;
  58. }
  59. $del = Dever::url('admin/user.del?id=' . $v['id'] . '&state=' . $state, 'factory');
  60. if ($state == 2) {
  61. $button .= '&nbsp;&nbsp;<a href="'.$del.'" class="oper_delete"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-danger layui-btn-xs"><span class="am-icon-trash-o"></span>封禁</button></a>';
  62. } else {
  63. $button .= '&nbsp;&nbsp;<a href="'.$del.'" class="oper_delete"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-danger layui-btn-xs"><span class="am-icon-trash-o"></span>恢复</button></a>';
  64. }
  65. $html .= '<tr><td>'.$v['name'].'</td><td>'.$v['mobile'].'</td><td>'.$v['role_name'].'</td><td>'.$cdate.'</td><td>'.$button.'</td></tr>';
  66. }
  67. }
  68. return $html;
  69. }
  70. # 获取基本信息
  71. public function getConfig()
  72. {
  73. $data['update'] = Dever::url('admin/user.update', 'factory');
  74. $data['add'] = Dever::url('user_edit', 'factory');
  75. $data['add'] = 'fastEdit($(this), \''.$data['add'].'\', \'添加新员工\', \'\', 1)';
  76. $data['search'] = Dever::url('user', 'factory');
  77. $data['delete'] = Dever::url('admin/del', 'factory');
  78. return $data;
  79. }
  80. # 认证
  81. public function update_api()
  82. {
  83. $input = Dever::input();
  84. $update['name'] = $input['update_name'];
  85. $update['avatar'] = $input['update_avatar'];
  86. $update['mobile'] = $input['update_mobile'];
  87. $update['role_id'] = $input['update_role_id'];
  88. $update['factory_id'] = $this->id;
  89. $update['where_id'] = Dever::input('update_where_id');
  90. if ($update['where_id']) {
  91. Dever::db('factory/member')->update($update);
  92. } else {
  93. Dever::db('factory/member')->insert($update);
  94. }
  95. return 'reload';
  96. }
  97. # 删除
  98. public function del_api()
  99. {
  100. $update['where_id'] = Dever::input('id');
  101. if ($update['where_id']) {
  102. $update['state'] = Dever::input('state');
  103. Dever::db('factory/member')->update($update);
  104. }
  105. return 'reload';
  106. }
  107. }