|
@@ -213,12 +213,34 @@ class EmployeeService extends Service
|
|
public function employeeDel($data){
|
|
public function employeeDel($data){
|
|
if($this->isEmpty($data,'id')) return [false,'请选择删除的数据!'];
|
|
if($this->isEmpty($data,'id')) return [false,'请选择删除的数据!'];
|
|
|
|
|
|
- Employee::whereIn('id',$data['id'])->update([
|
|
|
|
- 'del_time'=>time()
|
|
|
|
- ]);
|
|
|
|
- EmployeeRole::where('del_time',0)->whereIn('employee_id',$data['id'])->update([
|
|
|
|
- 'del_time'=>time()
|
|
|
|
- ]);
|
|
|
|
|
|
+ try{
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+
|
|
|
|
+ $pic = Employee::whereIn('id',$data['id'])
|
|
|
|
+ ->select('pic')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $pic = array_filter(array_column($pic,'pic'));
|
|
|
|
+
|
|
|
|
+ Employee::whereIn('id',$data['id'])->update([
|
|
|
|
+ 'del_time'=>time()
|
|
|
|
+ ]);
|
|
|
|
+ EmployeeRole::where('del_time',0)->whereIn('employee_id',$data['id'])->update([
|
|
|
|
+ 'del_time'=>time()
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if(! empty($pic)){
|
|
|
|
+ foreach ($pic as $value){
|
|
|
|
+ // 使用正则表达式匹配特定路径部分并替换为空
|
|
|
|
+ $pattern = '/^https?:\/\/[^\/]+\/image\//';
|
|
|
|
+ $replacedUrl = preg_replace($pattern, '', $value);
|
|
|
|
+ (new FileUploadService())->delLocalPublicFile($replacedUrl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Throwable $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
|
+ }
|
|
|
|
|
|
return [true,'删除成功'];
|
|
return [true,'删除成功'];
|
|
}
|
|
}
|