ANG YU 4 yıl önce
ebeveyn
işleme
08c3c8b6b4

+ 33 - 17
app/Http/Controllers/TestController.php

@@ -15,7 +15,7 @@ use App\Http\Requests\OrderDelivering;
 use App\Jobs\CacheShelfTaskJob;
 use App\Jobs\OrderCreateInstantBill;
 use App\Jobs\OrderCreateWaybill;
-use App\Jobs\SettlementBillReportTask;
+use App\Jobs\SettlementBillReportJob;
 use App\Jobs\StoreCreateInstantBill;
 use App\Jobs\TestJob;
 use App\Jobs\WeightUpdateInstantBill;
@@ -390,26 +390,42 @@ sql;
 
     public function init_在途异常()
     {
+//        $logistic_numbers = OrderPackage::query()
+//            ->select('logistic_number')
+//            ->where('exception_status', 5)
+//            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
+//            ->pluck('logistic_number');
+        /** @var OrderPackageReceivedSyncService $service */
+        $service = app('OrderPackageReceivedSyncService');
+//        $service->syncLogisticRoute(false, $logistic_numbers);
+
+
         $logistic_numbers = OrderPackage::query()
-            ->select('logistic_number')
-            ->where('exception_status', 5)
+            ->select(['logistic_number', 'order_id', 'id'])
+            ->whereIn('order_id', function ($query) {
+                $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
+                    $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
+                });
+            })
             ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
+            ->whereNull('received_at')
+            ->where('status', '!=',7)
             ->pluck('logistic_number');
-        /** @var OrderPackageReceivedSyncService $service */
-        $service = app('OrderPackageReceivedSyncService');
-        $service->syncLogisticRoute(false, $logistic_numbers);
+        $service->syncLogisticRouteByAliJiSu($logistic_numbers);
+    }
 
+    public function update_order_packages_已签收()
+    {
+        OrderPackage::query()
+            ->where('status', 7)
+            ->where('exception_status','!=',0)
+            ->update([
+                'exception_status' => 0,
+            ]);
+    }
 
-//        $logistic_numbers = OrderPackage::query()
-//            ->select(['logistic_number', 'order_id', 'id'])
-//            ->whereIn('order_id', function ($query) {
-//                $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
-//                    $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
-//                });
-//            })
-//            ->where('exception_status', 5)
-//            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
-//            ->pluck('logistic_number');
-//        $service->syncLogisticRouteByAliJiSu($logistic_numbers);
+    public function init_SettlementBillReportTask()
+    {
+        $this->dispatch(new SettlementBillReportJob('2021-08-01',[]));
     }
 }

+ 1 - 1
app/Interfaces/SettlementBillReportInterface.php

@@ -13,7 +13,7 @@ interface SettlementBillReportInterface
      * 如果参数$counting_month为2021-01-01 则统计2021-01-01 -- 2021-01-31之间的数据
      * @param null $counting_month 统计月份,默认统计上个月的 2021-05-01
      */
-    public function recordReport($counting_month = null);
+    public function recordReport($counting_month = null, array $ownerIds = []);
 
 
     /**

+ 3 - 6
app/Jobs/LogisticAliJiSuSync.php

@@ -19,14 +19,11 @@ class LogisticAliJiSuSync implements ShouldQueue
 
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
-    /**
-     * @var $logisticAliJiSuApiService LogisticAliJiSuApiService
-     * @var $orderPackageReceivedSyncService OrderPackageReceivedSyncService
-     * @var $logistic_number string
-     */
-
+    /** @var $logistic_number string */
     protected $logistic_number;
+    /** @var  $logisticAliJiSuApiService LogisticAliJiSuApiService  */
     protected $logisticAliJiSuApiService;
+    /** @var $orderPackageReceivedSyncService OrderPackageReceivedSyncService */
     protected $orderPackageReceivedSyncService;
 
     /**

+ 16 - 7
app/Jobs/SettlementBillReportTask.php → app/Jobs/SettlementBillReportJob.php

@@ -13,11 +13,11 @@ use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 
 /**
- * 快递 出库 入库 统计报表生成任务
+ * 快递 出库 入库 总账单 统计报表生成任务
  * Class SettlementBillReportTask
  * @package App\Jobs
  */
-class SettlementBillReportTask implements ShouldQueue
+class SettlementBillReportJob implements ShouldQueue
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
@@ -27,14 +27,22 @@ class SettlementBillReportTask implements ShouldQueue
 
     public $tries = 2;
 
+    //生成报告的日期 2021-08-01 生成8月份的报告
     public $init_date;
+    /**
+     * 初始化的货主,填[]为全部
+     * @var $ownerIds array
+     */
+    public $ownerIds;
 
     /**
      * @param $init_date
+     * @param $ownerIds
      */
-    public function __construct($init_date)
+    public function __construct($init_date, $ownerIds)
     {
         $this->init_date = $init_date;
+        $this->ownerIds = $ownerIds;
     }
 
 
@@ -48,21 +56,22 @@ class SettlementBillReportTask implements ShouldQueue
         //快递
         /** @var OwnerLogisticFeeReportService $expressFeeReportService */
         $expressFeeReportService = app('OwnerLogisticFeeReportService');
-        $expressFeeReportService->recordReport($this->init_date);
+        $expressFeeReportService->recordReport($this->init_date, $this->ownerIds);
 
         //入库
         /** @var OwnerStoreFeeReportService $storeFeeReportService */
         $storeFeeReportService = app('OwnerStoreFeeReportService');
-        $storeFeeReportService->recordReport($this->init_date);
+        $storeFeeReportService->recordReport($this->init_date, $this->ownerIds);
 
         //出库
         /** @var OwnerStoreOutFeeReportService $storeOutFeeReportService */
         $storeOutFeeReportService = app('OwnerStoreOutFeeReportService');
-        $storeOutFeeReportService->recordReport($this->init_date);
+        $storeOutFeeReportService->recordReport($this->init_date, $this->ownerIds);
 
         //总账单
         /** @var OwnerFeeTotalService $feeTotal */
         $feeTotal = app('OwnerFeeTotalService');
-        $feeTotal->record($this->init_date);
+        $feeTotal->record($this->init_date, $this->ownerIds);
+
     }
 }

+ 23 - 22
app/Services/OrderPackageService.php

@@ -358,22 +358,22 @@ class OrderPackageService
                 'message' => '输入快递单号为空',
             ];
         }
-        $orderPackageCount = OrderPackage::query()->whereIn('logistic_number', $logistic_numbers)
-            ->whereIn('order_id', function ($query) {
-                $query->from('orders')->select('id')->whereIn('logistic_id', function ($query) {
-                    $query->from('logistics')->select('id')->whereIn('code', [
-                        'ZTO',
-                        'ZTO-1',
-                        'WPZTO',
-                    ]);
-                });
-            })->count();
-        if ($orderPackageCount !== count($logistic_numbers)) {
-            return [
-                'success' => false,
-                'message' => '输入的快递单号异常,请检查承运商是否全部为中通',
-            ];
-        }
+//        $orderPackageCount = OrderPackage::query()->whereIn('logistic_number', $logistic_numbers)
+//            ->whereIn('order_id', function ($query) {
+//                $query->from('orders')->select('id')->whereIn('logistic_id', function ($query) {
+//                    $query->from('logistics')->select('id')->whereIn('code', [
+//                        'ZTO',
+//                        'ZTO-1',
+//                        'WPZTO',
+//                    ]);
+//                });
+//            })->count();
+//        if ($orderPackageCount !== count($logistic_numbers)) {
+//            return [
+//                'success' => false,
+//                'message' => '输入的快递单号异常,请检查承运商是否全部为中通',
+//            ];
+//        }
 
         $url = config('api_logistic.collectUpload.ZTO.test.url');
         $xAppKey = config('api_logistic.collectUpload.ZTO.test.x-appKey');
@@ -381,7 +381,7 @@ class OrderPackageService
         $appId = config('api_logistic.collectUpload.ZTO.test.appId');
         //中通接口最大支持100条
         $logistic_numbers_chunked = array_chunk($logistic_numbers, 100);
-
+        $errorMessage = [];
         foreach ($logistic_numbers_chunked as $logistic_numbers_chunked_items) {
             $orderPackages = OrderPackage::query()
                 ->select('weight', 'logistic_number')
@@ -412,12 +412,13 @@ class OrderPackageService
                 $responseBody->statusCode === 'PARAM_ERROR'||//揽收上传信息为空
                 $responseBody->statusCode === 'SYSTEM_ERROR'//系统异常,请联系系统管理员
             ) {
-                return [
-                    'success' => false,
-                    'message' => $responseBody->message,
-                ];
+                $errorMessage[] = $responseBody->statusCode;
             }
         }
-        return ['success' => true, 'message' => '一键揽收上传成功'];
+        if (empty($errorMessage)) {
+            return ['success' => true, 'message' => '一键揽收上传成功'];
+        }else{
+            return ['success' => false, 'message' => $errorMessage];
+        }
     }
 }

+ 5 - 1
app/Services/OwnerDischargeTaskSettlementBillService.php

@@ -65,7 +65,11 @@ class OwnerDischargeTaskSettlementBillService implements \App\Interfaces\Settlem
     }
 
 
-    public function recordReport($counting_month = null)
+    /**
+     * @param null $counting_month
+     * @param array $ownerIds
+     */
+    public function recordReport($counting_month = null, array $ownerIds = [])
     {
         // TODO: Implement recordReport() method.
     }

+ 8 - 4
app/Services/OwnerFeeTotalService.php

@@ -5,7 +5,6 @@ namespace App\Services;
 use App\OrderIssue;
 use App\Owner;
 use App\OwnerBillReport;
-use App\OwnerFeeOperation;
 use App\OwnerPriceOperation;
 use App\OwnerPriceOperationItem;
 use App\OwnerStoreOutFeeReport;
@@ -26,8 +25,9 @@ class OwnerFeeTotalService
     /**
      * 生成统计数据
      * @param string|null $counting_month string 统计月份默认为上一个月
+     * @param array $ownerIds
      */
-    public function record(string $counting_month = null)
+    public function record(string $counting_month = null, array $ownerIds = [])
     {
         if (is_null($counting_month)) {
             $counting_month = now()->subMonth()->startOfMonth()->toDateString();
@@ -52,7 +52,7 @@ class OwnerFeeTotalService
          * 1. 计算得出:总税费/总金额
          */
         //仓储:ownerStoragePriceModels。入库,出库:ownerPriceOperations
-        $owners = Owner::query()
+        $builder = Owner::query()
             ->with([
                 "ownerStoragePriceModels.unit:id,name",
                 "ownerStoragePriceModels.timeUnit:id,name",
@@ -64,7 +64,11 @@ class OwnerFeeTotalService
                     }]);
                 }])
             ->where('deleted_at', '>=', now()->subMonth()->startOfMonth())
-            ->orWhereNull('deleted_at')->get();
+            ->orWhereNull('deleted_at');
+        if (!empty($ownerIds)) {
+            $builder->whereIn('id', $ownerIds);
+        }
+        $owners = $builder->get();
         foreach ($owners as $owner) {
             $information = $this->buildInformation($owner, $counting_month);
             $ownerFeeTotal = [];

+ 8 - 4
app/Services/OwnerLogisticFeeReportService.php

@@ -63,14 +63,14 @@ class OwnerLogisticFeeReportService implements \App\Interfaces\SettlementBillRep
         $this->confirmBillFeeTotal($counting_month, $owner_id);
     }
 
-    public function recordReport($counting_month = null)
+    public function recordReport($counting_month = null,array $ownerIds = [])
     {
         if (is_null($counting_month)) {
             //默认统计上个月的数据
             $counting_month = now()->subMonth()->startOfMonth()->toDateTimeString();
         }
         list($start, $end) = $this->getStartAndEnd($counting_month);
-        $ownerLogisticFeeDetails = OwnerFeeExpress::query()
+        $builder = OwnerFeeExpress::query()
             ->selectRaw("
             province_id,
             logistic_id,
@@ -81,12 +81,16 @@ class OwnerLogisticFeeReportService implements \App\Interfaces\SettlementBillRep
             additional_weight_price,
             additional_weight,
             sum(additional_weight_amount) as additional_amount,
-            sum(total_fee*tax_rate) as tax_fee,
+            sum(total_fee*tax_rate/100) as tax_fee,
             sum(total_fee) as fee,
             sum(total_fee) as fee,
             created_at,
             owner_id")
-            ->whereBetween('created_at', [$start, $end])
+            ->whereBetween('created_at', [$start, $end]);
+        if (!empty($ownerIds)) {
+            $builder->whereIn('owner_id', $ownerIds);
+        }
+        $ownerLogisticFeeDetails = $builder
             ->groupBy(
                 'initial_weight',
                 'initial_weight_price',

+ 13 - 11
app/Services/OwnerStoreFeeReportService.php

@@ -31,7 +31,7 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
      * 如果参数$counting_month为2021-01-01 则统计2021-01-01 -- 2021-01-31之间的数据
      * @param null $counting_month 统计月份,默认统计上个月的 2021-05-01
      */
-    public function recordReport($counting_month = null)
+    public function recordReport($counting_month = null,array $ownerIds = [])
     {
         $this->detailService = app('OwnerStoreFeeDetailService');
         if (is_null($counting_month)) {
@@ -39,11 +39,10 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
             $counting_month = now()->subMonth()->startOfMonth()->toDateString();
         }
         list($start, $end) = $this->getStartAndEnd($counting_month);
-        $details =
-            DB::table('owner_fee_operations')
-                ->leftJoin('owner_fee_operation_details','owner_fee_operations.id','=','owner_fee_operation_details.owner_fee_operation_id')
-                ->leftJoin('owner_price_operations','owner_fee_operations.model_id','=','owner_price_operations.id')
-                ->selectRaw("
+        $builder = DB::table('owner_fee_operations')
+            ->leftJoin('owner_fee_operation_details', 'owner_fee_operations.id', '=', 'owner_fee_operation_details.owner_fee_operation_id')
+            ->leftJoin('owner_price_operations', 'owner_fee_operations.model_id', '=', 'owner_price_operations.id')
+            ->selectRaw("
                 DATE_FORMAT(owner_fee_operations.worked_at,'%Y-%m') as counting_month,
                 owner_fee_operation_details.unit_id,
                 owner_fee_operation_details.price,
@@ -54,11 +53,14 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
                 sum(owner_fee_operation_details.price*owner_fee_operation_details.amount) as fee,
                 sum(owner_fee_operation_details.price*owner_fee_operation_details.amount*owner_fee_operations.tax_rate) as tax_fee
                 ")
-                ->whereBetween('owner_fee_operations.worked_at', [$start, $end])
-                ->whereNotNull('owner_fee_operation_details.price')
-                ->whereNotNull('owner_fee_operation_details.amount')
-                ->whereIn('model_id',\App\OwnerPriceOperation::query()->select('id')->where('operation_type','入库'))
-                ->groupBy(
+            ->whereBetween('owner_fee_operations.worked_at', [$start, $end])
+            ->whereNotNull('owner_fee_operation_details.price')
+            ->whereNotNull('owner_fee_operation_details.amount')
+            ->whereIn('model_id', \App\OwnerPriceOperation::query()->select('id')->where('operation_type', '入库'));
+        if (!empty($ownerIds)) {
+            $builder->whereIn('owner_fee_operations.owner_id', $ownerIds);
+        }
+        $details = $builder->groupBy(
                     'counting_month',
                     'owner_id',
                     'unit_id',

+ 13 - 11
app/Services/OwnerStoreOutFeeReportService.php

@@ -29,18 +29,17 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
     private $archiveService;
 
 
-    public function recordReport($counting_month = null)
+    public function recordReport($counting_month = null,array  $ownerIds = [])
     {
         if (is_null($counting_month)) {
             //默认统计上个月的数据
             $counting_month = now()->subMonth()->startOfMonth()->toDateString();
         }
         list($start, $end) = $this->getStartAndEnd($counting_month);
-        $details =
-            DB::table('owner_fee_operations')
-                ->leftJoin('owner_fee_operation_details','owner_fee_operations.id','=','owner_fee_operation_details.owner_fee_operation_id')
-                ->leftJoin('owner_price_operations','owner_fee_operations.model_id','=','owner_price_operations.id')
-                ->selectRaw("
+        $builder = DB::table('owner_fee_operations')
+            ->leftJoin('owner_fee_operation_details', 'owner_fee_operations.id', '=', 'owner_fee_operation_details.owner_fee_operation_id')
+            ->leftJoin('owner_price_operations', 'owner_fee_operations.model_id', '=', 'owner_price_operations.id')
+            ->selectRaw("
                 DATE_FORMAT(owner_fee_operations.worked_at,'%Y-%m') as counting_month,
                 owner_fee_operation_details.unit_id,
                 owner_fee_operation_details.price,
@@ -51,11 +50,14 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
                 sum(owner_fee_operation_details.price*owner_fee_operation_details.amount) as fee,
                 sum(owner_fee_operation_details.price*owner_fee_operation_details.amount*owner_fee_operations.tax_rate) as tax_fee
                 ")
-                ->whereBetween('owner_fee_operations.worked_at', [$start, $end])
-                ->whereNotNull('owner_fee_operation_details.price')
-                ->whereNotNull('owner_fee_operation_details.amount')
-                ->whereIn('model_id', OwnerPriceOperation::query()->select('id')->where('operation_type','出库'))
-                ->groupBy(
+            ->whereBetween('owner_fee_operations.worked_at', [$start, $end])
+            ->whereNotNull('owner_fee_operation_details.price')
+            ->whereNotNull('owner_fee_operation_details.amount')
+            ->whereIn('model_id', OwnerPriceOperation::query()->select('id')->where('operation_type', '出库'));
+        if (!empty($ownerIds)) {
+            $builder->whereIn('owner_fee_operations.owner_id', $ownerIds);
+        }
+        $details = $builder->groupBy(
                     'counting_month',
                     'owner_id',
                     'unit_id',

+ 1 - 1
app/Services/OwnerSundryFeeDetailService.php

@@ -58,7 +58,7 @@ class OwnerSundryFeeDetailService implements \App\Interfaces\SettlementBillRepor
             ->get();
     }
 
-    public function recordReport($counting_month = null)
+    public function recordReport($counting_month = null,array $ownerIds = [])
     {
         // TODO: Implement recordReport() method.
     }

+ 1 - 1
app/Services/SettlementBillsAreaFeeService.php

@@ -78,7 +78,7 @@ class SettlementBillsAreaFeeService implements \App\Interfaces\SettlementBillRep
         // TODO: Implement add() method.
     }
 
-    public function recordReport($counting_month = null)
+    public function recordReport($counting_month = null,array $ownerIds = [])
     {
         // TODO: Implement recordReport() method.
     }

+ 7 - 2
app/Traits/LogisticSyncTrait.php

@@ -22,7 +22,8 @@ trait LogisticSyncTrait
             $orderPackage->exception_status === '无法获取路由') {//这种类型的单,不需要再更新状态
             return $data;
         }
-
+        /** @var \Carbon\Carbon $sent_at */
+        $sent_at = $orderPackage->sent_at;
         /**执行该方法时,默认没有异常,
          *1. 之前有异常的件,
          *  1.1 新的状态是无异常的可以更新为正常
@@ -35,7 +36,7 @@ trait LogisticSyncTrait
         $created_at = Carbon::parse($orderPackage->created_at);
         //当天的16:30
         $transfer_status = $data['transfer_status'] ?? [];
-        if (empty($orderPackage->sent_at)) {//没复核
+        if (empty($sent_at)) {//没复核
             if (empty($transfer_status)) {//没有路由信息
                 //延迟发货
                 $created_at_clone = deep_copy($created_at);
@@ -134,6 +135,10 @@ trait LogisticSyncTrait
                 }
             }
         }
+        //如果复核时间>前一天的18.00,则不添加异常信息
+        if ((!empty($sent_at)) &&($sent_at->gt(now()->subDay()->startOfDay()->addHours(18))) && isset($data['exception_status'])) {
+            unset($data['exception_status']);
+        }
         return $data;
     }
 }

+ 1 - 1
config/api_logistic.php

@@ -219,7 +219,7 @@ return [
                 'url' => 'https://japi.zto.com/zto.network.collectUpload',
                 'x-appKey' => 'c51c718eb899e9f706979',
                 'appSecret' => '9f664e3ab08049874aa417720840161a',
-                'appId' => '9f664e3ab08049874aa417720840161a',
+                'appId' => 'GJWL',
             ]
         ]
     ]

+ 26 - 0
tests/Services/LogisticAliJiSuSync/SyncTest.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace Tests\Services\LogisticAliJiSuSync;
+
+use App\Jobs\LogisticAliJiSuSync;
+use App\Jobs\LogisticYTOSync;
+use Tests\TestCase;
+
+class SyncTest extends TestCase
+{
+
+
+
+    function setUp(): void
+    {
+        parent::setUp();
+    }
+
+    /**
+     * @test
+     */
+    public function format_test()
+    {
+        LogisticAliJiSuSync::dispatch('9884189700485');
+    }
+}

+ 28 - 0
tests/Services/OwnerFeeTotalService/RecordTest.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace OwnerFeeTotalService;
+
+use App\Services\OwnerFeeTotalService;
+use Tests\TestCase;
+
+class RecordTest extends TestCase
+{
+    /** @var OwnerFeeTotalService $service */
+    private $service;
+
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('OwnerFeeTotalService');
+    }
+
+    function tearDown(): void
+    {
+        parent::tearDown();
+    }
+
+    public function test_01()
+    {
+        $this->service->record('2021-08-01',[4]);
+    }
+}