zhanglinxin il y a 1 an
Parent
commit
9a66d73fd6

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

@@ -251,12 +251,17 @@ class Approveinfo extends Base
      *          @Apidoc\Returned("avatar", type="string", desc="头像地址"),
      *      ),
      * )
-     * @Apidoc\Returned("approve_info_user", type="object", desc="申请人信息",
+     * @Apidoc\Returned("create_user", type="object", desc="提交人信息",
      *     @Apidoc\Returned("userid", type="string", desc="用户userid"),
      *     @Apidoc\Returned("name", type="string", desc="用户姓名"),
      *     @Apidoc\Returned("avatar", type="string", desc="头像地址"),
      *     @Apidoc\Returned("create_at", type="string", desc="日期"),
      * )
+     * @Apidoc\Returned("apply_user", type="object", desc="申请人信息",
+     *     @Apidoc\Returned("userid", type="string", desc="用户userid"),
+     *     @Apidoc\Returned("name", type="string", desc="用户姓名"),
+     *     @Apidoc\Returned("avatar", type="string", desc="头像地址"),
+     * )
      * @Apidoc\Returned("department_data", type="array", desc="所在部门列表",
      *     @Apidoc\Returned("dept_id", type="string", desc="部门ID"),
      *     @Apidoc\Returned("name", type="string", desc="部门名称"),

+ 78 - 39
application/common/service/ApproveInfoService.php

@@ -33,17 +33,18 @@ class ApproveInfoService
     public static function create($id, $module, $params, $user)
     {
         $userid = $user['userid'];
+        $apply_user_id = $userid;
         $department = $user['department'];
-        $apply_user_id = $params['apply_user_id'];
 
         // 申请人信息
         if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
-            $apply_user = User::field('department')
-                ->where('userid', $apply_user_id)
+            $apply_user = User::field('userid,department')
+                ->where('userid', $params['apply_user_id'])
                 ->find();
             if (!$apply_user) {
                 except('申请人信息不存在或已删除');
             }
+            $apply_user_id = $apply_user['userid'];
             $department = $apply_user['department'];
         }
 
@@ -582,10 +583,8 @@ class ApproveInfoService
      **/
     public static function get_detail($id, $user, $type)
     {
-        $where = $user ? ['user_id' => $user['userid']] : [];
         $info = ApproveInfo::field('is_deleted', true)
-            ->where($where)
-            ->where(function ($query) use ($user) {
+            ->when($user,function ($query) use ($user) {
                 $query->where('user_id', $user['userid'])->whereOr('apply_user_id', $user['userid']);
             })
             ->where('is_deleted', CommonConstant::IS_DELETED_0);
@@ -611,21 +610,59 @@ class ApproveInfoService
             ]);
             $info = $info->find($id);
             if ($info) {
-                // 审批申请人信息
+                $module = $info['module'];
+                // 审批提交人申请人信息
                 if ($user) {
-                    $approve_info_user = [
+                    $apply_user = [
                         'userid' => $user['userid'],
                         'name' => $user['name'],
                         'avatar' => $user['avatar'],
-                        'create_at' => $info['create_at'],
                     ];
+                    $create_user = $apply_user;
+                    $create_user['create_at'] = $info['create_at'];
+
+                    if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
+                        if($info['userid'] != $info['apply_user_id']){
+                            $apply_user_info = User::field('userid,name,avatar')
+                                ->where('userid', $info['apply_user_id'])
+                                ->find();
+                            $apply_user = [
+                                'userid' => $apply_user_info['userid'],
+                                'name' => $apply_user_info['name'],
+                                'avatar' => $apply_user_info['avatar'],
+                            ];
+                        }
+                    }
                 } else {
-                    $approve_info_user = User::field('userid,name,avatar')->where('userid', $info['user_id'])->find();
-                    $approve_info_user['create_at'] = $info['create_at'];
+                    $apply_user = User::field('userid,name,avatar')
+                        ->where('userid', $info['apply_user_id'])
+                        ->find();
+                    $apply_user = [
+                        'userid' => $apply_user['userid'],
+                        'name' => $apply_user['name'],
+                        'avatar' => $apply_user['avatar'],
+                    ];
+                    $create_user = $apply_user;
+                    $create_user['create_at'] = $info['create_at'];
+                    if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
+                        if($info['userid'] != $info['apply_user_id']){
+                            $apply_user_info = User::field('userid,name,avatar')
+                                ->where('userid', $info['userid'])
+                                ->find();
+                            $create_user = [
+                                'userid' => $apply_user_info['userid'],
+                                'name' => $apply_user_info['name'],
+                                'avatar' => $apply_user_info['avatar'],
+                            ];
+                        }
+                    }
                 }
                 // 部门列表
-                $department_data = Department::field('dept_id,name')->where('dept_id', 'in', $info['department'])->select();
-                $info['approve_info_user'] = $approve_info_user;
+                $department_data = Department::field('dept_id,name')
+                    ->where('dept_id', 'in', $info['department'])
+                    ->select();
+                $info['create_user'] = $create_user;
+                $info['apply_user'] = $apply_user;
                 $info['department_data'] = $department_data;
             }
         } else {
@@ -634,7 +671,7 @@ class ApproveInfoService
             ]);
             $info = $info->find($id);
         }
-        $info = self::get_item($info, $type);
+        $info = self::get_item($info,$type);
         return $info;
     }
 
@@ -791,31 +828,33 @@ class ApproveInfoService
      **/
     public static function get_item($info, $type)
     {
-        $module = $info['module'];
-        switch ($module) {
-            case CommonConstant::MODULE_1:
-                if ($type == 'detail') {
-                    $info['apply_goods'] = $info->applyGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
-                } else {
-                    $info->apply_goods;
-                }
-                break;
-            case CommonConstant::MODULE_3:
-                if ($type == 'detail') {
-                    $info['stock_goods'] = $info->stockGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
-                } else {
-                    $info->stock_goods;
-                }
-                break;
-            case CommonConstant::MODULE_4:
-                break;
-            case CommonConstant::MODULE_5:
-                if ($type == 'detail') {
-                    $info['peer_user'] = $info->peerUser()->field('id,info_id,name')->select();
-                } else {
-                    $info->peer_user;
-                }
-                break;
+        if($info){
+            $module = $info['module'];
+            switch ($module) {
+                case CommonConstant::MODULE_1:
+                    if ($type == 'detail') {
+                        $info['apply_goods'] = $info->applyGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
+                    } else {
+                        $info->apply_goods;
+                    }
+                    break;
+                case CommonConstant::MODULE_3:
+                    if ($type == 'detail') {
+                        $info['stock_goods'] = $info->stockGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
+                    } else {
+                        $info->stock_goods;
+                    }
+                    break;
+                case CommonConstant::MODULE_4:
+                    break;
+                case CommonConstant::MODULE_5:
+                    if ($type == 'detail') {
+                        $info['peer_user'] = $info->peerUser()->field('id,info_id,name')->select();
+                    } else {
+                        $info->peer_user;
+                    }
+                    break;
+            }
         }
         return $info;
     }