123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Services\Base;
- use App\Repositories\Criteria\Base\CompanyCriteria;
- use App\Repositories\Eloquent\Base\CompanyRepositoryEloquent;
- use App\Repositories\Presenters\Base\CompanyPresenter;
- use Illuminate\Http\Request;
- class CompanyService
- {
- /**
- * @var CompanyRepositoryEloquent
- */
- private $companyRepository;
- /**
- * CompanyService constructor.
- *
- * @param CompanyRepositoryEloquent $companyRepositoryEloquent
- */
- public function __construct(CompanyRepositoryEloquent $companyRepositoryEloquent)
- {
- $this->companyRepository = $companyRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->companyRepository->pushCriteria(new CompanyCriteria($request));
- $this->companyRepository->setPresenter(CompanyPresenter::class);
- return $this->companyRepository->searchCompanysByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->companyRepository->setPresenter(CompanyPresenter::class);
- return $this->companyRepository->searchCompanyBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $company = $this->companyRepository->create($data);
- return $company;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $company = $this->companyRepository->update($data, $data['id']);
- return $company;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->companyRepository->delete($id);
- }
- /**
- * 选项数据
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleSelectOptions(Request $request)
- {
- $this->companyRepository->pushCriteria(new CompanyCriteria($request));
- return $this->companyRepository->all([
- 'id',
- 'name',
- 'sort',
- ]);
- }
- }
|