OwnerStoreOutFeeDetailController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $this->middleware('auth');
  25. }
  26. public function index(Request $request)
  27. {
  28. $paginateParams = $request->input();
  29. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  30. $details = $this->service->get([
  31. 'counting_month' => $counting_month,
  32. 'owner_id' => $owner_id,
  33. 'paginateParams' => $paginateParams,
  34. ]);
  35. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  36. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  37. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  38. $request = $this->buildRequest($request, $counting_month);
  39. return view('finance.settlementBills.storeOutFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  40. }
  41. public function confirmBill(Request $request): RedirectResponse
  42. {
  43. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  44. $billReport = OwnerBillReport::query()
  45. ->select('id')
  46. ->where('owner_id', $owner_id)
  47. ->where('counting_month', $counting_month)
  48. ->firstOr(function () {
  49. return new OwnerBillReport();
  50. });
  51. OwnerBillReportArchive::query()->create([
  52. 'owner_bill_report_id' => $billReport->id ?? null,
  53. 'owner_id' => $owner_id,
  54. 'counting_month' => $counting_month,
  55. 'type' => $this->service::TYPE,
  56. 'archiver_id' => auth()->id(),
  57. 'archived_at' => now(),
  58. 'information' => [],
  59. ]);
  60. return back()->with('success', '确认成功');
  61. }
  62. public function export(Request $request)
  63. {
  64. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  65. $query = $this->service->getSql($owner_id, $counting_month);
  66. if (!$request->exists('checkAllSign')) {
  67. $query->whereIn('id', explode(',', $request['data']));
  68. }
  69. $details = $query->get();
  70. $json = $this->service->buildExport($details);
  71. $row = ['作业时间', '作业名称', '上游单号', '订单号', '商品条码', '商品名称', '商品数量', '价格', '合计'];
  72. return Export::make($row, $json, "出库费明细");
  73. }
  74. }