12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?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)
- {
- $where = [];
- if(isset($request['id'])){
- $where[] = ['id', '=', $request['id']];
- }
- return $this->configPickupGroup->where($where)->orderBy('id', 'asc')->paginate(20);
- }
- /**
- * 添加自提点
- */
- 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, '添加失败');
- }
- }
- }
|