Explorar o código

android需求-波次修复

Zhouzhendong %!s(int64=4) %!d(string=hai) anos
pai
achega
be36520ee4

+ 9 - 0
app/Batch.php

@@ -14,6 +14,15 @@ class Batch extends Model
     protected $fillable = [
         'id','code','type', 'wms_type', 'status', 'wms_status', 'wms_created_at',"remark","owner_id",
     ];
+
+    const WMS_STATUS = [
+        '00' => '创建',
+        '40' => '部分收货',
+        '90' => '取消',
+        '99' => '完成',
+        '62' => '部分装箱'
+    ];
+
     public function orders(){
         return $this->hasMany('App\Order','batch_id','id');
     }

+ 44 - 0
app/Http/ApiControllers/OrderController.php

@@ -0,0 +1,44 @@
+<?php
+
+
+namespace App\Http\ApiControllers;
+
+
+use App\Components\ApiResponse;
+use App\Http\Requests\AndroidGateRequest;
+
+class OrderController
+{
+    use ApiResponse;
+
+    /**
+     * @api {get} /order/batchRecover 波次修复
+     * @apiName batchRecover
+     * @apiGroup Order
+     *
+     * @apiParam {string} code 波次号
+     *
+     * @apiSuccess {string} message 响应描述
+     * @apiSuccess {int} status_code HTTP响应码
+     * @apiSuccess {bool} data 结果
+     *
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *     {
+     *       "message": "请求成功",
+     *       "status_code": "200"
+     *       "data":true
+     *     }
+     *
+     */
+    public function recoverBatch(AndroidGateRequest $request)
+    {
+        $code = $request->input("code");
+
+        $prefix = "W".date("ymd")."000000";
+        if (strlen($code)<13)$code = substr($prefix,0,13-strlen($code)).$code;
+
+        $result = app("BatchService")->repairBatch($code);
+        $this->response($result, 200 ,$result ? '请求成功' : '修复失败,信息缺失');
+    }
+}

+ 0 - 3
app/Http/ApiControllers/WaybillController.php

@@ -113,9 +113,6 @@ class WaybillController
         $result = Waybill::query()->where("id",$request->input("id"))
             ->update($request->validated());
         if ($result==0)$this->response(false,204,"单据状态发生变化,修改失败");
-//        $startDate = "";
-//        $endDate = "";
-//        $res = ["2021-10-08"=>20,"2021-10-09"=>21];
         $this->response(true);
     }
 

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

@@ -288,6 +288,10 @@ class TestController extends Controller
     private static $delayedHour = 48;
     public function test(Request $request)
     {
+        $prefix = "W".date("ymd")."000000";
+        $code = "123";
+        dd(substr($prefix,0,13-strlen($code)).$code);
+
         $s = new LogisticService();
         dd($s->assertExpressCompany("312087577032867"));
         dd(DB::connection("aliyunMysql")->select(DB::raw("select * from units limit 1")));
@@ -305,7 +309,14 @@ class TestController extends Controller
     }
 
 
-
+    public function init_labor_company_dispatch()
+    {
+        $dispatches = LaborCompanyDispatch::all();
+        foreach ($dispatches as $dispatch) {
+            $dispatch->warehouse_id = $dispatch->laborCompany->warehouse_id ?? null;
+            $dispatch->save();
+        }
+    }
 
     private function t2()
     {

+ 39 - 0
app/Services/BatchService.php

@@ -8,6 +8,7 @@ use App\Exceptions\ErrorException;
 use App\Jobs\BatchTaskJob;
 use App\OracleActAllocationDetails;
 use App\Order;
+use App\OrderBin;
 use App\OrderCommodity;
 use App\Owner;
 use App\Station;
@@ -145,4 +146,42 @@ class BatchService
             }
         }
     }
+
+    /**
+     * 修复波次
+     */
+    public function repairBatch(string $code):bool
+    {
+        if (!$code)return false;
+        $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
+        if (!$wave)return false;
+        $owner = app("OwnerService")->codeGetOwner($wave->customerid);
+        $obj = [
+            "wms_status" => Batch::WMS_STATUS[$wave->wavestatus] ?? $wave->wavestatus,
+            "wms_type"=>$wave->descr,
+            "created_at"=>date("Y-m-d H:i:s"),
+            "wms_created_at"=>$wave->addtime,
+            "updated_at"=>$wave->edittime,
+            "owner_id"=>$owner->id,
+        ];
+        $wave = Batch::query()->where("code",$code)->first();
+        if (!$wave) $wave = Batch::query()->create($obj);
+        else Batch::query()->where("code",$code)->update($obj);
+        $orderNos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
+        $count = Order::query()->whereIn("code",$orderNos)->count();
+        if (count($orderNos)!=$count)app("OrderService")->syncOrderByCodes($orderNos);
+        Order::query()->whereIn("code",$orderNos)->update(["batch_id"=>$wave->id]);
+        $orders = Order::query()->with(["batch","bin"])->whereIn("code",$orderNos)->get();
+        if (count($orderNos)!=count($orders))return false;
+        foreach ($orders as $order){
+            if ($order->bin)continue;
+            $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),
+                [$order->batch->code,$order->code]);
+            if ($bin) OrderBin::query()->create([
+                'order_id' => $order->id,
+                'number' => $bin->seqno,
+            ]);
+        }
+        return true;
+    }
 }

+ 3 - 1
routes/api.php

@@ -24,12 +24,14 @@ Route::prefix("v1")->group(function (){
         ->group(function () {
             Route::prefix("waybill")->group(function () {
                 Route::prefix("dispatch")->group(function () {
-                    //登录
                     Route::GET('/', 'WaybillController@getData');
                     Route::POST('/', 'WaybillController@dispatch');
                     Route::POST('dailyBilling', 'WaybillController@dailyBilling');
                 });
             });
+            Route::prefix("order")->group(function () {
+                Route::GET('batchRecover', 'OrderController@recoverBatch');
+            });
         });
 });