Zhouzhendong 4 лет назад
Родитель
Сommit
b0c78f4ead

+ 1 - 2
app/Http/Controllers/TestController.php

@@ -120,7 +120,6 @@ class TestController extends Controller
 
     public function test3()
     {
-        $order = Order::query()->find(3716054);
-        app("OrderService")->createInstantBill($order);
+        Station::query()->update(["status"=>0]);
     }
 }

+ 10 - 6
app/Http/Controllers/api/thirdPart/haiq/StorageController.php

@@ -272,19 +272,23 @@ class StorageController
     public function lightOff(Request $request){
         return $this->light($request,$this->lightOff);
     }
-    public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
-        LogService::log('海柔请求','taskUpdate',
-            json_encode($request->all()));
+
+    /**
+     * 海柔通知:任务状态变更
+     *
+     * @param ForeignHaiRobotic_taskUpdateRequest $request
+     * @return array
+     */
+    public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request):array
+    {
+        LogService::log('海柔请求','taskUpdate', json_encode($request->all()));
         try{
             $stationTaskMaterialBox_id = explode('_',$request['taskCode'])[0];
             $this->service->taskUpdate(
-//                $request['groupCode']
                 $stationTaskMaterialBox_id
                 ,$request['updateEventType']
                 ,$request['status']
                 ,$request['binCode']
-//                ,$request['kubotId']
-//                ,$request['description']
             );
             return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
         }catch (\Exception $e){

+ 39 - 45
app/Services/ForeignHaiRoboticsService.php

@@ -4,6 +4,7 @@
 namespace App\Services;
 
 
+use App\Components\ErrorPush;
 use App\Exceptions\ErrorException;
 use App\Exceptions\Exception;
 use App\Jobs\CacheShelfTaskJob;
@@ -21,7 +22,7 @@ use App\Traits\ServiceAppAop;
 
 class ForeignHaiRoboticsService
 {
-    use ServiceAppAop;
+    use ServiceAppAop,ErrorPush;
 
     /** @var  $stationTaskMaterialBoxService StationTaskMaterialBoxService */
     private $stationTaskMaterialBoxService;
@@ -334,58 +335,51 @@ class ForeignHaiRoboticsService
         return $controlSuccess;
     }
 
+    /**
+     * 任务变更时的动作
+     *
+     * @param $stationTaskMaterialBox_id
+     * @param $updateEventType
+     * @param $status
+     * @param $binCode
+     * @return bool
+     */
     public function taskUpdate(
-//        $groupCode,
         $stationTaskMaterialBox_id, //实际对应传入的字段 taskCode, 这里用料箱任务号做taskCode
         $updateEventType,   //0:task_begin(取货)1:task_end(放货)
         $status,            //0:任务成功1:任务失败
         $binCode
     ):bool{
-        LogService::log('海柔请求','taskUpdateIn',
-            json_encode([
-                $stationTaskMaterialBox_id,
-                $updateEventType,
-                $status,
-                $binCode
-            ]));
         $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
-        try{
-            if(($failed
-                    =$status)==1){
-                throw new ErrorException('海柔任务失败');
-            }
-            if($料箱不匹配=
-                !$stationTaskMaterialBox
-                    =(function()use($stationTaskMaterialBox_id,$binCode){
-                    $stationTaskMaterialBox=StationTaskMaterialBox::query()->find($id=$stationTaskMaterialBox_id);
-                    if($stationTaskMaterialBox['materialBox']['code']==$binCode)return $stationTaskMaterialBox;
-                    return null;
-                })()){
-                throw new ErrorException('发回的料箱和任务号(ID)不匹配:$stationTaskMaterialBox_id:'
-                    .$stationTaskMaterialBox_id.' $binCode:'.$binCode. ' '.
-                    StationTaskMaterialBox::query()
-                        ->where('id', $id=$stationTaskMaterialBox_id)
-                        ->get()
-                        ->toJson());
+        if ($status==1){ //海柔失败
+            $this->push(__METHOD__."->".__LINE__,"海柔任务异常",json_encode(request()->input()));
+            return false;
+        }
+        //获取下达任务
+        /** @var StationTaskMaterialBox|\stdClass $stationTaskMaterialBox */
+        $stationTaskMaterialBox = $stationTaskMaterialBox_id ? StationTaskMaterialBox::query()->with("materialBox:id,code")
+            ->find($stationTaskMaterialBox_id) : null;
+        if (!$stationTaskMaterialBox || !$stationTaskMaterialBox->materialBox){
+            $this->push(__METHOD__."->".__LINE__,"海柔任务不存在",json_encode(request()->input()));
+            return false;
+        }
+        if ($stationTaskMaterialBox->materialBox->code != $binCode){
+            $this->push(__METHOD__."->".__LINE__,"海柔任务料箱号不匹配",json_encode(request()->input()));
+            return false;
+        }
+        try {
+            switch ($updateEventType){
+                case 0://已取出
+                    $this->stationTaskMaterialBoxService->markHasTaken($stationTaskMaterialBox);
+                    break;
+                case 1://已放置
+                    $this->stationTaskMaterialBoxService->markHasPut($stationTaskMaterialBox);
+                    break;
+                default:
+                    throw new \Exception("任务进行状态错误,未捕获");
             }
-            if(($标记已放置=
-                function()use($updateEventType,$stationTaskMaterialBox){
-                    if(($isPut
-                            =$updateEventType)==1){
-                        $this->stationTaskMaterialBoxService->markHasPut($stationTaskMaterialBox);
-                        return true;
-                    }return false;
-                })())
-                    return true;
-            ($标记已取出=
-                function()use($updateEventType,$stationTaskMaterialBox){
-                    if(($isGet
-                            =$updateEventType)==0){
-                        $this->stationTaskMaterialBoxService->markHasTaken($stationTaskMaterialBox);
-                    }
-                })();
-        }catch (\Exception $e){
-            $this->excepted($stationTaskMaterialBox_id, $binCode, $e->getMessage());
+        }catch (\Exception $err){
+            $this->push(__METHOD__."->".__LINE__,"海柔任务通知失败",json_encode(request()->input())." | ".$err->getMessage());
             return false;
         }
         return true;

+ 0 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -172,7 +172,6 @@ class StationTaskMaterialBoxService
                 case '入立库':
                     $stationTaskMaterialBox->materialBox['status']='在立库';
                     $stationTaskMaterialBox->materialBox->update();
-                    //$this->storageService->checkMark($stationTaskMaterialBox); //检查标记并做一些特殊处理
                     break;
                 case '入缓存架':
                     $stationTaskMaterialBox->materialBox['status']='在缓存架';

+ 2 - 2
app/Services/StorageService.php

@@ -97,8 +97,8 @@ class StorageService
                     }
                     app("CacheShelfService")->lightUp($stationTaskMaterialBox->station->code,'2','0',$options);
                     Cache::forget("CACHE_SHELF_OCCUPANCY_{$stationTaskMaterialBox->station->id}");//关闭无限亮灯
-                }
-            }else app("StationService")->locationFreed($stationTaskMaterialBox->station->code); //释放库位占用
+                }else app("StationService")->locationFreed($stationTaskMaterialBox->station->code); //释放库位占用
+            }
             DB::commit();
         }catch (\Exception $e){
             DB::rollBack();

+ 1 - 1
database/migrations/2021_08_13_093836_create_owner_fee_operation_details.php

@@ -15,7 +15,7 @@ class CreateOwnerFeeOperationDetails extends Migration
     {
         Schema::create('owner_fee_operation_details', function (Blueprint $table) {
             $table->id();
-            $table->bigInteger("owner_fee_operation_id")->comment("外键父级");
+            $table->bigInteger("owner_fee_operation_id")->index()->comment("外键父级");
             $table->string("name")->comment("名称");
             $table->decimal("amount",10,3)->comment("数量");
             $table->decimal("price",10,3)->comment("单价");