zhanglinxin 1 年之前
父節點
當前提交
2b710d04cf

+ 2 - 16
application/api/controller/Approve.php

@@ -114,14 +114,7 @@ class Approve extends Base
         $status = input('status');
         $remark = input('remark');
         $params = compact("id", "status", "remark");
-        Db::startTrans();
-        try {
-            ApproveService::make($id, $params, $this->user, 'audit');
-            Db::commit();
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
+        ApproveService::make($id, $params, $this->user, 'audit');
         $this->success('确认成功');
     }
 
@@ -161,14 +154,7 @@ class Approve extends Base
         $remark = input('remark');
         $peer_user = input('peer_user');
         $params = compact("id", "module", "reason", "desc", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user");
-        Db::startTrans();
-        try {
-            ApproveService::make($id, $params, $this->user, 'edit');
-            Db::commit();
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
+        ApproveService::make($id, $params, $this->user, 'edit');
         $this->success('修改成功');
     }
 

+ 3 - 0
application/api/controller/Approveinfo.php

@@ -77,6 +77,7 @@ class Approveinfo extends Base
      */
     public function create()
     {
+        // {"id": "","module": "1","reason": "测试","type": "1","desc": "","start_time": "","end_time": "","document": "","images": "","remark": "","total_amount": "1000","pay_type": "1","word_size": "","number": "","is_who": "","start_am": "","end_am": "","time": "","reach_address": "","end_address": "","scope": "","legal_opinion": "","founder": "","serial_number": "","apply_date": "","degree": "","department": "","department_sign": "","approve_user": "1925696723824730358","copy_user": "","apply_goods": [{"id": "1","goods_category_first": "1","goods_category_id": "3","goods_no": "100001","goods_name": "医疗口罩一次性","goods_brand": "一次性口罩","goods_stock": [{"id": "1","name": "均码,白色","price": "1","stock": "110"},{"id": "2","name": "均码,蓝色","price": "1","stock": "100"},{"id": "19","name": "均码,红色","price": "1","stock": "120"}]},{"id": "2","goods_category_first": "1","goods_category_id": "3","goods_no": "100002","goods_name": "84消毒液","goods_brand": "安其生","goods_stock": [{"id": "3","name": "380ml,低浓度","price": "1","stock": "110"},{"id": "4","name": "380ml,高浓度","price": "1","stock": "100"}]},{"id": "","goods_category_first": "1","goods_category_id": "3","goods_no": "100003","goods_name": "一次性手套丁腈橡胶","goods_brand": "万力","goods_stock": [{"name": "白色","price": "0.2","stock": "110"},{"name": "蓝色","price": "0.2","stock": "100"}]}],"peer_user": [{"is_who": "","user_id": "","name": "","desc": ""}]}
         $id = input('id');
         $module = input('module');
         $reason = input('reason');
@@ -129,6 +130,8 @@ class Approveinfo extends Base
      * @Apidoc\Returned("order_no", type="string", desc="审批编号")
      * @Apidoc\Returned("apply_date", type="string", desc="申请日期")
      * @Apidoc\Returned("reason", type="string", desc="事由")
+     * @Apidoc\Returned("type", type="string", desc="类型:采购类型,呈批类型,出差类型,请假类型,维修类型,合同类型")
+     * @Apidoc\Returned("desc", type="string", desc="缓急程度,具体内容,来文单位")
      * @Apidoc\Returned("start_time", type="string", desc="开始时间")
      * @Apidoc\Returned("end_time", type="string", desc="结束时间")
      * @Apidoc\Returned("approve_one", type="object", desc="审批人信息 status=2,4",

+ 1 - 1
application/common/model/ApplyGoods.php

@@ -10,7 +10,7 @@ use think\Model;
 class ApplyGoods extends Model
 {
     // 表名
-    protected $name = 'apply_goods';
+    protected $name = 'approve_apply_goods';
 
     // 追加属性
     protected $append = [

+ 15 - 9
application/common/model/ApproveInfo.php

@@ -30,27 +30,33 @@ class ApproveInfo extends Model
         ], $models);
     }
 
-    // 关联出差同行人员 (我的申请记录 详情/信息)
-    public function peerUser()
-    {
-        return $this->hasMany(ApproveEvectionPeerUser::class, 'info_id', 'id');
-    }
-
     // 关联审批 (详情/信息)
     public function approve()
     {
         return $this->hasMany(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);
+    }
+
     // 关联审批 (我的申请记录)
     public function approveOne()
     {
         return $this->hasOne(Approve::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
     }
 
-    // 关联抄送 (详情/信息)
-    public function approveCopy()
+    // 关联出差同行人员 (我的申请记录 详情/信息)
+    public function peerUser()
     {
-        return $this->hasMany(ApproveCopy::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
+        return $this->hasMany(ApproveEvectionPeerUser::class, 'info_id', 'id');
+    }
+
+    // 关联申购商品 (我的申请记录 详情/信息)
+    public function applyGoods()
+    {
+        return $this->hasMany(ApplyGoods::class, 'info_id', 'id');
     }
 }

+ 71 - 27
application/common/service/ApproveInfoService.php

@@ -37,7 +37,9 @@ class ApproveInfoService
             $info = ApproveInfo::field('user_id,is_deleted', true)
                 ->where('user_id', $userid)
                 ->where('is_deleted', CommonConstant::IS_DELETED_0)
-                ->with(['moduleInfo'])
+                ->with([
+                    'moduleInfo'
+                ])
                 ->find($id);
             if (!$info) {
                 except('申请记录不存在或已删除');
@@ -413,15 +415,19 @@ class ApproveInfoService
 
         $data = [];
         foreach ($params as $value) {
-            $data[] = [
-                'info_id' => $info_id,
-                'is_who' => $value['is_who'],
-                'user_id' => isset($value['user_id']) ? $value['user_id'] : '',
-                'name' => $value['name'],
-                'desc' => isset($value['desc']) ? $value['desc'] : '',
-            ];
+            if (isset($value['name']) && !empty($value['name'])) {
+                $data[] = [
+                    'info_id' => $info_id,
+                    'is_who' => $value['is_who'],
+                    'user_id' => isset($value['user_id']) ? $value['user_id'] : '',
+                    'name' => $value['name'],
+                    'desc' => isset($value['desc']) ? $value['desc'] : '',
+                ];
+            }
+        }
+        if ($data) {
+            ApproveEvectionPeerUser::insertAll($data);
         }
-        ApproveEvectionPeerUser::insertAll($data);
     }
 
     /**
@@ -562,7 +568,9 @@ class ApproveInfoService
                 $info['department_data'] = $department_data;
             }
         } else {
-            $info->with(['moduleInfo']);
+            $info->with([
+                'moduleInfo'
+            ]);
             $info = $info->find($id);
         }
         $info = self::get_item($info, $type);
@@ -571,20 +579,45 @@ class ApproveInfoService
 
     public static function get_with($list, $module, $status)
     {
+        $field = 'id,info_id,status,approve_user';
         switch ($module) {
             case CommonConstant::MODULE_1:
-            case CommonConstant::MODULE_2:
-            case CommonConstant::MODULE_3:
-            case CommonConstant::MODULE_4:
                 if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
                     // 审批中或审批驳回 才关联 审批人信息
                     $list = $list->with([
-                        'approveOne' => function ($query) use ($status) {
-                            $query->field('id,info_id,status,approve_user')
+                        'approveOne' => function ($query) use ($status, $field) {
+                            $query->field($field)
                                 ->where('status', $status)
                                 ->with(['user' => function ($query) {
                                     $query->field('userid,name');
                                 }]);
+                        },
+                        'applyGoods' => function ($query) {
+                            $query->field('id,info_id,goods_name');
+                        },
+                    ]);
+                } else {
+                    $list = $list->with([
+                        'applyGoods' => function ($query) {
+                            $query->field('id,info_id,goods_name');
+                        },
+                    ]);
+                }
+                break;
+            case CommonConstant::MODULE_2:
+            case CommonConstant::MODULE_3:
+            case CommonConstant::MODULE_4:
+                if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
+                    // 审批中或审批驳回 才关联 审批人信息
+                    $list = $list->with([
+                        'approveOne' => function ($query) use ($status, $field) {
+                            $query->field($field)
+                                ->where('status', $status)
+                                ->with([
+                                    'user' => function ($query) {
+                                        $query->field('userid,name');
+                                    }
+                                ]);
                         }
                     ]);
                 }
@@ -593,20 +626,22 @@ class ApproveInfoService
                 if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
                     // 审批中或审批驳回 才关联 审批人信息
                     $list = $list->with([
-                        'approveOne' => function ($query) use ($status) {
-                            $query->field('id,info_id,status,approve_user')
+                        'approveOne' => function ($query) use ($status, $field) {
+                            $query->field($field)
                                 ->where('status', $status)
-                                ->with(['user' => function ($query) {
-                                    $query->field('userid,name');
-                                }]);
+                                ->with([
+                                    'user' => function ($query) {
+                                        $query->field('userid,name');
+                                    }
+                                ]);
                         },
-                        'peer_user' => function ($query) {
+                        'peerUser' => function ($query) {
                             $query->field('id,info_id,name');
                         },
                     ]);
                 } else {
                     $list = $list->with([
-                        'peer_user' => function ($query) {
+                        'peerUser' => function ($query) {
                             $query->field('id,info_id,name');
                         },
                     ]);
@@ -621,12 +656,14 @@ class ApproveInfoService
                 if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
                     // 审批中或审批驳回 才关联 审批人信息
                     $list = $list->with([
-                        'approveOne' => function ($query) use ($status) {
-                            $query->field('id,info_id,status,approve_user')
+                        'approveOne' => function ($query) use ($status, $field) {
+                            $query->field($field)
                                 ->where('status', $status)
-                                ->with(['user' => function ($query) {
-                                    $query->field('userid,name');
-                                }]);
+                                ->with([
+                                    'user' => function ($query) {
+                                        $query->field('userid,name');
+                                    }
+                                ]);
                         }
                     ]);
                 }
@@ -639,6 +676,13 @@ class ApproveInfoService
     {
         $module = $info['module'];
         switch ($module) {
+            case CommonConstant::MODULE_1:
+                if ($type == 'detail') {
+                    $info['applyGoods'] = $info->applyGoods()->field('id,info_id,goods_name,total_amount,goods_data')->select();
+                } else {
+                    $info->applyGoods;
+                }
+                break;
             case CommonConstant::MODULE_5:
                 if ($type == 'detail') {
                     $info['peer_user'] = $info->peerUser()->field('id,info_id,name')->select();

+ 37 - 23
application/common/service/ApproveService.php

@@ -121,19 +121,26 @@ 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) {
-                $query->field('id,info_id,status,approve_user')
-                    ->where('status', CommonConstant::STATUS_2)
-                    ->with(['user' => function ($query) {
-                        $query->field('userid,name');
-                    }]);
-            }]);
+            $list->with([
+                'approveInfoUser' => function ($query) {
+                    $query->field('userid,name');
+                },
+                'approveOne' => function ($query) {
+                    $query->field('id,info_id,status,approve_user')
+                        ->where('status', CommonConstant::STATUS_2)
+                        ->with([
+                            'user' => function ($query) {
+                                $query->field('userid,name');
+                            }
+                        ]);
+                }
+            ]);
         } else {
-            $list->with(['approveInfoUser' => function ($query) {
-                $query->field('userid,name');
-            }]);
+            $list->with([
+                'approveInfoUser' => function ($query) {
+                    $query->field('userid,name');
+                }
+            ]);
         }
         $list = $list->limit($offset, $length)
             ->order('approve_id desc')
@@ -209,27 +216,34 @@ class ApproveService
             ])
             ->find($id);
         if (!$info) {
-            throw new Exception('审批记录不存在或已删除');
+            except('审批记录不存在或已删除');
         }
         if ($info->status != CommonConstant::STATUS_2) {
-            throw new Exception('非待处理状态无法操作');
+            except('非待处理状态无法操作');
         }
         $approve_info = $info->approve_info;
         if (!$approve_info) {
-            throw new Exception(CommonConstant::get_module_list()[$approve_info->module] . '记录不存在或已删除');
+            except(CommonConstant::get_module_list()[$approve_info->module] . '记录不存在或已删除');
         }
         if ($approve_info->status != CommonConstant::STATUS_2) {
-            throw new Exception('非待处理状态无法操作!');
+            except('非待处理状态无法操作!');
         }
 
-        switch ($type) {
-            case 'audit':
-                self::audit($info, $params['status'], $params['remark']);
-                break;
-            case 'edit':
-                self::edit($info, $params['module'], $params);
-                break;
+        Db::startTrans();
+        try {
+            switch ($type) {
+                case 'audit':
+                    self::audit($info, $params['status'], $params['remark']);
+                    break;
+                case 'edit':
+                    self::edit($info, $params['module'], $params);
+                    break;
+            }
+            Db::commit();
+        } catch (Exception $e) {
+            except('出现错误:' . $e->getMessage(), 2, $e);
         }
+        return true;
     }
 
     /**