You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7KB

  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\HtpmsCustomer\Deposit\Deposit;
  4. use App\Models\HtpmsCustomer\Mst\Shop;
  5. use App\Models\User;
  6. use App\Repositories\BaseRepository;
  7. use Illuminate\Database\Query\JoinClause;
  8. use Illuminate\Support\Collection;
  9. use Illuminate\Support\Facades\DB;
  10. class ShopRepository extends BaseRepository
  11. {
  12. const CONDITION_SHOP_ID = 'shop_id';
  13. const CONDITION_NAME = 'name';
  14. const TABLE_SHOP = "shop";
  15. const TABLE_DEPOSIT = "deposit";
  16. /**
  17. * コレクションを取得する
  18. *
  19. * @param array $condition
  20. * @return Collection<ShopRepositoryData>
  21. */
  22. public function get(array $condition): Collection
  23. {
  24. $table = Shop::getBuilder(static::TABLE_SHOP);
  25. $table->leftJoinSub(Deposit::getBuilder(), static::TABLE_DEPOSIT, function (JoinClause $join) {
  26. $join->on(
  27. $this->makeColumnName([static::TABLE_SHOP, Shop::COL_NAME_ID]),
  28. $this->makeColumnName([static::TABLE_DEPOSIT, Deposit::COL_NAME_SHOP_ID])
  29. );
  30. });
  31. // -----検索条件
  32. // SHOP_ID
  33. $this->where($table, $condition, static::CONDITION_SHOP_ID, $this->makeColumnName([static::TABLE_SHOP, Shop::COL_NAME_ID]));
  34. // 名前
  35. $name = data_get($condition, static::CONDITION_NAME);
  36. if ($name) {
  37. $table->where($this->makeColumnName([static::TABLE_SHOP, Shop::COL_NAME_NAME]), 'like', "%{$name}%");
  38. }
  39. $table->select($this->columns());
  40. $main = DB::connection("htpms_customer")->table($table, "main");
  41. // ソート
  42. $this->sort($main, $condition);
  43. $main->orderBy(static::CONDITION_SHOP_ID);
  44. // リミット
  45. $this->limit($main, $condition);
  46. return LoginUserRepositoryData::makeList($main->get());
  47. }
  48. private function columns()
  49. {
  50. $shop = static::TABLE_SHOP;
  51. $deposit = static::TABLE_DEPOSIT;
  52. $columns = [
  53. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_NAME]),
  54. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_MEMO]),
  55. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_QR_SERVICE_EXPIRE_MIN]),
  56. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_UNDER_AMOUNT_WHEN_AUTH]),
  57. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_UNDER_AMOUNT_WHEN_CREATE]),
  58. $this->makeColumnNameForSelect([$shop, Shop::COL_NAME_UNDER_AMOUNT_WHEN_USE]),
  59. $this->makeColumnNameForSelect([$deposit, Deposit::COL_NAME_SHOP_ID]),
  60. $this->makeColumnNameForSelect([$deposit, Deposit::COL_NAME_DEPOSIT]),
  61. ];
  62. return $columns;
  63. }
  64. }