|
|
@@ -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]);
|
|
|
+ }
|
|
|
}
|