123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /**
- * @copyright Copyright (c) 2021 勾股工作室
- * @license https://opensource.org/licenses/GPL-3.0
- * @link https://www.gougucms.com
- */
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\BaseController;
- use app\admin\validate\PositionCheck;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\View;
- use app\admin\model\Department as DepartmentModel;
- use app\admin\model\Position as PositionModel;
- class Position extends BaseController
- {
- protected $Departmentmodel;
- protected $Positionmodel;
- public function initialize(){
- parent::initialize();
- $this->Departmentmodel = new DepartmentModel;
- $this->Positionmodel = new PositionModel;
- }
- public function index()
- {
- if (request()->isAjax()) {
-
- $list = $this->Departmentmodel->with('position')->where('pid', 0)->select();
-
- $data = array();
- $length = 0;
- for($i = 0;$i < count($list); $i++){
- $data[$length++] = [
-
- 'd_id' => $list[$i]['id'],
- 'id' => -1,
- 'title' => $list[$i]['title'],
- 'did' => 0,
- 'remark' => $list[$i]['remark'],
- 'status' => $list[$i]['status'],
- ];
- $position = $list[$i]['position'];
- for($j = 0;$j < count($position); $j++){
- $data[$length++] = [
- 'd_id' => -1,
- 'id' => $position[$j]['id'],
- 'title' => $position[$j]['title'],
- 'did' => $position[$j]['did'],
- 'remark' => $position[$j]['remark'],
- 'status' => $position[$j]['status'],
-
- ];
- }
- }
-
- // halt($data);
- return to_assign(0, '', $data);
- } else {
- return view();
- }
- }
- //添加&编辑
- public function add()
- {
- $param = get_params();
- if (request()->isAjax()) {
- if (!empty($param['id']) && $param['id'] > 0) {
- try {
- validate(PositionCheck::class)->scene('edit')->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- $res = Db::name('Position')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
- if($res!==false){
- add_log('edit', $param['id'], $param);
- return to_assign();
- }
- else{
- return to_assign(1, '提交失败');
- }
- } else {
- try {
- validate(PositionCheck::class)->scene('add')->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
-
- $pid = Db::name('Position')->strict(false)->field(true)->insertGetId($param);
- if($pid>0){
- add_log('add', $pid, $param);
- return to_assign();
- }
- else{
- return to_assign(1, '提交失败');
- }
- }
- }
- else{
- $id = isset($param['id']) ? $param['id'] : 0;
- if ($id > 0) {
- $detail = Db::name('Position')->where(['id' => $id])->find();
- View::assign('detail', $detail);
- }
- View::assign('id', $id);
- return view();
- }
- }
- //删除
- public function delete()
- {
- $id = get_params("id");
- if ($id == 1) {
- return to_assign(0, "超级岗位,不能删除");
- }
- $data['status'] = '-1';
- $data['id'] = $id;
- $data['update_time'] = time();
- if (Db::name('Position')->update($data) !== false) {
- add_log('delete', $id);
- return to_assign(0, "删除岗位成功");
- } else {
- return to_assign(1, "删除失败");
- }
- }
- }
|