ConfigPickupGroupRepository.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\ConfigPickupGroup;
  4. use Symfony\Component\HttpKernel\Exception\HttpException;
  5. class ConfigPickupGroupRepository {
  6. public function __construct(ConfigPickupGroup $configPickupGroup) {
  7. $this->configPickupGroup = $configPickupGroup;
  8. }
  9. //列表
  10. public function index($request)
  11. {
  12. $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
  13. $where = [];
  14. if(isset($request['id'])){
  15. $where[] = ['id', '=', $request['id']];
  16. }
  17. return $this->configPickupGroup->where($where)->orderBy('id', 'asc')->paginate($perPage);
  18. }
  19. /**
  20. * 添加自提点分组
  21. */
  22. public function create($request)
  23. {
  24. if($this->configPickupGroup->where('name', trim($request['name']))->exists()){
  25. throw new HttpException(500, '该自提点已经存在');
  26. }
  27. $data = [
  28. 'name' => $request['name'],
  29. ];
  30. if (!$this->configPickupGroup->create($data)) {
  31. throw new HttpException(500, '添加失败');
  32. }
  33. }
  34. }