zhanglinxin преди 1 година
родител
ревизия
5bd6715184

+ 74 - 5
application/api/controller/Approve.php

@@ -42,7 +42,7 @@ class Approve extends Base
         $search = input('search');
         $offset = $this->off_set;
         $length = $this->page_num;
-        $data = ApproveService::get_list($status,$module, $start_time, $end_time,$search, $offset, $length, $this->user);
+        $data = ApproveService::get_list($status, $module, $start_time, $end_time, $search, $offset, $length, $this->user);
         $this->success('审批列表', $data);
     }
 
@@ -50,11 +50,11 @@ class Approve extends Base
      * 详情
      *
      * @Apidoc\Method("POST")
-     * @Apidoc\Param("id", type="integer",require=true, desc="审批ID")
+     * @Apidoc\Param("approve_id", type="integer",require=true, desc="审批ID")
      */
     public function get_detail()
     {
-        $id = input('id');
+        $id = input('approve_id');
         $info = ApproveService::get_detail($id, $this->user, 'detail');
         $this->success('详情', $info);
     }
@@ -64,13 +64,82 @@ class Approve extends Base
      *
      * @Apidoc\Desc("修改信息")
      * @Apidoc\Method("POST")
-     * @Apidoc\Param("id", type="integer",require=true, desc="审批ID")
+     * @Apidoc\Param("approve_id", type="integer",require=true, desc="审批ID")
      */
     public function get_info()
     {
-        $id = input('id');
+        $id = input('approve_id');
         $info = ApproveService::get_detail($id, $this->user, 'info');
         $this->success('信息', $info);
     }
 
+    /**
+     * 审批
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("approve_id", type="integer",require=true, desc="审批ID")
+     * @Apidoc\Param("status", type="integer",require=true, desc="审批状态:3=审批同意,4=审批驳回")
+     * @Apidoc\Param("remark", type="sting",require=false, desc="审批意见")
+     **/
+    public function audit()
+    {
+        $id = input('approve_id');
+        $status = input('status');
+        $remark = input('remark');
+        Db::startTrans();
+        try {
+            ApproveService::audit($id, $status, $remark, $this->user);
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('确认成功');
+    }
+
+    /**
+     * 修改
+     *
+     * @Apidoc\Method("POST")
+     * @Apidoc\Param("approve_id", type="integer",require=true, desc="审批ID")
+     * @Apidoc\Param("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
+     * @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="同行员工数据 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="姓名"),
+     *     @Apidoc\Param("desc", type="string", require=false, desc="备注"),
+     * )
+     **/
+    public function edit(){
+        $id = input('approve_id');
+        $module = input('module');
+        $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');
+        $params = compact("module", "id", "reason", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user");
+        Db::startTrans();
+        try {
+            ApproveService::edit($id, $module, $params, $this->user);
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('修改成功');
+    }
+
 }

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

@@ -24,8 +24,8 @@ 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("module", type="integer", require=true, desc="模块类型:1=申购申请,2=呈批申请,3=入库申请,4=领用申请,5=出差申请,6=请假申请,7=用车申请,8=维修申请,9=合同呈批,10=收文批阅,11=学校文件")
      * @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="结束时间")
@@ -45,8 +45,8 @@ class Approveinfo extends Base
      */
     public function create()
     {
-        $module = input('module');
         $id = input('id');
+        $module = input('module');
         $reason = input('reason');
         $start_time = input('start_time');
         $end_time = input('end_time');
@@ -61,7 +61,7 @@ class Approveinfo extends Base
         $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);
+            ApproveInfoService::create($id, $module, $params, $this->user);
             Db::commit();
         } catch (Exception $e) {
             Db::rollback();

+ 93 - 80
application/api/controller/Base.php

@@ -14,6 +14,7 @@
 // +----------------------------------------------------------------------
 
 namespace app\api\controller;
+
 use app\common\constant\CommonConstant;
 use app\common\model\User;
 use Firebase\JWT\JWT;
@@ -42,72 +43,76 @@ class Base extends Controller
     protected $ret_msg = ''; // 返回提示信息
     protected $is_test = false;
     protected $need_login = [];
-    public function initialize(){
+
+    public function initialize()
+    {
         $modulename = $this->request->module();
         $controllername = Loader::parseName($this->request->controller());
         $actionname = strtolower($this->request->action());
         $this->checking($modulename, $controllername, $actionname);
 
-        $this->page = input('page',1);
-        $this->page_num = input('page_num',20);
-        $this->off_set   =   $this->page * $this->page_num - $this->page_num;
-        $this->is_test = input('test',0);// 测试用的
-        $path = explode('/',$this->request->path());
-        if( input('user_id')) $this->user_id = input('user_id');
-        if( input('user')) $this->user_id = input('user');
-        if(!empty($this->need_login) && in_array(end($path),$this->need_login)) $this->checkLogin();
+        $this->page = input('page', 1);
+        $this->page_num = input('page_num', 20);
+        $this->off_set = $this->page * $this->page_num - $this->page_num;
+        $this->is_test = input('test', 0);// 测试用的
+        $path = explode('/', $this->request->path());
+        if (input('user_id')) $this->user_id = input('user_id');
+        if (input('user')) $this->user_id = input('user');
+        if (!empty($this->need_login) && in_array(end($path), $this->need_login)) $this->checkLogin();
     }
+
     //校验jwt权限API
     protected function checkLogin()
     {
         $authorization = app()->request->header('Authorization');
-        if(empty($authorization) || $authorization == null){
-            if($this->is_test == 1) {
-                $this->user_id = input('user_id')  ? input('user_id') : 22;
-                if(input('user')) $this->user_id = input('user');
+        if (empty($authorization) || $authorization == null) {
+            if ($this->is_test == 1) {
+                $this->user_id = input('user_id') ? input('user_id') : 22;
+                if (input('user')) $this->user_id = input('user');
                 return true;
             }
-            $this->error('Token不存在,拒绝访问--','',0,-1);
+            $this->error('Token不存在,拒绝访问--', '', 0, -1);
         }
         $key = md5(config('app.jwt'));
         try {
             $check_authorization = JWT::decode($authorization, $key, array('HS256'));
-            if($check_authorization['code'] !=200) $this->exception($check_authorization['msg']);
+            if ($check_authorization['code'] != 200) $this->exception($check_authorization['msg']);
             $authInfo = json_decode(json_encode($check_authorization['data']), true);
             if (!empty($authInfo['uid'])) {
                 $member = User::find($authInfo['uid']);
-                if(empty($member) || $member['is_deleted'])  $this->error('会员不存在','',0);
+                if (empty($member) || $member['is_deleted']) $this->error('会员不存在', '', 0);
                 //if(!empty($authInfo['facility_code']) && !in_array($authInfo['facility_code'],[$member['facility_1'],$member['facility_2'],$member['facility_3'],$member['facility_4'],$member['facility_5']]))    $this->error('该设备已被禁用','',0,-1);
-                if($member['status']){
+                if ($member['status']) {
                     $this->user_id = $authInfo['uid'];
                     $this->user = $member;
                     return $this->user_id;
-                }else{
-                    $this->error('该会员已被禁用','',0,-1);
+                } else {
+                    $this->error('该会员已被禁用', '', 0, -1);
                 }
             } else {
-                $this->error('Token验证不通过,用户不存在','',0,-1);
+                $this->error('Token验证不通过,用户不存在', '', 0, -1);
             }
         } catch (\Exception $e) {
-            $this->error($e->getMessage(),'',0,-1);
+            $this->error($e->getMessage(), '', 0, -1);
         }
     }
 
 
-    protected function setUid(){
+    protected function setUid()
+    {
         $authorization = app()->request->header('Authorization');
         $key = md5(config('app.jwt'));
-        if(empty($authorization) || $authorization == null) return false;
+        if (empty($authorization) || $authorization == null) return false;
         try {
             $check_authorization = JWT::decode($authorization, $key, array('HS256'));
-            if($check_authorization['code'] !=200) $this->exception($check_authorization['msg']);
+            if ($check_authorization['code'] != 200) $this->exception($check_authorization['msg']);
             $authInfo = json_decode(json_encode($check_authorization['data']), true);
             if (!empty($authInfo['uid'])) {
-                $member = Db::name('store_member')->field('status')->where('id',$authInfo['uid'])->find();
-                if($member['status']){
+                $member = Db::name('store_member')->field('status')->where('id', $authInfo['uid'])->find();
+                if ($member['status']) {
                     $this->user_id = $authInfo['uid'];
                     $this->user_id;
-                    return  true;
+                    return true;
                 }
             }
         } catch (\Exception $e) {
@@ -117,62 +122,67 @@ class Base extends Controller
     }
 
     // 获取用户信息
-    function userInfo($field =''){
-        if(!$this->user_id)  return [];
-        return $field ?  Db::name('store_member')->field($field)->find($this->user_id) : Db::name('store_member')->find($this->user_id);
+    function userInfo($field = '')
+    {
+        if (!$this->user_id) return [];
+        return $field ? Db::name('store_member')->field($field)->find($this->user_id) : Db::name('store_member')->find($this->user_id);
     }
 
     // 验证短信验证码
-    protected function checkPhoneCode($phone,$code){
+    protected function checkPhoneCode($phone, $code)
+    {
         //return true;
-        $sel_time =date('Y-m-d H:i:s',time()-600);
+        $sel_time = date('Y-m-d H:i:s', time() - 600);
         $store_member_sms = Db::name('store_member_sms')
-            ->field('id,code')->where('phone',$phone)
-            ->where('create_at','> time',$sel_time)
-            ->where('used',0)->order('id desc')->find();
-        return !empty($store_member_sms) && $store_member_sms['code'] == $code ? $store_member_sms['id'] :0;
+            ->field('id,code')->where('phone', $phone)
+            ->where('create_at', '> time', $sel_time)
+            ->where('used', 0)->order('id desc')->find();
+        return !empty($store_member_sms) && $store_member_sms['code'] == $code ? $store_member_sms['id'] : 0;
     }
 
     // 更新验证码状态
-    protected function updatePhoneCode($code_id){
-        Db::name('store_member_sms')->where('id',$code_id)->update(['used'=>1]);
+    protected function updatePhoneCode($code_id)
+    {
+        Db::name('store_member_sms')->where('id', $code_id)->update(['used' => 1]);
     }
+
     /**
      * 操作成功返回的数据
-     * @param string $msg   提示信息
-     * @param mixed $data   要返回的数据
-     * @param int   $code   错误码,默认为1
-     * @param string $type  输出类型
+     * @param string $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为1
+     * @param string $type 输出类型
      * @param array $header 发送的 Header 信息
      */
-    protected function success($msg = 'ok', $data = null , $is_login = 1, $code = 1, $type = null, array $header = [])
+    protected function success($msg = 'ok', $data = null, $is_login = 1, $code = 1, $type = null, array $header = [])
     {
         $this->results($msg, $data, $is_login, $code, $type, $header);
     }
 
     /**
      * 操作失败返回的数据
-     * @param string $msg   提示信息
-     * @param mixed $data   要返回的数据
-     * @param int   $code   错误码,默认为0
-     * @param string $type  输出类型
+     * @param string $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为0
+     * @param string $type 输出类型
      * @param array $header 发送的 Header 信息
      */
     protected function error($msg = '', $data = null, $is_login = 1, $code = 0, $type = null, array $header = [])
     {
-        if(empty($this->user_id)){
+        if (empty($this->user_id)) {
             $is_login = 0;
         }
         $this->results($msg, $data, $is_login, $code, $type, $header);
     }
+
     /**
      * 返回封装后的 API 数据到客户端
      * @access protected
-     * @param mixed  $msg    提示信息
-     * @param mixed  $data   要返回的数据
-     * @param int    $code   错误码,默认为0
-     * @param string $type   输出类型,支持json/xml/jsonp
-     * @param array  $header 发送的 Header 信息
+     * @param mixed $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为0
+     * @param string $type 输出类型,支持json/xml/jsonp
+     * @param array $header 发送的 Header 信息
      * @return void
      * @throws HttpResponseException
      */
@@ -181,20 +191,17 @@ class Base extends Controller
         $result = [
             'code' => $code,
             'is_login' => $is_login,
-            'msg'  => $msg,
+            'msg' => $msg,
             'time' => \think\facade\Request::instance()->server('REQUEST_TIME'),
             'data' => $data,
         ];
         // 如果未设置类型则自动判断
         $type = $type ? $type : 'json';
 
-        if (isset($header['statuscode']))
-        {
+        if (isset($header['statuscode'])) {
             $code = $header['statuscode'];
             unset($header['statuscode']);
-        }
-        else
-        {
+        } else {
             //未设置状态码,根据code值判断
             $code = $code >= 1000 || $code < 200 ? 200 : $code;
         }
@@ -204,7 +211,7 @@ class Base extends Controller
 
 
     //token加密
-    public function createJwt($uid,$facility_code='')
+    public function createJwt($uid, $facility_code = '')
     {
         $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到
         $time = time(); //签发时间
@@ -222,22 +229,24 @@ class Base extends Controller
         return $jwt;
     }
 
-    protected function exception($msg){
+    protected function exception($msg)
+    {
         throw new Exception($msg);
     }
 
     // 事务返回
-    protected function transReturn($data = []){
-        $this->is_commit ? $this->success($this->ret_msg,$data):$this->error($this->ret_msg);
+    protected function transReturn($data = [])
+    {
+        $this->is_commit ? $this->success($this->ret_msg, $data) : $this->error($this->ret_msg);
     }
 
     protected function checking($modulename, $controllername, $action_name)
     {
         $params = $this->request->post();
-        if (in_array($action_name,['get_data','create'])) {
+        if (in_array($action_name, ['get_data', 'create', 'edit'])) {
             $get_module_list = CommonConstant::get_module_list();
             $rule = [
-                'module|模块类型' => 'require|in:'.implode(',',array_keys($get_module_list)),
+                'module|模块类型' => 'require|in:' . implode(',', array_keys($get_module_list)),
             ];
             $message = [
                 'module.in' => '请选择正确的模块类型',
@@ -256,19 +265,18 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-        }
-        if ($controllername == 'approveinfo') {
-            if ($action_name == 'get_detail') {
-                $rule = [
-                    'id|申请参数' => 'require|gt:0',
-                ];
-                $message = [];
-                $validate = new Validate($rule, $message);
-                if (!$validate->check($params)) {
+            if ($action_name == 'edit') {
+                $module = $this->request->post('module');
+                $validates = CommonConstant::get_module_validate_list();
+                $validate = $validates[$module];
+                $validate = new $validate;
+                if (!$validate->check($params, [], 'edit')) {
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'get_info') {
+        }
+        if ($controllername == 'approveinfo') {
+            if (in_array($action_name, ['get_detail', 'get_info', 'urging', 'cancel'])) {
                 $rule = [
                     'id|申请参数' => 'require|gt:0',
                 ];
@@ -278,9 +286,11 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'urging') {
+        }
+        if ($controllername == 'approve') {
+            if (in_array($action_name, ['get_detail', 'get_info'])) {
                 $rule = [
-                    'id|申请参数' => 'require|gt:0',
+                    'approve_id|审批参数' => 'require|gt:0',
                 ];
                 $message = [];
                 $validate = new Validate($rule, $message);
@@ -288,11 +298,14 @@ class Base extends Controller
                     $this->error($validate->getError());
                 }
             }
-            if ($action_name == 'cancel') {
+            if ($action_name == 'audit') {
                 $rule = [
-                    'id|申请参数' => 'require|gt:0',
+                    'approve_id|审批参数' => 'require|gt:0',
+                    'status|审批状态' => 'require|in:' . CommonConstant::STATUS_3 . ',' . CommonConstant::STATUS_4,
+                ];
+                $message = [
+                    'status.in' => '请选择正确的审批状态',
                 ];
-                $message = [];
                 $validate = new Validate($rule, $message);
                 if (!$validate->check($params)) {
                     $this->error($validate->getError());

+ 1 - 0
application/common.php

@@ -172,6 +172,7 @@ function get32Str($length='32'){
     return $randstr;
 }
 
+
 /**
  * 用于测试打印数组数据
  **/

+ 2 - 2
application/common/constant/CommonConstant.php

@@ -145,7 +145,7 @@ class CommonConstant
     }
 
 
-    // 审核状态:1=待审批,2=审批中,3=审批通过,4=审批驳回,5=审批撤销
+    // 审核状态:1=待审批,2=审批中,3=审批同意,4=审批驳回,5=审批撤销
     const STATUS_1 = 1;
     const STATUS_2 = 2;
     const STATUS_3 = 3;
@@ -156,7 +156,7 @@ class CommonConstant
     {
         return [
             self::STATUS_2 => '审批中',
-            self::STATUS_3 => '审批通过',
+            self::STATUS_3 => '审批同意',
             self::STATUS_4 => '审批驳回',
             self::STATUS_5 => '审批撤销',
         ];

+ 6 - 0
application/common/model/Approve.php

@@ -32,4 +32,10 @@ class Approve extends Model
         return $this->hasOne(Approve::class, 'info_id', 'info_id')->where('is_deleted',CommonConstant::IS_DELETED_0);
     }
 
+    // 关联审批申请 (审批)
+    public function approveInfo()
+    {
+        return $this->belongsTo(ApproveInfo::class, 'info_id', 'id')->where('is_deleted',CommonConstant::IS_DELETED_0);
+    }
+
 }

+ 2 - 2
application/common/service/ApproveFlowService.php

@@ -15,8 +15,8 @@ class ApproveFlowService
     /**
      * 获取流程
      *
-     * @param $module
-     * @param $user
+     * @param integer $module 模块类型
+     * @param mixed $user 用户信息
      **/
     public static function get_data($module, $user)
     {

+ 18 - 18
application/common/service/ApproveInfoService.php

@@ -21,12 +21,12 @@ class ApproveInfoService
     /**
      * 申请/重新发起
      *
-     * @param $module
-     * @param $id
-     * @param $params
-     * @param $user
+     * @param integer $id 申请ID
+     * @param integer $module 模块类型
+     * @param array $params
+     * @param mixed $user 用户信息
      **/
-    public static function create($module, $id, $params, $user)
+    public static function create($id, $module, $params, $user)
     {
 
         $userid = $user['userid'];
@@ -193,12 +193,12 @@ class ApproveInfoService
     /**
      * 我的申请记录
      *
-     * @param $module
-     * @param $status
-     * @param $search
-     * @param $offset
-     * @param $length
-     * @param $user
+     * @param integer $module 模块类型
+     * @param integer $status 审批状态
+     * @param string $search 搜索
+     * @param integer$offset 起始位置
+     * @param integer $length 查询数量
+     * @param mixed $user 用户信息
      **/
     public static function get_list($module, $status, $search, $offset, $length, $user)
     {
@@ -228,9 +228,9 @@ class ApproveInfoService
     /**
      * 详情/信息
      *
-     * @param integer $id
-     * @param mixed $user 有数据=审批申请详情,没有数据=审批详情
-     * @param string $type
+     * @param integer $id 申请ID
+     * @param mixed $user 用户信息 有数据=审批申请详情,没有数据=审批详情
+     * @param string $type 类型:detail=详情,info=信息
      **/
     public static function get_detail($id, $user, $type)
     {
@@ -283,7 +283,7 @@ class ApproveInfoService
                 break;
             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');
@@ -332,9 +332,9 @@ class ApproveInfoService
     /**
      * 操作方法
      *
-     * @param $id
-     * @param $user
-     * @param $type
+     * @param integer $id 申请ID
+     * @param mixed $user 用户信息
+     * @param string $type 类型:urging=催办,cancel=撤销
      */
     public static function make($id, $user, $type)
     {

+ 89 - 16
application/common/service/ApproveService.php

@@ -17,14 +17,14 @@ class ApproveService
     /**
      * 审批列表
      *
-     * @param $status
-     * @param $module
-     * @param $start_time
-     * @param $end_time
-     * @param $search
-     * @param $offset
-     * @param $length
-     * @param $user
+     * @param integer $status 处理状态
+     * @param integer $module 模块类型
+     * @param string $start_time 申请开始时间
+     * @param string $end_time 申请结束时间
+     * @param string $search 搜索
+     * @param integer $offset 起始位置
+     * @param integer $length 查询数量
+     * @param mixed $user 用户信息
      **/
     public static function get_list($status, $module, $start_time, $end_time, $search, $offset, $length, $user)
     {
@@ -40,7 +40,7 @@ class ApproveService
         $userid = $user['userid'];
         $aliasName = 'approve.';
         $jobName = 'approveInfo.';
-        $field = 'id,info_id,status,create_at';
+        $field = 'id as approve_id,info_id,status,create_at';
         $joinField = 'user_id,order_no,apply_date,reason,type,desc,start_time,end_time';
         $field = self::getAliasField($field, $aliasName);
         $joinField = self::getAliasField($joinField, $jobName);
@@ -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) {
@@ -94,7 +94,7 @@ class ApproveService
             }]);
         }
         $list = $list->limit($offset, $length)
-            ->order('id desc')
+            ->order('approve_id desc')
             ->select();
 
 //        $info_ids = [];
@@ -126,14 +126,14 @@ class ApproveService
     /**
      * 详情
      *
-     * @param integer $id
-     * @param mixed $user
-     * @param string $type
+     * @param integer $id 审批ID
+     * @param mixed $user 用户信息
+     * @param string $type 类型:detail=详情,info=信息
      **/
-    public static function get_detail($id, $user,$type)
+    public static function get_detail($id, $user, $type)
     {
         $userid = $user['userid'];
-        $info = Approve::field('info_id,status')
+        $info = Approve::field('id,info_id,status')
             ->where('approve_user', $userid)
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
             ->find($id);
@@ -147,6 +147,79 @@ class ApproveService
     }
 
     /**
+     * 审批
+     *
+     * @param integer $id 审批ID
+     * @param string $status 审批状态
+     * @param string $remark 审批意见
+     * @param mixed $user 用户信息
+     **/
+    public static function audit($id, $status, $remark, $user)
+    {
+        $userid = $user['userid'];
+        $info = Approve::field('id,info_id,status,approve_flow,approve_time')
+            ->where('approve_user', $userid)
+            ->where('is_deleted', CommonConstant::IS_DELETED_0)
+            ->with([
+                'approveInfo' => function ($query) {
+                    $query->field('is_deleted', true);
+                }
+            ])
+            ->find($id);
+        if (!$info) {
+            throw new Exception('审批记录不存在或已删除');
+        }
+        if ($info->status != CommonConstant::STATUS_2) {
+            throw new Exception('非待处理状态无法操作');
+        }
+        $approve_info = $info->approve_info;
+        if (!$approve_info) {
+            throw new Exception(CommonConstant::get_module_list()[$approve_info->module] . '记录不存在或已删除');
+        }
+        if ($approve_info->status != CommonConstant::STATUS_2) {
+            throw new Exception('非待处理状态无法操作!');
+        }
+
+        $approve_time = date('Y-m-d H:i:s');
+        $duration = time() - strtotime($info['approve_time']);
+
+        // 更新审批
+        $info->status = $status;
+        $info->approve_time = $approve_time;
+        $info->remark = $remark;
+        $info->time = $duration;
+        $info->time_text = get_stay_time($duration);
+        $info->save();
+
+        // 更新审批申请
+        if ($status == CommonConstant::STATUS_3) {
+            if ($info['approve_flow'] < $approve_info['approve_num']) {
+                // 更新下一级审批状态
+                Approve::where(['info_id' => $info['info_id'], 'approve_flow' => $info['approve_flow'] + 1])->update(['status' => CommonConstant::STATUS_2, 'approve_time' => $approve_time]);
+            } else {
+                $approve_info->status = $status;
+            }
+        } else {
+            $approve_info->status = $status;
+        }
+        $approve_info->cur_num = $approve_info['cur_num'] + 1;
+        $approve_info->save();
+    }
+
+    /**
+     * 修改
+     *
+     * @param integer $id 审批ID
+     * @param integer $module 模块类型
+     * @param array $params 数组
+     * @param mixed $user 用户信息
+     **/
+    public static function edit($id, $module, $params, $user)
+    {
+        $userid = $user['userid'];
+    }
+
+    /**
      * 拼接查询字段
      */
     public static function getAliasField($field, $aliasName)

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

@@ -29,6 +29,7 @@ class ApproveEvection extends Validate
     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'],
+        'edit' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark'],
     ];
 
     /**

+ 1 - 1
config/database.php

@@ -19,7 +19,7 @@ return [
     // 数据库类型
     'type'        => 'mysql',
     // 服务器地址
-    'hostname'    => '127.0.0.1',
+    'hostname'    => '120.79.86.50',
     // 数据库名
     'database'    => 'dingding_hdlkeji',
     // 用户名