cqp 3 месяцев назад
Родитель
Сommit
1767c98980

+ 1 - 1
app/Exports/SingleSheetExport.php

@@ -82,7 +82,7 @@ class SingleSheetExport extends DefaultValueBinder implements
 
                 // 1. 设置下拉筛选 (Auto Filter)
                 // 范围从 A5 开始到最后一列的最后一行
-                $sheet->setAutoFilter('A5:' . $highestColumn . $highestRow);
+//                $sheet->setAutoFilter('A5:' . $highestColumn . $highestRow);
 
                 // --- 原有的配置定义 ---
                 $config = [

+ 24 - 0
app/Http/Controllers/Api/StatisticsController.php

@@ -30,4 +30,28 @@ class StatisticsController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function rdLockList(Request $request){
+        $service = new StatisticsService();
+        $userData = $request->userData;
+        list($status,$data) = $service->rdLockList($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function rdLock(Request $request){
+        $service = new StatisticsService();
+        $userData = $request->userData;
+        list($status,$data) = $service->rdLock($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 1 - 0
app/Model/RD.php

@@ -11,6 +11,7 @@ class RD extends UseScopeBaseModel
     const employee_column = "crt_id";
 
     public static $field = ['order_number','id','item_id','start_time_hour','crt_time','order_time','crt_id','start_time_min','end_time_hour','end_time_min','total_hours'];
+    public static $field_2 = ['a.belong_month','a.type','b.id'];
 
     protected $dateFormat = 'U';
 

+ 21 - 0
app/Model/RdLock.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class RdLock extends Model
+{
+    protected $guarded = [];
+    protected $table = "rd_lock"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const type_one = 1;
+    const type_two = 2;
+    public static $type_name = [
+        self::type_one => '研发人工时单',
+        self::type_two => '研发设备工时单',
+    ];
+}

+ 20 - 0
app/Service/RDService.php

@@ -7,17 +7,30 @@ use App\Model\Employee;
 use App\Model\Item;
 use App\Model\RD;
 use App\Model\RdDetails;
+use App\Model\RdLock;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Str;
 
 class RDService extends Service
 {
     public function rdCreate($data, $user){
+        $month = $data['month'];
+        $lock = RdLock::where('del_time',0)
+            ->where('belong_month', strtotime(date($data['month'] . '-01')))
+            ->where('type', RD::type_one)
+            ->exists();
+        if($lock) return [false, RD::$type_name[RD::type_one] . '在' . $month . '已封存,生成失败'];
         list($status, $msg) = (new RdGenerateService())->generate($data);
         return [$status, $msg];
     }
 
     public function rdCreate2($data, $user){
+        $month = $data['month'];
+        $lock = RdLock::where('del_time',0)
+            ->where('belong_month', strtotime(date($data['month'] . '-01')))
+            ->where('type', RD::type_two)
+            ->exists();
+        if($lock) return [false, RD::$type_name[RD::type_two] . '在' . $month . '已封存,生成失败'];
         list($status, $msg) = (new RdGenerateDeviceService())->generate($data);
         return [$status, $msg];
     }
@@ -261,6 +274,13 @@ class RDService extends Service
         if(empty($data['order_time'])) return [false, '订单日期不能为空'];
         $data['order_time'] = $this->changeDateToDate($data['order_time']);
 
+        $month = date('Y-m', $data['order_time']);
+        $lock = RdLock::where('del_time',0)
+            ->where('belong_month', strtotime(date('Y-m-01', $data['order_time'])))
+            ->where('type', $data['type'])
+            ->exists();
+        if($lock) return [false, $type_title . '在' . $month . '已封存,单据创建失败'];
+
         if($data['type'] == RD::type_one){
             if(empty($data['man_list'])) return [false, '研发人员不能为空'];
             foreach ($data['man_list'] as $value){

+ 131 - 0
app/Service/StatisticsService.php

@@ -9,8 +9,11 @@ use App\Model\Employee;
 use App\Model\EmployeeDetails;
 use App\Model\EmployeeRole;
 use App\Model\Item;
+use App\Model\RD;
 use App\Model\RdDetails;
+use App\Model\RdLock;
 use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
 
 class StatisticsService extends Service
 {
@@ -535,4 +538,132 @@ class StatisticsService extends Service
 
         return $device;
     }
+
+    public function rdLockList($data,$user){
+        $model = $this->rdLockListCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->rdLockListFillData($list,$data);
+
+        return [true, $list];
+    }
+
+    public function rdLockListCommon($data,$user){
+        if(empty($field)) $field = RD::$field_2;
+
+        $model = RD::from('rd as a')
+            ->leftJoin('rd_lock as b', function ($join) {
+                $join->on('a.type', '=', 'b.type')
+                    ->on('a.belong_month', '=', 'b.belong_month')
+                    ->where('b.del_time', '=', 0);
+            })
+            ->where('a.del_time', 0)
+            // 分开写,就不会混淆参数了
+            ->select($field)
+            ->groupBy('a.belong_month', 'a.type')
+            ->orderByRaw("a.belong_month DESC");
+
+        if(! empty($data['type'])) $model->where('a.type', $data['type']);
+        if(! empty($data['belong_month'])) {
+            $time = strtotime($data['belong_month'] . '-01');
+            $model->where('a.belong_month', $time);
+        }
+        if (isset($data['is_fc'])) {
+            if ($data['is_fc'] == 1) {
+                // 匹配成功:b.id 必须存在
+                $model->whereNotNull('b.id');
+            } else {
+                // 匹配失败:b.id 必须为空
+                $model->whereNull('b.id');
+            }
+        }
+
+        return $model;
+    }
+
+    public function rdLockListFillData($data, $ergs){
+        if(empty($data['data'])) return $data;
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['type_title'] = RdLock::$type_name[$value['type']] ?? "";
+            $data['data'][$key]['belong_month_show'] = $value['belong_month'] ? date('Y-m', $value['belong_month']) : '';
+            $data['data'][$key]['id'] = $value['id'] ?? 0;
+            $data['data'][$key]['id_show'] = $value['id'] ? '已封存' : '未封存';
+        }
+
+        return $data;
+    }
+
+    public function rdLock($data,$user){
+        if(empty($data['lock_array'])) return [false, '请选择数据'];
+        if(empty($data['lock_type'])) return [false, 'lock_type不能为空'];
+
+        $insert = [];$time = time();
+        foreach ($data['lock_array'] as $value){
+            if(empty($value['belong_month'])) return [false, 'belong_month不能为空'];
+            if(empty($value['type'])) return [false, 'type不能为空'];
+            $insert[] = [
+                'belong_month' => $value['belong_month'],
+                'type' => $value['type'],
+                'crt_time' => $time
+            ];
+        }
+
+        $count = $this->checkRdExists($data);
+
+        try {
+            if($data['lock_type'] == 1){//操作封存
+                if($count != 0) return [false, '含有已封存数据,开启封存失败'];
+                RdLock::insert($insert);
+            }elseif ($data['lock_type'] == 2){//解除封存
+                if($count != count($data['lock_array'])) return [false, '含有未封存数据,解除封存失败'];
+                $this->delRdExists($data, $time);
+            }else{
+                return [false, '操作类型错误'];
+            }
+        }catch (\Exception $exception){
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function checkRdExists($data) {
+        $lockArray = $data['lock_array'];
+
+        $query = RdLock::where('del_time', 0);
+
+        // 1. 构造批量查询条件
+        $query->where(function($q) use ($lockArray) {
+            foreach ($lockArray as $item) {
+                $q->orWhere(function($sub) use ($item) {
+                    $sub->where('belong_month', $item['belong_month'])
+                        ->where('type', $item['type']);
+                });
+            }
+        });
+
+        // 2. 获取数据库中实际存在的【唯一组合】数量
+        return $query->selectRaw('belong_month, type')
+            ->groupBy('belong_month', 'type')
+            ->get()
+            ->count();
+    }
+
+    public function delRdExists($data, $now) {
+        $lockArray = $data['lock_array'];
+
+        $query = RdLock::where('del_time', 0);
+
+        // 1. 构造批量查询条件
+        $query->where(function($q) use ($lockArray) {
+            foreach ($lockArray as $item) {
+                $q->orWhere(function($sub) use ($item) {
+                    $sub->where('belong_month', $item['belong_month'])
+                        ->where('type', $item['type']);
+                });
+            }
+        });
+
+        $query->update(['del_time' => $now]);
+    }
 }

+ 21 - 0
config/header/82.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'belong_month_show',
+        'value' => '所属年月',
+    ],
+    [
+        'key' =>'type_title',
+        'value' => '单据类型',
+    ],
+    [
+        'key' =>'id_show',
+        'value' => '是否封存',
+    ],
+];

+ 3 - 0
routes/api.php

@@ -124,6 +124,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //统计
     $route->any('statisticsEmployee', 'Api\StatisticsController@statisticsEmployee');
     $route->any('statisticsDevice', 'Api\StatisticsController@statisticsDevice');
+    //封存
+    $route->any('rdLockList', 'Api\StatisticsController@rdLockList');
+    $route->any('rdLock', 'Api\StatisticsController@rdLock');
 
     //获取默认表头
     $route->any('getTableHead','Api\TableHeadController@tableHeadGet');