Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

75 lines
2.4KB

  1. <?php
  2. namespace App\Repositories;
  3. use App\Exceptions\AppCommonException;
  4. use App\Models\ColumnName;
  5. use App\Models\HtpmsCustomer\Deposit\DepositTransfer;
  6. use App\Repositories\BaseRepository;
  7. use Illuminate\Support\Collection;
  8. use Illuminate\Support\Facades\DB;
  9. class DepositTransferRepository extends BaseRepository
  10. {
  11. const CONDITION_ID = 'id';
  12. const CONDITION_SHOP_ID = ColumnName::SHOP_ID;
  13. const TABLE_TRANSFER = "transfer";
  14. /**
  15. * コレクションを取得する
  16. *
  17. * @param array $condition
  18. * @return Collection<int,DepositTransferRepositoryData>
  19. */
  20. public function get(array $condition): Collection
  21. {
  22. $table = DepositTransfer::getBuilder(static::TABLE_TRANSFER);
  23. // -----検索条件
  24. // SHOP_ID 必須項目
  25. $shopId = data_get($condition, self::CONDITION_SHOP_ID);
  26. if ($shopId) {
  27. $this->where($table, $condition, static::CONDITION_SHOP_ID, $this->makeColumnName([static::TABLE_TRANSFER, DepositTransfer::COL_NAME_SHOP_ID]));
  28. } else {
  29. throw new AppCommonException("SHOP_ID不正");
  30. }
  31. // ID
  32. $this->where($table, $condition, static::CONDITION_ID, $this->makeColumnName([static::TABLE_TRANSFER, DepositTransfer::COL_NAME_ID]));
  33. $table->select($this->columns());
  34. $main = DB::connection("htpms_customer")->table($table, "main");
  35. // ソート
  36. $this->sort($main, $condition);
  37. $main->orderByDesc($this->makeColumnName([DepositTransfer::COL_NAME_TRANSFER_DATETIME]));
  38. // リミット
  39. $this->limit($main, $condition);
  40. return LoginUserRepositoryData::makeList($main->get());
  41. }
  42. private function columns()
  43. {
  44. $transfer = static::TABLE_TRANSFER;
  45. $columns = [
  46. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_ID]),
  47. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_TRANSFER_DATETIME]),
  48. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_TRANSFER_AMOUNT]),
  49. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_TRANSFER_REASON]),
  50. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_AFTER_AMOUNT]),
  51. $this->makeColumnNameForSelect([$transfer, DepositTransfer::COL_NAME_BEFORE_AMOUNT]),
  52. ];
  53. return $columns;
  54. }
  55. }