zhanglinxin 1 年之前
父節點
當前提交
bd0fa22454

+ 185 - 2
application/api/controller/Approveinfo.php

@@ -26,7 +26,7 @@ class Approveinfo extends Base
      * @Apidoc\Method("POST")
      * @Apidoc\Param("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
      * @Apidoc\Param("id", type="integer", require=false, desc="申请ID 重新发起必传")
-     * @Apidoc\Param("reason", type="string", require=true, desc="出差事由")
+     * @Apidoc\Param("reason", type="string", require=true, desc="事由")
      * @Apidoc\Param("start_time", type="string", require=true, desc="开始时间")
      * @Apidoc\Param("end_time", type="string", require=true, desc="结束时间")
      * @Apidoc\Param("document", type="string", require=false, desc="附件(多个用英文逗号隔开)")
@@ -34,7 +34,7 @@ class Approveinfo extends Base
      * @Apidoc\Param("type", type="integer", require=true, desc="出差类型:1=市内,2=市外")
      * @Apidoc\Param("is_who", type="integer", require=false, desc="是否跨关内关外:0=否,1=是")
      * @Apidoc\Param("remark", type="string", require=false, desc="备注")
-     * @Apidoc\Param("peer_user", type="array", require=false, desc="同行员工数据",
+     * @Apidoc\Param("peer_user", type="array", require=false, desc="同行员工数据 module=5",
      *     @Apidoc\Param("is_who", type="integer", require=true, desc="是否外部人员:0=否,1=是"),
      *     @Apidoc\Param("user_id", type="string", require=false, desc="用户userid"),
      *     @Apidoc\Param("name", type="string", require=true, desc="姓名"),
@@ -70,4 +70,187 @@ class Approveinfo extends Base
         $this->success('申请已提交,请等待审核');
     }
 
+    /**
+     * 我的申请记录
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("page", type="integer",require=true, desc="页数")
+     * @Apidoc\Param("page_num", type="integer", require=true, desc="每页数量")
+     * @Apidoc\Param("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @Apidoc\Param("status", type="integer", require=true, desc="审核状态:2=审批中,3=审批通过,4=审批驳回,5=审批撤销")
+     * @Apidoc\Param("search", type="string", require=false, desc="搜索 事由 编号")
+     * @Apidoc\Returned("id", type="integer", desc="申请ID")
+     * @Apidoc\Returned("status", type="integer", desc="审核状态:2=审批中,3=审批通过,4=审批驳回,5=审批撤销")
+     * @Apidoc\Returned("create_at", type="string", desc="创建时间")
+     * @Apidoc\Returned("order_no", type="string", desc="审批编号")
+     * @Apidoc\Returned("apply_date", type="string", desc="申请日期")
+     * @Apidoc\Returned("reason", type="string", desc="事由")
+     * @Apidoc\Returned("start_time", type="string", desc="开始时间")
+     * @Apidoc\Returned("end_time", type="string", desc="结束时间")
+     * @Apidoc\Returned("peer_user", type="array", desc="同行人员列表 module=5",
+     *     @Apidoc\Returned("id", type="integer", desc="同行人员ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("name", type="string", desc="姓名"),
+     * )
+     * @Apidoc\Returned("approve_info", type="object", desc="审批信息",
+     *     @Apidoc\Returned("id", type="integer", desc="审批ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("approve_user", type="string", desc="审批人userid"),
+     *     @Apidoc\Returned("user", type="object", desc="审批人信息",
+     *          @Apidoc\Returned("userid", type="string", desc="用户userid"),
+     *          @Apidoc\Returned("name", type="string", desc="姓名"),
+     *      ),
+     * )
+     */
+    public function get_list()
+    {
+        $module = input('module');
+        $status = input('status');
+        $search = input('search');
+        $offset = $this->off_set;
+        $length = $this->page_num;
+        $list = ApproveInfoService::get_list($module, $status, $search, $offset, $length, $this->user);
+        $this->success('我的申请记录', $list);
+    }
+
+    /**
+     * 详情
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("id", type="integer",require=true, desc="申请ID")
+     * @Apidoc\Returned("id", type="integer", desc="申请ID")
+     * @Apidoc\Returned("module", type="integer", desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @Apidoc\Returned("module_id", type="integer", desc="对应模块ID")
+     * @Apidoc\Returned("status", type="integer", desc="审核状态:2=审批中,3=审批通过,4=审批驳回,5=审批撤销")
+     * @Apidoc\Returned("create_at", type="string", desc="创建时间")
+     * @Apidoc\Returned("order_no", type="string", desc="审批编号")
+     * @Apidoc\Returned("apply_date", type="string", desc="申请日期")
+     * @Apidoc\Returned("module_info", type="object", desc="模块信息",
+     *     @Apidoc\Returned("id", type="integer", desc="模块ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("create_at", type="string", desc="创建时间"),
+     *     @Apidoc\Returned("reason", type="string", desc="事由"),
+     *     @Apidoc\Returned("start_time", type="string", desc="开始时间"),
+     *     @Apidoc\Returned("end_time", type="string", desc="结束时间"),
+     *     @Apidoc\Returned("type", type="integer", desc="出差类型:1=市内,2=市外"),
+     *     @Apidoc\Returned("is_who", type="integer", desc="是否跨关内关外:0=否,1=是"),
+     *     @Apidoc\Returned("remark", type="string", desc="备注"),
+     *     @Apidoc\Returned("document_text", type="array", desc="附件列表"),
+     *     @Apidoc\Returned("images_text", type="array", desc="图片列表"),
+     * )
+     * @Apidoc\Returned("peer_user", type="array", desc="同行人员列表 module=5",
+     *     @Apidoc\Returned("id", type="integer", desc="同行人员ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("name", type="string", desc="姓名"),
+     * )
+     * @Apidoc\Returned("approve_info", type="object", desc="审批信息",
+     *     @Apidoc\Returned("id", type="integer", desc="审批ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("status", type="integer", desc="审批状态:1=待审批,2=审批中,3=审批通过,4=审批拒绝"),
+     *     @Apidoc\Returned("create_at", type="string", desc="创建时间"),
+     *     @Apidoc\Returned("approve_flow", type="integer", desc="流程批次"),
+     *     @Apidoc\Returned("approve_user", type="string", desc="审批人userid"),
+     *     @Apidoc\Returned("approve_time", type="string", desc="审批时间"),
+     *     @Apidoc\Returned("remark", type="string", desc="审批备注"),
+     *     @Apidoc\Returned("time", type="string", desc="审批时长(上一次审批完成到本次审批的时间,单位秒)"),
+     *     @Apidoc\Returned("time_text", type="string", desc="审批时长文本"),
+     *     @Apidoc\Returned("user", type="object", desc="审批人信息",
+     *          @Apidoc\Returned("userid", type="string", desc="用户userid"),
+     *          @Apidoc\Returned("name", type="string", desc="姓名"),
+     *      ),
+     * )
+     * @Apidoc\Returned("department", type="array", desc="所在部门列表",
+     *     @Apidoc\Returned("dept_id", type="string", desc="部门ID"),
+     *     @Apidoc\Returned("name", type="string", desc="部门名称"),
+     * )
+     */
+    public function get_detail()
+    {
+        $id = input('id');
+        $info = ApproveInfoService::get_detail($id, $this->user, 'detail');
+        $this->success('详情', $info);
+    }
+
+    /**
+     * 信息
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Desc("重新发起信息/修改信息")
+     * @Apidoc\Param("id", type="integer",require=true, desc="申请ID")
+     * @Apidoc\Returned("id", type="integer", desc="申请ID")
+     * @Apidoc\Returned("module", type="integer", desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @Apidoc\Returned("module_id", type="integer", desc="对应模块ID")
+     * @Apidoc\Returned("status", type="integer", desc="审核状态:2=审批中,3=审批通过,4=审批驳回,5=审批撤销")
+     * @Apidoc\Returned("create_at", type="string", desc="创建时间")
+     * @Apidoc\Returned("order_no", type="string", desc="审批编号")
+     * @Apidoc\Returned("apply_date", type="string", desc="申请日期")
+     * @Apidoc\Returned("module_info", type="object", desc="模块信息",
+     *     @Apidoc\Returned("id", type="integer", desc="模块ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("create_at", type="string", desc="创建时间"),
+     *     @Apidoc\Returned("reason", type="string", desc="事由"),
+     *     @Apidoc\Returned("start_time", type="string", desc="开始时间"),
+     *     @Apidoc\Returned("end_time", type="string", desc="结束时间"),
+     *     @Apidoc\Returned("type", type="integer", desc="出差类型:1=市内,2=市外"),
+     *     @Apidoc\Returned("is_who", type="integer", desc="是否跨关内关外:0=否,1=是"),
+     *     @Apidoc\Returned("remark", type="string", desc="备注"),
+     *     @Apidoc\Returned("document_text", type="array", desc="附件列表"),
+     *     @Apidoc\Returned("images_text", type="array", desc="图片列表"),
+     * )
+     * @Apidoc\Returned("peer_user", type="array", desc="同行人员列表 module=5",
+     *     @Apidoc\Returned("id", type="integer", desc="同行人员ID"),
+     *     @Apidoc\Returned("info_id", type="integer", desc="申请ID"),
+     *     @Apidoc\Returned("is_who", type="integer", desc="是否外部人员:0=否,1=是"),
+     *     @Apidoc\Returned("user_id", type="string", desc="用户userid"),
+     *     @Apidoc\Returned("name", type="string", desc="姓名"),
+     *     @Apidoc\Returned("desc", type="string", desc="备注"),
+     * )
+     **/
+    public function get_info()
+    {
+        $id = input('id');
+        $info = ApproveInfoService::get_detail($id, $this->user, 'info');
+        $this->success('信息', $info);
+    }
+
+    /**
+     * 催办
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("id", type="integer",require=true, desc="申请ID")
+     */
+    public function urging()
+    {
+        $id = input('id');
+        Db::startTrans();
+        try {
+            ApproveInfoService::make($id, $this->user, 'urging');
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('催办成功');
+    }
+
+    /**
+     * 撤销
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("id", type="integer",require=true, desc="申请ID")
+     */
+    public function cancel()
+    {
+        $id = input('id');
+        Db::startTrans();
+        try {
+            ApproveInfoService::make($id, $this->user, 'cancel');
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('撤销成功');
+    }
+
 }

+ 24 - 35
application/api/controller/Base.php

@@ -233,44 +233,33 @@ class Base extends Controller
     protected function checking($modulename, $controllername, $action_name)
     {
         $params = $this->request->post();
-        if ($controllername == 'approveflow') {
-            if ($action_name == 'get_data') {
-                $get_module_list = CommonConstant::get_module_list();
-                $rule = [
-                    'module|模块类型' => 'require|in:'.implode(',',array_keys($get_module_list)),
-                ];
-                $message = [
-                    'module.in' => '请选择正确的模块类型',
-                ];
-                $validate = new Validate($rule, $message);
-                if (!$validate->check($params)) {
-                    $this->error($validate->getError());
-                }
+        if (in_array($action_name,['get_data','create'])) {
+            $get_module_list = CommonConstant::get_module_list();
+            $rule = [
+                'module|模块类型' => 'require|in:'.implode(',',array_keys($get_module_list)),
+            ];
+            $message = [
+                'module.in' => '请选择正确的模块类型',
+            ];
+            $validate = new Validate($rule, $message);
+            if (!$validate->check($params)) {
+                $this->error($validate->getError());
             }
-        }
-        if ($controllername == 'evection') {
             if ($action_name == 'create') {
                 $id = $this->request->post('id');
-                $validate = new \app\common\validate\EvectionInfo();
+                $module = $this->request->post('module');
+                $validates = CommonConstant::get_module_validate_list();
+                $validate = $validates[$module];
+                $validate = new $validate;
                 if (!$validate->check($params, [], $id > 0 ? 'update' : 'create')) {
                     $this->error($validate->getError());
                 }
             }
+        }
+        if ($controllername == 'approveinfo') {
             if ($action_name == 'get_detail') {
                 $rule = [
-                    'id|出差参数' => 'require|gt:0',
-                ];
-                $message = [
-                    'audit_status.in' => '请选择正确的状态',
-                ];
-                $validate = new Validate($rule, $message);
-                if (!$validate->check($params)) {
-                    $this->error($validate->getError());
-                }
-            }
-            if ($action_name == 'urging') {
-                $rule = [
-                    'id|出差参数' => 'require|gt:0',
+                    'id|申请参数' => 'require|gt:0',
                 ];
                 $message = [];
                 $validate = new Validate($rule, $message);
@@ -278,9 +267,9 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'cancel') {
+            if ($action_name == 'get_info') {
                 $rule = [
-                    'id|出差参数' => 'require|gt:0',
+                    'id|申请参数' => 'require|gt:0',
                 ];
                 $message = [];
                 $validate = new Validate($rule, $message);
@@ -288,9 +277,9 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'get_info') {
+            if ($action_name == 'urging') {
                 $rule = [
-                    'id|出差参数' => 'require|gt:0',
+                    'id|申请参数' => 'require|gt:0',
                 ];
                 $message = [];
                 $validate = new Validate($rule, $message);
@@ -298,9 +287,9 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'again') {
+            if ($action_name == 'cancel') {
                 $rule = [
-                    'id|出差参数' => 'require|gt:0',
+                    'id|申请参数' => 'require|gt:0',
                 ];
                 $message = [];
                 $validate = new Validate($rule, $message);

+ 60 - 32
application/common/constant/CommonConstant.php

@@ -9,29 +9,41 @@ class CommonConstant
 {
 
     // 模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件
-    const MODULE_1 = '1';
-    const MODULE_2 = '2';
-    const MODULE_3 = '3';
-    const MODULE_4 = '4';
-    const MODULE_5 = '5';
-    const MODULE_6 = '6';
-    const MODULE_7 = '7';
-    const MODULE_8 = '8';
-    const MODULE_9 = '9';
-    const MODULE_10 = '10';
-    const MODULE_11 = '11';
-
-    const MODULE_1_MODEL = 'app\common\model\UserCandidate';
-    const MODULE_2_MODEL = 'app\common\model\UserHr';
-    const MODULE_3_MODEL = 'app\common\model\UserHeadhunter';
-    const MODULE_4_MODEL = 'app\common\model\UserSchool';
+    const MODULE_1 = 1;
+    const MODULE_2 = 2;
+    const MODULE_3 = 3;
+    const MODULE_4 = 4;
+    const MODULE_5 = 5;
+    const MODULE_6 = 6;
+    const MODULE_7 = 7;
+    const MODULE_8 = 8;
+    const MODULE_9 = 9;
+    const MODULE_10 = 10;
+    const MODULE_11 = 11;
+
+    const MODULE_1_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_2_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_3_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_4_MODEL = \app\common\model\ApproveEvection::class;
     const MODULE_5_MODEL = \app\common\model\ApproveEvection::class;
-    const MODULE_6_MODEL = 'app\admin\model\Admin';
-    const MODULE_7_MODEL = 'app\admin\model\Admin';
-    const MODULE_8_MODEL = 'app\admin\model\Admin';
-    const MODULE_9_MODEL = 'app\admin\model\Admin';
-    const MODULE_10_MODEL = 'app\admin\model\Admin';
-    const MODULE_11_MODEL = 'app\admin\model\Admin';
+    const MODULE_6_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_7_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_8_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_9_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_10_MODEL = \app\common\model\ApproveEvection::class;
+    const MODULE_11_MODEL = \app\common\model\ApproveEvection::class;
+
+    const MODULE_1_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_2_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_3_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_4_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_5_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_6_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_7_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_8_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_9_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_10_VALIDATE = \app\common\validate\ApproveEvection::class;
+    const MODULE_11_VALIDATE = \app\common\validate\ApproveEvection::class;
 
     public static function get_module_list()
     {
@@ -67,6 +79,22 @@ class CommonConstant
         ];
     }
 
+    public static function get_module_validate_list()
+    {
+        return [
+            self::MODULE_1 => self::MODULE_1_VALIDATE,
+            self::MODULE_2 => self::MODULE_2_VALIDATE,
+            self::MODULE_3 => self::MODULE_3_VALIDATE,
+            self::MODULE_4 => self::MODULE_4_VALIDATE,
+            self::MODULE_5 => self::MODULE_5_VALIDATE,
+            self::MODULE_6 => self::MODULE_6_VALIDATE,
+            self::MODULE_7 => self::MODULE_7_VALIDATE,
+            self::MODULE_8 => self::MODULE_8_VALIDATE,
+            self::MODULE_9 => self::MODULE_9_VALIDATE,
+            self::MODULE_10 => self::MODULE_10_VALIDATE,
+            self::MODULE_11 => self::MODULE_11_VALIDATE,
+        ];
+    }
 
     // 删除状态:0=正常,1=删除
     const IS_DELETED_0 = '0';
@@ -117,20 +145,20 @@ class CommonConstant
     }
 
 
-    // 审核状态:0=待审批,1=审批中,2=审批通过,3=审批驳回,4=审批撤销
-    const STATUS_0 = '0';
-    const STATUS_1 = '1';
-    const STATUS_2 = '2';
-    const STATUS_3 = '3';
-    const STATUS_4 = '4';
+    // 审核状态:1=待审批,2=审批中,3=审批通过,4=审批驳回,5=审批撤销
+    const STATUS_1 = 1;
+    const STATUS_2 = 2;
+    const STATUS_3 = 3;
+    const STATUS_4 = 4;
+    const STATUS_5 = 5;
 
     public static function get_status_list()
     {
         return [
-            self::STATUS_1 => '审批中',
-            self::STATUS_2 => '审批通过',
-            self::STATUS_3 => '审批驳回',
-            self::STATUS_4 => '审批撤销',
+            self::STATUS_2 => '审批中',
+            self::STATUS_3 => '审批通过',
+            self::STATUS_4 => '审批驳回',
+            self::STATUS_5 => '审批撤销',
         ];
     }
 }

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

@@ -0,0 +1,23 @@
+<?php
+
+namespace app\common\model;
+
+use app\common\constant\CommonConstant;
+use think\Model;
+
+/**
+ * 审批抄送模型
+ */
+class ApproveCopy extends Model
+{
+    // 表名
+    protected $name = 'approve_copy';
+
+
+    // 关联用户
+    public function user()
+    {
+        return $this->belongsTo(User::class, 'approve_user', 'userid')->where('is_deleted',CommonConstant::IS_DELETED_0);
+    }
+
+}

+ 0 - 20
application/common/model/ApproveEvection.php

@@ -2,7 +2,6 @@
 
 namespace app\common\model;
 
-use app\common\constant\CommonConstant;
 use think\Model;
 
 /**
@@ -32,23 +31,4 @@ class ApproveEvection extends Model
         return $value ? explode(',', $value) : [];
     }
 
-
-    // 关联出差同行人员
-    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 approveInfo()
-    {
-        return $this->hasOne(Approve::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0)->where('approve_type', CommonConstant::TYPE_1);
-    }
-
 }

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

@@ -15,22 +15,8 @@ class ApproveInfo extends Model
 
     // 追加属性
     protected $append = [
-        'document_text',
-        'images_text',
-    ];
-
-
-    public function getDocumentTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['document']) ? $data['document'] : '');
-        return $value ? explode(',', $value) : [];
-    }
 
-    public function getImagesTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['images']) ? $data['images'] : '');
-        return $value ? explode(',', $value) : [];
-    }
+    ];
 
 
     // 审批多态显示
@@ -39,7 +25,7 @@ class ApproveInfo extends Model
         $models = CommonConstant::get_module_model_list();
 
         return $this->morphTo([
-            'group_id',
+            'module',
             'module_id'
         ], $models);
     }
@@ -50,16 +36,16 @@ class ApproveInfo extends Model
         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 approveInfo()
     {
-        return $this->hasOne(Approve::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0)->where('approve_type', CommonConstant::TYPE_1);
+        return $this->hasOne(Approve::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
     }
 
 }

+ 133 - 102
application/common/service/ApproveInfoService.php

@@ -3,11 +3,11 @@
 namespace app\common\service;
 
 use app\common\constant\CommonConstant;
-use app\common\model\Department;
 use app\common\model\Approve;
-use app\common\model\ApproveInfo;
-use app\common\model\ApproveEvection;
+use app\common\model\ApproveCopy;
 use app\common\model\ApproveEvectionPeerUser;
+use app\common\model\ApproveInfo;
+use app\common\model\Department;
 use app\common\model\User;
 use think\Exception;
 
@@ -25,30 +25,36 @@ class ApproveInfoService
      * @param $params
      * @param $user
      **/
-    public static function create($module,$id,$params, $user)
+    public static function create($module, $id, $params, $user)
     {
+
         $userid = $user['userid'];
         // 编辑
         if ($id > 0) {
             $info = ApproveInfo::field('user_id,is_deleted', true)
                 ->where('user_id', $userid)
                 ->where('is_deleted', CommonConstant::IS_DELETED_0)
+                ->with(['module_info'])
                 ->find($id);
             if (!$info) {
-                throw new Exception('出差记录不存在或已删除');
+                throw new Exception('申请记录不存在或已删除');
+            }
+            if (!$info['module_info']) {
+                throw new Exception(CommonConstant::get_module_list()[$module] . '记录不存在或已删除');
             }
-            if($info->status != CommonConstant::STATUS_3){
+            if ($info->status != CommonConstant::STATUS_4) {
                 throw new Exception('非审批驳回状态无法操作');
             }
         }
 
-        $order_no = get_order_sn($user->id);
+        $order_no = get_order_sn($user['id']);
         $approve_user = explode(',', $params['approve_user']);
         $copy_user = explode(',', $params['copy_user']);
         $approve_num = count($approve_user);
         $data = [
             'module' => $module,
             'user_id' => $userid,
+            'status' => CommonConstant::STATUS_2,
             'approve_num' => $approve_num,
             'cur_num' => 0,
             'order_no' => $order_no,
@@ -60,155 +66,180 @@ class ApproveInfoService
         if ($id > 0) {
             // 编辑出差申请
             $save_data = [
-                'status' => CommonConstant::STATUS_1,
                 'create_at' => date('Y-m-d H:i:s'),
             ];
             $data = array_merge($data, $save_data);
             $info->save($data);
 
-            // 编辑审批
-            self::create_approve($id, $approve_user, $copy_user,'create');
-
-            // 编辑同行人员
-            self::create_peer_user($id, $params['peer_user'],'update');
-
+            // 编辑对应模块
+            self::create_module($id, $module, $params, $info, 'update');
 
+            // 编辑审批抄送
+            self::create_approve($id, $approve_user, $copy_user, 'update');
         } else {
             // 添加审批申请
             $info = ApproveInfo::create($data);
+            $info_id = $info->id;
 
             // 添加对应模块
-            self::create_module($module,$params);
-
-            // 添加审批
-            self::create_approve($info->id, $approve_user, $copy_user);
+            $module_data = self::create_module($info_id, $module, $params, [], 'create');
+            $info->save(['module_id' => $module_data->id]);
 
-            // 添加同行人员
-            self::create_peer_user($info->id, $params['peer_user']);
+            // 添加审批抄送
+            self::create_approve($info_id, $approve_user, $copy_user, 'create');
+        }
+    }
 
+    // 添加对应模块
+    public static function create_module($info_id, $module, $params, $info, $type)
+    {
+        $data['info_id'] = $info_id;
+        $data['reason'] = $params['reason'];
+        $data['start_time'] = $params['start_time'];
+        $data['end_time'] = $params['end_time'];
+        $data['document'] = $params['document'];
+        $data['images'] = $params['images'];
+        $data['type'] = $params['type'];
+        $data['is_who'] = $params['is_who'];
+        $data['remark'] = $params['remark'];
+        if ($type == 'update') {
+            $info->module_info->save($data);
+        } else {
+            $models = CommonConstant::get_module_model_list();
+            $model = $models[$module];
+            $module_data = $model::create($data);
+        }
 
+        switch ($module) {
+            case CommonConstant::MODULE_5:
+                self::create_peer_user($info_id, $params['peer_user'], $type);
+                break;
         }
+
+        return $module_data;
     }
 
-    protected static function create_module($module,$params){
-        $data = [
-            'module' => $module,
-            'user_id' => $userid,
-            'approve_num' => $approve_num,
-            'cur_num' => 0,
-            'order_no' => $order_no,
-            'apply_date' => date("Y-m-d"),
-            'reason' => $params['reason'],
-            'start_time' => $params['start_time'],
-            'end_time' => $params['end_time'],
-            'document' => $params['document'],
-            'images' => $params['images'],
-            'type' => $params['type'],
-            'is_who' => $params['is_who'],
-            'remark' => $params['remark'],
-        ];
+    // 添加同行人员
+    public static function create_peer_user($info_id, $params, $type)
+    {
+        if (!$params) {
+            return true;
+        }
 
-        $models = CommonConstant::get_module_model_list();
-        $models = $models[$module] ?? '';
+        if ($type == 'update') {
+            ApproveEvectionPeerUser::where('info_id', $info_id)->delete();
+        }
+
+        $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'] : '',
+            ];
+        }
+        ApproveEvectionPeerUser::insertAll($data);
     }
 
-    protected static function create_approve($info_id, $approve_user, $copy_user,$type = 'create')
+    // 添加审批抄送
+    public static function create_approve($info_id, $approve_user, $copy_user, $type)
     {
-        if($type == 'update'){
+        if ($type == 'update') {
             Approve::where('info_id', $info_id)->delete();
+            ApproveCopy::where('info_id', $info_id)->delete();
         }
 
         $data = [];
+        $copy_data = [];
         $flow_num = 0;
+        $copy_num = 0;
         $create_at = date('Y-m-d H:i:s');
         // 审批人
         foreach ($approve_user as $key => $value) {
             $flow_num++;
             $data[] = [
                 'info_id' => $info_id,
+                'create_at' => $create_at,
+                'status' => $flow_num == 1 ? CommonConstant::STATUS_2 : CommonConstant::STATUS_1,
                 'approve_flow' => $flow_num,
-                'approve_type' => CommonConstant::TYPE_1,
+//                'approve_type' => CommonConstant::TYPE_1,
                 'approve_user' => $value,
                 'approve_time' => $create_at,
-                'create_at' => $create_at,
-                'status' => $flow_num == 1 ? CommonConstant::STATUS_1 : CommonConstant::STATUS_0,
             ];
         }
         // 抄送人
         foreach ($copy_user as $key => $value) {
-            $data[] = [
+            $copy_num++;
+            $copy_data[] = [
                 'info_id' => $info_id,
-                'approve_flow' => 0,
-                'approve_type' => CommonConstant::TYPE_2,
-                'approve_user' => $value,
-                'approve_time' => $create_at,
                 'create_at' => $create_at,
-                'status' => CommonConstant::STATUS_0,
+                'approve_flow' => $copy_num,
+                'approve_user' => $value,
             ];
         }
-        Approve::insertAll($data);
-    }
-
-    protected static function create_peer_user($info_id, $params,$type = 'create')
-    {
-        if (!$params) {
-            return true;
-        }
-
-        if($type == 'update'){
-            ApproveEvectionPeerUser::where('info_id', $info_id)->delete();
+        if ($data) {
+            Approve::insertAll($data);
         }
-
-        $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 ($copy_data) {
+            ApproveCopy::insertAll($copy_data);
         }
-        ApproveEvectionPeerUser::insertAll($data);
     }
 
-
     /**
      * 列表
      *
+     * @param $module
      * @param $status
      * @param $search
      * @param $offset
      * @param $length
      * @param $user
      **/
-    public static function get_list($status, $search, $offset, $length, $user)
+    public static function get_list($module, $status, $search, $offset, $length, $user)
     {
+        if (!array_key_exists($module, CommonConstant::get_module_list())) {
+            return [];
+        }
+        if (!array_key_exists($status, CommonConstant::get_status_list())) {
+            return [];
+        }
+
         $userid = $user['userid'];
-        $list = ApproveInfo::field('id,status,create_at,order_no,reason,start_time,end_time')
+        $list = ApproveInfo::field('module,module_id,user_id,is_deleted', true)
+            ->where('module', $module)
             ->where('user_id', $userid)
+            ->where('status', $status)
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
-            ->when(array_key_exists($status, CommonConstant::get_status_list()), function ($query) use ($status) {
-                $query->where('status', $status);
-            })
             ->when($search, function ($query) use ($search) {
                 $query->where('order_no|reason', 'like', '%' . $search . '%');
-            })
-            ->with(['peer_user' => function ($query) {
-                $query->field('id,info_id,name');
-            }, 'approve_info' => function ($query) use ($status) {
-                $query->field('id,info_id,status,approve_user')
-                    ->where('status', $status)
-                    ->with(['user' => function ($query) {
-                        $query->field('userid,name');
-                    }]);
-            }])
-            ->limit($offset, $length)
+            });
+        $list = self::get_with($list, $module, $status);
+        $list = $list->limit($offset, $length)
             ->order('id desc')
             ->select();
         return $list;
     }
 
+    public static function get_with($list, $module, $status)
+    {
+        switch ($module) {
+            case CommonConstant::MODULE_5:
+                $list = $list->with(['peer_user' => function ($query) {
+                    $query->field('id,info_id,name');
+                }, 'approve_info' => function ($query) use ($status) {
+                    $query->field('id,info_id,status,approve_user')
+                        ->where('status', $status)
+                        ->with(['user' => function ($query) {
+                            $query->field('userid,name');
+                        }]);
+                }]);
+                break;
+        }
+        return $list;
+    }
+
     /**
      * 详情/信息
      *
@@ -216,14 +247,14 @@ class ApproveInfoService
      * @param $user
      * @param $type
      **/
-    public static function get_detail($id, $user,$type)
+    public static function get_detail($id, $user, $type)
     {
         $userid = $user['userid'];
-        if($type == 'detail'){
+        if ($type == 'detail') {
             $info = ApproveInfo::field('user_id,is_deleted', true)
                 ->where('user_id', $userid)
                 ->where('is_deleted', CommonConstant::IS_DELETED_0)
-                ->with(['peer_user' => function ($query) {
+                ->with(['module_info', 'peer_user' => function ($query) {
                     $query->field('id,info_id,name');
                 }, 'approve' => function ($query) {
                     $query->field('is_deleted,create_at', true)
@@ -235,11 +266,11 @@ class ApproveInfoService
             if ($info) {
                 $info['department'] = Department::where('dept_id', 'in', $user['department'])->field('dept_id,name')->select();
             }
-        } else{
+        } else {
             $info = ApproveInfo::field('user_id,is_deleted', true)
                 ->where('user_id', $userid)
                 ->where('is_deleted', CommonConstant::IS_DELETED_0)
-                ->with(['peer_user'])
+                ->with(['module_info', 'peer_user'])
                 ->find($id);
         }
         return $info;
@@ -252,30 +283,30 @@ class ApproveInfoService
      * @param $user
      * @param $type
      */
-    public static function make($id, $user,$type)
+    public static function make($id, $user, $type)
     {
         $userid = $user['userid'];
-        $info = ApproveInfo::field('id,status')
+        $info = ApproveInfo::field('id,module,status')
             ->where('user_id', $userid)
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
             ->find($id);
-        if(!$info) {
-            throw new Exception('出差记录不存在或已删除');
+        if (!$info) {
+            throw new Exception(CommonConstant::get_module_list()[$info->module] . '记录不存在或已删除');
         }
-        switch ($type){
+        switch ($type) {
             case 'urging':
-                if($info->status != CommonConstant::STATUS_1){
+                if ($info->status != CommonConstant::STATUS_2) {
                     throw new Exception('其他人已操作');
                 }
 
                 // 钉钉接口 TODO
                 break;
             case 'cancel':
-                if($info->status != CommonConstant::STATUS_3){
+                if ($info->status != CommonConstant::STATUS_4) {
                     throw new Exception('非审批驳回状态无法操作');
                 }
 
-                $info->status = CommonConstant::STATUS_4;
+                $info->status = CommonConstant::STATUS_5;
                 $info->save();
                 break;
         }

+ 76 - 0
application/common/validate/ApproveEvection.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace app\common\validate;
+
+use think\Validate;
+
+class ApproveEvection extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+        'reason' => 'require',
+        'start_time' => 'require|check_start_time',
+        'end_time' => 'require|check_end_time',
+        'type' => 'require|in:1,2',
+        'is_who' => 'requireIf:type,1',
+        'remark' => 'requireIf:is_who,1',
+        'approve_user' => 'require',
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'create' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark', 'approve_user'],
+        'update' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark', 'approve_user'],
+    ];
+
+    /**
+     * 构造函数
+     * @access public
+     * @param array $rules 验证规则
+     * @param array $message 验证提示信息
+     * @param array $field 验证字段描述信息
+     */
+    public function __construct(array $rules = [], $message = [], $field = [])
+    {
+        $this->field = [
+            'reason' => '事由',
+            'start_time' => '出差开始时间',
+            'end_time' => '出差结束时间',
+            'type' => '出差类型',
+            'is_who' => '是否跨关内关外',
+            'remark' => '备注',
+            'approve_user' => '审批人',
+        ];
+        $this->message = array_merge($this->message, [
+            'start_time.check_start_time' => '出差开始时间必须大于当前时间',
+            'end_time.check_end_time' => '出差结束时间必须大于开始时间',
+            'type.in' => '请选择出差类型',
+        ]);
+        parent::__construct($rules, $message, $field);
+    }
+
+    protected function check_start_time($value, $rule, $data)
+    {
+        if ($value <= date('Y-m-d H:i')) {
+            return false;
+        }
+        return true;
+    }
+
+    protected function check_end_time($value, $rule, $data)
+    {
+        if ($data['start_time'] >= $value) {
+            return false;
+        }
+        return true;
+    }
+
+}