ConfigPickupGroupRepository.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. $where = [];
  13. if(isset($request['id'])){
  14. $where[] = ['id', '=', $request['id']];
  15. }
  16. return $this->configPickupGroup->where($where)->orderBy('id', 'asc')->paginate(20);
  17. }
  18. /**
  19. * 添加自提点
  20. */
  21. public function create($request)
  22. {
  23. if($this->configPickupGroup->where('name', trim($request['name']))->exists()){
  24. throw new HttpException(500, '该自提点已经存在');
  25. }
  26. $data = [
  27. 'name' => $request['name'],
  28. ];
  29. if (!$this->configPickupGroup->create($data)) {
  30. throw new HttpException(500, '添加失败');
  31. }
  32. }
  33. }