request->only(['page' => 1, 'size' => 10, 'status' => '', 'resign_uid' => '', 'hand_uid' => '', 'start' => '', 'end' => '', 'companyNo' => ''], 'post', 'trim'); $where = [['is_del', "=", 0]]; if ($param['status'] !== '') $where[] = ['status', '=', $param['status']]; if ($param['resign_uid'] !== '') $where[] = ['resign_uid', '=', $param['resign_uid']]; if ($param['hand_uid'] !== '') $where[] = ['hand_uid', '=', $param['hand_uid']]; if ($param['start'] != '') $where[] = ['addtime', '>=', $param['start']]; if ($param['end'] != '') $where[] = ['addtime', '<=', $param['end']]; if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%']; // $role = $this->checkDataShare(); // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["hand_uid", "in", $role[DataGroupModel::$type_全部]]; $role = $this->checkDataShare(); $hand = resign_hand_user($this->uid, 0); if (!empty($role[DataGroupModel::$type_全部])) { $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部])); $where[] = ['hand_uid|resign_uid', 'in', $arr]; } $count = Db::name('resign_info') ->where($where) ->count('id'); $list = Db::name('resign_info') ->where($where) ->order("addtime desc") ->page($param['page'], $param['size']) ->append(['is_allow_update']) ->withAttr('is_allow_update', function ($val, $data) use ($role) { return (in_array($this->roleid, [1, 33]) || in_array($data['hand_uid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限 }) ->select() ->toArray(); return app_show(0, "获取成功", ['list' => $list, 'count' => $count]); } //创建 public function create() { $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $val = Validate::rule([ 'resign_uid|离职人' => 'require|number|gt:0', 'hand_uid|交接人' => 'require|number|gt:0', 'resign_date|离职日期' => 'require|date', 'expire_date|生效时间' => 'require|date', // 'companyNo|所属公司' => 'require|max:255', 'is_hand|是否交接' => 'require|number|in:0,1', 'remark|备注' => 'max:255', ]); if ($val->check($post) == false) return json_show(1004, $val->getError()); $userCommon = new \app\admin\common\User(); $rs = $userCommon->handle('userlist', ['uid' => [$post['resign_uid'], $post['hand_uid']]]); $uid_nickname = array_column($rs['data']['list'], 'nickname', 'id'); if (!isset($uid_nickname[$post['resign_uid']])) return json_show(1004, '离职人不存在或不属于该公司'); if (!isset($uid_nickname[$post['hand_uid']])) return json_show(1004, '交接人不存在或不属于该公司'); Db::startTrans(); try { $status = 0; $data = [ // 'companyNo' => $post['companyNo'], "resign_uid" => $post['resign_uid'], "hand_uid" => $post['hand_uid'], "resign_name" => $uid_nickname[$post['resign_uid']], "hand_name" => $uid_nickname[$post['hand_uid']], "resign_date" => $post['resign_date'], "expire_date" => $post['expire_date'], "is_hand" => $post['is_hand'], "apply_id" => $this->uid, "apply_name" => $this->uname, "status" => $status, "remark" => $post['remark'], "is_del" => 0, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s"), ]; $in = Db::name('resign_info')->insertGetId($data); $stn = ["order_code" => '', "status" => $status, "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $status, $stn); $process = ["order_code" => '', "order_id" => $in, "order_status" => $status, "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process); Db::commit(); return json_show(0, "添加成功"); } catch (Exception $exception) { Db::rollback(); return json_show(1002, '添加失败,' . $exception->getMessage()); } } //详情 public function selec() { $id = $this->request->post('id/d', 0, 'trim'); if ($id == 0) return error_show(1002, "离职人员信息不存在"); $rid = Db::name('resign_info') ->where(['is_del' => 0, 'id' => $id]) ->findOrEmpty(); return app_show(0, "获取成功", $rid); } //编辑 public function edit() { $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', 'resign_uid|离职人' => 'require|number|gt:0', 'hand_uid|交接人' => 'require|number|gt:0', 'resign_date|离职日期' => 'require|date', 'expire_date|生效时间' => 'require|date', // 'companyNo|所属公司' => 'require|max:255', 'is_hand|是否交接' => 'require|number|in:0,1', 'remark|备注' => 'max:255', ]); if ($val->check($post) == false) return json_show(1004, $val->getError()); $userCommon = new \app\admin\common\User(); $rs = $userCommon->handle('userlist', ['uid' => [$post['resign_uid'], $post['hand_uid']]]); $uid_nickname = array_column($rs['data']['list'], 'nickname', 'id'); if (!isset($uid_nickname[$post['resign_uid']])) return json_show(1004, '离职人不存在或不属于该公司'); if (!isset($uid_nickname[$post['hand_uid']])) return json_show(1004, '交接人不存在或不属于该公司'); Db::startTrans(); try { $rs = Db::name('resign_info') ->field('id,status') ->where(['is_del' => 0, 'id' => $post['id']]) ->findOrEmpty(); if (empty($rs)) throw new Exception('离职信息不存在'); $str = [ "hand_name" => $uid_nickname[$post['hand_uid']], "id" => $post['id'], "resign_name" => $uid_nickname[$post['resign_uid']], "resign_uid" => $post['resign_uid'], "hand_uid" => $post['hand_uid'], "is_hand" => $post['is_hand'], "resign_date" => date('Y-m-d H:i:s'), "is_del" => 0, // 'companyNo' => $post['companyNo'], "updatetime" => date('Y-m-d H:i:s'), ]; $it = Db::name('resign_info')->where(['is_del' => 0, 'id' => $post['id']])->save($str); $stn = ["order_code" => $post['id'], "status" => 0, "action_remark" => '', "action_type" => "edit"]; ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn); $process = ["order_code" => '', "order_id" => $post['id'], "order_status" => $rs['status'], "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid]; ProcessOrder::AddProcess(['id' => $post['hand_uid'], 'nickname' => $uid_nickname[$post['hand_uid']]], $process); return error_show(0, "编辑成功"); Db::commit(); return json_show(0, "编辑成功"); } catch (Exception $exception) { Db::rollback(); return json_show(1002, '编辑失败,' . $exception->getMessage()); } } //删除 public function del() { $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : ""; $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->findOrEmpty(); if (empty($fid)) return error_show(1002, "离职人员不存在"); Db::startTrans(); try { $num = Db::name('resign_info') ->where(['is_del' => 0, 'id' => $id]) ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]); if ($num) { $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"]; ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn); //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表) Db::name('process_wait') ->where([ 'order_type' => 'LZJJ', 'order_id' => $id, 'status' => ProcessWait::$status_wait, ])->update(['status' => ProcessWait::$status_interrupt]); Db::commit(); return app_show(0, "删除成功"); } else throw new Exception(); } catch (Exception $exception) { Db::rollback(); return error_show(1004, '删除失败,', $exception->getMessage()); } } //启禁用 public function statu() { $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : ""; if ($id == "") { return error_show(1002, "离职人id不能为空"); } $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : ""; $stauts = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; if ($stauts === "") { return error_show(1002, "状态不能为空"); } $st = Db::name('resign_info')->where(['id' => $id, "is_del" => 0])->find(); if (empty($st)) { return error_show(1002, "离职人员信息未找到"); } $tn = $st['status']; $st['remark'] = $remark; $st['status'] = $stauts == 3 && strtotime($st['expire_date']) <= time() ? 4 : $stauts; $st['updatetime'] = date('Y-m-d H:i:s'); $sv = Db::name('resign_info')->save($st); if ($sv) { $stn = ["order_code" => $id, "status" => $tn, "action_remark" => '', "action_type" => "edit"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $stauts, $st); $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process); return error_show(0, "状态更新成功"); } else { return error_show(1002, "状态更新失败"); } } }