zhanglinxin 1 年之前
父节点
当前提交
08bd3c3fcf
共有 2 个文件被更改,包括 39 次插入33 次删除
  1. 10 9
      application/common/model/ApproveFlow.php
  2. 29 24
      application/common/service/ApproveFlowService.php

+ 10 - 9
application/common/model/ApproveFlow.php

@@ -2,6 +2,7 @@
 
 namespace app\common\model;
 
+use app\common\constant\CommonConstant;
 use think\Model;
 
 /**
@@ -11,20 +12,20 @@ class ApproveFlow extends Model
 {
 
     /**
-     * 获取流程条件
+     * 审批流程条件
      *
      * @param integer $module 模块类型
-     * @param integer $type 流程类型
-     * @param integer $is_special 是否特殊:0=通用,1=特殊
-     * @param string $userid 特殊的用户userid
+     * @param integer $flow_type 审批流类型:1=审批人,2=抄送人
+     * @param integer $flow_item 审批流项:module=5出差类型,module=6请假周期
      **/
-    public static function get_where($module, $type, $is_special, $userid = '')
+    public static function get_where($module,  $flow_type, $flow_item)
     {
         return self::where('module', $module)
-            ->where('type', $type)
-            ->where('is_special', $is_special)
-            ->when($userid, function ($query) use ($userid) {
-                $query->where('special_user_id', $userid);
+            ->where('flow_type', $flow_type)
+            ->where(function ($query) use ($module, $flow_item) {
+                if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6])) {
+                    $query->where('flow_item', $flow_item);
+                }
             });
     }
 

+ 29 - 24
application/common/service/ApproveFlowService.php

@@ -19,40 +19,45 @@ class ApproveFlowService
      * @param integer $flow_item 审批流项
      * @param mixed $user 用户信息
      **/
-    public static function get_data($module,$flow_item,$user)
+    public static function get_data($module, $flow_item, $user)
     {
-        $userid = $user['userid'];
-        $field = 'id,user_ids';
+        $approve_user = [];
+        $copy_user = [];
+        $field = 'id,user_data';
+
         // 审批
-        $approve = ApproveFlow::get_where($module, CommonConstant::TYPE_1, CommonConstant::IS_SPECIAL_1, $userid)
-            ->field($field)
-            ->find();
+        $approve = ApproveFlow::get_where($module, CommonConstant::TYPE_1, $flow_item)->field($field)->find();
         if ($approve) {
-            $approve_user_ids = $approve['user_ids'];
-        } else {
-            $approve_info = ApproveFlow::get_where($module, CommonConstant::TYPE_1, CommonConstant::IS_SPECIAL_0)
-                ->field($field)
-                ->find();
-            $approve_user_ids = $approve_info ? $approve_info['user_ids'] : [];
+            $approve_user_data = json_decode($approve['user_data'], JSON_UNESCAPED_UNICODE);
+            foreach ($approve_user_data as &$value) {
+                if ($value['user_type'] == 1) {
+                    $value['userid'] = $user->manager_userid;
+                }
+            }
+            $approve_user_data = array_column($approve_user_data, null, 'userid');
+            $user_ids = array_keys($approve_user_data);
+            $user_list = self::get_user_list($user_ids);
+            if ($user_list) {
+                $user_data = array_column($user_list->toArray(), null, 'userid');
+                foreach ($approve_user_data as $val) {
+                    if (array_key_exists($val['userid'], $user_data)) {
+                        $approve_user[] = $user_data[$val['userid']];
+                    }
+                }
+            }
         }
-        $approve_user = self::get_user_list($approve_user_ids);
         // 抄送
         $name = 'is_copy_' . $module;
         $is_copy = sysconf($name); // 是否允许用户自己添加抄送人 0=否,1=是
-        $copy_user = [];
         if (!$is_copy) {
-            $copy = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_1, $userid)
-                ->field($field)
-                ->find();
+            $copy = ApproveFlow::get_where($module, CommonConstant::TYPE_2, $flow_item)->field($field)->find();
             if ($copy) {
-                $copy_user_ids = $copy['user_ids'];
-            } else {
-                $copy_info = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_0)
-                    ->field($field)
-                    ->find();
-                $copy_user_ids = $copy_info ? $copy_info['user_ids'] : [];
+                $copy_user_data = json_decode($copy['user_data'], JSON_UNESCAPED_UNICODE);
+                $copy_user_data = array_column($copy_user_data, null, 'userid');
+                $user_ids = array_keys($copy_user_data);
+                $user_list = self::get_user_list($user_ids);
+                $copy_user = $user_list;
             }
-            $copy_user = self::get_user_list($copy_user_ids);
         }
         return compact('approve_user', 'copy_user', 'is_copy');
     }