SettlementBillExpressFeeDetailController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Interfaces\SettlementBillControllerInterface;
  4. use App\Owner;
  5. use App\OwnerBillReportArchive;
  6. use App\Services\OwnerBillReportArchiveService;
  7. use App\Services\OwnerLogisticFeeDetailService;
  8. use App\Traits\SettlementBillTrait;
  9. use Illuminate\Http\Request;
  10. use Oursdreams\Export\Export;
  11. class SettlementBillExpressFeeDetailController extends Controller implements SettlementBillControllerInterface
  12. {
  13. use SettlementBillTrait;
  14. /** @var $service OwnerLogisticFeeDetailService */
  15. private $service;
  16. /** @var $archiveService OwnerBillReportArchiveService */
  17. private $archiveService;
  18. /**
  19. * OwnerLogisticFeeDetailController constructor.
  20. */
  21. public function __construct()
  22. {
  23. $this->service = app('OwnerLogisticFeeDetailService');
  24. $this->archiveService = app('OwnerBillReportArchiveService');
  25. }
  26. /**
  27. * Display a listing of the resource.
  28. *
  29. */
  30. public function index(Request $request)
  31. {
  32. $paginateParams = $request->input();
  33. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month,$request->owner_id);
  34. $details = $this->service->get([
  35. 'owner_id' => $owner_id,
  36. 'counting_month' => $counting_month,
  37. 'paginateParams' => $paginateParams,
  38. ]);
  39. // dd($details);
  40. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  41. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  42. $this->archiveService = app('OwnerBillReportArchiveService');
  43. $request = $this->buildRequest($request, $counting_month,$owner_id);
  44. return view('finance.settlementBills.expressFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request'));
  45. }
  46. public function export(Request $request)
  47. {
  48. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month,$request->owner_id );
  49. $query = $this->service->getSql($owner_id, $counting_month);
  50. if (!$request->exists('checkAllSign')) {
  51. $query->whereIn('id', explode(',', $request['data']));
  52. }
  53. $details = $this->service->buildExport($query->get());
  54. $json = [];
  55. foreach ($details as $detail) {
  56. $json[] = array_values($detail);
  57. }
  58. $row = ['主键', '快递公司', '省份', '快递单号', '重量', '首重价格', '续重价格', '快递费',];
  59. return Export::make($row, $json, "快递费用详情");
  60. }
  61. }