Member.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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\DingtalkService;
  17. use app\common\service\UserService;
  18. use library\Controller;
  19. /**
  20. * 员工
  21. */
  22. class Member extends Controller
  23. {
  24. /**
  25. * 绑定数据表
  26. * @var string
  27. */
  28. protected $table = 'StoreMember';
  29. /**
  30. * 控制器初始化
  31. */
  32. protected function initialize()
  33. {
  34. $this->get_status_list = CommonConstant::get_status_list();
  35. $this->get_signature_status_list = CommonConstant::get_signature_status_list();
  36. }
  37. /**
  38. * 列表
  39. * @auth true
  40. * @menu true
  41. * @throws \think\Exception
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. */
  46. public function index()
  47. {
  48. $status = input('status');
  49. $signature_status = input('signature_status');
  50. $this->title = '员工列表';
  51. $query = $this->_query($this->table)
  52. ->field('is_deleted',true)
  53. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  54. ->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
  55. $query->where('status', $status);
  56. })
  57. ->when(array_key_exists($signature_status, $this->get_signature_status_list), function ($query) use ($signature_status) {
  58. $query->where('signature_status', $signature_status);
  59. })
  60. ->like('name,mobile,title');
  61. $query->page();
  62. }
  63. /**
  64. * 列表数据处理
  65. * @param array $data
  66. * @throws \Exception
  67. */
  68. protected function _index_page_filter(&$data)
  69. {
  70. if($data){
  71. $department_list = UserService::get_department_column();
  72. $this->user_list = UserService::get_list(1);
  73. $user_object = array_column($this->user_list->toArray(),null,'userid');
  74. foreach ($data as &$value) {
  75. // 所属部门
  76. $department_ids = explode(',',$value['department']);
  77. $department_text = '';
  78. foreach ($department_ids as $val){
  79. if(array_key_exists($val,$department_list)){
  80. $department_text .= $department_list[$val].',';
  81. }
  82. }
  83. $value['department_text'] = $department_text;
  84. // 员工的直属主管
  85. $manager_text = !empty($value['manager_userid']) && array_key_exists($value['manager_userid'],$user_object) ? $user_object[$value['manager_userid']]['name'] : '';
  86. $value['manager_text'] = $manager_text;
  87. }
  88. }
  89. }
  90. /**
  91. * 编辑
  92. * @auth true
  93. * @throws \think\Exception
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. * @throws \think\exception\PDOException
  98. */
  99. public function edit()
  100. {
  101. $this->title = '编辑';
  102. $this->_form($this->table, 'form');
  103. }
  104. /**
  105. * 表单处理
  106. * @param array $data
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. protected function _form_filter(&$data)
  112. {
  113. // 编辑
  114. if($data['id'] > 0){
  115. if($this->request->isGet()) {
  116. $department_list = UserService::get_department_column();
  117. $this->user_list = UserService::get_list(1);
  118. // 所属部门
  119. $department_ids = explode(',',$data['department']);
  120. $department_text = '';
  121. foreach ($department_ids as $val){
  122. if(array_key_exists($val,$department_list)){
  123. $department_text .= $department_list[$val].',';
  124. }
  125. }
  126. $data['department_text'] = $department_text;
  127. }
  128. if($this->request->isPost()){
  129. if (isset_full($data, 'signature_status')) {
  130. if(!in_array($data['signature_status'],[CommonConstant::SIGNATURE_STATUS_3,CommonConstant::SIGNATURE_STATUS_4])){
  131. unset($data['signature_status']);
  132. }
  133. }
  134. }
  135. }
  136. }
  137. /**
  138. * 启用
  139. * @auth true
  140. * @throws \think\Exception
  141. * @throws \think\exception\PDOException
  142. */
  143. public function resume()
  144. {
  145. $this->applyCsrfToken();
  146. $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
  147. }
  148. /**
  149. * 禁用
  150. * @auth true
  151. * @throws \think\Exception
  152. * @throws \think\exception\PDOException
  153. */
  154. public function forbid()
  155. {
  156. $this->applyCsrfToken();
  157. $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
  158. }
  159. /**
  160. * 审核签名
  161. * @auth true
  162. * @throws \think\Exception
  163. * @throws \think\exception\PDOException
  164. */
  165. public function signature_status()
  166. {
  167. $signature_status = input('signature_status');
  168. if(!array_key_exists($signature_status,CommonConstant::get_signature_status_list())){
  169. $this->controller->error('审核状态参数错误');
  170. }
  171. $this->applyCsrfToken();
  172. $this->_save($this->table, ['signature_status' => $signature_status]);
  173. }
  174. /**
  175. * 更新员工和部门
  176. **/
  177. public function renew(){
  178. DingtalkService::renew();
  179. $this->success('更新员工和部门成功');
  180. }
  181. }