Flow.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace app\admin\controller\qingdong\work;
  3. use addons\qingdong\model\Customer;
  4. use addons\qingdong\model\Staff;
  5. use app\admin\model\AuthGroup;
  6. use app\common\controller\Backend;
  7. use addons\qingdong\model\Form;
  8. use addons\qingdong\model\Flow as FlowModel;
  9. use fast\Tree;
  10. /**
  11. * 审批流程
  12. */
  13. class Flow extends Backend {
  14. protected $relationSearch = true;
  15. protected $searchFields = 'id,name';
  16. /**
  17. * @var \addons\qingdong\model\Flow
  18. */
  19. protected $model = null;
  20. public function _initialize() {
  21. parent::_initialize();
  22. $this->model = new FlowModel();
  23. $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
  24. //角色组
  25. $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
  26. Tree::instance()->init($groupList);
  27. $groupdata = [];
  28. if ($this->auth->isSuperAdmin()) {
  29. $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
  30. foreach ($result as $k => $v) {
  31. $groupdata[$v['id']] = $v['name'];
  32. }
  33. } else {
  34. $result = [];
  35. $groups = $this->auth->getGroups();
  36. foreach ($groups as $m => $n) {
  37. $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
  38. $temp = [];
  39. foreach ($childlist as $k => $v) {
  40. $temp[$v['id']] = $v['name'];
  41. }
  42. $result[__($n['name'])] = $temp;
  43. }
  44. $groupdata = $result;
  45. }
  46. $this->view->assign('groupdata', $groupdata);
  47. }
  48. /**
  49. * 查看
  50. */
  51. public function index()
  52. {
  53. //设置过滤方法
  54. $this->request->filter(['strip_tags', 'trim']);
  55. if ($this->request->isAjax()) {
  56. $forms = $this->model->where([])->select();
  57. $forms = collection($forms)->toArray();
  58. $result = array("total" => count($forms), "rows" => $forms);
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 新增
  65. * @return string
  66. */
  67. public function add()
  68. {
  69. if ($this->request->isAjax()) {
  70. $row = $this->request->post('row/a');
  71. $findType = $this->model->where(array('relation_type'=>$row['relation_type']))->find();
  72. if($findType){
  73. $this->error('关联对象已存在,请在列表中进行修改');
  74. }
  75. if($row['status'] == 1){
  76. $examine_ids = json_decode($row['examine_ids'],true);
  77. if(!$examine_ids){
  78. $this->error('请选择审批人');
  79. }
  80. foreach($examine_ids as $k=>$v){
  81. if(!$v['staff_id'] && $v['stafftype'] !=3){
  82. $this->error('请选择审批人');
  83. }
  84. }
  85. }
  86. $data = [
  87. 'name' => $row['name'],
  88. 'relation_type' => $row['relation_type'],
  89. 'status' => $row['status'],
  90. 'examine_ids' => $row['examine_ids'],
  91. 'remark' => $row['remark'],
  92. 'group_ids' => implode(',',$row['group_ids']??[]),
  93. 'last_modified'=>time(),
  94. 'last_admin_id'=>$this->auth->id
  95. ];
  96. $result = $this->model->allowField(true)->save($data);
  97. if (!$result) {
  98. $this->error('提交失败');
  99. }
  100. $this->success('提交成功');
  101. }
  102. return $this->view->fetch();
  103. }
  104. /**
  105. * 修改
  106. * @return string
  107. */
  108. public function edit($ids = null) {
  109. $row = $this->model->get($ids);
  110. if (!$row) {
  111. $this->error(__('No Results were found'));
  112. }
  113. $adminIds = $this->getDataLimitAdminIds();
  114. if (is_array($adminIds)) {
  115. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  116. $this->error(__('You have no permission'));
  117. }
  118. }
  119. if ($this->request->isAjax()) {
  120. $row = $this->request->post('row/a');
  121. if($row['status'] == 1){
  122. $examine_ids = json_decode($row['examine_ids'],true);
  123. if(!$examine_ids){
  124. $this->error('请选择审批人');
  125. }
  126. foreach($examine_ids as $k=>$v){
  127. if(!$v['staff_id'] && $v['stafftype'] !=3){
  128. $this->error('请选择审批人');
  129. }
  130. }
  131. }
  132. $result = $this->model::destroy(['id'=>$ids]);
  133. if (!$result) {
  134. $this->error('删除失败');
  135. }
  136. $data = [
  137. 'name' => $row['name'],
  138. 'relation_type' => $row['relation_type'],
  139. 'status' => $row['status'],
  140. 'examine_ids' => $row['examine_ids'],
  141. 'remark' => $row['remark'],
  142. 'group_ids' => implode(',',$row['group_ids']),
  143. 'last_modified'=>time(),
  144. 'last_admin_id'=>$this->auth->id
  145. ];
  146. $result = $this->model->allowField(true)->save($data);
  147. if (!$result) {
  148. $this->error(__('No rows were updated'));
  149. }
  150. $this->success();
  151. }
  152. $this->view->assign("row", $row);
  153. return $this->view->fetch();
  154. }
  155. /**
  156. * 删除
  157. * @param null $ids
  158. * @return string|void
  159. */
  160. public function del($ids = null) {
  161. if ($this->request->isAjax()) {
  162. $map['id'] = $ids;
  163. $row=$this->model->get($ids);
  164. if(!$row){
  165. $this->error('数据不存在');
  166. }
  167. $result = $this->model->destroy($map);
  168. if (!$result) {
  169. $this->error('删除失败');
  170. }
  171. $this->success('删除成功');
  172. }
  173. return $this->view->fetch();
  174. }
  175. /**
  176. * 员工列表
  177. */
  178. public function getstaff()
  179. {
  180. $pageSize = input('pageSize');
  181. $pageNumber = input('pageNumber');
  182. $where = [];
  183. if ($keyValue = $this->request->request("keyValue")) {
  184. $where['id'] = ['in',explode(',',$keyValue)];
  185. }
  186. $name = input('name');
  187. if (!empty($name)) {
  188. $where['name'] = ['like', '%' . $name . '%'];
  189. }
  190. $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  191. return json(['list' => $customer->items(), 'total' => $customer->total()]);
  192. }
  193. }