UrsPartnerDividendDetailRepository.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Module\UrsPromotion\Repositories;
  3. use App\Module\UrsPromotion\Models\UrsPartnerDividendDetail;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. /**
  6. * URS合伙人分红详情仓库类
  7. *
  8. * 仅供后台管理数据访问使用
  9. */
  10. class UrsPartnerDividendDetailRepository extends EloquentRepository
  11. {
  12. /**
  13. * 模型类
  14. */
  15. protected $eloquentClass = UrsPartnerDividendDetail::class;
  16. /**
  17. * 预加载关联关系
  18. */
  19. protected $with = [];
  20. /**
  21. * 构造函数
  22. *
  23. * @param array $with 预加载关联关系
  24. */
  25. public function __construct(array $with = [])
  26. {
  27. $this->with = $with;
  28. parent::__construct();
  29. }
  30. /**
  31. * 获取查询构建器
  32. */
  33. public function getQueryBuilder()
  34. {
  35. $query = parent::getQueryBuilder();
  36. if (!empty($this->with)) {
  37. $query->with($this->with);
  38. }
  39. return $query;
  40. }
  41. /**
  42. * 查询详情页面数据
  43. */
  44. public function detail(\Dcat\Admin\Show $show): array
  45. {
  46. $result = $this->eloquentClass::with($this->with ?? [])
  47. ->where($this->getKeyName(), $show->getKey())
  48. ->first();
  49. if (!$result) {
  50. abort(404);
  51. }
  52. return $result->toArray();
  53. }
  54. }