Flow.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace app\admin\controller\qingdongams\work;
  3. use addons\qingdongams\model\Customer;
  4. use addons\qingdongams\model\Staff;
  5. use app\admin\model\AuthGroup;
  6. use app\common\controller\Backend;
  7. use addons\qingdongams\model\Form;
  8. use addons\qingdongams\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\qingdongams\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. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  57. $list = $this->model->where($where)->order($sort, $order)->paginate($limit);
  58. $row = $list->items();
  59. $result = array("total" => $list->total(), "rows" => $row);
  60. return json($result);
  61. }
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 新增
  66. * @return string
  67. */
  68. public function add()
  69. {
  70. if ($this->request->isAjax()) {
  71. $row = $this->request->post('row/a');
  72. $findType = $this->model->where(array('relation_type'=>$row['relation_type']))->find();
  73. if($findType){
  74. $this->error('关联对象已存在,请在列表中进行修改');
  75. }
  76. if($row['status'] == 1){
  77. $examine_ids = json_decode($row['examine_ids'],true);
  78. if(!$examine_ids){
  79. $this->error('请选择审批人');
  80. }
  81. foreach($examine_ids as $k=>$v){
  82. if(!$v['staff_id'] && $v['stafftype'] !=3){
  83. $this->error('请选择审批人');
  84. }
  85. }
  86. }
  87. $data = [
  88. 'name' => $row['name'],
  89. 'relation_type' => $row['relation_type'],
  90. 'status' => $row['status'],
  91. 'examine_ids' => $row['examine_ids'],
  92. 'remark' => $row['remark'],
  93. 'group_ids' => implode(',',$row['group_ids']??[]),
  94. 'last_modified'=>time(),
  95. 'last_admin_id'=>$this->auth->id
  96. ];
  97. $result = $this->model->allowField(true)->save($data);
  98. if (!$result) {
  99. $this->error('提交失败');
  100. }
  101. $this->success('提交成功');
  102. }
  103. return $this->view->fetch();
  104. }
  105. /**
  106. * 修改
  107. * @return string
  108. */
  109. public function edit($ids = null) {
  110. $row = $this->model->get($ids);
  111. if (!$row) {
  112. $this->error(__('No Results were found'));
  113. }
  114. $adminIds = $this->getDataLimitAdminIds();
  115. if (is_array($adminIds)) {
  116. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  117. $this->error(__('You have no permission'));
  118. }
  119. }
  120. if ($this->request->isAjax()) {
  121. $row = $this->request->post('row/a');
  122. if($row['status'] == 1){
  123. $examine_ids = json_decode($row['examine_ids'],true);
  124. if(!$examine_ids){
  125. $this->error('请选择审批人');
  126. }
  127. foreach($examine_ids as $k=>$v){
  128. if(!$v['staff_id']){
  129. $this->error('请选择审批人');
  130. }
  131. }
  132. }
  133. $findType = $this->model->where(array('relation_type'=>$row['relation_type']))->find();
  134. if(!$findType){
  135. $this->error('审批类型不存在');
  136. }
  137. $data = [
  138. 'name' => $row['name'],
  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->where(array('id'=>$findType['id']))->update($data);
  147. if (!$result) {
  148. $this->error('修改失败');
  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. }