OwnerStoreOutFeeDetailService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Services;
  3. use App\Interfaces\SettlementBillDetailInterface;
  4. use App\Traits\ServiceAppAop;
  5. use App\OwnerStoreOutFeeDetail;
  6. use App\Traits\SettlementBillServiceTrait;
  7. use Illuminate\Contracts\Pagination\LengthAwarePaginator;
  8. use Illuminate\Database\Eloquent\Builder;
  9. class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
  10. {
  11. const TYPE = '出库费-明细';
  12. use ServiceAppAop;
  13. use SettlementBillServiceTrait;
  14. protected $modelClass = OwnerStoreOutFeeDetail::class;
  15. /**
  16. * 详情的查询不管是否却认都是原始数据且分页
  17. * @param array $kvPairs
  18. * @return LengthAwarePaginator
  19. */
  20. public function get(array $kvPairs): LengthAwarePaginator
  21. {
  22. return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  23. }
  24. public function getSql($owner_id, $counting_month): Builder
  25. {
  26. list($start, $end) = $this->getStartAndEnd($counting_month);
  27. return OwnerStoreOutFeeDetail::query()
  28. ->with([
  29. 'commodity:id,name,sku',
  30. 'ownerFeeDetail:id,worked_at,operation_bill,work_fee',
  31. 'ownerPriceOperation.items.unit',
  32. ])
  33. ->where('owner_id', $owner_id)
  34. ->whereBetween('created_at', [$start, $end]);
  35. }
  36. public function switchType($type)
  37. {
  38. // TODO: Implement switchType() method.
  39. }
  40. public function buildExport($details): array
  41. {
  42. $result = [];
  43. foreach ($details as $detail) {
  44. $result[] = [
  45. $detail->ownerFeeDetail->worked_at,
  46. $detail->ownerPriceOperation->name ?? '',
  47. $detail->source_bill,
  48. $detail->ownerFeeDetail->operation_bill,
  49. $detail->commodity->sku,
  50. $detail->commodity->name,
  51. $detail->amount,
  52. $detail->price_remark,
  53. $detail->ownerFeeDetail->work_fee,
  54. ];
  55. }
  56. return $result;
  57. }
  58. public function add(array $model)
  59. {
  60. // TODO: Implement add() method.
  61. }
  62. // public function buildPriceRemarks(&$storeOutFeeDetails)
  63. // {
  64. // foreach ($storeOutFeeDetails as &$ownerStoreOutFeeDetail) {
  65. // //起步: 3 件 / 2.7000元 (满减单价: 0-19999 单(2.7元) , 20000-49999 单(2.5元) , 50000-99999 单(2元) , 100000+ 单(1.6元) )
  66. // //默认续费: 1 件 / 0.5000元 (满减单价: 0-19999 单(0.5元) , 20000-49999 单(0.4元) , 50000-99999 单(0.3元) , 100000+ 单(0.2元) )
  67. // $discount_counts = explode(',', $ownerStoreOutFeeDetail->ownerPriceOperation->discount_count);
  68. // $priceRemarks = [];
  69. // foreach ($ownerStoreOutFeeDetail->ownerPriceOperation->items as $operationItem) {
  70. // $discount_prices = explode(',', $operationItem->discount_price);
  71. // $strategy = $operationItem->strategy == '起步' ? '起步' : '默认续费';
  72. // $priceRemark = "{$strategy}: {$operationItem->amount} {$operationItem->unit->name}/{$operationItem->unit_price}元";
  73. // if (!empty($discount_prices)) {
  74. // $priceRemark .= "(满减单价:";
  75. // for ($i = 0; $i < count($discount_counts) - 1; $i++) {
  76. // $next_discount_count = $discount_counts[$i + 1] ?? '+';
  77. // $discount_count = $discount_counts[$i] ?? '';
  78. // $discount_price = $discount_prices[$i] ?? '';
  79. // $priceRemark .= "{$discount_count}-{$next_discount_count} {$operationItem->unit->name} {$discount_price}元,";
  80. // }
  81. // $priceRemark .= ")";
  82. // }
  83. // $priceRemarks[] = $priceRemark;
  84. // }
  85. // $ownerStoreOutFeeDetail['price_remarks'] = $priceRemarks;
  86. // }
  87. // }
  88. }