Member.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\user\controller;
  15. use app\common\constant\CommonConstant;
  16. use app\common\model\Department;
  17. use library\Controller;
  18. /**
  19. * 员工
  20. */
  21. class Member extends Controller
  22. {
  23. /**
  24. * 绑定数据表
  25. * @var string
  26. */
  27. protected $table = 'StoreMember';
  28. /**
  29. * 控制器初始化
  30. */
  31. protected function initialize()
  32. {
  33. $this->get_status_list = CommonConstant::get_status_list();
  34. $this->get_signature_status_list = CommonConstant::get_signature_status_list();
  35. }
  36. /**
  37. * 列表
  38. * @auth true
  39. * @menu true
  40. * @throws \think\Exception
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function index()
  46. {
  47. $status = input('status');
  48. $signature_status = input('signature_status');
  49. $this->title = '员工列表';
  50. $query = $this->_query($this->table)
  51. ->field('is_deleted,create_at',true)
  52. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  53. ->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
  54. $query->where('status', $status);
  55. })
  56. ->when(array_key_exists($signature_status, $this->get_signature_status_list), function ($query) use ($signature_status) {
  57. $query->where('signature_status', $signature_status);
  58. })
  59. ->like('name,mobile,title');
  60. $query->page();
  61. }
  62. /**
  63. * 列表数据处理
  64. * @param array $data
  65. * @throws \Exception
  66. */
  67. protected function _index_page_filter(&$data)
  68. {
  69. $user_object = array_column($data,null,'userid');
  70. $department_list = Department::column('dept_id,name');
  71. foreach ($data as &$value) {
  72. // 所属部门
  73. $department_ids = explode(',',$value['department']);
  74. $department_text = '';
  75. foreach ($department_ids as $val){
  76. if(array_key_exists($val,$department_list)){
  77. $department_text .= $department_list[$val].',';
  78. }
  79. }
  80. $value['department_text'] = $department_text;
  81. // 员工的直属主管
  82. $manager_text = !empty($value['manager_userid']) && array_key_exists($value['manager_userid'],$user_object) ? $user_object[$value['manager_userid']]['name'] : '';
  83. $value['manager_text'] = $manager_text;
  84. }
  85. }
  86. /**
  87. * 编辑
  88. * @auth true
  89. * @throws \think\Exception
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. * @throws \think\exception\PDOException
  94. */
  95. public function edit()
  96. {
  97. $this->title = '编辑';
  98. $this->_form($this->table, 'form');
  99. }
  100. /**
  101. * 表单处理
  102. * @param array $data
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @throws \think\exception\DbException
  106. */
  107. protected function _form_filter(&$data)
  108. {
  109. // p($data);
  110. }
  111. /**
  112. * 启用
  113. * @auth true
  114. * @throws \think\Exception
  115. * @throws \think\exception\PDOException
  116. */
  117. public function resume()
  118. {
  119. $this->applyCsrfToken();
  120. $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
  121. }
  122. /**
  123. * 禁用
  124. * @auth true
  125. * @throws \think\Exception
  126. * @throws \think\exception\PDOException
  127. */
  128. public function forbid()
  129. {
  130. $this->applyCsrfToken();
  131. $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
  132. }
  133. /**
  134. * 审核签名
  135. * @auth true
  136. * @throws \think\Exception
  137. * @throws \think\exception\PDOException
  138. */
  139. public function signature_status()
  140. {
  141. $signature_status = input('signature_status');
  142. if(!array_key_exists($signature_status,CommonConstant::get_signature_status_list())){
  143. $this->controller->error('审核状态参数错误');
  144. }
  145. $this->applyCsrfToken();
  146. $this->_save($this->table, ['signature_status' => $signature_status]);
  147. }
  148. }