Member.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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\service\UserService;
  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',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. if($data){
  70. $department_list = UserService::get_department_column();
  71. $this->user_list = UserService::get_list(1);
  72. $user_object = array_column($this->user_list->toArray(),null,'userid');
  73. foreach ($data as &$value) {
  74. // 所属部门
  75. $department_ids = explode(',',$value['department']);
  76. $department_text = '';
  77. foreach ($department_ids as $val){
  78. if(array_key_exists($val,$department_list)){
  79. $department_text .= $department_list[$val].',';
  80. }
  81. }
  82. $value['department_text'] = $department_text;
  83. // 员工的直属主管
  84. $manager_text = !empty($value['manager_userid']) && array_key_exists($value['manager_userid'],$user_object) ? $user_object[$value['manager_userid']]['name'] : '';
  85. $value['manager_text'] = $manager_text;
  86. }
  87. }
  88. }
  89. /**
  90. * 编辑
  91. * @auth true
  92. * @throws \think\Exception
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @throws \think\exception\DbException
  96. * @throws \think\exception\PDOException
  97. */
  98. public function edit()
  99. {
  100. $this->title = '编辑';
  101. $this->_form($this->table, 'form');
  102. }
  103. /**
  104. * 表单处理
  105. * @param array $data
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. */
  110. protected function _form_filter(&$data)
  111. {
  112. // 编辑
  113. if($data['id'] > 0){
  114. if($this->request->isGet()) {
  115. $department_list = UserService::get_department_column();
  116. $this->user_list = UserService::get_list(1);
  117. // 所属部门
  118. $department_ids = explode(',',$data['department']);
  119. $department_text = '';
  120. foreach ($department_ids as $val){
  121. if(array_key_exists($val,$department_list)){
  122. $department_text .= $department_list[$val].',';
  123. }
  124. }
  125. $data['department_text'] = $department_text;
  126. }
  127. if($this->request->isPost()){
  128. if (isset_full($data, 'signature_status')) {
  129. if(!in_array($data['signature_status'],[CommonConstant::SIGNATURE_STATUS_3,CommonConstant::SIGNATURE_STATUS_4])){
  130. unset($data['signature_status']);
  131. }
  132. }
  133. }
  134. }
  135. }
  136. /**
  137. * 启用
  138. * @auth true
  139. * @throws \think\Exception
  140. * @throws \think\exception\PDOException
  141. */
  142. public function resume()
  143. {
  144. $this->applyCsrfToken();
  145. $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
  146. }
  147. /**
  148. * 禁用
  149. * @auth true
  150. * @throws \think\Exception
  151. * @throws \think\exception\PDOException
  152. */
  153. public function forbid()
  154. {
  155. $this->applyCsrfToken();
  156. $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
  157. }
  158. /**
  159. * 审核签名
  160. * @auth true
  161. * @throws \think\Exception
  162. * @throws \think\exception\PDOException
  163. */
  164. public function signature_status()
  165. {
  166. $signature_status = input('signature_status');
  167. if(!array_key_exists($signature_status,CommonConstant::get_signature_status_list())){
  168. $this->controller->error('审核状态参数错误');
  169. }
  170. $this->applyCsrfToken();
  171. $this->_save($this->table, ['signature_status' => $signature_status]);
  172. }
  173. }