123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace App\Services\Dwbs;
- use App\Repositories\Criteria\Dwbs\ShopGoodCriteria;
- use App\Repositories\Eloquent\Dwbs\ShopGoodRepositoryEloquent;
- use App\Repositories\Presenters\Dwbs\ShopGoodPresenter;
- use Illuminate\Http\Request;
- class ShopGoodService
- {
- /**
- * @var ShopGoodRepositoryEloquent
- */
- private $repository;
- /**
- * ShopGoodService constructor.
- *
- * @param ShopGoodRepositoryEloquent $shopGoodRepositoryEloquent
- */
- public function __construct(ShopGoodRepositoryEloquent $repository)
- {
- $this->repository = $repository;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->repository->pushCriteria(new ShopGoodCriteria($request));
- $this->repository->setPresenter(ShopGoodPresenter::class);
- return $this->repository->searchListsPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->repository->setPresenter(ShopGoodPresenter::class);
- return $this->repository->searchBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $shopGood = $this->repository->create($data);
- return $shopGood;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $shopGood = $this->repository->update($data,$data['id']);
- return $shopGood;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->repository->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->repository->pushCriteria(new ShopGoodCriteria($request));
- return $this->repository->all(['id', 'name']);
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->repository->whereIn('id', $ids)->delete();
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->repository->pushCriteria(new ShopGoodCriteria($request));
- $this->repository->setPresenter(ShopGoodPresenter::class);
- return $this->repository->get();
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleIds(Request $request)
- {
- $this->repository->pushCriteria(new ShopGoodCriteria($request));
- return $this->repository->pluck('id');
- }
- }
|