123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace app\admin\controller\qingdongams\work;
- use addons\qingdongams\model\Customer;
- use addons\qingdongams\model\Staff;
- use app\admin\model\AuthGroup;
- use app\common\controller\Backend;
- use addons\qingdongams\model\Form;
- use addons\qingdongams\model\Flow as FlowModel;
- use fast\Tree;
- /**
- * 审批流程
- */
- class Flow extends Backend {
- protected $relationSearch = true;
- protected $searchFields = 'id,name';
- /**
- * @var \addons\qingdongams\model\Flow
- */
- protected $model = null;
- public function _initialize() {
- parent::_initialize();
- $this->model = new FlowModel();
- $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
- //角色组
- $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
- Tree::instance()->init($groupList);
- $groupdata = [];
- if ($this->auth->isSuperAdmin()) {
- $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
- foreach ($result as $k => $v) {
- $groupdata[$v['id']] = $v['name'];
- }
- } else {
- $result = [];
- $groups = $this->auth->getGroups();
- foreach ($groups as $m => $n) {
- $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
- $temp = [];
- foreach ($childlist as $k => $v) {
- $temp[$v['id']] = $v['name'];
- }
- $result[__($n['name'])] = $temp;
- }
- $groupdata = $result;
- }
- $this->view->assign('groupdata', $groupdata);
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model->where($where)->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 新增
- * @return string
- */
- public function add()
- {
- if ($this->request->isAjax()) {
- $row = $this->request->post('row/a');
- $findType = $this->model->where(array('relation_type'=>$row['relation_type']))->find();
- if($findType){
- $this->error('关联对象已存在,请在列表中进行修改');
- }
- if($row['status'] == 1){
- $examine_ids = json_decode($row['examine_ids'],true);
- if(!$examine_ids){
- $this->error('请选择审批人');
- }
- foreach($examine_ids as $k=>$v){
- if(!$v['staff_id'] && $v['stafftype'] !=3){
- $this->error('请选择审批人');
- }
- }
- }
- $data = [
- 'name' => $row['name'],
- 'relation_type' => $row['relation_type'],
- 'status' => $row['status'],
- 'examine_ids' => $row['examine_ids'],
- 'remark' => $row['remark'],
- 'group_ids' => implode(',',$row['group_ids']??[]),
- 'last_modified'=>time(),
- 'last_admin_id'=>$this->auth->id
- ];
- $result = $this->model->allowField(true)->save($data);
- if (!$result) {
- $this->error('提交失败');
- }
- $this->success('提交成功');
- }
- return $this->view->fetch();
- }
- /**
- * 修改
- * @return string
- */
- public function edit($ids = null) {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isAjax()) {
- $row = $this->request->post('row/a');
- if($row['status'] == 1){
- $examine_ids = json_decode($row['examine_ids'],true);
- if(!$examine_ids){
- $this->error('请选择审批人');
- }
- foreach($examine_ids as $k=>$v){
- if(!$v['staff_id']){
- $this->error('请选择审批人');
- }
- }
- }
- $findType = $this->model->where(array('relation_type'=>$row['relation_type']))->find();
- if(!$findType){
- $this->error('审批类型不存在');
- }
- $data = [
- 'name' => $row['name'],
- 'status' => $row['status'],
- 'examine_ids' => $row['examine_ids'],
- 'remark' => $row['remark'],
- 'group_ids' => implode(',',$row['group_ids']),
- 'last_modified'=>time(),
- 'last_admin_id'=>$this->auth->id
- ];
- $result = $this->model->where(array('id'=>$findType['id']))->update($data);
- if (!$result) {
- $this->error('修改失败');
- }
- $this->success();
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * 删除
- * @param null $ids
- * @return string|void
- */
- public function del($ids = null) {
- if ($this->request->isAjax()) {
- $map['id'] = $ids;
- $row=$this->model->get($ids);
- if(!$row){
- $this->error('数据不存在');
- }
- $result = $this->model->destroy($map);
- if (!$result) {
- $this->error('删除失败');
- }
- $this->success('删除成功');
- }
- return $this->view->fetch();
- }
- /**
- * 员工列表
- */
- public function getstaff()
- {
- $pageSize = input('pageSize');
- $pageNumber = input('pageNumber');
- $where = [];
- if ($keyValue = $this->request->request("keyValue")) {
- $where['id'] = ['in',explode(',',$keyValue)];
- }
- $name = input('name');
- if (!empty($name)) {
- $where['name'] = ['like', '%' . $name . '%'];
- }
- $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
- return json(['list' => $customer->items(), 'total' => $customer->total()]);
- }
- }
|