cqpCow 1 year ago
parent
commit
c1fdb25541

+ 5 - 2
.idea/workspace.xml

@@ -3,7 +3,10 @@
   <component name="ChangeListManager">
     <list default="true" id="b5852db3-28ab-419d-82cf-b6c0f6b99397" name="变更" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/app/Service/EmployeeService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/EmployeeService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/MeasureController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/MeasureController.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/MaterialService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/MaterialService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/MeasureService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/MeasureService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/Service.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/Service.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -146,7 +149,7 @@
       <workItem from="1685595177391" duration="2533000" />
       <workItem from="1685669123669" duration="2439000" />
       <workItem from="1685952381761" duration="726000" />
-      <workItem from="1686021203384" duration="6377000" />
+      <workItem from="1686021203384" duration="8475000" />
     </task>
     <servers />
   </component>

+ 0 - 8
app/Http/Controllers/Api/MeasureController.php

@@ -4,21 +4,13 @@ namespace App\Http\Controllers\Api;
 
 
 use App\Service\MeasureService;
-use App\Service\SysMenuService;
 use Illuminate\Http\Request;
 
 
 class MeasureController extends BaseController
 {
-
-
-
-
-
     public function add(Request $request)
     {
-
-
         $service = new MeasureService();
         $user = $request->get('auth');
         list($status,$data) = $service->add($request->all(),$request->all());

+ 20 - 2
app/Service/MaterialService.php

@@ -69,6 +69,11 @@ class MaterialService extends Service
                 $data['data'][$key]['crt_time'] = time();
             }else{
                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
+                $bool = BasicMaterial::where('del_time',0)
+                    ->where('parent_id',$data['id'])
+                    ->exists();
+                if($bool) return [false,'物料分类下存在子集!'];
+
                 $bool = BasicMaterial::where('title',$value['title'])
                     ->where('id','<>',$data['id'])
                     ->where('del_time',0)
@@ -176,11 +181,24 @@ class MaterialService extends Service
     }
 
     public function MaterialList($data){
-        $list = Material::where('del_time',0)
+        $model = Material::where('del_time',0)
             ->select('title','b_m_id','abbreviation_title','unit','crt_time','upd_time','id')
             ->orderBy('id','desc');
 
-        $list = $this->limit($list,'',$data);
+        if(! empty($data['b_m_id'])) {
+            $type = BasicMaterial::where('del_time',0)
+                ->select('id','parent_id')
+                ->get()->toArray();
+            $this->getAllIdsArr($type,0,'',$ids);
+            $string = $this->getLongestStr($ids, $data['b_m_id']);
+            $pos = strpos($string, (string)$data['b_m_id']);
+            if ($pos !== false) $id = substr($string, $pos);
+            $res_id = [];
+            if(! empty($id)) $res_id = explode(',',$id);
+            $model->whereIn("b_m_id", $res_id);
+        }
+
+        $list = $this->limit($model,'',$data);
 
         return [true,$list];
     }

+ 2 - 19
app/Service/MeasureService.php

@@ -2,17 +2,7 @@
 
 namespace App\Service;
 
-
-use App\Model\Depart;
-use App\Model\Employee;
-use App\Model\EmployeeDepartPermission;
-use App\Model\EmployeeMenuPermission;
-use App\Model\EmployeeTeamPermission;
 use App\Model\Measure;
-use App\Model\Role;
-use App\Model\SysMenu;
-use App\Model\Team;
-use Illuminate\Support\Facades\Hash;
 
 /**
  * 测量相关
@@ -20,7 +10,6 @@ use Illuminate\Support\Facades\Hash;
  */
 class MeasureService extends Service
 {
-
     public function edit($data){
         if($this->isEmpty($data,'id')) return [201,'ID不存在!'];
         list($status,$msg) = $this->rule($data);
@@ -32,30 +21,24 @@ class MeasureService extends Service
         $model = $model->where('id',$data['id'])->first();
         $model->title = $data['title'];
         $model->e_title = $data['e_title'] ;
-        $model->sort = $data['sort'] ?? 0;
 
         $model->save();
 
         return [true,'保存成功!'];
-
-
     }
 
     public function add($data,$user){
-
-
-//        if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
         list($status,$msg) = $this->rule($data);
         if(!$status) return [$status,$msg];
         $first = Measure::where('title',$data['title'])->where('del_time',0)->first();
         if(!empty($first))return [false,'名称已存在!'];
 
         $model = new Measure();
+        $sort = $model->max('sort');
 
         $model->title = $data['title'];
         $model->e_title = $data['e_title'] ;
-        $model->sort = $data['sort'] ?? 0;
-
+        $model->sort = $sort ? $sort + 1 : 1;
         $model->save();
 
         return [true,'保存成功!'];

+ 23 - 0
app/Service/Service.php

@@ -201,4 +201,27 @@ class Service
         return $result;
     }
 
+    function getAllIdsArr($data, $pid = 0, $prefix = '', &$result = []) {
+        foreach ($data as $node) {
+            if ($node['parent_id'] == $pid) {
+                $id = $prefix . $node['id'];
+                $result[] = $id;
+                $this->getAllIdsArr($data, $node['id'], $id . ',', $result);
+            }
+        }
+        return $result;
+    }
+
+    function getLongestStr($arr = [], $searchStr){
+        if(empty($arr) || ! $searchStr) return '';
+        if(! is_string($searchStr)) $searchStr = (string)$searchStr;
+
+        $longest = '';
+        foreach ($arr as $str) {
+            if (strpos($str, $searchStr) !== false && strlen($str) > strlen($longest)) {
+                $longest = $str;
+            }
+        }
+        return $longest;
+    }
 }