Approve.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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\home\controller;
  15. use app\api\BaseController;
  16. use think\facade\Db;
  17. use think\facade\View;
  18. class Approve extends BaseController
  19. {
  20. public function index()
  21. {
  22. $department = $this->did;
  23. $module = Db::name('FlowModule')->where(['status'=>1])->select()->toArray();
  24. $whereOr = [];
  25. if($this->uid>1){
  26. $map1=[
  27. ['department_ids', '=', '']
  28. ];
  29. $map2=[
  30. ['', 'exp', Db::raw("FIND_IN_SET('{$department}',department_ids)")]
  31. ];
  32. $whereOr =[$map1,$map2];
  33. }
  34. foreach ($module as &$row) {
  35. // 处理每一行数据
  36. $row['list'] = Db::name('FlowCate')
  37. ->where([['module_id','=',$row['id']],['status','=',1],['is_list','=',1]])
  38. ->where(function ($query) use($whereOr) {
  39. if (!empty($whereOr)){
  40. $query->whereOr($whereOr);
  41. }
  42. })
  43. ->select()->toArray();
  44. }
  45. View::assign('module', $module);
  46. return view();
  47. }
  48. public function get_list($where,$param)
  49. {
  50. $tables = Db::name('FlowCate')->field('name,check_table')->where('status',1)->select()->toArray();
  51. $prefix = get_config('database.connections.mysql.prefix');
  52. $sqlParts = [];
  53. $sqlCounts = [];
  54. $fortable =[];
  55. foreach ($tables as $table) {
  56. $dbname = $table['check_table'];
  57. if(in_array($dbname,$fortable)){
  58. continue;
  59. }
  60. $check_name = $table['name'];
  61. $tableName = $prefix.$dbname;
  62. $sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,'{$check_name}' as invoice_type,'{$check_name}' as types FROM {$tableName} WHERE {$where}";
  63. if($dbname=='invoice' || $dbname=='ticket'){
  64. $sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,invoice_type,'{$check_name}' as types FROM {$tableName} WHERE {$where}";
  65. }
  66. if($dbname=='approve'){
  67. $sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,'{$check_name}' as invoice_type,types FROM {$tableName} WHERE {$where}";
  68. }
  69. $sqlCount = "SELECT COUNT(*) AS count FROM {$tableName} WHERE {$where}";
  70. // 查询数据库中是否存在该数据表
  71. $is_table = Db::query("SHOW TABLES LIKE '{$tableName}'");
  72. // 判断查询结果
  73. if (!empty($is_table)) {
  74. $sqlParts[] = $sqlPart;
  75. $sqlCounts[] = $sqlCount;
  76. $fortable[] = $table['check_table'];
  77. }
  78. }
  79. // 使用implode将各个部分用UNION ALL连接起来
  80. $unionSql = implode(" UNION ALL ", $sqlParts);
  81. $totalCount = 0;
  82. foreach ($sqlCounts as $sql) {
  83. $count = Db::query($sql)[0]['count']; // 假设每个查询都返回了一个包含'count'键的数组
  84. $totalCount += $count;
  85. }
  86. // 添加排序和分页逻辑
  87. $page = isset($param['page']) ? $param['page'] : 1;
  88. $pageSize = $param['limit'];
  89. $offset = ($page - 1) * $pageSize;
  90. // 注意:不同的数据库分页语法可能有所不同,这里以MySQL为例
  91. $finalSql = $unionSql . " ORDER BY create_time DESC LIMIT {$offset}, {$pageSize}";
  92. // 执行查询
  93. $result = Db::query($finalSql);
  94. // 处理结果
  95. foreach ($result as &$row) {
  96. // 处理每一行数据
  97. $row['create_time'] = date('Y-m-d H:i:s',$row['create_time']);
  98. $row['admin_name'] = Db::name('Admin')->where('id',$row['admin_id'])->value('name');
  99. $row['department'] = Db::name('Department')->where('id',$row['did'])->value('title');
  100. $row['check_status_str'] = check_status_name($row['check_status']);
  101. if($row['check_status']==1 && !empty($row['check_uids'])){
  102. $check_users = Db::name('Admin')->where('id','in',$row['check_uids'])->column('name');
  103. $row['check_users'] = implode(',',$check_users);
  104. }
  105. else{
  106. $row['check_users']='-';
  107. }
  108. if(!empty($row['check_copy_uids'])){
  109. $check_copy_users = Db::name('Admin')->where('id','in',$row['check_copy_uids'])->column('name');
  110. $row['check_copy_users'] = implode(',',$check_copy_users);
  111. }
  112. else{
  113. $row['check_copy_users']='-';
  114. }
  115. $check_name=$row['check_name'];
  116. if($row['table_name'] == 'invoice' || $row['table_name']=='ticket'){
  117. if($row['invoice_type']==0){
  118. $check_name=$row['table_name'].'a';
  119. }
  120. else{
  121. $check_name=$row['table_name'];
  122. }
  123. }
  124. if($row['table_name'] == 'approve'){
  125. $check_name='approve_'.$row['types'];
  126. }
  127. $flow_cate = Db::name('FlowCate')->where('name',$check_name)->find();
  128. $row['types_name'] = $flow_cate['title'];
  129. $row['view_url'] = $flow_cate['view_url'];
  130. $row['add_url'] = $flow_cate['add_url'];
  131. }
  132. $list=array(
  133. 'data'=>$result,
  134. 'total'=>$totalCount
  135. );
  136. return $list;
  137. }
  138. //我申请的
  139. public function mylist()
  140. {
  141. if (request()->isAjax()) {
  142. $param = get_params();
  143. $status = isset($param['status']) ? $param['status'] : 0;
  144. $uid = $this->uid;
  145. $where = "delete_time = 0";
  146. if($status == 1){
  147. $where.= " AND check_status < 2";
  148. }
  149. if($status == 2){
  150. $where.= " AND check_status = 2";
  151. }
  152. if($status == 3){
  153. $where.= " AND check_status > 2";
  154. }
  155. $where.= ' AND admin_id = '.$uid;
  156. //关联抄送人
  157. //$where.= " AND FIND_IN_SET('{$uid}',check_copy_uids)";
  158. //关联审核人
  159. //$where.= " AND (FIND_IN_SET('{$uid}',check_uids) or FIND_IN_SET('{$uid}',check_history_uids))";
  160. $list = $this->get_list($where,$param);
  161. return table_assign(0, '', $list);
  162. } else {
  163. return view();
  164. }
  165. }
  166. public function checklist()
  167. {
  168. if (request()->isAjax()) {
  169. $param = get_params();
  170. $uid = $this->uid;
  171. $status = isset($param['status']) ? $param['status'] : 0;
  172. $where = "delete_time = 0";
  173. if($status == 0){
  174. $where.= " AND (FIND_IN_SET('{$uid}',check_uids) or FIND_IN_SET('{$uid}',check_history_uids))";
  175. }
  176. if($status == 1){
  177. $where.= " AND FIND_IN_SET('{$uid}',check_uids)";
  178. }
  179. if($status == 2){
  180. $where.= " AND FIND_IN_SET('{$uid}',check_history_uids)";
  181. }
  182. $list = $this->get_list($where,$param);
  183. return table_assign(0, '', $list);
  184. } else {
  185. return view();
  186. }
  187. }
  188. public function copylist()
  189. {
  190. if (request()->isAjax()) {
  191. $param = get_params();
  192. $status = isset($param['status']) ? $param['status'] : 0;
  193. $uid = $this->uid;
  194. $where = "delete_time = 0";
  195. if($status == 1){
  196. $where.= " AND check_status < 2";
  197. }
  198. if($status == 2){
  199. $where.= " AND check_status = 2";
  200. }
  201. if($status == 3){
  202. $where.= " AND check_status > 2";
  203. }
  204. //关联抄送人
  205. $where.= " AND FIND_IN_SET('{$uid}', check_copy_uids) > 0";
  206. $list = $this->get_list($where,$param);
  207. return table_assign(0, '', $list);
  208. } else {
  209. return view();
  210. }
  211. }
  212. //全部审批
  213. public function all()
  214. {
  215. $auth_approve = isAuth($this->uid,'office_admin','conf_1');
  216. if (request()->isAjax()) {
  217. if($auth_approve==0){
  218. return to_assign(1, '无权限访问');
  219. }
  220. $param = get_params();
  221. $status = isset($param['status']) ? $param['status'] : 0;
  222. $uid = $this->uid;
  223. $where = "delete_time = 0";
  224. if($status == 1){
  225. $where.= " AND check_status < 2";
  226. }
  227. if($status == 2){
  228. $where.= " AND check_status = 2";
  229. }
  230. if($status == 3){
  231. $where.= " AND check_status > 2";
  232. }
  233. if(!empty($param['uid'])){
  234. $where.= ' AND admin_id = '.$param['uid'];
  235. }
  236. $list = $this->get_list($where,$param);
  237. return table_assign(0, '', $list);
  238. } else {
  239. if($auth_approve==0){
  240. throw new \think\exception\HttpException(405, '无权限访问');
  241. }
  242. return view();
  243. }
  244. }
  245. }