Просмотр исходного кода

Merge branch 'yang' of ssh://47.103.131.176:10022/var/git/bswas into yang

 Conflicts:
	app/Http/Controllers/TestController.php
zhouzhendong 4 лет назад
Родитель
Сommit
6a7d99854b
41 измененных файлов с 647 добавлено и 325 удалено
  1. 4 5
      app/Events/SettlementBillCreateEvent.php
  2. 6 8
      app/Http/Controllers/SettlementBillStoreFeeReportController.php
  3. 1 2
      app/Http/Controllers/SettlementBillStoreOutFeeDetailController.php
  4. 5 5
      app/Http/Controllers/SettlementBillStoreOutFeeReportController.php
  5. 28 12
      app/Http/Controllers/TestController.php
  6. 66 0
      app/Jobs/SettlementBillReportTask.php
  7. 2 1
      app/OwnerLogisticFeeDetail.php
  8. 10 9
      app/OwnerStoreFeeDetail.php
  9. 10 35
      app/OwnerStoreFeeReport.php
  10. 6 6
      app/OwnerStoreOutFeeDetail.php
  11. 11 6
      app/OwnerStoreOutFeeReport.php
  12. 3 0
      app/Services/OwnerFeeTotalService.php
  13. 2 7
      app/Services/OwnerLogisticFeeDetailService.php
  14. 5 1
      app/Services/OwnerLogisticFeeReportService.php
  15. 8 22
      app/Services/OwnerStoreFeeDetailService.php
  16. 24 16
      app/Services/OwnerStoreFeeReportService.php
  17. 17 8
      app/Services/OwnerStoreOutFeeDetailService.php
  18. 35 37
      app/Services/OwnerStoreOutFeeReportService.php
  19. 1 0
      database/factories/OwnerFeeDetailFactory.php
  20. 1 0
      database/factories/OwnerLogisticFeeDetailFactory.php
  21. 19 8
      database/factories/OwnerStoreFeeDetailFactory.php
  22. 1 1
      database/factories/OwnerStoreFeeReportFactory.php
  23. 15 5
      database/factories/OwnerStoreOutFeeDetailFactory.php
  24. 0 2
      database/factories/OwnerStoreOutFeeReportFactory.php
  25. 32 0
      database/migrations/2021_07_14_101031_add_fee_to_owner_logistic_fee_details_table.php
  26. 34 0
      database/migrations/2021_07_15_112931_drop_fee_to_owner_store_out_fee_reports_table.php
  27. 46 0
      database/migrations/2021_07_15_154921_add_fee_and_other_to_owner_store_fee_details_table.php
  28. 34 0
      database/migrations/2021_07_15_163048_add_work_name_and_drop_other_to_owner_store_fee_reports_table.php
  29. 46 0
      database/migrations/2021_07_16_092933_add_work_name_and_drop_other_to_owner_store_out_fee_details_table.php
  30. 37 0
      database/migrations/2021_07_16_110120_add_work_name_and_drop_other_to_owner_store_out_fee_reports_table.php
  31. 0 1
      database/seeds/OwnerLogisticFeeDetailSeeder.php
  32. 6 11
      database/seeds/OwnerStoreFeeDetailSeeder.php
  33. 16 22
      database/seeds/OwnerStoreOutFeeDetailSeeder.php
  34. 8 1
      database/seeds/OwnerStoreOutFeeReportSeeder.php
  35. 0 9
      resources/views/finance/settlementBills/expressFee/report/index.blade.php
  36. 11 9
      resources/views/finance/settlementBills/storeFee/detail/index.blade.php
  37. 3 6
      resources/views/finance/settlementBills/storeFee/report/index.blade.php
  38. 8 4
      resources/views/finance/settlementBills/storeOutFee/detail/index.blade.php
  39. 2 2
      resources/views/finance/settlementBills/storeOutFee/report/index.blade.php
  40. 60 21
      tests/Services/OwnerStoreFeeReportService/RecordReportTest.php
  41. 24 43
      tests/Services/OwnerStoreOutFeeReportService/RecordReportTest.php

+ 4 - 5
app/Events/SettlementBillCreateEvent.php

@@ -18,14 +18,13 @@ use Illuminate\Queue\SerializesModels;
 class SettlementBillCreateEvent
 {
     use Dispatchable, InteractsWithSockets, SerializesModels;
-
-
+    //快递费
     const OWNER_LOGISTIC_FEE_DETAIL = OwnerLogisticFeeDetail::class;
-
+    //入库费
     const OWNER_STORE_FEE_DETAIL = OwnerStoreFeeDetail::class;
-
+    //出库
     const OWNER_STORE_OUT_FEE_DETAIL = OwnerStoreOutFeeDetail::class;
-
+    //物流费
     const OWNER_WAY_BILL_FEE_DETAIL = OwnerWayBillFeeDetail::class;
     public $createData;
 

+ 6 - 8
app/Http/Controllers/SettlementBillStoreFeeReportController.php

@@ -46,11 +46,9 @@ class SettlementBillStoreFeeReportController extends Controller
         $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
         $this->archiveService = app('OwnerBillReportArchiveService');
         $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
-
-        $request = $this->buildRequest($request, $counting_month,$owner_id);
-
+        $request = $this->buildRequest($request, $counting_month, $owner_id);
         return view('finance.settlementBills.storeFee.report.index',
-            compact('owners', 'owner', 'isArchived', 'request', 'reports', 'totalAmount', 'totalFee', 'owner_price_operation_fees'));
+            compact('owners', 'owner', 'isArchived', 'request', 'totalAmount', 'totalFee', 'owner_price_operation_fees'));
     }
 
     public function export(Request $request)
@@ -65,9 +63,9 @@ class SettlementBillStoreFeeReportController extends Controller
         ]);
         $json = [];
         foreach ($reports as $report) {
-            $operation = $owner_price_operation_fees->firstWhere('owner_price_operation_id',$report['owner_price_operation_id']);
+            $operation = $owner_price_operation_fees->firstWhere('work_name', $report['work_name']);
             $json[] = [
-                $operation['owner_price_operation']['name']??$operation['ownerPriceOperation']['name'],
+                $report['work_name'],
                 $report['unit_price'],
                 $report['amount'],
                 $operation['fee'],
@@ -85,9 +83,9 @@ class SettlementBillStoreFeeReportController extends Controller
     private function buildOwnerPriceOperationFees($reports, $owner_price_operation_fees)
     {
         $result = [];
-        $reports = $reports->groupBy('owner_price_operation_id');
+        $reports = $reports->groupBy('work_name');
         foreach ($owner_price_operation_fees as $price_operation) {
-            $price_operation['data'] = $reports[$price_operation['owner_price_operation_id']];
+            $price_operation['data'] = $reports[$price_operation['work_name']];
             $result[] = $price_operation;
         }
         return collect($result);

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

@@ -51,9 +51,8 @@ class SettlementBillStoreOutFeeDetailController extends Controller implements Se
             $query->whereIn('id', explode(',', $request['data']));
         }
         $details = $query->get();
-        $this->service->buildPriceRemarks($details);
         $json = $this->service->buildExport($details);
-        $row = ['作业时间', '作业名称', '上游单号', '订单号', '商品条码', '商品名称', '商品数量', '价格', '合计'];
+        $row = ['作业时间', '作业名称', '上游单号', '订单号', '商家编码', '商品条码', '商品名称', '商品数量', '单价', '价格描述', '合计'];
         return Export::make($row, $json, "出库费明细");
     }
 }

+ 5 - 5
app/Http/Controllers/SettlementBillStoreOutFeeReportController.php

@@ -43,7 +43,7 @@ class SettlementBillStoreOutFeeReportController extends Controller implements Se
         $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
         $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
         $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
-        $request = $this->buildRequest($request, $counting_month,$owner_id);
+        $request = $this->buildRequest($request, $counting_month, $owner_id);
         $work_name_fee_total = collect($this->buildWorkNameFeeTotal($reports, $work_name_fee_total));
         return view('finance.settlementBills.storeOutFee.report.index',
             compact('owners', 'owner', 'isArchived', 'request', 'work_name_fee_total', 'fee_total'));
@@ -62,9 +62,9 @@ class SettlementBillStoreOutFeeReportController extends Controller implements Se
         foreach ($work_name_fee_total as $work_name_fee_total_item) {
             foreach ($work_name_fee_total_item['data'] as $data_item) {
                 $json[] = [
-                    $work_name_fee_total_item['name'],
+                    $work_name_fee_total_item['work_name'],
                     $data_item['step'],
-                    $data_item['unit_price'],
+                    $data_item['unit_price'] . '/' . $data_item['unit']['name'] ?? '',
                     $data_item['amount'],
                     $work_name_fee_total_item['fee'],
                 ];
@@ -77,9 +77,9 @@ class SettlementBillStoreOutFeeReportController extends Controller implements Se
     private function buildWorkNameFeeTotal($reports, $work_name_fee_total): array
     {
         $result = [];
-        $reports_grouped = $reports->groupBy('owner_price_operation_id');
+        $reports_grouped = $reports->groupBy('work_name');
         foreach ($work_name_fee_total as $work_name_fee_total_item) {
-            $work_name_fee_total_item['data'] = $reports_grouped[$work_name_fee_total_item['id']]??[];
+            $work_name_fee_total_item['data'] = $reports_grouped[$work_name_fee_total_item['work_name']] ?? [];
             $result[] = $work_name_fee_total_item;
         }
         return $result;

Разница между файлами не показана из-за своего большого размера
+ 28 - 12
app/Http/Controllers/TestController.php


+ 66 - 0
app/Jobs/SettlementBillReportTask.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Services\OwnerFeeTotalService;
+use App\Services\OwnerLogisticFeeReportService;
+use App\Services\OwnerStoreFeeReportService;
+use App\Services\OwnerStoreOutFeeReportService;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * 快递 出库 入库 统计报表生成任务
+ * Class SettlementBillReportTask
+ * @package App\Jobs
+ */
+class SettlementBillReportTask implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    public $timeout = 120;
+
+    public $maxExceptions = 3;
+
+    public $tries = 2;
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        //快递
+        /** @var OwnerLogisticFeeReportService $expressFeeReportService */
+        $expressFeeReportService = app('OwnerLogisticFeeReportService');
+        $expressFeeReportService->recordReport();
+
+        //入库
+        /** @var OwnerStoreFeeReportService $storeFeeReportService */
+        $storeFeeReportService = app('OwnerStoreFeeReportService');
+        $storeFeeReportService->recordReport();
+
+        //出库
+        /** @var OwnerStoreOutFeeReportService $storeOutFeeReportService */
+        $storeOutFeeReportService = app('OwnerStoreOutFeeReportService');
+        $storeOutFeeReportService->recordReport();
+
+        //总账单
+        /** @var OwnerFeeTotalService $feeTotal */
+        $feeTotal = app('OwnerFeeTotalService');
+        $feeTotal->record();
+    }
+}

+ 2 - 1
app/OwnerLogisticFeeDetail.php

@@ -22,7 +22,8 @@ class OwnerLogisticFeeDetail extends Model
         'logistic_id',//承运商
         'owner_id',//货主
         'additional_weigh_weight',//续重重量
-        'tax_fee'//税费
+        'tax_fee',//税费
+        'fee'//费用
     ];
 
     public function ownerFeeDetail(): BelongsTo

+ 10 - 9
app/OwnerStoreFeeDetail.php

@@ -17,8 +17,14 @@ class OwnerStoreFeeDetail extends Model
         'unit_price', //单价
         'amount', //数量
         'owner_id', //货主
-        'store_item_id',
-        'owner_price_operation_id'
+        'fee',//费用
+        'commodity_id',
+        'packing_material_fee',//包材费
+        'tax_fee',//税费
+        'sku',//sku
+        'barcode',//条码
+        'work_name',//作业名称
+        'asn_code',//asn号
     ];
 
     public function ownerFeeDetail(): BelongsTo
@@ -42,13 +48,8 @@ class OwnerStoreFeeDetail extends Model
         return $this->belongsTo(Owner::class);
     }
 
-    public function storeItem(): BelongsTo
+    public function commodity(): BelongsTo
     {
-        return $this->belongsTo(StoreItem::class);
-    }
-
-    public function ownerPriceOperation(): BelongsTo
-    {
-        return $this->belongsTo(OwnerPriceOperation::class);
+        return $this->belongsTo(Commodity::class);
     }
 }

+ 10 - 35
app/OwnerStoreFeeReport.php

@@ -11,49 +11,24 @@ class OwnerStoreFeeReport extends Model
 {
     use ModelLogChanging;
 
-    public $fillable = ['owner_bill_report_id', 'owner_price_operation_id', 'owner_id', 'counting_month', 'unit_id', 'unit_price', 'amount', 'fee'];
+    public $fillable = [
+        'owner_bill_report_id',
+        'owner_id',
+        'counting_month', //统计月份
+        'unit_id', //单位
+        'unit_price', //单价
+        'amount', //数量
+        'fee',//费用
+        'work_name',//作业名称
+    ];
 
     public $timestamps = false;
 
-//    static public $enums = [
-//        'type' => [
-//            '' => 0,
-//            '退货入库' => 1,
-//            '新品入库' => 2,
-//        ],
-//    ];
-//
-//    function __construct(array $attributes = [])
-//    {
-//        foreach (self::$enums as &$enum) {
-//            $enum = $enum + array_flip($enum);
-//        }
-//        parent::__construct($attributes);
-//    }
-//
-//    public function getTypeAttribute($value)
-//    {
-//        if (!$value) return '';
-//        return self::$enums['type'][$value];
-//    }
-//
-//    public function setTypeAttribute($value)
-//    {
-//        if (!$value) return 0;
-//        $this->attributes['type'] = self::$enums['type'][$value];
-//    }
-
-
     public function ownerBillReport(): BelongsTo
     {
         return $this->belongsTo(OwnerBillReport::class);
     }
 
-    public function ownerPriceOperation(): BelongsTo
-    {
-        return $this->belongsTo(OwnerPriceOperation::class);
-    }
-
     public function owner(): BelongsTo
     {
         return $this->belongsTo(Owner::class);

+ 6 - 6
app/OwnerStoreOutFeeDetail.php

@@ -16,12 +16,17 @@ class OwnerStoreOutFeeDetail extends Model
         'commodity_id',//
         'owner_id',//
         'source_bill', // 上游单号
-        'owner_price_operation_id', //
         'unit_price', //价格
         'unit_id', //
         'amount',//数量
         'step',//阶梯
         'price_remark',//价格描述
+        'tax_fee',//税费
+        'sku',//商家编码
+        'packingMaterialFee',//耗材费
+        'barcode',//商品条码
+        'work_name',//作业名称
+        'fee',//费用
         ];
 
     public function ownerFeeDetail(): BelongsTo
@@ -43,9 +48,4 @@ class OwnerStoreOutFeeDetail extends Model
     {
         return $this->belongsTo(Unit::class);
     }
-
-    public function ownerPriceOperation(): BelongsTo
-    {
-        return $this->belongsTo(OwnerPriceOperation::class);
-    }
 }

+ 11 - 6
app/OwnerStoreOutFeeReport.php

@@ -11,7 +11,17 @@ class OwnerStoreOutFeeReport extends Model
 {
     use ModelLogChanging;
 
-    public $fillable = ['owner_bill_report_id', 'owner_price_operation_id', 'counting_month', 'step', 'unit_id', 'unit_price', 'amount', 'fee', 'owner_id'];
+    public $fillable = [
+        'owner_bill_report_id',
+        'counting_month',
+        'step', //阶梯
+        'unit_id',
+        'unit_price',//单价
+        'amount', //数量
+        'owner_id',
+        'work_name',//作业名称
+        'fee',//费用
+    ];
 
     public $timestamps = false;
 
@@ -20,11 +30,6 @@ class OwnerStoreOutFeeReport extends Model
         return $this->belongsTo(OwnerBillReport::class);
     }
 
-    public function ownerPriceOperation(): BelongsTo
-    {
-        return $this->belongsTo(OwnerPriceOperation::class);
-    }
-
     public function unit(): BelongsTo
     {
         return $this->belongsTo(Unit::class);

+ 3 - 0
app/Services/OwnerFeeTotalService.php

@@ -139,6 +139,7 @@ class OwnerFeeTotalService
      */
     private function buildInformation($owner, $counting_month): array
     {
+        //获取特征信息
         $features = app("FeatureService")->getMapArray();
         OwnerPriceOperation::$features = $features;
         OwnerPriceOperationItem::$features = $features;
@@ -150,6 +151,7 @@ class OwnerFeeTotalService
                 if ($item["strategy"] == "起步") $item["type"] = $item["amount"] ? 0 : 1;
             }
         }
+
         $information = [
             //仓储
             'storageFee' => [],
@@ -176,6 +178,7 @@ class OwnerFeeTotalService
         /**@var $storeOutFeeDetailsService OwnerStoreOutFeeDetailService */
         $storeOutFeeDetailsService = app('OwnerStoreOutFeeDetailService');
         $workFeeTotalGrouped = $storeOutFeeDetailsService->getTotalFee($owner->id, $counting_month)->groupBy('owner_price_operation_id');
+
         //入库
         foreach ($ownerPriceOperationsGrouped['入库'] ?? [] as $ownerPriceOperationsGroupedItem) {
             $information['storeFee'][] = [

+ 2 - 7
app/Services/OwnerLogisticFeeDetailService.php

@@ -23,7 +23,6 @@ class OwnerLogisticFeeDetailService implements \App\Interfaces\SettlementBillDet
      */
     protected $modelClass = OwnerLogisticFeeDetail::class;
 
-    //插入数据 ServiceAppAop的 insert 方法 支持批量
 
     /**
      * 根据货主查询 和时间段查询
@@ -92,7 +91,8 @@ class OwnerLogisticFeeDetailService implements \App\Interfaces\SettlementBillDet
                 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量
                 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
                 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
-                'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
+//                'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
+                'logistic_fee' => $ownerLogisticFeeDetail->fee,//快递费
             ];
         }
         return $items;
@@ -100,23 +100,18 @@ class OwnerLogisticFeeDetailService implements \App\Interfaces\SettlementBillDet
 
     public function switchType($type)
     {
-        // TODO: Implement switchType() method.
     }
 
     public function buildExport($details): array
     {
-        // TODO: Implement buildExport() method.
     }
 
     public function add(array $model)
     {
-        // TODO: Implement add() method.
     }
 
     public function getTotalFee($owner_id, $counting_month)
     {
-        // TODO: Implement getTotalFee() method.
     }
 
-
 }

+ 5 - 1
app/Services/OwnerLogisticFeeReportService.php

@@ -93,6 +93,7 @@ class OwnerLogisticFeeReportService implements \App\Interfaces\SettlementBillRep
             additional_weight,
             sum(additional_weigh_weight) as additional_amount,
             sum(tax_fee) as tax_fee,
+            sum(fee) as fee,
             created_at,
             owner_id")
             ->whereBetween('created_at', [$start, $end])
@@ -111,11 +112,14 @@ class OwnerLogisticFeeReportService implements \App\Interfaces\SettlementBillRep
                 'additional_weight' => $ownerLogisticFeeDetail->additional_weight,
                 'additional_price' => $ownerLogisticFeeDetail->additional_price,
                 'additional_amount' => $ownerLogisticFeeDetail->additional_amount,
-                'fee' => ($ownerLogisticFeeDetail['initial_weight_price'] * $ownerLogisticFeeDetail['initial_amount']) + ($ownerLogisticFeeDetail['additional_amount'] * $ownerLogisticFeeDetail['additional_price']),
+                'fee' => $ownerLogisticFeeDetail->fee,
                 'tax_fee' => $ownerLogisticFeeDetail->tax_fee,
                 'owner_id' => $ownerLogisticFeeDetail->owner_id,
             ];
         }
+        //保证接口幂等性 删除统计月的数据
+        OwnerLogisticFeeReport::query()->where('counted_date', $counting_month)->delete();
+
         OwnerLogisticFeeReport::query()->insertOrIgnore($ownerLogisticFeeReportArray);
     }
 

+ 8 - 22
app/Services/OwnerStoreFeeDetailService.php

@@ -24,19 +24,6 @@ class OwnerStoreFeeDetailService
     }
 
 
-//    /**
-//     * @param $type
-//     * @return int|mixed
-//     */
-//    public function switchType($type)
-//    {
-//        //枚举转换
-//        if (is_string($type)) {
-//            $type = OwnerStoreFeeDetail::$enums['type'][$type];
-//        }
-//        return $type;
-//    }
-
     /**
      * @param $counting_month
      * @param $owner_id
@@ -47,10 +34,9 @@ class OwnerStoreFeeDetailService
         list($start, $end) = $this->getStartAndEnd($counting_month);
         return OwnerStoreFeeDetail::query()
             ->with([
-                'ownerFeeDetail:id,work_fee,worked_at',
-                'storeItem' => function ($query) {$query->selectRaw("id,asn_line_code,sku,commodity_id")->with('commodity:id,name');},
-                'ownerPriceOperation:id,name'
-                ])
+                'ownerFeeDetail:id,worked_at',
+                'commodity:id,name',
+             ])
             ->whereBetween('created_at', [$start, $end])
             ->where('owner_id', $owner_id);
     }
@@ -61,13 +47,13 @@ class OwnerStoreFeeDetailService
         foreach ($details as $detail) {
             $results[] = [
                 $detail->ownerFeeDetail->worked_at ?? null,
-                $detail->type ?? null,
-                $detail->storeItem->asn_line_code ?? null,
-                $detail->storeItem->sku ?? null,
-                $detail->storeItem->commodity->name ?? null,
+                $detail->work_name ?? null,
+                $detail->asn_code ?? null,
+                $detail->sku ?? null,
+                $detail->commodity->name ?? null,
                 $detail->amount ?? null,
                 $detail->unit_price ?? null,
-                $detail->ownerFeeDetail->work_fee ?? null,
+                $detail->fee ?? null,
             ];
         }
         return $results;

+ 24 - 16
app/Services/OwnerStoreFeeReportService.php

@@ -44,17 +44,24 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
         $end = Carbon::parse($this->reportDate)->endOfMonth()->toDateString();
         $details =
             DB::table('owner_store_fee_details')
-                ->leftJoin('owner_fee_details', 'owner_fee_detail_id', '=', 'owner_fee_details.id')
-                ->selectRaw("DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m') as counting_month,
+                ->selectRaw("
+                DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m') as counting_month,
                 unit_id,
                 unit_price,
+                work_name,
                 sum(amount) as amounts ,
                 owner_store_fee_details.owner_id,
                 owner_fee_detail_id,
-                sum(owner_fee_details.work_fee) as work_fee,
-                owner_store_fee_details.owner_price_operation_id")
+                sum(owner_store_fee_details.fee) as fee
+                ")
                 ->whereBetween('owner_store_fee_details.created_at', [$start, $end])
-                ->groupBy('counting_month', 'owner_store_fee_details.owner_id', 'owner_store_fee_details.owner_price_operation_id', 'unit_id', 'unit_price')
+                ->groupBy(
+                    'counting_month',
+                    'owner_id',
+                    'unit_id',
+                    'unit_price',
+                    'work_name'
+                )
                 ->get();
         $reports = [];
         foreach ($details as $detail) {
@@ -65,16 +72,19 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
                 ->where('counting_month', $counting_month)->first();
             $reports[] = [
                 'owner_bill_report_id' => $ownerBillReport->id ?? null,
-                'owner_price_operation_id' => $detail->owner_price_operation_id,
                 'owner_id' => $detail->owner_id,
                 'counting_month' => $counting_month,
                 'unit_id' => $detail->unit_id,
                 'unit_price' => $detail->unit_price,
                 'amount' => $detail->amounts,
-                'fee' => $detail->work_fee,
+                'fee' => $detail->fee,
+                'work_name' => $detail->work_name,
             ];
         }
-        $reports_chunked =  array_chunk($reports,1000 );
+        $reports_chunked = array_chunk($reports, 1000);
+        //保证幂等性 插入前删除该月的统计数据
+        OwnerStoreFeeReport::query()->where('counting_month', $counting_month)->delete();
+
         foreach ($reports_chunked as $items) {
             OwnerStoreFeeReport::query()->insertOrIgnore($items);
         }
@@ -92,18 +102,16 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
             $totalFee = $archived->information['totalFee'];
             $owner_price_operation_fees = collect($archived->information['owner_price_operation_fees']);
         } else {
-            $reports = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->orderByDesc('owner_price_operation_id')->get();
+            $reports = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->get();
             $totalAmount = $reports->sum('amount');
-            $totalFee = number_format($reports->sum('fee'),2);
-
-            $owner_price_operation_fees =   OwnerStoreFeeReport::query()
-                ->with('ownerPriceOperation:id,name')
-                ->selectRaw("sum(fee) as fee,owner_price_operation_id")
+            $totalFee = number_format($reports->sum('fee'), 2);
+            $owner_price_operation_fees = OwnerStoreFeeReport::query()
+                ->selectRaw("sum(fee) as fee,work_name")
                 ->where('owner_id', $kvPairs['owner_id'])
                 ->where('counting_month', $kvPairs['counting_month'])
-                ->groupBy('owner_price_operation_id')->get();
+                ->groupBy('work_name')->get();
         }
-        return array($reports, $totalAmount, $totalFee,$owner_price_operation_fees);
+        return array($reports, $totalAmount, $totalFee, $owner_price_operation_fees);
     }
 
     /**

+ 17 - 8
app/Services/OwnerStoreOutFeeDetailService.php

@@ -3,11 +3,13 @@
 namespace App\Services;
 
 use App\Interfaces\SettlementBillDetailInterface;
+use App\OwnerFeeDetail;
 use App\Traits\ServiceAppAop;
 use App\OwnerStoreOutFeeDetail;
 use App\Traits\SettlementBillServiceTrait;
 use Illuminate\Contracts\Pagination\LengthAwarePaginator;
 use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
 
 class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
 {
@@ -34,8 +36,7 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
         return OwnerStoreOutFeeDetail::query()
             ->with([
                 'commodity:id,name,sku',
-                'ownerFeeDetail:id,worked_at,operation_bill,work_fee',
-                'ownerPriceOperation.items.unit',
+                'ownerFeeDetail:id,worked_at,operation_bill,work_fee'
             ])
             ->where('owner_id', $owner_id)
             ->whereBetween('created_at', [$start, $end]);
@@ -53,14 +54,16 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
         foreach ($details as $detail) {
             $result[] = [
                 $detail->ownerFeeDetail->worked_at,
-                $detail->ownerPriceOperation->name ?? '',
+                $detail->work_name,
                 $detail->source_bill,
                 $detail->ownerFeeDetail->operation_bill,
-                $detail->commodity->sku,
-                $detail->commodity->name,
+                $detail->sku,
+                $detail->barcode,
+                $detail->commodity->name ?? '',
                 $detail->amount,
+                $detail->unit_price,
                 $detail->price_remark,
-                $detail->ownerFeeDetail->work_fee,
+                $detail->fee,
             ];
         }
         return $result;
@@ -71,10 +74,16 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
         // TODO: Implement add() method.
     }
 
+    /**
+     * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费
+     * @param $owner_id
+     * @param $counting_month
+     * @return Builder[]|Collection
+     */
     public function getTotalFee($owner_id, $counting_month)
     {
-       list($start, $end) = $this->getStartAndEnd($counting_month);
-        return \App\OwnerFeeDetail::query()
+        list($start, $end) = $this->getStartAndEnd($counting_month);
+        return OwnerFeeDetail::query()
             ->selectRaw("owner_price_operation_id,
             sum(work_fee) as work_fee,
             sum(work_tax_fee) as work_tax_fee

+ 35 - 37
app/Services/OwnerStoreOutFeeReportService.php

@@ -5,7 +5,9 @@ namespace App\Services;
 use App\Interfaces\SettlementBillReportInterface;
 use App\OwnerBillReport;
 use App\OwnerBillReportArchive;
+use App\OwnerFeeDetail;
 use App\OwnerStoreFeeReport;
+use App\OwnerStoreOutFeeDetail;
 use App\Traits\ServiceAppAop;
 use App\OwnerStoreOutFeeReport;
 use Carbon\Carbon;
@@ -37,29 +39,27 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
         $this->reportDate = $counting_month;
         $start = $this->reportDate;
         $end = Carbon::parse($this->reportDate)->endOfMonth()->toDateString();
-        $details =
-            DB::table('owner_store_out_fee_details')
-                ->leftJoin('owner_fee_details', 'owner_store_out_fee_details.owner_fee_detail_id', '=', 'owner_fee_details.id')
-                ->leftJoin('owner_price_operations', 'owner_store_out_fee_details.owner_price_operation_id', '=', 'owner_price_operations.id')
-                ->selectRaw("
+        $details = OwnerStoreOutFeeDetail::query()
+            ->selectRaw("
                 DATE_FORMAT(owner_store_out_fee_details.created_at,'%Y-%m') as counting_month,
-                owner_store_out_fee_details.unit_id,
-                owner_store_out_fee_details.unit_price,
-                sum(owner_store_out_fee_details.amount) as amounts ,
-                owner_store_out_fee_details.owner_id,
-                owner_store_out_fee_details.owner_fee_detail_id,
-                owner_store_out_fee_details.owner_price_operation_id,
-                owner_store_out_fee_details.step,
-                sum(owner_fee_details.work_fee) as work_fee,
-                owner_price_operations.name
-                ")
-                ->whereBetween('owner_store_out_fee_details.created_at', [$start, $end])
-                ->groupBy('counting_month',
-                    'owner_store_out_fee_details.owner_id',
-                    'owner_store_out_fee_details.step',
-                    'owner_price_operations.id'
-                )
-                ->get();
+                step,
+                unit_id,
+                unit_price,
+                sum(amount) as  amount ,
+                sum(fee) as  fee ,
+                owner_id,
+                work_name
+            ")
+            ->whereBetween('created_at', [$start, $end])
+            ->groupBy(
+                'counting_month',
+                'step',
+                'unit_id',
+                'unit_price',
+                'owner_id',
+                'work_name'
+            )->get();
+
         $reports = [];
         foreach ($details as $detail) {
             $counting_month = Carbon::parse($detail->counting_month)->startOfMonth()->toDateString();
@@ -69,16 +69,20 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
                 ->where('counting_month', $counting_month)->first();
             $reports[] = [
                 'owner_bill_report_id' => $ownerBillReport->id ?? null,
-                'owner_price_operation_id' => $detail->owner_price_operation_id,
                 'owner_id' => $detail->owner_id,
                 'counting_month' => $counting_month,
                 'step' => $detail->step,
                 'unit_id' => $detail->unit_id,
                 'unit_price' => $detail->unit_price,
-                'amount' => $detail->amounts,
-                'fee' => $detail->work_fee,
+                'amount' => $detail->amount,
+                'fee' => $detail->fee,
+                'work_name' => $detail->work_name,
             ];
         }
+
+        //保证幂等性 插入前删除该月的统计数据
+        OwnerStoreOutFeeReport::query()->where('counting_month', $counting_month)->delete();
+
         foreach (array_chunk($reports, 1000) as $reports_chunked) {
             OwnerStoreOutFeeReport::query()->insertOrIgnore($reports_chunked);
         }
@@ -104,6 +108,7 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
     function get(array $kvPairs)
     {
         $this->archiveService = app('OwnerBillReportArchiveService');
+        list($start, $end) = $this->getStartAndEnd($kvPairs['counting_month']);
         if ($this->archiveService->isArchived($kvPairs['counting_month'], $kvPairs['owner_id'], $kvPairs['type']) == 1) {
             //查询存档数据
             $archived = $this->archiveService->get($kvPairs);
@@ -115,25 +120,18 @@ class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
                 ->with(['unit:id,name'])
                 ->where('owner_id', $kvPairs['owner_id'])
                 ->where('counting_month', $kvPairs['counting_month'])
-                ->orderBy('owner_price_operation_id')
                 ->get();
 
             $work_name_fee_total = OwnerStoreOutFeeReport::query()
-                ->leftJoin('owner_price_operations', 'owner_store_out_fee_reports.owner_price_operation_id', '=', 'owner_price_operations.id')
                 ->selectRaw("
-                sum(owner_store_out_fee_reports.fee) as fee,
-                owner_price_operations.name,
-                owner_price_operations.id
+                    sum(fee) as fee,
+                    work_name
                 ")
+                ->where('counting_month' , $kvPairs['counting_month'])
                 ->where('owner_id', $kvPairs['owner_id'])
-                ->where('counting_month', $kvPairs['counting_month'])
-                ->groupBy('owner_price_operations.name')
+                ->groupBy('work_name')
                 ->get();
-
-            $fee_total = OwnerStoreOutFeeReport::query()
-                ->where('owner_id', $kvPairs['owner_id'])
-                ->where('counting_month', $kvPairs['counting_month'])
-                ->sum('fee');
+            $fee_total = $work_name_fee_total->sum('fee');
         }
         return array($reports, $work_name_fee_total, $fee_total);
     }

+ 1 - 0
database/factories/OwnerFeeDetailFactory.php

@@ -26,5 +26,6 @@ $factory->define(OwnerFeeDetail::class, function (Faker $faker) {
         "logistic_tax_fee" => mt_rand(100, 10000) / 10,     //物流税费
         "province" => $faker->randomElement($province),     //物流费
         "logistic_id" => rand(1,100),     //物流费
+        'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(1, 28)),
     ];
 });

+ 1 - 0
database/factories/OwnerLogisticFeeDetailFactory.php

@@ -20,6 +20,7 @@ $factory->define(OwnerLogisticFeeDetail::class, function (Faker $faker) {
         'owner_id' => random_int(1, 100),
         'additional_weigh_weight' => random_int(1, 100),
         'tax_fee' => random_int(1, 100),
+        'fee' => random_int(1, 100),
         'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(1, 28))->toDateTimeString(),
         'updated_at' => now()->subMonth()->startOfMonth()->addDays(random_int(1, 28))->toDateTimeString(),
     ];

+ 19 - 8
database/factories/OwnerStoreFeeDetailFactory.php

@@ -6,16 +6,27 @@ use App\OwnerStoreFeeDetail;
 use Faker\Generator as Faker;
 
 $factory->define(OwnerStoreFeeDetail::class, function (Faker $faker) {
-    //['owner_fee_detail_id', 'unit_id', 'unit_price', 'amount', 'owner_id', 'store_item_id','owner_price_operation_id']
+    $prices = [1.2, 1.3, 1.5, 1.5];
+    $work_names = ['入库费1', '入库费2'];
+
+    $price = $faker->randomElement($prices);
+    $amount = random_int(1, 100);
+
     return [
         //
-        'owner_fee_detail_id' => random_int(1,100),
-        'owner_price_operation_id' => random_int(1, 100),
-        'unit_id' => random_int(1, 11),
-        'unit_price' => mt_rand(10, 100),
-        'amount' => mt_rand(10, 100),
-        'owner_id' => 8,
-        'store_item_id' =>random_int(1,100),
+        'owner_fee_detail_id' => random_int(1, 100),
+        'unit_id' => random_int(1, 3),
+        'unit_price' => $price,
+        'amount' => $amount,
+        'owner_id' => random_int(1, 100),
+        'fee' => $price * $amount,//费用
+        'commodity_id' => random_int(1, 100),
+        'packing_material_fee' => random_int(1, 100),//包材费
+        'tax_fee' => random_int(1, 100),//税费
+        'sku' => $faker->uuid,//sku
+        'barcode' => $faker->uuid,//条码
+        'work_name' => $faker->randomElement($work_names),//作业名称
+        'asn_code' => $faker->uuid,//条码
         'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),
         'updated_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),
     ];

+ 1 - 1
database/factories/OwnerStoreFeeReportFactory.php

@@ -8,12 +8,12 @@ use Faker\Generator as Faker;
 $factory->define(OwnerStoreFeeReport::class, function (Faker $faker) {
     return [
         'owner_bill_report_id' => random_int(1, 100),
-        'owner_price_operation_id' => random_int(1, 100),
         'owner_id' => 8,
         'counting_month' => now()->subMonth()->startOfMonth()->toDateString(),
         'unit_id'=>random_int(1, 10),
         'unit_price'=>random_int(1, 100),
         'amount'=>random_int(1, 100),
         'fee'=>random_int(1, 100),
+        'work_name' => $faker->name,
     ];
 });

+ 15 - 5
database/factories/OwnerStoreOutFeeDetailFactory.php

@@ -7,6 +7,12 @@ use Faker\Generator as Faker;
 
 $factory->define(OwnerStoreOutFeeDetail::class, function (Faker $faker) {
     $step = ['0-20000', '20000-50000', '50000-100000'];
+    $prices = [1.2, 1.3, 1.5, 1.5];
+    $work_names = ['出库费1','出库费2'];
+
+
+    $price = $faker->randomElement($prices);
+    $amount = random_int(1, 100);
     return [
         'owner_fee_detail_id' => random_int(1, 100),
 
@@ -16,17 +22,21 @@ $factory->define(OwnerStoreOutFeeDetail::class, function (Faker $faker) {
 
         'source_bill' => $faker->uuid,
 
-        'owner_price_operation_id' => random_int(1, 100),
 
-        'unit_price' => random_int(1, 100),
+        'unit_price' => $price,
 
 
-        'unit_id' => random_int(1, 10),
+        'unit_id' => random_int(1, 3),
 
-        'amount' => random_int(1, 100),
+        'amount' => $amount,
 
         'step' => $faker->randomElement($step),
-
+        'tax_fee' => random_int(1, 100),//税费
+        'sku' => $faker->uuid,//商家编码
+        'packingMaterialFee' => random_int(1, 100),//耗材费
+        'barcode' => $faker->uuid,//商品条码
+        'work_name' => $faker->randomElement($work_names),//作业名称
+        'fee' => $price * $amount,//费用
         'price_remark' => '起步费:2.2元(5件以内),续费:0.2元/件',
         'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),
         'updated_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),

+ 0 - 2
database/factories/OwnerStoreOutFeeReportFactory.php

@@ -21,8 +21,6 @@ $factory->define(OwnerStoreOutFeeReport::class, function (Faker $faker) {
 
         'amount'=>random_int(1,100),
 
-        'fee'=>random_int(1,100),
-
         'owner_id'=>random_int(1,100),
     ];
 });

+ 32 - 0
database/migrations/2021_07_14_101031_add_fee_to_owner_logistic_fee_details_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddFeeToOwnerLogisticFeeDetailsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_logistic_fee_details', function (Blueprint $table) {
+            $table->decimal('fee')->comment('快递费');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_logistic_fee_details', function (Blueprint $table) {
+            $table->dropColumn('fee');
+        });
+    }
+}

+ 34 - 0
database/migrations/2021_07_15_112931_drop_fee_to_owner_store_out_fee_reports_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class DropFeeToOwnerStoreOutFeeReportsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_store_out_fee_reports', function (Blueprint $table) {
+            //
+            $table->dropColumn('fee');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_store_out_fee_reports', function (Blueprint $table) {
+            //
+            $table->decimal('fee')->comment('费用');
+        });
+    }
+}

+ 46 - 0
database/migrations/2021_07_15_154921_add_fee_and_other_to_owner_store_fee_details_table.php

@@ -0,0 +1,46 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddFeeAndOtherToOwnerStoreFeeDetailsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_store_fee_details', function (Blueprint $table) {
+            $table->decimal('fee')->comment('费用');
+            $table->integer('commodity_id')->comment('');
+            $table->decimal('packing_material_fee')->comment('包材费');
+            $table->decimal('tax_fee')->comment('税费');
+            $table->string('sku')->comment('sku');
+            $table->string('barcode')->comment('条码');
+            $table->string('work_name')->comment('作业名称');
+            $table->string('asn_code')->comment('asn号');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_store_fee_details', function (Blueprint $table) {
+            $table->dropColumn('fee');
+            $table->dropColumn('commodity_id');
+            $table->dropColumn('packing_material_fee');
+            $table->dropColumn('tax_fee');
+            $table->dropColumn('sku');
+            $table->dropColumn('barcode');
+            $table->dropColumn('work_name');
+            $table->dropColumn('asn_code');
+        });
+    }
+}

+ 34 - 0
database/migrations/2021_07_15_163048_add_work_name_and_drop_other_to_owner_store_fee_reports_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddWorkNameAndDropOtherToOwnerStoreFeeReportsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_store_fee_reports', function (Blueprint $table) {
+            $table->string('work_name')->comment('作业名称');
+            $table->dropColumn('owner_price_operation_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_store_fee_reports', function (Blueprint $table) {
+            $table->dropColumn('work_name');
+            $table->integer('owner_price_operation_id');
+        });
+    }
+}

+ 46 - 0
database/migrations/2021_07_16_092933_add_work_name_and_drop_other_to_owner_store_out_fee_details_table.php

@@ -0,0 +1,46 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddWorkNameAndDropOtherToOwnerStoreOutFeeDetailsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_store_out_fee_details', function (Blueprint $table) {
+            $table->decimal('tax_fee')->comment('税费');
+            $table->string('sku')->comment('商家编码');
+            $table->decimal('packingMaterialFee')->comment('耗材费');
+            $table->string('barcode')->comment('商品条码');
+            $table->string('work_name')->comment('作业名称');
+            $table->decimal('fee')->comment('费用');
+
+            $table->dropColumn('owner_price_operation_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_store_out_fee_details', function (Blueprint $table) {
+            $table->dropColumn('tax_fee');
+            $table->dropColumn('sku');
+            $table->dropColumn('packingMaterialFee');
+            $table->dropColumn('barcode');
+            $table->dropColumn('work_name');
+            $table->dropColumn('fee');
+
+            $table->integer('owner_price_operation_id');
+        });
+    }
+}

+ 37 - 0
database/migrations/2021_07_16_110120_add_work_name_and_drop_other_to_owner_store_out_fee_reports_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddWorkNameAndDropOtherToOwnerStoreOutFeeReportsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_store_out_fee_reports', function (Blueprint $table) {
+            $table->string('work_name')->comment('作业名称');
+            $table->decimal('fee')->comment('费用');
+            $table->dropColumn('owner_price_operation_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_store_out_fee_reports', function (Blueprint $table) {
+            $table->dropColumn('work_name');
+            $table->dropColumn('fee');
+
+            $table->integer('owner_price_operation_id');
+        });
+    }
+}

+ 0 - 1
database/seeds/OwnerLogisticFeeDetailSeeder.php

@@ -66,7 +66,6 @@ class OwnerLogisticFeeDetailSeeder extends Seeder
             factory(OwnerLogisticFeeDetail::class)->times(200)->create([
                 'owner_id' => $owner->id,
                 'owner_fee_detail_id' => $feeDetail->id,
-
             ]);
         }
     }

+ 6 - 11
database/seeds/OwnerStoreFeeDetailSeeder.php

@@ -18,24 +18,19 @@ class OwnerStoreFeeDetailSeeder extends Seeder
     {
         //
         OwnerStoreFeeDetail::query()->truncate();
-        StoreItem::query()->truncate();
-        Commodity::query()->truncate();
-        OwnerPriceOperation::query()->truncate();
         $owners = \App\Owner::query()->limit(10)->get();
         foreach ($owners as $owner) {
-            $ownerPriceOperations = factory(\App\OwnerPriceOperation::class)->times(2)->create(['operation_type' => '出库']);
-            foreach ($ownerPriceOperations as $operation) {
-                $feeDetails = factory(OwnerFeeDetail::class)->times(100)->create(['owner_id' => $owner->id]);
-                foreach ($feeDetails as $feeDetail) {
-                    factory(OwnerStoreFeeDetail::class)->create([
-                        'owner_price_operation_id' => $operation->id,
+            $feeDetails = factory(OwnerFeeDetail::class)->times(5)->create(['owner_id' => $owner->id]);
+            $commodities = factory(Commodity::class)->times(5)->create();
+            foreach ($feeDetails as $feeDetail) {
+                foreach ($commodities as $commodity) {
+                    factory(OwnerStoreFeeDetail::class)->times(10)->create([
                         'owner_id' => $owner->id,
                         'owner_fee_detail_id' => $feeDetail->id,
+                        'commodity_id' => $commodity->id,
                     ]);
                 }
             }
-            factory(StoreItem::class)->times(100)->create();
-            factory(Commodity::class)->times(100)->create(['owner_id' => $owner->id]);
         }
 
 

+ 16 - 22
database/seeds/OwnerStoreOutFeeDetailSeeder.php

@@ -1,6 +1,7 @@
 <?php
 
 use App\Commodity;
+use App\Owner;
 use App\OwnerFeeDetail;
 use App\OwnerPriceOperation;
 use App\OwnerPriceOperationItem;
@@ -17,32 +18,25 @@ class OwnerStoreOutFeeDetailSeeder extends Seeder
     public function run()
     {
         OwnerStoreOutFeeDetail::query()->truncate();
-        OwnerFeeDetail::query()->truncate();
-        Commodity::query()->truncate();
-        OwnerPriceOperation::query()->truncate();
-        OwnerPriceOperationItem::query()->truncate();
-
-        $owners = \App\Owner::query()->limit(10)->get();
+        $owners = Owner::query()->limit(10)->get();
         foreach ($owners as $owner) {
-            $priceOperations =  factory(\App\OwnerPriceOperation::class)->times(2)->create([
-                'operation_type' => '出库',
-                'discount_count'=>"0,30000,60000"
+
+            $commoditys = factory(Commodity::class)->times(10)->create();
+            $feeDetails = factory(OwnerFeeDetail::class)->times(3)->create([
+                'type' => '发货',
+                'owner_id' => $owner->id,
             ]);
-            foreach ($priceOperations as $item) {
-                factory(OwnerPriceOperationItem::class)->times(2)->create([
-                    'owner_price_operation_id' => $item->id,
-                    'discount_price' => "2.5,2.2,1.6",
-                ]);
-            }
-            for ($i=0;$i<100;$i++) {
-                factory(OwnerStoreOutFeeDetail::class)->create([
-                    'owner_id'=>$owner->id,
-                    'owner_price_operation_id' => $priceOperations->random(1)->first()->id,
-                ]);
+            foreach ($feeDetails as $feeDetail) {
+                foreach ($commoditys as $commodity) {
+                    factory(OwnerStoreOutFeeDetail::class)->times(5)->create([
+                        'owner_id' => $owner->id,
+                        'owner_fee_detail_id' => $feeDetail->id,
+                        'commodity_id' => $commodity->id,
+                    ]);
+                }
             }
 
-            factory(OwnerFeeDetail::class)->times(100)->create(['owner_id'=>$owner->id]);
-            factory(Commodity::class)->times(100)->create(['owner_id'=>$owner->id]);
+
         }
 
     }

+ 8 - 1
database/seeds/OwnerStoreOutFeeReportSeeder.php

@@ -1,5 +1,8 @@
 <?php
 
+use App\Owner;
+use App\OwnerFeeDetail;
+use App\OwnerPriceOperation;
 use App\OwnerStoreOutFeeReport;
 use Illuminate\Database\Seeder;
 
@@ -13,8 +16,12 @@ class OwnerStoreOutFeeReportSeeder extends Seeder
     public function run()
     {
         OwnerStoreOutFeeReport::query()->truncate();
-        $owners = \App\Owner::query()->limit(10)->get();
+        OwnerFeeDetail::query()->truncate();
+        OwnerPriceOperation::query()->truncate();
+        $owners = Owner::query()->limit(10)->get();
         foreach ($owners as $owner) {
+            $priceOperation =  factory(OwnerPriceOperation::class)->create(['operation_type'=>'出库']);
+            factory(\App\OwnerFeeDetail::class)->create(['owner_price_operation_id'=>$priceOperation->id,'owner_id'=>$owner->id]);
             factory(OwnerStoreOutFeeReport::class)->times(100)->create(['owner_id' => $owner->id]);
         }
     }

+ 0 - 9
resources/views/finance/settlementBills/expressFee/report/index.blade.php

@@ -94,15 +94,6 @@
                     <td>@{{ report.fee }}</td>
                 </tr>
             </table>
-{{--            <div class="container" v-if="!(isArchived===1) && reports.length>0">--}}
-{{--                <div class="row">--}}
-{{--                    <div class="col-10"></div>--}}
-{{--                    <div class="col-2">--}}
-{{--                   --}}
-{{--                    </div>--}}
-{{--                </div>--}}
-{{--            </div>--}}
-<!--不是存档的展示分页            -->
             @if($isArchived===2 )
                 <div class="text-info h5 btn btn">{{$reportPaginator->count()??''}}
                     /{{$reportPaginator->total()??''}}</div>

+ 11 - 9
resources/views/finance/settlementBills/storeFee/detail/index.blade.php

@@ -36,13 +36,14 @@
                     <td><input class="checkItem" type="checkbox" :value="detail.id"></td>
                     <td>@{{ i+1 }}</td>
                     <td>@{{ detail.owner_fee_detail.worked_at }}</td>
-                    <td>@{{ detail.owner_price_operation?detail.owner_price_operation.name:'' }}</td>
-                    <td>@{{ detail.store_item.asn_line_code }}</td>
-                    <td>@{{ detail.store_item.sku }}</td>
-                    <td>@{{ detail.store_item.commodity?detail.store_item.commodity.name:'' }}</td>
-                    <td>@{{ detail.amount}}</td>
-                    <td>@{{ detail.unit_price}}</td>
-                    <td>@{{ detail.owner_fee_detail.work_fee }}</td>
+                    <td>@{{ detail.work_name }}</td>
+                    <td>@{{ detail.asn_code }}</td>
+                    <td>@{{ detail.sku }}</td>
+                    <td>@{{ detail.barcode }}</td>
+                    <td>@{{ detail.commodity.name }}</td>
+                    <td>@{{ detail.amount }}</td>
+                    <td>@{{ detail.unit_price }}</td>
+                    <td>@{{ detail.fee }}</td>
                 </tr>
             </table>
             <div class="text-info h5 btn btn">{{$details->count()}}/{{$details->total()}}</div>
@@ -137,8 +138,9 @@
                     {name: 'index', value: '序号', neglect: true},
                     {name: 'worked_at', value: '作业时间'},
                     {name: 'work_type', value: '作业名称'},
-                    {name: 'asn_number', value: '入库单号'},
-                    {name: 'sku', value: '商品条码'},
+                    {name: 'asn', value: '入库单号'},
+                    {name: 'sku', value: '商家编码'},
+                    {name: 'barcode', value: '商品条码'},
                     {name: 'commodity_name', value: '商品名称'},
                     {name: 'amount', value: '数量'},
                     {name: 'price', value: '单价'},

+ 3 - 6
resources/views/finance/settlementBills/storeFee/report/index.blade.php

@@ -81,9 +81,9 @@
                     <th>合计</th>
                 </tr>
                 <tr v-for="(report,i) in reports">
-                    <td class="text-center pt-4 bg-light">@{{ report.owner_price_operation?report.owner_price_operation.name:'' }}</td>
+                    <td class="text-center pt-4 bg-light">@{{ report.work_name }}</td>
                     <td class="m-0 p-0">
-                        <table class="table table-striped table-sm m-0 p-0">
+                        <table class="table  m-0 p-0">
                             <tr v-for="item in report.data">
                                 <td>@{{ item.unit_price }}/@{{ item.unit.name }}</td>
                             </tr>
@@ -91,7 +91,7 @@
 
                     </td>
                     <td class="m-0 p-0">
-                        <table class="table table-striped table-sm m-0 p-0">
+                        <table class="table  m-0 p-0">
                             <tr v-for="item in report.data">
                                 <td>@{{ item.amount }}</td>
                             </tr>
@@ -187,9 +187,6 @@
                 _this.form.init();
             },
             methods: {
-                calRowspan(type) {
-                    return this.reports.filter(item => item.type === type).length;
-                },
                 reportExport(sign) {
                     let url = '{{url('finance/settlementBills/storeFee/report/export')}}';
                     let token = '{{ csrf_token() }}';

+ 8 - 4
resources/views/finance/settlementBills/storeOutFee/detail/index.blade.php

@@ -34,14 +34,16 @@
                     <td><input class="checkItem" type="checkbox" :value="detail.id"></td>
                     <td>@{{ i+1 }}</td>
                     <td>@{{ detail.owner_fee_detail.worked_at }}</td>
-                    <td>@{{ detail.owner_price_operation?detail.owner_price_operation.name:'' }}</td>
+                    <td>@{{ detail.work_name }}</td>
                     <td>@{{ detail.source_bill }}</td>
                     <td>@{{ detail.owner_fee_detail.operation_bill }}</td>
-                    <td>@{{ detail.commodity.sku }}</td>
+                    <td>@{{ detail.sku }}</td>
+                    <td>@{{ detail.barcode }}</td>
                     <td>@{{ detail.commodity?detail.commodity.name:'' }}</td>
                     <td>@{{ detail.amount}}</td>
+                    <td>@{{ detail.unit_price}}</td>
                     <td>@{{ detail.price_remark}}</td>
-                    <td>@{{ detail.owner_fee_detail.work_fee }}</td>
+                    <td>@{{ detail.fee }}</td>
                 </tr>
             </table>
             <div class="text-info h5 btn btn">{{$details->count()}}/{{$details->total()}}</div>
@@ -138,10 +140,12 @@
                     {name: 'work_type', value: '作业名称'},
                     {name: 'source_bill', value: '上游单号'},
                     {name: 'operation_bill', value: '订单号'},
+                    {name: 'barcode', value: '商家编码'},
                     {name: 'sku', value: '商品条码'},
                     {name: 'commodity_name', value: '商品名称'},
                     {name: 'amount', value: '商品数量'},
-                    {name: 'price', value: '价格'},
+                    {name: 'price', value: '单价'},
+                    {name: 'price_remark', value: '价格描述'},
                     {name: 'fee', value: '合计'},
                 ];
                 new Header({

+ 2 - 2
resources/views/finance/settlementBills/storeOutFee/report/index.blade.php

@@ -76,7 +76,7 @@
                     @click="selectTr===i+1?selectTr=0:selectTr=i+1"
                     :class="selectTr===i+1?'focusing' : ''">
                     <td>
-                        @{{ report.name }}
+                        @{{ report.work_name }}
                     </td>
                     <td class="m-0 p-0">
                         <table class="table table-striped table-sm m-0 p-0">
@@ -88,7 +88,7 @@
                     <td class="m-0 p-0">
                         <table class="table table-striped table-sm m-0 p-0">
                             <tr v-for="item in report.data">
-                                <td>@{{ item.unit_price }}</td>
+                                <td>@{{ item.unit_price }}/@{{ item.unit.name }}</td>
                             </tr>
                         </table>
                     </td>

+ 60 - 21
tests/Services/OwnerStoreFeeReportService/RecordReportTest.php

@@ -24,31 +24,70 @@ class RecordReportTest extends TestCase
     {
         parent::setUp();
         $this->service = app('OwnerStoreFeeReportService');
-//        $this->data['ownerStoreFeeReports']
-//            = factory(OwnerStoreFeeReport::class, $this->amount)
-//            ->create();
     }
 
     public function testReturned()
     {
-//        OwnerPriceOperation::query()->truncate();
-//        OwnerFeeDetail::query()->truncate();
-//        OwnerStoreFeeDetail::query()->truncate();
-//        OwnerBillReport::query()->truncate();
-//        OwnerStoreFeeReport::query()->truncate();
-//        $ownerPriceOperationIds = factory(OwnerPriceOperation::class)->times(10)->create()->pluck('id');
-//        $ownerFeeDetailIds = [];
-//        foreach ($ownerPriceOperationIds as $ownerPriceOperationId) {
-//            $ownerFeeDetailIds[] = factory(OwnerFeeDetail::class)->create(['owner_price_operation_id' => $ownerPriceOperationId]);
-//        }
-//        foreach ($ownerFeeDetailIds as $ownerFeeDetailId) {
-//            $detail =  factory(OwnerStoreFeeDetail::class)->create(['owner_fee_detail_id' => $ownerFeeDetailId]);
-//            factory(OwnerBillReport::class)->create(['owner_id'=>$detail->owner_id,'counting_month'=>$detail->created_at->startOfMonth()->toDateString()]);
-//
-//        }
-//
-//        $this->service->recordReport();
-        $this->assertTrue(true);
+        OwnerStoreFeeDetail::query()->truncate();
+        OwnerStoreFeeReport::query()->truncate();
+
+        $ownerStoreFeeDetail_xx_1_2 = factory(OwnerStoreFeeDetail::class)->times(100)
+            ->create([
+                'owner_id' => 8,
+                'work_name' => 'xx入库费',
+                'unit_price' => 1.2,
+                'unit_id' => 1,
+            ]);
+
+        $ownerStoreFeeDetail_xx_1_4 = factory(OwnerStoreFeeDetail::class)->times(100)
+            ->create([
+                'owner_id' => 8,
+                'work_name' => 'xx入库费',
+                'unit_price' => 1.4,
+                'unit_id' => 1,
+            ]);
+
+        $ownerStoreFeeDetail_xx2_1_6 = factory(OwnerStoreFeeDetail::class)->times(100)
+            ->create([
+                'owner_id' => 8,
+                'work_name' => 'xx入库费2',
+                'unit_price' => 1.2,
+                'unit_id' => 1,
+            ]);
+        $this->service->recordReport();
+
+
+
+        $report =  OwnerStoreFeeReport::query()
+            ->where('unit_price', '1.2')
+            ->where('owner_id', 8)
+            ->where('unit_id', 1)
+            ->where('work_name', 'xx入库费')
+            ->first();
+
+        $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('amount'), $report->amount);
+        $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('fee'), $report->fee);
+
+        $report =  OwnerStoreFeeReport::query()
+            ->where('unit_price', '1.4')
+            ->where('owner_id', 8)
+            ->where('unit_id', 1)
+            ->where('work_name', 'xx入库费')
+            ->first();
+
+        $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('amount'), $report->amount);
+        $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('fee'), $report->fee);
+
+
+        $report =  OwnerStoreFeeReport::query()
+            ->where('unit_price', '1.2')
+            ->where('owner_id', 8)
+            ->where('unit_id', 1)
+            ->where('work_name', 'xx入库费2')
+            ->first();
+
+        $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('amount'), $report->amount);
+        $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('fee'), $report->fee);
     }
 
     function tearDown(): void

+ 24 - 43
tests/Services/OwnerStoreOutFeeReportService/RecordReportTest.php

@@ -28,50 +28,31 @@ class RecordReportTest extends TestCase
         $this->service = app('OwnerStoreOutFeeReportService');
     }
 
-    public function testReturned()
+    public function test_record()
     {
-//        OwnerPriceOperation::query()->truncate();
-//        OwnerFeeDetail::query()->truncate();
-//        OwnerStoreOutFeeDetail::query()->truncate();
-//        OwnerBillReport::query()->truncate();
-//        OwnerStoreOutFeeReport::query()->truncate();
-//        $ownerPriceOperationIds = factory(OwnerPriceOperation::class)->times(10)->create()->pluck('id');
-//        $ownerFeeDetailIds = [];
-//        foreach ($ownerPriceOperationIds as $ownerPriceOperationId) {
-//            $ownerFeeDetailIds[] = factory(OwnerFeeDetail::class)->create(['owner_price_operation_id' => $ownerPriceOperationId]);
-//        }
-//        foreach ($ownerFeeDetailIds as $ownerFeeDetailId) {
-//            $details = factory(OwnerStoreOutFeeDetail::class)->times(2)->create(['owner_fee_detail_id' => $ownerFeeDetailId]);
-//            foreach ($details as $detail) {
-//                factory(OwnerBillReport::class)->create(['owner_id' => $detail->owner_id, 'counting_month' => $detail->created_at->startOfMonth()->toDateString()]);
-//            }
-//        }
-
-//        $this->service->recordReport();
-        $this->assertTrue(true);
-    }
-
-    public function testReturned2()
-    {
-//        OwnerFeeDetail::query()->truncate();
-//        OwnerStoreOutFeeDetail::query()->truncate();
-//        OwnerStoreOutFeeReport::query()->truncate();
-//        $feeDetails = factory(OwnerFeeDetail::class)->times(10)->create(['owner_id' => 8]);
-//        foreach ($feeDetails as $feeDetail) {
-//            factory(OwnerStoreOutFeeDetail::class)->create([
-//                'owner_fee_detail_id' => $feeDetail->id,
-//                'owner_id' => 8,
-//                'work_name' => 'aaa',
-//                'unit_price' => '1000',
-//                'unit_id' => 1,
-//                'amount' => 10,
-//                'remark' => 'vbbbb',
-//                'step' => '100-200',
-//            ]);
-//        }
-//        $this->service->recordReport();
-        $this->assertTrue(true);
-
+        OwnerStoreOutFeeReport::query()->truncate();
+        OwnerFeeDetail::query()->truncate();
+        OwnerPriceOperation::query()->truncate();
+        OwnerStoreOutFeeDetail::query()->truncate();
+
+        $ownerFeeDetails = factory(OwnerFeeDetail::class)->times(10)->create();
+        $ownerPriceOperations = factory(OwnerPriceOperation::class)->times(2)->create();
+        $ownerStoreOutFeeDetails = [];
+        foreach ($ownerFeeDetails as $ownerFeeDetail) {
+            $id = $ownerPriceOperations->random(1)[0]->id;
+            $ownerStoreOutFeeDetails[] =  factory(OwnerStoreOutFeeDetail::class)->create([
+                'owner_fee_detail_id' => $ownerFeeDetail->id,
+                'owner_id' => 8,
+                'owner_price_operation_id' => $id,
+            ]);
+            $ownerStoreOutFeeDetails[] =  factory(OwnerStoreOutFeeDetail::class)->create([
+                'owner_fee_detail_id' => $ownerFeeDetail->id,
+                'owner_id' => 8,
+                'owner_price_operation_id' => $id,
+            ]);
+        }
+        $this->service->recordReport();
+        $this->assertEquals(collect($ownerFeeDetails)->sum('work_fee'), OwnerStoreOutFeeReport::query()->sum('fee'));
     }
 
     function tearDown(): void

Некоторые файлы не были показаны из-за большого количества измененных файлов