Przeglądaj źródła

自动揽收与一些TODO标记清除
退货计费自生成模型

Zhouzhendong 4 lat temu
rodzic
commit
a556f4f814

+ 8 - 0
app/Feature.php

@@ -59,6 +59,14 @@ class Feature extends Model
             10=> 'packages.commodities.total',
             12=> "total",
             13=> "logistic.english_name",
+        ],
+        "rejected_bill" => [
+            0 => "items.name_goods",
+            5 => "items.remark",
+            7 => "remark",
+            8 => "items.amount",
+            10=> "items.total",
+            12=> "goods_amount",
         ]
     ];
 }

+ 0 - 1
app/Http/Controllers/ControlPanelController.php

@@ -247,7 +247,6 @@ COUNT(1) total FROM order_packages LEFT JOIN orders ON order_packages.order_id=o
 WHERE orders.wms_status != '订单取消'  {$where}
 AND order_packages.created_at like '{$date}%' GROUP BY date,order_packages.measuring_machine_id
 sql;
-            //todo 新写
             $info = DB::select(DB::raw($sql));
             if (empty($info)) return  $res;
             foreach ($info as $v){

+ 20 - 0
app/Http/Controllers/CustomerController.php

@@ -11,6 +11,9 @@ use App\Owner;
 use App\OwnerAreaReport;
 use App\OwnerBillReport;
 use App\OwnerFeeDetail;
+use App\OwnerFeeLogistic;
+use App\OwnerFeeOperation;
+use App\OwnerFeeOperationDetail;
 use App\OwnerReport;
 use App\Services\LogService;
 use App\Services\OwnerAreaReportService;
@@ -521,6 +524,23 @@ class CustomerController extends Controller
         $details = OwnerFeeDetail::query()->where("worked_at",">=",$startData." 00:00:00");
         if ($endDate)$details->where("worked_at","<=",$endDate." 23:59:59");
         if (count($owner)>0)$details->whereIn("owner_id",$owner);
+
+        $fee = OwnerFeeDetail::query()->where("created_at",">=",$startData." 00:00:00");
+        if ($endDate)$fee->where("created_at","<=",$endDate." 23:59:59");
+        if (count($owner)>0)$fee->whereIn("owner_id",$owner);
+        $fee->delete();
+
+        $feeQuery = OwnerFeeOperation::query()->where("worked_at",">=",$startData);
+        if ($endDate)$feeQuery->where("worked_at","<=",$endDate);
+        if (count($owner)>0)$feeQuery->whereIn("owner_id",$owner);
+        OwnerFeeOperationDetail::query()->whereIn("owner_fee_operation_id",$feeQuery)->delete();
+        $feeQuery->delete();
+
+        $fee = OwnerFeeLogistic::query()->where("created_at",">=",$startData." 00:00:00");
+        if ($endDate)$fee->where("created_at","<=",$endDate." 23:59:59");
+        if (count($owner)>0)$fee->whereIn("owner_id",$owner);
+        $fee->delete();
+
         $details->get()->each(function ($detail){
             dispatch(new ResetInstantBill($detail));
         });

+ 0 - 1
app/Http/Controllers/OwnerFeeTotalController.php

@@ -70,7 +70,6 @@ class OwnerFeeTotalController extends Controller implements \App\Interfaces\Sett
 
     public function export(Request $request)
     {
-        // TODO: Implement export() method.
     }
 
     public function confirmBill(Request $request): \Illuminate\Http\RedirectResponse

+ 0 - 3
app/Http/Controllers/OwnerWaybillSettlementBillController.php

@@ -9,16 +9,13 @@ class OwnerWaybillSettlementBillController extends Controller implements \App\In
     //
     public function index(Request $request)
     {
-        // TODO: Implement index() method.
     }
 
     public function confirmBill(Request $request): \Illuminate\Http\RedirectResponse
     {
-        // TODO: Implement confirmBill() method.
     }
 
     public function export(Request $request)
     {
-        // TODO: Implement export() method.
     }
 }

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

@@ -195,8 +195,14 @@ class TestController extends Controller
 
     public function test()
     {
-        $a = memory_get_usage();
+        /** @var OwnerPriceOperationService $service */
+        $service = app("OwnerPriceOperationService");
+        $rejected = RejectedBill::query()->with("items")->find(838755);
+        list($id,$money,$taxFee) = $service->matching($rejected, Feature::MAPPING["rejected_bill"], $rejected->id_owner, "入库");
+        dd($id,$money,$taxFee);
+        dd($rejected);
 
+        $a = memory_get_usage();
         $tmp = str_repeat('http://blog.huachen.me/', 4000);
         $b = memory_get_usage();
         dump($b-$a);

+ 55 - 0
app/Jobs/PackageCollectingAllocation.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Jobs;
+
+use App\OrderPackage;
+use App\Services\OrderPackageService;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Support\Facades\Log;
+
+class PackageCollectingAllocation implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable;
+
+    /** @var OrderPackage|\stdClass $orderPackage */
+    private $orderPackage;
+
+    /** @var int|null|string */
+    private $lineNo;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(OrderPackage $package,int $lineNo)
+    {
+        $this->orderPackage = $package;
+        $this->lineNo = $lineNo;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        /** @var OrderPackageService $orderPackageService */
+        $orderPackageService = app('OrderPackageService');
+        $result = $orderPackageService->collectUpload([$this->orderPackage->logistic_number]);
+        if (!$result["success"]){
+            Log::warning("自动揽收失败",["message"=>$result["message"],"param"=>$this->orderPackage->logistic_number]);
+            return;
+        }
+        $result = app("OrderService")->allocation($this->orderPackage->order->code,$this->lineNo);
+        if (mb_substr($result,0,3)=='000'){
+            if (OrderPackage::query()->where("id",$this->orderPackage->id)
+                ->where("collecting_status",'0')->update(["collecting_status"=>'1'])!=1)
+                Log::warning("自动揽收异常",["message"=>"未能成功修改揽收标记","param"=>$this->orderPackage->toArray()]);
+        }else Log::warning("自动揽收失败",["message"=>"分配失败:{$result}","param"=>$this->orderPackage->order->code." : {$this->lineNo}"]);
+    }
+}

+ 8 - 14
app/Jobs/ResetInstantBill.php

@@ -7,12 +7,9 @@ use App\Order;
 use App\OwnerFeeDetail;
 use App\OwnerFeeDetailLogistic;
 use App\OwnerFeeExpress;
+use App\OwnerFeeLogistic;
 use App\Process;
-use App\Province;
-use App\RejectedBill;
-use App\Services\CacheService;
 use App\Services\OwnerPriceDirectLogisticService;
-use App\Services\OwnerPriceExpressService;
 use App\Services\OwnerPriceLogisticService;
 use App\Services\OwnerPriceOperationService;
 use App\Store;
@@ -22,12 +19,10 @@ use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\SerializesModels;
-use Illuminate\Support\Facades\Cache;
 
 class ResetInstantBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    use Dispatchable, InteractsWithQueue, Queueable;
 
     /** @var \stdClass $detail  */
     private $detail;
@@ -79,9 +74,8 @@ class ResetInstantBill implements ShouldQueue
                     "work_tax_fee"      => $workTaxFee,
                     "logistic_tax_fee"  => $logisticInfo["logisticTaxFee"],
                 ]);
-                //向指定表插入标记 TODO
-                //if ($logisticInfo["logisticFee"] && $logisticInfo["fee_info"])OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
-                /*if ($money>0)app("StoreService")->constructFeeInfo([
+                if ($logisticInfo["logisticFee"] && $logisticInfo["fee_info"])OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
+                if ($money>0)app("StoreService")->constructFeeInfo([
                     "worked_at" => $order->wms_edittime ?: $order->updated_at,
                     "owner_id" => $order->owner_id,
                     "model_id"  => $id,
@@ -91,7 +85,7 @@ class ResetInstantBill implements ShouldQueue
                     "total_fee"    =>0,
                     "tax_rate"     =>0,
                     "fee_description"=>'',
-                ]);*/
+                ]);
                 //后续处理
                 OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$this->detail->id)->delete();
                 foreach ($logisticInfo["items"] as &$item)$item["owner_fee_detail_id"] = $this->detail->id;
@@ -132,7 +126,7 @@ class ResetInstantBill implements ShouldQueue
                     $service = app("OwnerPriceLogisticService");
                     list($fee,$taxFee) = $service->matching($waybill->carrier_weight_other,$owner_id,$waybill->logistic_id,
                         $waybill->carrier_weight_unit_id_other,$provinceId, $cityId);
-                    //$this->buildWaybillFeeInfo(); TODO
+                    if (isset($GLOBALS["FEE_INFO"])) OwnerFeeLogistic::query()->create($GLOBALS["FEE_INFO"]);
                 }else{
                     /** @var OwnerPriceDirectLogisticService $service */
                     $service = app("OwnerPriceDirectLogisticService");
@@ -162,7 +156,7 @@ class ResetInstantBill implements ShouldQueue
                     "owner_price_operation_id" => $id,
                     "work_tax_fee" => $taxFee,
                 ]);
-               /* if ($money>0)$this->constructFeeInfo([
+                if ($money>0)app("StoreService")->constructFeeInfo([
                     "worked_at" => $store->updated_at,
                     "owner_id" => $store->owner_id,
                     "model_id"  => $id,
@@ -172,7 +166,7 @@ class ResetInstantBill implements ShouldQueue
                     "total_fee"    =>0,
                     "tax_rate"     =>0,
                     "fee_description"=>'',
-                ]);*/
+                ]);
                 break;
             case "rejected_bills":
                 /** @var \stdClass $rejectedBill */

+ 20 - 0
app/Order.php

@@ -42,6 +42,26 @@ class Order extends Model
      * 仓库                 warehouse_id=>DOC_ORDER_HEADER['WAREHOUSEID']
      */
 
+    const STATUS = [
+        '00' => "创建订单",
+        '10' => "部分预配",
+        '20' => "预配完成",
+        '30' => "部分分配",
+        '40' => "分配完成",
+        '50' => "部分拣货",
+        '60' => "拣货完成",
+        '61' => "播种完成",
+        '62' => "部分装箱",
+        '63' => "完全装箱",
+        '65' => "部分装车",
+        '66' => "装车完成",
+        '70' => "部分发运",
+        '80' => "完全发运",
+        '90' => "订单取消",
+        '98' => "等待释放",
+        '99' => "订单完成",
+    ];
+
     public function cancel(){
         $this['status'] = '取消';
         $this->update();

+ 0 - 1
app/Services/Express/CaiNiaoExpress.php

@@ -86,7 +86,6 @@ class CaiNiaoExpress implements expressinterface
 
     function searElectronicSingle()
     {
-        // TODO: Implement searElectronicSingle() method.
     }
 
     /**

+ 0 - 1
app/Services/Express/PDDExpress.php

@@ -6,7 +6,6 @@ namespace App\Services\Express;
 
 class PDDExpress implements ExpressInterface
 {
-    // TODO 目前获取快递单号请求参数
 
     private $app_key = '';
     private $sign_method = '';

+ 13 - 8
app/Services/OrderPackageService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Jobs\PackageCollectingAllocation;
 use App\Order;
 use App\OrderPackage;
 use App\OrderPackageCommodities;
@@ -280,12 +281,12 @@ class OrderPackageService
         foreach ($packages as $package) {
             if ($package->sent_at) continue;
             try {
-                $checktime = $map[$package->logistic_number];
+                $checktime = $map[$package->logistic_number]->checktime;
             } catch (\Exception $e) {
                 continue;
             }
             if ($checktime) {
-                $this->checkingAndProcess($package); //检查和处理揽收
+                $this->checkingAndProcess($package,$map[$package->logistic_number]->orderlineno); //检查和处理揽收
                 $update_params[] = [
                     'id' => $package->id,
                     'sent_at' => $checktime,
@@ -298,13 +299,17 @@ class OrderPackageService
     /**
      * 检查和处理揽收
      *
-     * @param OrderPackage $package
+     * @param OrderPackage|\stdClass $package
      */
-    public function checkingAndProcess(OrderPackage $package)
+    public function checkingAndProcess(OrderPackage $package, int $lineNo)
     {
-        //TODO 揽收与分配回馈时间不定 这里应该推进队列处理
-        //检查快递商来判断该快递商是否允许自动揽收发货
-        //检查揽收标记来判断是否已被揽收过
+        //校验快递商 订单状态 复核标记 揽收标记
+        $package->loadMissing("order.logistic");
+        if ($package->collecting_status == '1' || !$package->logistic_number)return;
+        if (strpos($package->order->logistic->code ?? '','ZTO') === false)return;
+        $statusMapping = array_flip(Order::STATUS);
+        if (($statusMapping[$package->order->wms_status] ?? 0) > 63)return;
+        //dispatch(new PackageCollectingAllocation($package,$lineNo));
     }
 
     /**
@@ -318,7 +323,7 @@ class OrderPackageService
             $actAllocationDetails = $orderHeader->actAllocationDetails;
             foreach ($actAllocationDetails as $actAllocationDetail) {
                 $logistic_number = $actAllocationDetail->picktotraceid;
-                $map[$logistic_number] = $actAllocationDetail->checktime;
+                $map[$logistic_number] = $actAllocationDetail;
             }
         }
         return $map;

+ 1 - 0
app/Services/OwnerPriceOperationService.php

@@ -422,6 +422,7 @@ class OwnerPriceOperationService
     {
         $need = "";
         foreach (Feature::TYPE_NODE as $index){
+            if (!isset($columnMapping[$index]))continue;
             if (!$need)$need=strstr($columnMapping[$index],".",true);
             $columnMapping[$index] = ltrim(strstr($columnMapping[$index],"."),".");
         }

+ 32 - 4
app/Services/RejectedBillService.php

@@ -349,10 +349,10 @@ class RejectedBillService
     {
         /** @var \stdClass $rejectedBill */
         $number = array_column(StoreRejected::query()->where("logistic_number_return",$rejectedBill->logistic_number_return)->get()->toArray(),"store_id");
-
-        foreach (Store::query()->with("storeItems")->whereIn("id",$number)->get() as $store){
-            /** @var OwnerPriceOperationService $service */
-            $service = app("OwnerPriceOperationService");
+        $stores = Store::query()->with("storeItems")->whereIn("id",$number)->get();
+        /** @var OwnerPriceOperationService $service */
+        $service = app("OwnerPriceOperationService");
+        foreach ($stores as $store){
             $GLOBALS["FEE_INFO"] = [];
             list($id,$money,$taxFee) = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库",0);
             $bill = OwnerFeeDetail::query()->where("outer_id",$store->id)->where("outer_table_name","stores")->first();
@@ -389,5 +389,33 @@ class RejectedBillService
                 "fee_description"=>'',
             ]);
         }
+        if ($stores->count())return;
+        $rejectedBill->loadMissing("items");
+        $GLOBALS["FEE_INFO"] = [];
+        list($id,$money,$taxFee) = $service->matching($rejectedBill, Feature::MAPPING["rejected_bill"], $rejectedBill->id_owner, "入库",0);
+        app("OwnerFeeDetailService")->create([
+            "owner_id" => $rejectedBill->id_owner,
+            "worked_at" => $rejectedBill->updated_at,
+            "type" => "收货",
+            "operation_bill" => null,
+            "commodity_amount" => $rejectedBill->goods_amount,
+            "work_fee" => $money,
+            "owner_price_operation_id" => $id,
+            "created_at" => date('Y-m-d H:i:s'),
+            "outer_id" => $rejectedBill->id,
+            "outer_table_name" => "rejected_bills",
+            "work_tax_fee" => $taxFee,
+        ]);
+        app("StoreService")->constructFeeInfo([
+            "worked_at" => $rejectedBill->updated_at,
+            "owner_id" => $rejectedBill->id_owner,
+            "model_id"  => $id,
+            "source_number"=> null,
+            "doc_number"   => null,
+            "commodity_id" => 0,
+            "total_fee"    =>0,
+            "tax_rate"     =>0,
+            "fee_description"=>'',
+        ]);
     }
 }