|
@@ -2,54 +2,32 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
-
|
|
|
-use App\Model\SysMenu;
|
|
|
-use App\Models\BasicProcess;
|
|
|
-use App\Models\Process;
|
|
|
+use App\Model\BasicProcess;
|
|
|
+use App\Model\Process;
|
|
|
|
|
|
/**
|
|
|
- * 工艺相关
|
|
|
+ * 工序相关
|
|
|
* @package App\Models
|
|
|
*/
|
|
|
class ProcessService extends Service
|
|
|
{
|
|
|
-
|
|
|
public function basicProcessEdit($data){
|
|
|
- list($status,$msg) = $this->basicProcessRule($data);
|
|
|
+ list($status,$msg) = $this->basicProcessRule($data,false);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
- if($this->isEmpty($data,'id')) return [false,'ID不存在'];
|
|
|
- $first = BasicProcess::where('title',$data['title'])->where('del_time',0)->first();
|
|
|
- if(!empty($first))return [false,'名称已存在!'];
|
|
|
-
|
|
|
-
|
|
|
- $model = new BasicProcess();
|
|
|
- $model = $model->where('id',$data['id'])->first();
|
|
|
- $model->title = $data['title'];
|
|
|
- $model->parent_id = $data['parent_id'] ;
|
|
|
- $model->save();
|
|
|
|
|
|
+ $update = $msg['data'][0];
|
|
|
+ BasicProcess::where('id',$data['id'])->update($update);
|
|
|
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function basicProcessAdd($data,$user){
|
|
|
-
|
|
|
-
|
|
|
-// if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
|
|
|
list($status,$msg) = $this->basicProcessRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
- $first = BasicProcess::where('title',$data['title'])->where('del_time',0)->first();
|
|
|
- if(!empty($first))return [false,'名称已存在!'];
|
|
|
-
|
|
|
- $model = new BasicProcess();
|
|
|
|
|
|
- $model->title = $data['title'];
|
|
|
- $model->parent_id = $data['parent_id'] ;
|
|
|
- $model->save();
|
|
|
+ BasicProcess::insert($msg['data']);
|
|
|
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function basicProcessDel($data){
|
|
@@ -63,19 +41,48 @@ class ProcessService extends Service
|
|
|
}
|
|
|
|
|
|
public function basicProcessList($data){
|
|
|
- $list = BasicProcess::where('del_time',0)->select('title','parent_id','crt_time','upd_time')->get()->toArray();
|
|
|
+ $list = BasicProcess::where('del_time',0)->select('title','parent_id','crt_time','upd_time','id')->get()->toArray();
|
|
|
$return = $this->makeTree(0,$list);
|
|
|
$return = $this->set_sort_circle($return);
|
|
|
|
|
|
-
|
|
|
return [200,$return];
|
|
|
}
|
|
|
|
|
|
- public function basicProcessRule($data){
|
|
|
- if($this->isEmpty($data,'title')) return [false,'名称不存在!'];
|
|
|
- if($this->isEmpty($data,'parent_id')) return [false,'父级不存在!'];
|
|
|
-
|
|
|
- return [true,''];
|
|
|
+ public function basicProcessRule($data,$is_add = true){
|
|
|
+ if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
|
|
|
+ $title = array_column($data['data'],'title');
|
|
|
+ $title = array_map(function($val) {
|
|
|
+ return $val !== null ? $val : 0;
|
|
|
+ }, $title);
|
|
|
+ $title_count = array_count_values($title);
|
|
|
+ foreach ($title as $value){
|
|
|
+ if(empty($value)) return [false,'名称不能为空!'];
|
|
|
+ if($title_count[$value] > 1) return [false,'名称不能重复'];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['upd_time'] = time();
|
|
|
+ if($is_add){
|
|
|
+ $bool = BasicProcess::where('title',$value['title'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->exists();
|
|
|
+ $data['data'][$key]['crt_time'] = time();
|
|
|
+ }else{
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
|
|
|
+ $bool = BasicProcess::where('del_time',0)
|
|
|
+ ->where('parent_id',$data['id'])
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false,'物料分类下存在子集!'];
|
|
|
+
|
|
|
+ $bool = BasicProcess::where('title',$value['title'])
|
|
|
+ ->where('id','<>',$data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->exists();
|
|
|
+ }
|
|
|
+ if($bool) return [false,'名称不能重复'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,$data];
|
|
|
}
|
|
|
|
|
|
public function processEdit($data){
|
|
@@ -85,22 +92,16 @@ class ProcessService extends Service
|
|
|
$first = Process::where('title',$data['title'])->where('id','<>',$data['id'])->where('del_time',0)->first();
|
|
|
if(!empty($first))return [false,'名称已存在!'];
|
|
|
|
|
|
-
|
|
|
$model = new Process();
|
|
|
$model = $model->where('id',$data['id'])->first();
|
|
|
$model->title = $data['title'];
|
|
|
$model->p_id = $data['p_id'] ;
|
|
|
$model->save();
|
|
|
|
|
|
-
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function processAdd($data,$user){
|
|
|
-
|
|
|
-
|
|
|
-// if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
|
|
|
list($status,$msg) = $this->processRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
$first = Process::where('title',$data['title'])->where('del_time',0)->first();
|
|
@@ -113,7 +114,6 @@ class ProcessService extends Service
|
|
|
$model->save();
|
|
|
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function processDel($data){
|
|
@@ -127,10 +127,8 @@ class ProcessService extends Service
|
|
|
}
|
|
|
|
|
|
public function processList($data){
|
|
|
- $list = Process::where('del_time',0)->select('title','p_id','crt_time','upd_time');
|
|
|
-// $return = $this->makeTree(0,$list);
|
|
|
-// $return = $this->set_sort_circle($return);
|
|
|
- $list = $this->limit($list,'',$list);
|
|
|
+ $list = Process::where('del_time',0)->select('title','p_id','crt_time','upd_time','id');
|
|
|
+ $list = $this->limit($list,'',$data);
|
|
|
|
|
|
return [200,$list];
|
|
|
}
|
|
@@ -141,6 +139,4 @@ class ProcessService extends Service
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|