1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Repositories;
- use App\Models\ConfigPickupGroup;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- class ConfigPickupGroupRepository {
- public function __construct(ConfigPickupGroup $configPickupGroup) {
- $this->configPickupGroup = $configPickupGroup;
- }
- //列表
- public function index($request)
- {
- $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
- $where = [];
- if(isset($request['id'])){
- $where[] = ['id', '=', $request['id']];
- }
- return $this->configPickupGroup->where($where)->orderBy('id', 'asc')->paginate($perPage);
- }
- /**
- * 添加自提点分组
- */
- public function create($request)
- {
- if($this->configPickupGroup->where('name', trim($request['name']))->exists()){
- throw new HttpException(500, '该自提点已经存在');
- }
- $data = [
- 'name' => $request['name'],
- ];
- if (!$this->configPickupGroup->create($data)) {
- throw new HttpException(500, '添加失败');
- }
- }
- }
|