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.

79 lines
2.2KB

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