ConfigPickupGroupRepository.php 1.1 KB

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