zhanglinxin 1 年之前
父节点
当前提交
dd17b2854d

+ 47 - 0
application/api/controller/Approve.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\service\ApproveFlowService;
+use hg\apidoc\annotation as Apidoc;
+use think\Db;
+use think\Exception;
+
+/**
+ * @Apidoc\Title("审批")
+ * @Apidoc\Group("api")
+ * @Apidoc\Sort("0")
+ */
+class Approve extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * 获取审批流程
+     *
+     * @Apidoc\Desc("获取流程")
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @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_data()
+    {
+        $module = input('module');
+        $data = ApproveFlowService::get_data($module, $this->user);
+        $this->success('获取审批流程', $data);
+    }
+
+}

+ 47 - 0
application/api/controller/Approveflow.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\service\ApproveFlowService;
+use hg\apidoc\annotation as Apidoc;
+use think\Db;
+use think\Exception;
+
+/**
+ * @Apidoc\Title("审批流程")
+ * @Apidoc\Group("api")
+ * @Apidoc\Sort("0")
+ */
+class Approveflow extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * 获取审批流程
+     *
+     * @Apidoc\Desc("获取审批流程")
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @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_data()
+    {
+        $module = input('module');
+        $data = ApproveFlowService::get_data($module, $this->user);
+        $this->success('获取审批流程', $data);
+    }
+
+}

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

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\constant\CommonConstant;
+use app\common\service\ApproveInfoService;
+use hg\apidoc\annotation as Apidoc;
+use think\Db;
+use think\Exception;
+
+/**
+ * @Apidoc\Title("审批申请")
+ * @Apidoc\Group("api")
+ * @Apidoc\Sort("0")
+ */
+class Approveinfo extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * 申请/重新发起
+     *
+     * @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("start_time", type="string", require=true, desc="开始时间")
+     * @Apidoc\Param("end_time", type="string", require=true, desc="结束时间")
+     * @Apidoc\Param("document", type="string", require=false, desc="附件(多个用英文逗号隔开)")
+     * @Apidoc\Param("images", type="string", require=false, desc="图片(多个用英文逗号隔开)")
+     * @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("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="姓名"),
+     *     @Apidoc\Param("desc", type="string", require=false, desc="备注"),
+     * )
+     * @Apidoc\Param("approve_user", type="string", require=true, desc="审批人id(多个用英文逗号隔开)")
+     * @Apidoc\Param("copy_user", type="string", require=false, desc="抄送人id(多个用英文逗号隔开)")
+     */
+    public function create()
+    {
+        $module = input('module');
+        $id = input('id');
+        $reason = input('reason');
+        $start_time = input('start_time');
+        $end_time = input('end_time');
+        $document = input('document');
+        $images = input('images');
+        $type = input('type');
+        $is_who = input('is_who');
+        $remark = input('remark');
+        $peer_user = input('peer_user');
+        $approve_user = input('approve_user');
+        $copy_user = input('copy_user');
+        $params = compact("module", "id", "reason", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user", "approve_user", "copy_user");
+        Db::startTrans();
+        try {
+            ApproveInfoService::create($module, $id, $params, $this->user);
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('申请已提交,请等待审核');
+    }
+
+}

+ 16 - 0
application/api/controller/Base.php

@@ -14,6 +14,7 @@
 // +----------------------------------------------------------------------
 
 namespace app\api\controller;
+use app\common\constant\CommonConstant;
 use Firebase\JWT\JWT;
 use think\Controller;
 use think\Db;
@@ -232,6 +233,21 @@ 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 ($controllername == 'evection') {
             if ($action_name == 'create') {
                 $id = $this->request->post('id');

+ 56 - 31
application/common/constant/CommonConstant.php

@@ -8,7 +8,31 @@ namespace app\common\constant;
 class CommonConstant
 {
 
-    // 模块类型:1=请假,2=用车,3=出差,4=呈批,5=维修,6=学校文件
+    // 删除状态:0=正常,1=删除
+    const IS_DELETED_0 = '0';
+    const IS_DELETED_1 = '1';
+
+    public static function get_is_deleted_list()
+    {
+        return [
+            self::IS_DELETED_0 => '正常',
+            self::IS_DELETED_1 => '删除',
+        ];
+    }
+
+    // 是否状态:0=否,1=是
+    const IS_WHO_0 = '0';
+    const IS_WHO_1 = '1';
+
+    public static function get_is_who_list()
+    {
+        return [
+            self::IS_WHO_0 => '否',
+            self::IS_WHO_1 => '是',
+        ];
+    }
+
+    // 模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件
     const MODULE_1 = '1';
     const MODULE_2 = '2';
     const MODULE_3 = '3';
@@ -16,16 +40,25 @@ class CommonConstant
     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';
 
-    public static function get_module_list(){
+    public static function get_module_list()
+    {
         return [
-            self::MODULE_1=> '请假',
-            self::MODULE_2=> '用车',
-            self::MODULE_3=> '出差',
-            self::MODULE_4=> '呈批',
-            self::MODULE_5=> '维修',
-            self::MODULE_6=> '学校文件',
-            self::MODULE_7=> '合同',
+            self::MODULE_1 => '申购',
+            self::MODULE_2 => '呈批',
+            self::MODULE_3 => '入库',
+            self::MODULE_4 => '领用',
+            self::MODULE_5 => '出差',
+            self::MODULE_6 => '请假',
+            self::MODULE_7 => '用车',
+            self::MODULE_8 => '维修',
+            self::MODULE_9 => '合同呈批',
+            self::MODULE_10 => '收文批阅',
+            self::MODULE_11 => '学校文件',
         ];
     }
 
@@ -33,10 +66,11 @@ class CommonConstant
     const TYPE_1 = '1';
     const TYPE_2 = '2';
 
-    public static function get_type_list(){
+    public static function get_type_list()
+    {
         return [
-            self::TYPE_1=> '审批人',
-            self::TYPE_2=> '抄送人',
+            self::TYPE_1 => '审批人',
+            self::TYPE_2 => '抄送人',
         ];
     }
 
@@ -44,25 +78,15 @@ class CommonConstant
     const IS_SPECIAL_0 = '0';
     const IS_SPECIAL_1 = '1';
 
-    public static function get_is_special_list(){
+    public static function get_is_special_list()
+    {
         return [
-            self::IS_SPECIAL_0=> '通用',
-            self::IS_SPECIAL_1=> '特殊',
+            self::IS_SPECIAL_0 => '通用',
+            self::IS_SPECIAL_1 => '特殊',
         ];
     }
 
 
-    // 删除状态:0=正常,1=删除
-    const IS_DELETED_0 = '0';
-    const IS_DELETED_1 = '1';
-
-    public static function get_is_deleted_list(){
-        return [
-            self::IS_DELETED_0=> '正常',
-            self::IS_DELETED_1=> '删除',
-        ];
-    }
-
     // 审核状态:0=待审批,1=审批中,2=审批通过,3=审批驳回,4=审批撤销
     const STATUS_0 = '0';
     const STATUS_1 = '1';
@@ -70,12 +94,13 @@ class CommonConstant
     const STATUS_3 = '3';
     const STATUS_4 = '4';
 
-    public static function get_status_list(){
+    public static function get_status_list()
+    {
         return [
-            self::STATUS_1=> '审批中',
-            self::STATUS_2=> '审批通过',
-            self::STATUS_3=> '审批驳回',
-            self::STATUS_4=> '审批撤销',
+            self::STATUS_1 => '审批中',
+            self::STATUS_2 => '审批通过',
+            self::STATUS_3 => '审批驳回',
+            self::STATUS_4 => '审批撤销',
         ];
     }
 }

+ 6 - 1
application/common/model/ApproveFlow.php

@@ -1,7 +1,12 @@
 <?php
+
 namespace app\common\model;
+
 use think\Model;
-// 审批流程设置
+
+/**
+ * 审批流程设置模型
+ */
 class ApproveFlow extends Model
 {
     protected  $module_desc = [

+ 14 - 15
application/common/service/ApproveFlowService.php

@@ -5,8 +5,6 @@ namespace app\common\service;
 use app\common\constant\CommonConstant;
 use app\common\model\ApproveFlow;
 use app\common\model\User;
-use think\Db;
-use think\Exception;
 
 /**
  * 审批流程服务类
@@ -25,44 +23,45 @@ class ApproveFlowService
         $userid = $user['userid'];
         $field = 'id,user_ids';
         // 审批
-        $approve = ApproveFlow::where('module', $module)
+        $approve = ApproveFlow::field($field)
+            ->where('module', $module)
             ->where('type', CommonConstant::TYPE_1)
             ->where('is_special', CommonConstant::IS_SPECIAL_1)
             ->where('special_user_id', $userid)
-            ->field($field)
             ->find();
         if ($approve) {
             $approve_user_ids = $approve['user_ids'];
         } else {
-            $approve_info = ApproveFlow::where('module', $module)
+            $approve_info = ApproveFlow::field($field)
+                ->where('module', $module)
                 ->where('type', CommonConstant::TYPE_1)
                 ->where('is_special', CommonConstant::IS_SPECIAL_0)
-                ->field($field)
                 ->find();
-            $approve_user_ids = $approve_info['user_ids'];
+            $approve_user_ids = $approve_info ? $approve_info['user_ids'] : [];
         }
         $approve_user = self::get_user_list($approve_user_ids);
         // 抄送
-        $is_copy = sysconf('is_copy_3'); // 是否允许用户自己添加抄送人
-        if($is_copy == 1){
-            $copy = ApproveFlow::where('module', $module)
+        $name = 'is_copy_' . $module;
+        $is_copy = sysconf($name); // 是否允许用户自己添加抄送人 0=否,1=是
+        if (!$is_copy) {
+            $copy = ApproveFlow::field($field)
+                ->where('module', $module)
                 ->where('type', CommonConstant::TYPE_2)
                 ->where('is_special', CommonConstant::IS_SPECIAL_1)
                 ->where('special_user_id', $userid)
-                ->field($field)
                 ->find();
             if ($copy) {
                 $copy_user_ids = $copy['user_ids'];
             } else {
-                $copy_info = ApproveFlow::where('module', $module)
+                $copy_info = ApproveFlow::field($field)
+                    ->where('module', $module)
                     ->where('type', CommonConstant::TYPE_2)
                     ->where('is_special', CommonConstant::IS_SPECIAL_0)
-                    ->field($field)
                     ->find();
-                $copy_user_ids = $copy_info['user_ids'];
+                $copy_user_ids = $copy_info ? $copy_info['user_ids'] : [];
             }
             $copy_user = self::get_user_list($copy_user_ids);
-        } else{
+        } else {
             $copy_user = [];
         }
         return compact('approve_user', 'copy_user');

+ 257 - 0
application/common/service/ApproveInfoService.php

@@ -0,0 +1,257 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\constant\CommonConstant;
+use app\common\model\Department;
+use app\common\model\EvectionApprove;
+use app\common\model\EvectionInfo;
+use app\common\model\EvectionPeerUser;
+use app\common\model\User;
+use think\Exception;
+
+/**
+ * 审批申请服务类
+ */
+class ApproveInfoService
+{
+
+    /**
+     * 申请/重新发起
+     *
+     * @param $module
+     * @param $id
+     * @param $params
+     * @param $user
+     **/
+    public static function create($module,$id,$params, $user)
+    {
+        $userid = $user['userid'];
+        // 编辑
+        if ($id > 0) {
+            $info = EvectionInfo::field('user_id,is_deleted', true)
+                ->where('user_id', $userid)
+                ->where('is_deleted', CommonConstant::IS_DELETED_0)
+                ->find($id);
+            if (!$info) {
+                throw new Exception('出差记录不存在或已删除');
+            }
+            if($info->status != CommonConstant::STATUS_3){
+                throw new Exception('非审批驳回状态无法操作');
+            }
+        }
+
+        $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 = [
+            'user_id' => $userid,
+            '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'],
+            'approve_num' => $approve_num,
+            'cur_num' => 0,
+        ];
+        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_peer_user($id, $params['peer_user'],'update');
+
+            // 编辑出差审批
+            self::create_evection_approve($id, $approve_user, $copy_user,'create');
+        } else {
+            // 添加出差申请
+            $info = EvectionInfo::create($data);
+
+            // 添加同行人员
+            self::create_peer_user($info->id, $params['peer_user']);
+
+            // 添加出差审批
+            self::create_evection_approve($info->id, $approve_user, $copy_user);
+        }
+    }
+
+    protected static function create_peer_user($info_id, $params,$type = 'create')
+    {
+        if (!$params) {
+            return true;
+        }
+
+        if($type == 'update'){
+            EvectionPeerUser::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'] : '',
+            ];
+        }
+        EvectionPeerUser::insertAll($data);
+    }
+
+    protected static function create_evection_approve($info_id, $approve_user, $copy_user,$type = 'create')
+    {
+        if($type == 'update'){
+            EvectionApprove::where('info_id', $info_id)->delete();
+        }
+
+        $data = [];
+        $flow_num = 0;
+        $create_at = date('Y-m-d H:i:s');
+        // 审批人
+        foreach ($approve_user as $key => $value) {
+            $flow_num++;
+            $data[] = [
+                'info_id' => $info_id,
+                'approve_flow' => $flow_num,
+                '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[] = [
+                '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,
+            ];
+        }
+        EvectionApprove::insertAll($data);
+    }
+
+    /**
+     * 列表
+     *
+     * @param $status
+     * @param $search
+     * @param $offset
+     * @param $length
+     * @param $user
+     **/
+    public static function get_list($status, $search, $offset, $length, $user)
+    {
+        $userid = $user['userid'];
+        $list = EvectionInfo::field('id,status,create_at,order_no,reason,start_time,end_time')
+            ->where('user_id', $userid)
+            ->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)
+            ->order('id desc')
+            ->select();
+        return $list;
+    }
+
+    /**
+     * 详情/信息
+     *
+     * @param $id
+     * @param $user
+     * @param $type
+     **/
+    public static function get_detail($id, $user,$type)
+    {
+        $userid = $user['userid'];
+        if($type == 'detail'){
+            $info = EvectionInfo::field('user_id,is_deleted', true)
+                ->where('user_id', $userid)
+                ->where('is_deleted', CommonConstant::IS_DELETED_0)
+                ->with(['peer_user' => function ($query) {
+                    $query->field('id,info_id,name');
+                }, 'approve' => function ($query) {
+                    $query->field('is_deleted,create_at', true)
+                        ->with(['user' => function ($query) {
+                            $query->field('userid,headimg,name');
+                        }]);
+                }])
+                ->find($id);
+            if ($info) {
+                $info['department'] = Department::where('dept_id', 'in', $user['department'])->field('dept_id,name')->select();
+            }
+        } else{
+            $info = EvectionInfo::field('user_id,is_deleted', true)
+                ->where('user_id', $userid)
+                ->where('is_deleted', CommonConstant::IS_DELETED_0)
+                ->with(['peer_user'])
+                ->find($id);
+        }
+        return $info;
+    }
+
+    /**
+     * 操作方法
+     *
+     * @param $id
+     * @param $user
+     * @param $type
+     */
+    public static function make($id, $user,$type)
+    {
+        $userid = $user['userid'];
+        $info = EvectionInfo::field('id,status')
+            ->where('user_id', $userid)
+            ->where('is_deleted', CommonConstant::IS_DELETED_0)
+            ->find($id);
+        if(!$info) {
+            throw new Exception('出差记录不存在或已删除');
+        }
+        switch ($type){
+            case 'urging':
+                if($info->status != CommonConstant::STATUS_1){
+                    throw new Exception('其他人已操作');
+                }
+
+                // 钉钉接口 TODO
+                break;
+            case 'cancel':
+                if($info->status != CommonConstant::STATUS_3){
+                    throw new Exception('非审批驳回状态无法操作');
+                }
+
+                $info->status = CommonConstant::STATUS_4;
+                $info->save();
+                break;
+        }
+    }
+
+}