Flow.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\adm\controller;
  15. use app\base\BaseController;
  16. use app\adm\validate\FlowCateCheck;
  17. use app\adm\validate\FlowCheck;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Flow extends BaseController
  22. {
  23. public function datalist()
  24. {
  25. if (request()->isAjax()) {
  26. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  27. $list = Db::name('Flow')
  28. ->field('f.*,fc.title as cate,fm.title as module')
  29. ->alias('f')
  30. ->join('FlowCate fc', 'fc.id = f.cate_id', 'left')
  31. ->join('FlowModule fm', 'fm.id = fc.module_id', 'left')
  32. ->order('id desc')->paginate(['list_rows'=> $rows])
  33. ->each(function($item, $key){
  34. if(!empty($item['department_ids'])){
  35. $item['departments']=get_department_name($item['department_ids']);
  36. }
  37. else{
  38. $item['departments']='全部';
  39. }
  40. if(!empty($item['copy_uids'])){
  41. $copy_unames=Db::name('Admin')->where([['status','=',1],['id','in',$item['copy_uids']]])->column('name');
  42. $item['copy_unames']=implode(',',$copy_unames);
  43. }
  44. else{
  45. $item['copy_unames']='-';
  46. }
  47. return $item;
  48. });
  49. return table_assign(0, '', $list);
  50. } else {
  51. return view();
  52. }
  53. }
  54. //添加新增/编辑
  55. public function add()
  56. {
  57. $param = get_params();
  58. if (request()->isAjax()) {
  59. $param['flow_list'] = '';
  60. $flow_list=[];
  61. //固定审批流
  62. if($param['check_type']==2){
  63. $roleData = isset($param['check_role']) ? $param['check_role'] : '';
  64. $positionIdData = isset($param['check_position_id']) ? $param['check_position_id'] : '';
  65. $checkUidsData = isset($param['check_uids_a']) ? $param['check_uids_a'] : '';
  66. $checkTypesData = isset($param['check_types']) ? $param['check_types'] : '';
  67. foreach ($roleData as $key => $value) {
  68. if (!$value) {
  69. continue;
  70. }
  71. if($value==3 && $positionIdData[$key]==''){
  72. return to_assign(1, '第'.($key+1).'行的指定岗位职称未选择');
  73. break;
  74. }
  75. if($value>3 && $checkUidsData[$key]==''){
  76. return to_assign(1, '第'.($key+1).'行的指定人未选择');
  77. break;
  78. }
  79. $item = [];
  80. $item['check_role'] = $value;
  81. $item['check_position_id'] = $positionIdData[$key];
  82. $item['check_uids'] = $checkUidsData[$key];
  83. $item['check_types'] = $checkTypesData[$key];
  84. $flow_list[]=$item;
  85. }
  86. $param['flow_list'] = serialize($flow_list);
  87. }
  88. //可回退审批流
  89. if($param['check_type']==3){
  90. $flowNameData = isset($param['flow_name']) ? $param['flow_name'] : '';
  91. $checkUidsData = isset($param['check_uids_b']) ? $param['check_uids_b'] : '';
  92. foreach ($flowNameData as $key => $value) {
  93. if (!$value) {
  94. continue;
  95. }
  96. if($checkUidsData[$key]==''){
  97. return to_assign(1, '第'.($key+1).'行的指定人未选择');
  98. break;
  99. }
  100. $item = [];
  101. $item['check_role'] = 5;
  102. $item['flow_name'] = $value;
  103. $item['check_uids'] = $checkUidsData[$key];
  104. $flow_list[]=$item;
  105. }
  106. if(empty($flow_list)){
  107. return to_assign(1, '审批流程信息未完善');
  108. }
  109. $param['flow_list'] = serialize($flow_list);
  110. }
  111. if ($param['id'] > 0) {
  112. try {
  113. validate(FlowCheck::class)->scene('edit')->check($param);
  114. } catch (ValidateException $e) {
  115. // 验证失败 输出错误信息
  116. return to_assign(1, $e->getError());
  117. }
  118. $param['update_time'] = time();
  119. Db::name('Flow')->strict(false)->field(true)->update($param);
  120. add_log('edit', $param['id'], $param);
  121. } else {
  122. try {
  123. validate(FlowCheck::class)->scene('add')->check($param);
  124. } catch (ValidateException $e) {
  125. // 验证失败 输出错误信息
  126. return to_assign(1, $e->getError());
  127. }
  128. $param['admin_id'] = $this->uid;
  129. $param['create_time'] = time();
  130. $mid = Db::name('Flow')->strict(false)->field(true)->insertGetId($param);
  131. add_log('add', $mid, $param);
  132. }
  133. return to_assign();
  134. } else {
  135. $id = isset($param['id']) ? $param['id'] : 0;
  136. $check_type = 1;
  137. if($id>0){
  138. $detail = Db::name('Flow')->where('id',$id)->find();
  139. $flow_list = unserialize($detail['flow_list']);
  140. if(!empty($flow_list)){
  141. foreach ($flow_list as $key => &$val) {
  142. $val['check_unames'] ='';
  143. $val['check_position_title'] ='';
  144. if($val['check_role']==3){
  145. $val['check_position_title'] = Db::name('Position')->where('id', '=', $val['check_position_id'])->value('title');
  146. }
  147. if($val['check_role']>3){
  148. $check_unames = Db::name('Admin')->where('id', 'in', $val['check_uids'])->column('name');
  149. $val['check_unames'] = implode(',', $check_unames);
  150. }
  151. }
  152. }
  153. $detail['flow_list'] = $flow_list;
  154. $detail['copy_unames'] ='';
  155. if($detail['copy_uids']!=''){
  156. $copy_unames = Db::name('Admin')->where('id', 'in', $detail['copy_uids'])->column('name');
  157. $detail['copy_unames'] = implode(',', $copy_unames);
  158. }
  159. $check_type = $detail['check_type'];
  160. //var_dump($flow_list);exit;
  161. View::assign('detail', $detail);
  162. }
  163. View::assign('check_type', $check_type);
  164. View::assign('id', $id);
  165. return view();
  166. }
  167. }
  168. //禁用/启用
  169. public function check()
  170. {
  171. $param = get_params();
  172. $param['update_time']= time();
  173. $res = Db::name('Flow')->strict(false)->field('status,update_time')->update($param);
  174. if($res!==false){
  175. if($param['status'] == 0){
  176. add_log('disable', $param['id'], $param);
  177. }
  178. else if($param['status'] == 1){
  179. add_log('recovery', $param['id'], $param);
  180. }
  181. return to_assign();
  182. }
  183. else{
  184. return to_assign(1,'操作失败');
  185. }
  186. }
  187. //审批模块
  188. public function modulelist()
  189. {
  190. if (request()->isAjax()) {
  191. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  192. $list = Db::name('FlowModule')
  193. ->order('sort desc,id desc')
  194. ->paginate(['list_rows'=> $rows]);
  195. return table_assign(0, '', $list);
  196. } else {
  197. return view();
  198. }
  199. }
  200. //添加模块
  201. public function module_add()
  202. {
  203. $param = get_params();
  204. if (request()->isAjax()) {
  205. if (!empty($param['id']) && $param['id'] > 0) {
  206. $param['update_time'] = time();
  207. $res = Db::name('FlowModule')->strict(false)->field(true)->update($param);
  208. if ($res) {
  209. add_log('edit', $param['id'], $param);
  210. }
  211. return to_assign();
  212. } else {
  213. $param['create_time'] = time();
  214. $insertId = Db::name('FlowModule')->strict(false)->field(true)->insertGetId($param);
  215. if ($insertId) {
  216. add_log('add', $insertId, $param);
  217. }
  218. return to_assign();
  219. }
  220. }else {
  221. $id = isset($param['id']) ? $param['id'] : 0;
  222. if ($id > 0) {
  223. $detail = Db::name('FlowModule')->find($id);
  224. View::assign('detail', $detail);
  225. }
  226. View::assign('id', $id);
  227. return view();
  228. }
  229. }
  230. //设置
  231. public function module_check()
  232. {
  233. $param = get_params();
  234. $res = Db::name('FlowModule')->strict(false)->field('id,status')->update($param);
  235. if ($res) {
  236. if($param['status'] == 0){
  237. add_log('disable', $param['id'], $param);
  238. }
  239. else if($param['status'] == 1){
  240. add_log('recovery', $param['id'], $param);
  241. }
  242. return to_assign();
  243. }
  244. else{
  245. return to_assign(0, '操作失败');
  246. }
  247. }
  248. //审批类型列表
  249. public function catelist()
  250. {
  251. if (request()->isAjax()) {
  252. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  253. $list = Db::name('FlowCate')
  254. ->field('fc.*,fm.title as module')
  255. ->alias('fc')
  256. ->join('FlowModule fm', 'fm.id = fc.module_id', 'left')
  257. ->order('fc.sort desc,fc.id desc')
  258. ->paginate(['list_rows'=> $rows])
  259. ->each(function($item, $key){
  260. if(!empty($item['department_ids'])){
  261. $item['departments']=get_department_name($item['department_ids']);
  262. }
  263. else{
  264. $item['departments']='全部';
  265. }
  266. return $item;
  267. });
  268. return table_assign(0, '', $list);
  269. } else {
  270. return view();
  271. }
  272. }
  273. //添加审批类型
  274. public function cate_add()
  275. {
  276. $param = get_params();
  277. if (request()->isAjax()) {
  278. if (!empty($param['id']) && $param['id'] > 0) {
  279. try {
  280. validate(FlowCateCheck::class)->scene('edit')->check($param);
  281. } catch (ValidateException $e) {
  282. // 验证失败 输出错误信息
  283. return to_assign(1, $e->getError());
  284. }
  285. $param['update_time'] = time();
  286. $res = Db::name('FlowCate')->strict(false)->field(true)->update($param);
  287. if ($res) {
  288. add_log('edit', $param['id'], $param);
  289. }
  290. return to_assign();
  291. } else {
  292. try {
  293. validate(FlowCateCheck::class)->scene('add')->check($param);
  294. } catch (ValidateException $e) {
  295. // 验证失败 输出错误信息
  296. return to_assign(1, $e->getError());
  297. }
  298. $param['create_time'] = time();
  299. $insertId = Db::name('FlowCate')->strict(false)->field(true)->insertGetId($param);
  300. if ($insertId) {
  301. add_log('add', $insertId, $param);
  302. }
  303. return to_assign();
  304. }
  305. }else {
  306. $id = isset($param['id']) ? $param['id'] : 0;
  307. if ($id > 0) {
  308. $detail = Db::name('FlowCate')->find($id);
  309. if(!empty($detail['department_ids'])){
  310. $detail['departments']=get_department_name($detail['department_ids']);
  311. }
  312. else{
  313. $detail['departments']='全部';
  314. }
  315. if($detail['template_id']>0){
  316. $detail['template_title'] = Db::name('Template')->where('id',$detail['template_id'])->value('title');
  317. }
  318. View::assign('detail', $detail);
  319. }
  320. View::assign('id', $id);
  321. return view();
  322. }
  323. }
  324. //审批类型设置
  325. public function cate_check()
  326. {
  327. $param = get_params();
  328. $res = Db::name('FlowCate')->strict(false)->field('id,status')->update($param);
  329. if ($res) {
  330. if($param['status'] == 0){
  331. add_log('disable', $param['id'], $param);
  332. }
  333. else if($param['status'] == 1){
  334. add_log('recovery', $param['id'], $param);
  335. }
  336. return to_assign();
  337. }
  338. else{
  339. return to_assign(0, '操作失败');
  340. }
  341. }
  342. }