ApproveFlow.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\approve\controller;
  15. use app\common\constant\CommonConstant;
  16. use app\common\constant\EvectionConstant;
  17. use app\common\constant\LeaveConstant;
  18. use app\common\constant\MaintainConstant;
  19. use app\common\service\UserService;
  20. use library\Controller;
  21. /**
  22. * 审批流程设置
  23. */
  24. class ApproveFlow extends Controller
  25. {
  26. /**
  27. * 绑定数据表
  28. * @var string
  29. */
  30. protected $table = 'ApproveFlow';
  31. /**
  32. * 控制器初始化
  33. */
  34. protected function initialize()
  35. {
  36. $this->get_module_list = CommonConstant::get_module_list();
  37. $this->get_type_list = CommonConstant::get_type_list();
  38. $this->get_user_type_list = CommonConstant::get_user_type_list();
  39. $this->get_user_type_list_json = json_encode($this->get_user_type_list,JSON_UNESCAPED_UNICODE);
  40. }
  41. /**
  42. * 列表
  43. * @auth true
  44. * @menu true
  45. * @throws \think\Exception
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @throws \think\exception\DbException
  49. */
  50. public function index()
  51. {
  52. $module = input('module');
  53. $this->get_item_list = self::get_item_list($module);
  54. $this->title = $this->get_module_list[$module].'审批流程';
  55. $query = $this->_query($this->table)
  56. ->where('module',$module);
  57. $query->page(false);
  58. }
  59. /**
  60. * 列表数据处理
  61. * @param array $data
  62. * @throws \Exception
  63. */
  64. protected function _index_page_filter(&$data)
  65. {
  66. foreach ($data as &$value) {
  67. }
  68. }
  69. /**
  70. * 编辑
  71. * @auth true
  72. */
  73. public function edit()
  74. {
  75. $this->title = '编辑';
  76. $this->_form($this->table, 'form');
  77. }
  78. /**
  79. * 表单处理
  80. * @param array $data
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. */
  85. protected function _form_filter(&$data)
  86. {
  87. if($this->request->isGet()) {
  88. if($data){
  89. $data['user_data_text'] = json_decode($data['user_data'],true);
  90. $this->get_item_list = self::get_item_list($data['module']);
  91. $this->user_list = UserService::get_list(1);
  92. $this->user_list_json = json_encode($this->user_list,JSON_UNESCAPED_UNICODE);
  93. }
  94. }
  95. if($this->request->isPost()) {
  96. if(!isset_full($data,'user_data')){
  97. $this->error('请添加审批层级');
  98. }
  99. $user_data = array_filter($data['user_data']);
  100. if(!$user_data){
  101. $this->error('请添加审批层级!');
  102. }
  103. $save_data = [];
  104. foreach ($user_data as $key=>$val){
  105. $save_data[] = [
  106. 'user_type'=>$val['user_type'],
  107. 'userid'=>$val['user_type'] == CommonConstant::USER_TYPE_1 ? '' : $val['userid'],
  108. ];
  109. }
  110. $data['user_data'] = json_encode($save_data,JSON_UNESCAPED_UNICODE);
  111. }
  112. }
  113. /**
  114. * 列表
  115. */
  116. public function flow()
  117. {
  118. $this->title = '审批流';
  119. $list = $this->get_module_list;
  120. return $this->fetch('', compact("list"));
  121. }
  122. /**
  123. * 根据模块获取审批流项
  124. **/
  125. public function get_item_list($module){
  126. $get_item_list = [];
  127. switch ($module){
  128. case CommonConstant::MODULE_5:
  129. $get_item_list = EvectionConstant::get_type_list();
  130. break;
  131. case CommonConstant::MODULE_6:
  132. $get_item_list = LeaveConstant::get_time_list();
  133. break;
  134. case CommonConstant::MODULE_8:
  135. $get_item_list = MaintainConstant::get_type_list();
  136. break;
  137. }
  138. return $get_item_list;
  139. }
  140. }