zhanglinxin 1 年之前
父节点
当前提交
2a8cfe5aef

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

@@ -151,10 +151,10 @@ class Approveinfo extends Base
         $params = compact("way", "id", "module", "apply_user_id", "reason", "type", "desc", "start_time", "end_time", "document", "images", "remark", "total_amount", "pay_type", "word_size", "apply_id", "number", "is_who", "start_am", "end_am", "time", "reach_address", "end_address", "scope", "legal_opinion", "founder", "serial_number", "degree", "department", "department_sign", "approve_user", "copy_user", "apply_goods", "stock_goods", "use_goods", "peer_user");
         $user = $this->user;
         if ($way == CommonConstant::edit) {
-            ApproveService::make($id, $params, $user, CommonConstant::edit);
+            ApproveService::make($id, $params, $user, $way);
             $this->success('修改成功');
         } else {
-            ApproveInfoService::create($id, $module, $params, $user);
+            ApproveInfoService::create($id, $module, $params, $user, $way);
             $this->success('申请已提交,请等待审批');
         }
     }

+ 1 - 1
application/api/controller/Base.php

@@ -273,7 +273,7 @@ class Base extends Controller
                 $way = $this->request->post('way');
                 $id = $this->request->post('id');
                 if (!$id && in_array($way, [CommonConstant::update, CommonConstant::edit])) {
-                    $this->error('ID参数不能为空');
+                    $this->error('申请参数不能为空');
                 }
                 $module = $this->request->post('module');
                 $validates = CommonConstant::get_module_validate_list();

+ 19 - 7
application/common/service/ApproveInfoService.php

@@ -33,13 +33,13 @@ class ApproveInfoService
      * @param integer $module 模块类型
      * @param array $params
      * @param mixed $user 用户信息
+     * @param string $way 方式:create=申请,update=重新发起
      **/
-    public static function create($id, $module, $params, $user)
+    public static function create($id, $module, $params, $user,$way)
     {
         $userid = $user['userid'];
         $apply_user_id = $userid;
         $department = $user['department'];
-        $reason = $params['reason'];
 
         // 5=出差申请,6=请假申请,7=用车申请 申请人信息
         if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
@@ -86,9 +86,6 @@ class ApproveInfoService
                         except('申购申请单不存在或已删除');
                     }
                 }
-                // 生成合同编号
-                $contract_no = CommonService::get_contract_no($params['type']);
-                $reason = $contract_no;
             }
         }
 
@@ -106,7 +103,7 @@ class ApproveInfoService
             'cur_num' => 0,
             'order_no' => $order_no,
             'apply_date' => date("Y-m-d"),
-            'reason' => $reason,
+            'reason' => $params['reason'],
             'type' => $params['type'],
             'desc' => $params['desc'],
             'start_time' => $module == CommonConstant::MODULE_6 ? $params['start_time'] . ' ' . $params['start_am'] : $params['start_time'],
@@ -151,6 +148,15 @@ class ApproveInfoService
         } catch (Exception $e) {
             except('出现错误:' . $e->getMessage());
         }
+
+        if($way == CommonConstant::create){
+            if ($module == CommonConstant::MODULE_9) {
+                // 生成合同编号
+                $contract_no = CommonService::get_contract_no($params['type']);
+                $info->save(['reason'=>$contract_no]);
+            }
+        }
+
         return true;
     }
 
@@ -1074,7 +1080,7 @@ class ApproveInfoService
     public static function make($id, $params, $user, $type)
     {
         $userid = $user['userid'];
-        $info = ApproveInfo::field('id,user_id,module,status')
+        $info = ApproveInfo::field('id,user_id,module,status,reason')
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
             ->find($id);
         if (!$info) {
@@ -1100,12 +1106,18 @@ class ApproveInfoService
 
                 $info->status = CommonConstant::STATUS_5;
                 $info->save();
+
+                if ($info->module == CommonConstant::MODULE_9) {
+                    // 9=合同呈批 释放合同编号
+                    CommonService::set_contract_no($info->reason);
+                }
                 break;
             case 'comment':
                 if ($info->status != CommonConstant::STATUS_3) {
                     except('非审批同意状态无法操作');
                 }
                 if ($info->module != CommonConstant::MODULE_8) {
+                    // 8=维修申请
                     except(CommonConstant::get_module_list()[CommonConstant::MODULE_8] . '记录不存在或已删除');
                 }
                 // TODO 没有判断评价状态

+ 30 - 3
application/common/service/CommonService.php

@@ -19,17 +19,44 @@ class CommonService
 
     /**
      * 生成合同编号
+     *
+     * @param integer $type 合同类型
      **/
     public static function get_contract_no($type){
+        $options = config('redis.');
+        $redis = new Redis($options);
+        $key = 'dingtalk_contract_no';
+        $key2 = 'dingtalk_contract_no_list';
+        if($redis->handler()->llen($key2) > 0){
+            $number = $redis->handler()->lpop($key2);
+        } else{
+            if($redis->has($key)){
+                $number = $redis->get($key);
+            } else{
+                $number = 1;
+            }
+            $redis->set($key,$number+1);
+        }
+        $new_number = filling_method($number,$number);
         $type_no = ContractConstant::get_type_no_list()[$type];
         $date = date('Ymd');
-        $number = 1; // TODO redis缓存
-        $number = filling_method($number,$number);
-        $data = 'SET'.$type_no.$date.$number;
+        $data = 'SET'.$type_no.$date.$new_number;
         return $data;
     }
 
     /**
+     * 释放合同编号
+     *
+     * @param string $contract_no 合同编号
+     **/
+    public static function set_contract_no($contract_no){
+        $options = config('redis.');
+        $redis = new Redis($options);
+        $key2 = 'dingtalk_contract_no_list';
+        return $redis->handler()->rpush($key2,substr($contract_no, 13));
+    }
+
+    /**
      * 拼接查询字段
      *
      * @param string $field