OwnerStoreOutFeeDetailController.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Interfaces\SettlementBillControllerInterface;
  4. use App\Owner;
  5. use App\OwnerBillReport;
  6. use App\OwnerBillReportArchive;
  7. use App\Services\OwnerBillReportArchiveService;
  8. use App\Services\OwnerStoreOutFeeDetailService;
  9. use App\Traits\SettlementBillTrait;
  10. use Illuminate\Http\RedirectResponse;
  11. use Illuminate\Http\Request;
  12. use Oursdreams\Export\Export;
  13. class OwnerStoreOutFeeDetailController extends Controller implements SettlementBillControllerInterface
  14. {
  15. use SettlementBillTrait;
  16. /** @var OwnerStoreOutFeeDetailService $service */
  17. private $service;
  18. /** @var OwnerBillReportArchiveService $archiveService */
  19. private $archiveService;
  20. public function __construct()
  21. {
  22. $this->service = app('OwnerStoreOutFeeDetailService');
  23. $this->archiveService = app('OwnerBillReportArchiveService');
  24. }
  25. public function index(Request $request)
  26. {
  27. $paginateParams = $request->input();
  28. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  29. $details = $this->service->get([
  30. 'counting_month' => $counting_month,
  31. 'owner_id' => $owner_id,
  32. 'paginateParams' => $paginateParams,
  33. ]);
  34. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  35. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  36. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  37. $request = $this->buildRequest($request, $counting_month);
  38. return view('finance.settlementBills.storeOutFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  39. }
  40. public function confirmBill(Request $request): RedirectResponse
  41. {
  42. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  43. $billReport = OwnerBillReport::query()
  44. ->select('id')
  45. ->where('owner_id', $owner_id)
  46. ->where('counting_month', $counting_month)
  47. ->firstOr(function () {
  48. return new OwnerBillReport();
  49. });
  50. OwnerBillReportArchive::query()->create([
  51. 'owner_bill_report_id' => $billReport->id ?? null,
  52. 'owner_id' => $owner_id,
  53. 'counting_month' => $counting_month,
  54. 'type' => $this->service::TYPE,
  55. 'archiver_id' => auth()->id(),
  56. 'archived_at' => now(),
  57. 'information' => [],
  58. ]);
  59. return back()->with('success', '确认成功');
  60. }
  61. public function export(Request $request)
  62. {
  63. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  64. $query = $this->service->getSql($owner_id, $counting_month);
  65. if (!$request->exists('checkAllSign')) {
  66. $query->whereIn('id', explode(',', $request['data']));
  67. }
  68. $details = $query->get();
  69. $json = $this->service->buildExport($details);
  70. $row = ['作业时间', '作业名称', '上游单号', '订单号', '商品条码', '商品名称', '商品数量', '价格', '合计'];
  71. return Export::make($row, $json, "出库费明细");
  72. }
  73. }