Преглед изворни кода

料箱多商品:部分逻辑处理块

Zhouzhendong пре 4 година
родитељ
комит
4704a063d6

+ 5 - 0
app/CommodityMaterialBoxModel.php

@@ -16,4 +16,9 @@ class CommodityMaterialBoxModel extends Model
     protected $fillable=[
         "commodity_id","material_box_model_id","maximum"
     ];
+
+    public function materialBoxModel()
+    {
+        return $this->belongsTo(MaterialBoxModel::class,"material_box_model_id","id");
+    }
 }

+ 16 - 4
app/Http/Controllers/MaterialBoxModelController.php

@@ -2,11 +2,13 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
 use App\MaterialBoxModel;
 use Illuminate\Support\Facades\Validator;
 
 class MaterialBoxModelController extends Controller
 {
+    use AsyncResponse;
     public function index()
     {
         $models = MaterialBoxModel::query()->get();
@@ -29,10 +31,20 @@ class MaterialBoxModelController extends Controller
             'maximum_kind'=>'最大商品种类',
             'description'=>'说明',
         ]);
-        if (!$id){
-            MaterialBoxModel::query()->create([
+        if ($errors->errors()->count())$this->success(["errors"=>$errors->errors()]);
+        if (!$id) $this->success(MaterialBoxModel::query()->create([
+                'code' => request("code"),
+                'maximum_kind' => request("maximum_kind"),
+                'description' => request("description"),
+            ]));
+        $model = MaterialBoxModel::query()->find($id);
+        if (!$model)$this->error("模型不存在");
+        $model->update(request()->only(["code",'maximum_kind',"description"]));
+        $this->success($model);
+    }
 
-            ]);
-        }
+    public function destroy()
+    {
+        $this->success(MaterialBoxModel::destroy(request("id")));
     }
 }

+ 4 - 3
app/Http/Controllers/StorageController.php

@@ -188,12 +188,13 @@ sql;
         if (!$boxId){
             if (!$modelId){
                 $box = null;
-                $models = CommodityMaterialBoxModel::query()->where("commodity_id",request("commodity_id"))->get();
+                $models = CommodityMaterialBoxModel::query()->with("materialBoxModel")->where("commodity_id",request("commodity_id"))->get();
                 foreach ($models as $model){
-                    $box = app("MaterialBoxService")->getAnEmptyBox([],$model->material_box_model_id);
+                    if (!$model->materialBoxModel)continue;
+                    $box = app("MaterialBoxService")->getAnEmptyBox($model->materialBoxModel);
                     if($box)break;
                 }
-            }else $box = app("MaterialBoxService")->getAnEmptyBox([],$modelId);
+            }else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
             if (!$box)$this->error("无可用料箱");
             $boxId = $box->id;
         }

+ 2 - 2
app/Services/ForeignHaiRoboticsService.php

@@ -510,13 +510,13 @@ class ForeignHaiRoboticsService
      *
      * @throws
      */
-    public function paddingCacheShelf($stations)
+    public function paddingCacheShelf($stations):?bool
     {
         $collection = new Collection();
         $stationCollection = new Collection();
         $blacklist = [];
         foreach ($stations as $station){
-            $box = app("MaterialBoxService")->getAnEmptyBox($blacklist);
+            $box = app("MaterialBoxService")->getAnEmptyBoxSortedByOwner(null,$blacklist);
             if (!$box)break;
             $task = StationTask::query()->create([
                 'status' => "待处理",

+ 27 - 10
app/Services/MaterialBoxService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 
 
 use App\MaterialBox;
+use App\MaterialBoxModel;
 use App\StationTaskMaterialBox;
 use App\Storage;
 use Illuminate\Database\Eloquent\Builder;
@@ -21,12 +22,12 @@ class MaterialBoxService
     /**
      * 获取一个空料箱
      *
+     * @param MaterialBoxModel|\stdClass $model
      * @param array $blacklist
-     * @param integer|null $modelId
      *
      * @return MaterialBox|null
      */
-    public function getAnEmptyBox(array $blacklist = [], $modelId = null)
+    public function getAnEmptyBox(MaterialBoxModel $model,array $blacklist = []):?MaterialBox
     {
         $id = 0;
         while (true){
@@ -36,8 +37,8 @@ class MaterialBoxService
                 ->where("id",">",$id)->where("code","like","IDE%")
                 ->where("status",4)->limit(50)->orderBy("id")
                 ->whereNotIn("id",StationTaskMaterialBox::query()->select("material_box_id")
-                    ->where("status","!=","完成")->groupBy("material_box_id"));
-            if ($modelId)$boxes->where("material_box_model_id",$modelId);
+                    ->whereNotIn("status",["完成","取消"])
+                    ->where("material_box_model_id",$model->id)->groupBy("material_box_id"));
             $boxes = $boxes->get();
             if ($boxes->count()==0)break;
             $id = $boxes[count($boxes)-1]->id;
@@ -53,7 +54,7 @@ class MaterialBoxService
                 ->whereNotIn("status",[0,4])->get();
             $haiBoxes->each(function ($haiBox)use(&$notCodes){$notCodes[$haiBox->bin_code] = true;});
 
-            //检测FLUX
+            //剔除FLUX已有库存并且库位内种类超出的料箱
             $ides = [];
             $str = "(";
             foreach ($boxes as $box){
@@ -64,17 +65,33 @@ class MaterialBoxService
             if (!$ides)continue;
             $str = rtrim($str,",").")";
             $sql = <<<sql
-SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID
+SELECT LOCATIONID FROM (SELECT LOCATIONID FROM (SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID,LOTNUM,CUSTOMERID,SKU) where qty>0) GROUP BY
+                            LOCATIONID HAVING (COUNT(*)>={$model->maximum_kind});
 sql;
-            foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item){
-                if ((int)$item->qty==0)return $ides[$item->locationid];
-                unset($ides[$item->locationid]);
-            }
+            foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item)unset($ides[$item->locationid]);
             if ($ides)return current($ides);
         }
         return null;
     }
 
+    /**
+     * 获取所有者排序的空盒子
+     *
+     * @param integer|null $ownerId
+     * @param array $blacklist
+     *
+     * @return MaterialBox|null
+     */
+    public function getAnEmptyBoxSortedByOwner(?int $ownerId=null, array $blacklist=[]):?MaterialBox
+    {
+        $models = app("MaterialBoxModelService")->getModelSortedByOwner($ownerId);
+        foreach ($models as $model){
+            $box = $this->getAnEmptyBox($model,$blacklist);
+            if ($box)return $box;
+        }
+        return null;
+    }
+
     /**
      * 获取料箱所在库区
      *

+ 0 - 31
app/Services/StorageService.php

@@ -23,37 +23,6 @@ class StorageService
     use ServiceAppAop;
     protected $modelClass=Storage::class;
 
-
-    /**
-     * 填充缓存架
-     *
-     * @param \Illuminate\Database\Eloquent\Collection $stations
-     */
-    public function paddingCacheShelf($stations)
-    {
-        $collection = new Collection();
-        $stationCollection = new Collection();
-        $blacklist = [];
-        foreach ($stations as $station){
-            $box = app("MaterialBoxService")->getAnEmptyBox($blacklist);
-            if (!$box)continue;
-            $task = StationTask::query()->create([
-                'status' => "待处理",
-                'station_id' => $station->id,
-            ]);
-            $collection->add(StationTaskMaterialBox::query()->create([
-                'station_id' => $station->id,
-                'material_box_id'=>$box->id,
-                'status'=>"待处理",
-                'type' => '取',
-                'station_task_id' => $task->id,
-            ]));
-            $stationCollection->add($station->code);
-            $blacklist[] = $box->id;
-        }
-        app("ForeignHaiRoboticsService")->fetchGroup_multiLocation($stationCollection,$collection,'','立架出至缓存架');
-    }
-
     /**
      * 缓存架放置记录
      *

+ 26 - 9
resources/views/maintenance/materialBoxModel/index.blade.php

@@ -18,8 +18,8 @@
                     <td>@{{ model.description }}</td>
                     <td>@{{ model.maximum_kind }}</td>
                     <td>
-                        <button class="btn btn-sm btn-outline-primary" @click="edit(city.id)">改</button>
-                        <button class="btn btn-sm btn-outline-dark" @click="destroy(city)">删</button>
+                        <button class="btn btn-sm btn-outline-primary" @click="openModal(model)">改</button>
+                        <button class="btn btn-sm btn-outline-dark" @click="destroy(model)">删</button>
                     </td>
                 </tr>
             </table>
@@ -37,24 +37,41 @@
                 errors:{},
             },
             methods:{
-                openModal(model= {maximum_kind:1}){
-                    this.model = model;
+                openModal(model=null){
+                    if (model) this.model = Object.assign({},model);
+                    else this.model = {maximum_kind:1};
                     $("#modal").modal("show");
                 },
                 submitModel(){
                     window.tempTip.postBasicRequest("{{url('maintenance/materialBoxModel/save')}}",this.model,res=>{
+                        if (res.errors){
+                            this.errors = res.errors;
+                            return;
+                        }
                         if (!this.model.id){
                             this.models.unshift(res);
-                            return "新增成功";
-                        }
-                        this.models.some((model,index)=>{
+                        }else this.models.some((model,index)=>{
                             if (model.id===res.id){
                                 this.$set(this.models,index,res);
                                 return true;
                             }
                         });
-                        return "修改成功";
-                    });
+                        $("#modal").modal("hide");
+                        return this.model.id ? "修改成功" : '新增成功';
+                    },true);
+                },
+                destroy(model){
+                    window.tempTip.confirm("确定要剔除此模型记录吗?",()=>{
+                        window.tempTip.postBasicRequest("{{url('maintenance/materialBoxModel/destroy')}}",{id:model.id},()=>{
+                            this.models.some((m,index)=> {
+                                if (m.id === model.id) {
+                                    this.$delete(this.models, index);
+                                    return true;
+                                }
+                            });
+                            return "删除成功";
+                        });
+                    })
                 },
             }
         });

+ 4 - 1
routes/web.php

@@ -81,7 +81,10 @@ Route::group(['middleware'=>'auth'],function ($route){
     $route->group(['prefix'=>'maintenance'],function(){
         /** 料箱型号 */
         Route::get("materialBoxModel","MaterialBoxModelController@index");
-        Route::get("save","MaterialBoxModelController@save");
+        Route::group(['prefix'=>"materialBoxModel"],function (){
+            Route::post("save","MaterialBoxModelController@save");
+            Route::post("destroy","MaterialBoxModelController@destroy");
+        });
         /** 菜单 */
         Route::get('menu', 'MenuController@index');
         Route::group(['prefix'=>"menu"],function (){