zhanglinxin 1 vuosi sitten
vanhempi
commit
7d2041c209

+ 27 - 9
application/api/controller/Approve.php

@@ -31,15 +31,6 @@ class Approve extends Base
      * @Apidoc\Param("start_time", type="string", require=false, desc="申请开始时间")
      * @Apidoc\Param("end_time", type="string", require=false, desc="申请结束时间")
      * @Apidoc\Param("search", type="string", require=false, desc="搜索 姓名 事由 编号")
-     * @Apidoc\Returned("approve_user", type="array", desc="审批人列表",
-     *     @Apidoc\Returned("userid", type="string", desc="用户userid"),
-     *     @Apidoc\Returned("headimg", type="string", desc="头像"),
-     *     @Apidoc\Returned("name", type="string", desc="姓名"),
-     * )
-     * @Apidoc\Returned("copy_user", type="array", desc="抄送人列表",
-     *     @Apidoc\Returned("userid", type="string", desc="用户userid"),
-     *     @Apidoc\Returned("headimg", type="string", desc="头像"),
-     *     @Apidoc\Returned("name", type="string", desc="姓名"),
      * )
      */
     public function get_list()
@@ -55,4 +46,31 @@ class Approve extends Base
         $this->success('审批列表', $data);
     }
 
+    /**
+     * 详情
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("id", type="integer",require=true, desc="审批ID")
+     */
+    public function get_detail()
+    {
+        $id = input('id');
+        $info = ApproveService::get_detail($id, $this->user, 'detail');
+        $this->success('详情', $info);
+    }
+
+    /**
+     * 信息
+     *
+     * @Apidoc\Desc("修改信息")
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("id", type="integer",require=true, desc="审批ID")
+     */
+    public function get_info()
+    {
+        $id = input('id');
+        $info = ApproveService::get_detail($id, $this->user, 'info');
+        $this->success('信息', $info);
+    }
+
 }

+ 1 - 1
application/api/controller/Approveinfo.php

@@ -174,7 +174,7 @@ class Approveinfo extends Base
     /**
      * 信息
      *
-     * @Apidoc\Desc("重新发起信息/修改信息")
+     * @Apidoc\Desc("重新发起信息")
      * @Apidoc\Method("POST")
      * @Apidoc\Param("id", type="integer",require=true, desc="申请ID")
      * @Apidoc\Returned("id", type="integer", desc="申请ID")

+ 7 - 0
application/common/model/ApproveCopy.php

@@ -13,4 +13,11 @@ class ApproveCopy extends Model
     // 表名
     protected $name = 'approve_copy';
 
+
+    // 关联用户
+    public function user()
+    {
+        return $this->belongsTo(User::class, 'approve_user', 'userid');
+    }
+
 }

+ 41 - 39
application/common/model/ApproveFlow.php

@@ -2,7 +2,6 @@
 
 namespace app\common\model;
 
-use app\common\constant\CommonConstant;
 use think\Model;
 
 /**
@@ -14,91 +13,94 @@ class ApproveFlow extends Model
     /**
      * 获取流程条件
      *
-     * @param $module
-     * @param $type
-     * @param $is_special
-     * @param $userid
+     * @param integer $module 模块类型
+     * @param integer $type 流程类型
+     * @param integer $is_special 是否特殊:0=通用,1=特殊
+     * @param string $userid 特殊的用户userid
      **/
-    public static function get_where($module,$type,$is_special,$userid = ''){
+    public static function get_where($module, $type, $is_special, $userid = '')
+    {
         return self::where('module', $module)
             ->where('type', $type)
             ->where('is_special', $is_special)
-            ->when($userid,function ($query) use ($userid){
+            ->when($userid, function ($query) use ($userid) {
                 $query->where('special_user_id', $userid);
             });
     }
 
 
-    protected  $module_desc = [
-        '1'=> '请假',
-        '2'=> '用车',
-        '3'=> '出差',
-        '4'=> '呈批',
-        '5'=> '维修',
-        '6'=> '学校文件',
-        '7'=> '合同',
+    protected $module_desc = [
+        '1' => '请假',
+        '2' => '用车',
+        '3' => '出差',
+        '4' => '呈批',
+        '5' => '维修',
+        '6' => '学校文件',
+        '7' => '合同',
     ];
+
     // 获取审批人
-    public static function getApproveUser($module,$user_id){
-        $check_flow = ApproveFlow::where('user_id',$user_id)->where('type',1)->where('module',$module)->find();
+    public static function getApproveUser($module, $user_id)
+    {
+        $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 1)->where('module', $module)->find();
         $where = [];
-        $where[] = ['l.type','=',1];
-        $where[] = ['l.module','=',$module];
-        if($check_flow)$where[] = ['l.sort','>',$check_flow->sort];
+        $where[] = ['l.type', '=', 1];
+        $where[] = ['l.module', '=', $module];
+        if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
         $list = static::field('l.user_id,u.name user_name,u.headimg')->alias('l')
             ->where($where)
             ->order('l.sort asc')
-            ->leftJoin('StoreMember u','u.id = l.user_id')
+            ->leftJoin('StoreMember u', 'u.id = l.user_id')
             ->select()->toArray();
         return $list;
     }
 
     // 获取抄送人
-    public static function getCopyTo($module,$user_id)
+    public static function getCopyTo($module, $user_id)
     {
-        $check_flow = ApproveFlow::where('user_id',$user_id)->where('type',2)->where('module',$module)->find();
+        $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 2)->where('module', $module)->find();
         $where = [];
-        $where[] = ['l.type','=',2];
-        $where[] = ['l.module','=',$module];
-        if($check_flow)$where[] = ['l.sort','>',$check_flow->sort];
+        $where[] = ['l.type', '=', 2];
+        $where[] = ['l.module', '=', $module];
+        if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
         $list = ApproveFlow::field('l.user_id,u.name user_name,u.headimg')
             ->alias('l')
             ->where($where)
             ->order('l.sort asc')
-            ->leftJoin('StoreMember u','u.id = l.user_id')
+            ->leftJoin('StoreMember u', 'u.id = l.user_id')
             ->select()->toArray();
-       return $list;
+        return $list;
     }
 
 
     // 获取审批流程数据
-    public static function getApproveData($flow_user,$copy_user,$info_id)
+    public static function getApproveData($flow_user, $copy_user, $info_id)
     {
         $flow_data = [];// 审批流程
         $flow_num = 0;
         // 审批人
-        foreach (explode(',',$flow_user) as $fk=>$fv) {
-            if(!$fv) continue;
+        foreach (explode(',', $flow_user) as $fk => $fv) {
+            if (!$fv) continue;
             $flow_num++;
             $flow_data[] = [
                 'info_id' => $info_id,
                 'approve_user' => $fv,
-                'flow'   =>$flow_num,
-                'create_at'=>date('Y-m-d H:i:s'),
-                'start_time'=> $flow_num == 1 ? date('Y-m-d H:i:s'):null,
-                'status'=> $flow_num == 1 ? 1 : 0,
+                'flow' => $flow_num,
+                'create_at' => date('Y-m-d H:i:s'),
+                'start_time' => $flow_num == 1 ? date('Y-m-d H:i:s') : null,
+                'status' => $flow_num == 1 ? 1 : 0,
             ];
         }
         // 抄送人
-        foreach (explode(',',$copy_user) as $ck=>$cv) {
-            if(!$cv) continue;
+        foreach (explode(',', $copy_user) as $ck => $cv) {
+            if (!$cv) continue;
             $flow_data[] = [
                 'info_id' => $info_id,
                 'approve_user' => $cv,
-                'approve_type'   =>2
+                'approve_type' => 2
             ];
         }
-        return ['flow_data'=>$flow_data,'flow_num'=>$flow_num];
+        return ['flow_data' => $flow_data, 'flow_num' => $flow_num];
     }
 
 

+ 5 - 0
application/common/model/ApproveInfo.php

@@ -48,4 +48,9 @@ class ApproveInfo extends Model
         return $this->hasOne(Approve::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
     }
 
+    // 关联抄送 (详情/信息)
+    public function approveCopy()
+    {
+        return $this->hasMany(ApproveCopy::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
+    }
 }

+ 49 - 28
application/common/service/ApproveInfoService.php

@@ -35,7 +35,7 @@ class ApproveInfoService
             $info = ApproveInfo::field('user_id,is_deleted', true)
                 ->where('user_id', $userid)
                 ->where('is_deleted', CommonConstant::IS_DELETED_0)
-                ->with(['module_info'])
+                ->with(['moduleInfo'])
                 ->find($id);
             if (!$info) {
                 throw new Exception('申请记录不存在或已删除');
@@ -55,6 +55,7 @@ class ApproveInfoService
         $data = [
             'module' => $module,
             'user_id' => $userid,
+            'department' => $user['department'],
             'status' => CommonConstant::STATUS_2,
             'approve_num' => $approve_num,
             'cur_num' => 0,
@@ -190,7 +191,7 @@ class ApproveInfoService
     }
 
     /**
-     * 列表
+     * 我的申请记录
      *
      * @param $module
      * @param $status
@@ -227,29 +228,44 @@ class ApproveInfoService
     /**
      * 详情/信息
      *
-     * @param $id
-     * @param $user
-     * @param $type
+     * @param integer $id
+     * @param mixed $user 有数据=审批申请详情,没有数据=审批详情
+     * @param string $type
      **/
     public static function get_detail($id, $user, $type)
     {
-        $userid = $user['userid'];
-        $info = ApproveInfo::field('user_id,is_deleted', true)
-            ->where('user_id', $userid)
+        $where = $user ? ['user_id' => $user['userid']] : [];
+        $info = ApproveInfo::field('is_deleted', true)
+            ->where($where)
             ->where('is_deleted', CommonConstant::IS_DELETED_0);
         if ($type == 'detail') {
-            $info->with(['module_info', 'approve' => function ($query) {
-                $query->field('is_deleted,create_at', true)
-                    ->with(['user' => function ($query) {
-                        $query->field('userid,headimg,name');
-                    }]);
-            }]);
+            $info->with([
+                'moduleInfo',
+                'approve' => function ($query) {
+                    $query->field('is_deleted,create_at', true)
+                        ->with(['user' => function ($query) {
+                            $query->field('userid,headimg,name');
+                        }]);
+                },
+                'approveCopy' => function ($query) {
+                    $query->field('is_deleted,create_at', true)
+                        ->with(['user' => function ($query) {
+                            $query->field('userid,headimg,name');
+                        }]);
+                }
+            ]);
             $info = $info->find($id);
             if ($info) {
-                $info['department'] = Department::where('dept_id', 'in', $user['department'])->field('dept_id,name')->select();
+                if (!$user) {
+                    // 审批申请人信息
+                    $approve_info_user = User::field('userid,name')->where('userid', 'in', $info['user_id'])->find();
+                    $info['approve_info_user'] = $approve_info_user;
+                }
+                $department_data = Department::field('dept_id,name')->where('dept_id', 'in', $info['department'])->select();
+                $info['department_data'] = $department_data;
             }
         } else {
-            $info->with(['module_info']);
+            $info->with(['moduleInfo']);
             $info = $info->find($id);
         }
         $info = self::get_item($info, $type);
@@ -268,19 +284,24 @@ class ApproveInfoService
             case CommonConstant::MODULE_5:
                 if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
                     // 审批中或审批驳回 才关联 审批信息
-                    $list = $list->with(['peer_user' => function ($query) {
-                        $query->field('id,info_id,name');
-                    }, 'approveOne' => function ($query) use ($status) {
-                        $query->field('id,info_id,status,approve_user')
-                            ->where('status', $status)
-                            ->with(['user' => function ($query) {
-                                $query->field('userid,name');
-                            }]);
-                    }]);
+                    $list = $list->with([
+                        'peer_user' => function ($query) {
+                            $query->field('id,info_id,name');
+                        },
+                        'approveOne' => function ($query) use ($status) {
+                            $query->field('id,info_id,status,approve_user')
+                                ->where('status', $status)
+                                ->with(['user' => function ($query) {
+                                    $query->field('userid,name');
+                                }]);
+                        }
+                    ]);
                 } else {
-                    $list = $list->with(['peer_user' => function ($query) {
-                        $query->field('id,info_id,name');
-                    }]);
+                    $list = $list->with([
+                        'peer_user' => function ($query) {
+                            $query->field('id,info_id,name');
+                        },
+                    ]);
                 }
                 break;
         }

+ 25 - 2
application/common/service/ApproveService.php

@@ -15,7 +15,7 @@ class ApproveService
 {
 
     /**
-     * 列表
+     * 审批列表
      *
      * @param $status
      * @param $module
@@ -78,7 +78,7 @@ class ApproveService
             })
             ->join('__APPROVE_INFO__ approveInfo', 'approve.info_id = approveInfo.id', 'INNER');
         if ($status == 1) {
-            // 待处理 才关联 审批信息
+            // 待处理(待审批 审批中) 才关联 审批信息
             $list->with(['approveInfoUser' => function ($query) {
                 $query->field('userid,name');
             }, 'approveOne' => function ($query) {
@@ -124,6 +124,29 @@ class ApproveService
     }
 
     /**
+     * 详情
+     *
+     * @param integer $id
+     * @param mixed $user
+     * @param string $type
+     **/
+    public static function get_detail($id, $user,$type)
+    {
+        $userid = $user['userid'];
+        $info = Approve::field('info_id,status')
+            ->where('approve_user', $userid)
+            ->where('is_deleted', CommonConstant::IS_DELETED_0)
+            ->find($id);
+        $data = [];
+        if ($info) {
+            $data = ApproveInfoService::get_detail($info['info_id'], '', $type);
+            $data['approve_id'] = $id;
+            $data['approve_status'] = $info['status'];
+        }
+        return $data;
+    }
+
+    /**
      * 拼接查询字段
      */
     public static function getAliasField($field, $aliasName)