Formapproval.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\admin\controller\qingdong\work;
  3. use app\common\controller\Backend;
  4. use addons\qingdong\model\Form;
  5. use addons\qingdong\model\Staff;
  6. use addons\qingdong\model\FormApproval as FormApprovalModel;
  7. use think\Db;
  8. use think\Exception;
  9. use addons\qingdong\library\Pingyin;
  10. /**
  11. * 审批字段管理
  12. */
  13. class Formapproval extends Backend {
  14. protected $relationSearch = true;
  15. /**
  16. * @var \addons\qingdong\model\FormApproval
  17. */
  18. protected $model = null;
  19. public function _initialize() {
  20. parent::_initialize();
  21. $this->model = new FormApprovalModel();
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index() {
  27. //设置过滤方法
  28. $this->request->filter(['strip_tags', 'trim']);
  29. if ($this->request->isAjax()) {
  30. $forms = $this->model->where([])->select();
  31. $forms = collection($forms)->toArray();
  32. $result = array("total" => count($forms), "rows" => $forms);
  33. return json($result);
  34. }
  35. return $this->view->fetch();
  36. }
  37. /**
  38. * 添加审批流程
  39. */
  40. public function add() {
  41. if ($this->request->isAjax()) {
  42. $data = $this->request->post('row/a');
  43. if(!$data['name']){
  44. $this->error('审批流程标题不能为空');
  45. }
  46. $pingyin = new Pingyin();
  47. $english = $pingyin->get_all_py($data['name']);
  48. $formFind = Form::where(array('type'=>$english))->find();
  49. if($formFind){
  50. $english = $english.genRandomString(5);
  51. }
  52. //表单
  53. $formRes = array(
  54. 'name'=>$data['name'],
  55. 'type'=>$english,
  56. );
  57. $resForm = Form::create($formRes);
  58. $insetId = Form::getLastInsID();
  59. $data['form_id'] = $insetId;
  60. $result = $this->model->allowField(true)->save($data);
  61. if (!$result || !$resForm) {
  62. $this->error('提交失败');
  63. }
  64. $this->success('提交成功');
  65. }
  66. $staffname = Staff::where(['status' => 1])->column('id,name');
  67. $staffs = ['' => '无'];
  68. foreach ($staffname as $id => $name) {
  69. $staffs[$id] = $name;
  70. }
  71. $this->view->assign('staffs', $staffs);
  72. return $this->view->fetch();
  73. }
  74. /**
  75. * 修改审批流程
  76. */
  77. public function edit($ids = null) {
  78. $row=$this->model->get($ids);
  79. if ($this->request->isAjax()) {
  80. $data = $this->request->post('row/a');
  81. $result = $this->model->allowField(true)->save($data,['id'=>$ids]);
  82. if($row['form_id']){
  83. Form::where(array('id'=>$row['form_id']))->update(array('name'=>$data['name']));
  84. }
  85. if (!$result) {
  86. $this->error('提交失败');
  87. }
  88. $this->success('提交成功');
  89. }
  90. $staffname = Staff::where(['status' => 1])->column('id,name');
  91. $staffs = ['' => '无'];
  92. foreach ($staffname as $id => $name) {
  93. $staffs[$id] = $name;
  94. }
  95. $this->view->assign('staffs', $staffs);
  96. $this->view->assign('row', $row);
  97. return $this->view->fetch();
  98. }
  99. /**
  100. * 删除审批流程
  101. */
  102. public function del($ids = null) {
  103. if ($this->request->isAjax()) {
  104. $map['id'] = $ids;
  105. $row=$this->model->get($ids);
  106. if(!$row){
  107. $this->error('数据不存在');
  108. }
  109. Form::destroy(array('id'=>$row['form_id']));
  110. $result = $this->model->destroy($map);
  111. if (!$result) {
  112. $this->error('删除失败');
  113. }
  114. $this->success('删除成功');
  115. }
  116. return $this->view->fetch();
  117. }
  118. /**
  119. * 获取员工列表
  120. */
  121. public function get_staff()
  122. {
  123. $pageSize = input('pageSize');
  124. $pageNumber = input('pageNumber');
  125. $where = [];
  126. if ($keyValue = $this->request->request("keyValue")) {
  127. $where['id'] = ['in',explode(',',$keyValue)];
  128. }
  129. $name = input('name');
  130. if (!empty($name)) {
  131. $where['name'] = ['like', '%' . $name . '%'];
  132. }
  133. $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  134. return json(['list' => $customer->items(), 'total' => $customer->total()]);
  135. }
  136. }