Work.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace app\bug\controller;
  3. use app\bug\model\WorkAction;
  4. use app\bug\model\WorkTemplate;
  5. use think\App;
  6. use think\facade\Validate;
  7. class Work extends Base{
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->model=new \app\bug\model\Work();
  11. }
  12. //岗位模板新建
  13. public function create(){
  14. $param=$this->request->param(["work_name"=>"","belong"=>"","level"=>""],"post","trim");
  15. $valid =Validate::rule([
  16. "work_name|岗位名称"=>"require|max:200",
  17. "belong|系统归属"=>"require|number|in:1,2,3",
  18. "level|账户等级"=>"require|number|in:1,2,3"
  19. ]);
  20. if($valid->check($param)==false)return error($valid->getError());
  21. $data = [
  22. 'work_name'=>$param['work_name'],
  23. 'belong'=>$param['belong'],
  24. 'level'=>$param['level'],
  25. 'apply_id'=>$this->uid,
  26. 'apply_name'=>$this->uname,
  27. ];
  28. $add = $this->model->save($data);
  29. return $add ? success("创建成功"):error("创建失败");
  30. }
  31. //岗位模板新建
  32. public function save(){
  33. $param=$this->request->param(["id"=>"",'work_name'=>'','belong'=>'','level'=>''],'post','trim');
  34. $valid =Validate::rule([
  35. 'id|岗位ID'=>'require|number|gt:0',
  36. 'work_name|岗位名称'=>'require|max:200',
  37. 'belong|系统归属'=>'require|number|in:1,2,3',
  38. 'level|账户等级'=>'require|number|in:1,2,3'
  39. ]);
  40. if($valid->check($param)==false)return error($valid->getError());
  41. $info = $this->model->findOrEmpty($param['id']);
  42. if($info->isEmpty()) error("未找到数据");
  43. $info->work_name= $param['work_name'];
  44. $info->belong= $param['belong'];
  45. $info->level= $param['level'];
  46. $info->work_name= $param['work_name'];
  47. $add = $info->save();
  48. return $add ? success('修改成功'):error('修改失败');
  49. }
  50. //岗位模板新建
  51. public function delete(){
  52. $id=$this->request->post("id/d");
  53. $info = $this->model->findOrEmpty($id);
  54. if($info->isEmpty()) error('未找到数据');
  55. $add = $info->delete();
  56. return $add ? success('删除成功'):error('删除失败');
  57. }
  58. //岗位模板新建
  59. public function list(){
  60. $param=$this->request->param(['work_name'=>'','belong'=>'','level'=>'','size'=>1,'page'=>15],'post','trim');
  61. $where=[];
  62. if($param['level']!='')$where[]=['level','=',$param['level']];
  63. if($param['belong']!='')$where[]=['belong','=',$param['belong']];
  64. if($param['work_name']!='')$where[]=['work_name','like',"%{$param['work_name']}%"];
  65. $list =$this->model->where($where)->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
  66. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  67. }
  68. //岗位模板新建
  69. public function status(){
  70. $param=$this->request->param(['id'=>'','sttaus'=>''],'post','trim');
  71. $valid =Validate::rule([
  72. 'id|岗位ID'=>'require|number|gt:0',
  73. 'status|状态'=>'require|number|in:0,1'
  74. ]);
  75. if($valid->check($param)==false)return error($valid->getError());
  76. $info = $this->model->findOrEmpty($param['id']);
  77. if($info->isEmpty()) error('未找到数据');
  78. $info->status= $param['status'];
  79. $status=\app\bug\model\Work::$statusCn[$param['status']];
  80. $add = $info->save();
  81. return $add ? success("{$status}成功"):error("{$status}失败");
  82. }
  83. public function WorkActionCreate(){
  84. $param=$this->request->param([
  85. 'belong_action'=>[],
  86. 'belong_process'=>[],
  87. 'menu_id'=>'',
  88. 'work_id'=>'',
  89. 'belong'=>0,
  90. 'action_name'=>''],'post','trim');
  91. $valid =Validate::rule([
  92. 'belong_action|系统功能集合'=>'require|array',
  93. 'belong_process|系统流程集合'=>'array',
  94. 'menu_id|菜单页面Id'=>'require|number',
  95. 'work_id|岗位Id'=>'require|number',
  96. 'belong|系统归属'=>'number|in:0,1,2,3',
  97. 'action_name|功能名称'=>'require|max:255',
  98. ]);
  99. if($valid->check($param)==false)return error($valid->getError());
  100. $work = $this->model->with(["workTemplate"])->findOrEmpty($param['work_id']);
  101. if($work->isEmpty())return error("岗位信息不存在");
  102. $this->model->startTrans();
  103. try{
  104. $data = [
  105. 'action_name'=>$param['action_name'],
  106. 'belong'=>$param['belong'],
  107. 'menu_id'=>$param['menu_id'],
  108. 'belong_action'=>$param['belong_action'],
  109. 'belong_process'=>$param['belong_process'],
  110. 'apply_id'=>$this->uid,
  111. 'apply_name'=>$this->uname,
  112. ];
  113. $add = WorkAction::create($data);
  114. if($add->isEmpty()) return error("功能新建失败");
  115. if(is_null($work->workTemplate)){
  116. $up=$work->workTemplate()
  117. ->save([
  118. "action"=>[$add->id],
  119. "process_action"=>[],
  120. "work_id"=>$param['work_id'],
  121. "apply_id"=>$this->uid,
  122. "apply_name"=>$this->uname,
  123. ]);
  124. }else{
  125. $action = $work->workTemplate->action;
  126. array_push($action,$add->id);
  127. $work->workTemplate->action=$action;
  128. $work->workTemplate->apply_id=$this->uid;
  129. $work->workTemplate->apply_name=$this->uname;
  130. $up=$work->workTemplate->save();
  131. }
  132. if($up==false) return error('功能新建失败');
  133. $this->model->commit();
  134. return success("创建成功");
  135. }catch (\Exception $e){
  136. $this->model->rollback();
  137. return error($e->getMessage());
  138. }
  139. }
  140. public function WorkActionSave(){
  141. $param=$this->request->param([
  142. "id"=>"",
  143. 'belong_action'=>[],
  144. 'belong_process'=>[],
  145. 'menu_id'=>'',
  146. 'belong'=>0,
  147. 'action_name'=>''],'post','trim');
  148. $valid =Validate::rule([
  149. 'id|岗位功能ID'=>'require|number',
  150. 'belong_action|系统功能集合'=>'require|array',
  151. 'belong_process|系统流程集合'=>'array',
  152. 'menu_id|菜单页面Id'=>'require|number',
  153. 'belong|系统归属'=>'number|in:0,1,2,3',
  154. 'action_name|岗位功能名称'=>'require|max:255',
  155. ]);
  156. if($valid->check($param)==false)return error($valid->getError());
  157. $info= WorkAction::where(["id"=>$param['id']])->findOrEmpty();
  158. if($info->isEmpty())return error("数据为找到");
  159. $info->action_name=$param['action_name'];
  160. $info->belong=$param['belong'];
  161. $info->menu_id=$param['menu_id'];
  162. $info->belong_action=$param['belong_action'];
  163. $info->belong_process=$param['belong_process'];
  164. $add = $info->save();
  165. return $add ? success('岗位功能修改成功'):error('岗位功能修改失败');
  166. }
  167. public function WorkActionDelete(){
  168. $id=$this->request->post('id/d');
  169. $info = WorkAction::where(['id'=>$id])->findOrEmpty();
  170. if($info->isEmpty()) error('未找到数据');
  171. $add = $info->delete();
  172. return $add ? success('删除成功'):error('删除失败');
  173. }
  174. public function WorkActionInfo(){
  175. $id=$this->request->post('id/d');
  176. $info = WorkAction::where(['id'=>$id])->findOrEmpty();
  177. if($info->isEmpty()) error('未找到数据');
  178. return success('获取成功',$info);
  179. }
  180. public function WorkActionList(){
  181. $param=$this->request->param(['menu_id'=>'','belong'=>0,'action_name'=>'',"page"=>1,"size"=>15],'post','trim');
  182. $where=[];
  183. if($param['menu_id']!="")$where[]=["menu_id","=",$param['menu_id']];
  184. if($param['belong']!="")$where[]=["belong","=",$param['belong']];
  185. if($param['action_name']!="")$where[]=["action_name","like","%{$param['action_name']}%"];
  186. $list = WorkAction::where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
  187. return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  188. }
  189. public function WorkTemplateSave(){
  190. $param=$this->request->param(["work_id"=>"","action"=>[],"process_action"=>[]],"post","trim");
  191. $valid =Validate::rule([
  192. 'work_id|岗位ID'=>'require|number',
  193. 'action|岗位功能集合'=>'require|array',
  194. 'process_action|流程节点'=>'array',
  195. ]);
  196. if($valid->check($param)==false)return error($valid->getError());
  197. $info= WorkTemplate::where(['work_id'=>$param['work_id']])->findOrEmpty();
  198. $info->work_id=$param['work_id'];
  199. $info->action=$param['action'];
  200. $info->process_action=$param['process_action'];
  201. $add = $info->save();
  202. return $add ? success('岗位模板修改成功'):error('岗位模板修改失败');
  203. }
  204. public function WorkTemplateInfo(){
  205. $work_id=$this->request->post('work_id/d');
  206. $info= WorkTemplate::where(['work_id'=>$work_id])->findOrEmpty();
  207. if($info->isEmpty()) error('未找到数据');
  208. $info->actionInfo= (new WorkAction())->GetTreeActionByIdArr($info->action,$info->workInfo->belong);
  209. return success('获取成功',$info);
  210. }
  211. }