123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\Repositories\Eloquent;
- use App\Repositories\Eloquent\BaseRepository;
- use App\Models\SpecialistCloumn;
- use App\Repositories\Contracts\SpecialistCloumnInterface;
- /**
- *
- * @author lilin
- *
- */
- class SpecialistCloumnFacadeRepository extends BaseRepository implements SpecialistCloumnInterface
- {
- public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
- {
- $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){
- if (isset($conditions['pid'])){
- $query->where('pid', $conditions['pid']);
- }
- if (isset($conditions['is_show'])){
- $query->where('is_show', $conditions['is_show']);
- }
- })->orderByRaw($sort)->paginate($limit, $fields);
-
- return $this->response($result);
- }
-
- public function findBy(array $conditions, array $fields){
- $result = SpecialistCloumn::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->first($fields);
- if ($result->banner){
- $newBanner = [];
- foreach ($result->banner as $banner){
- $newBanner[] = [
- 'pic' => config('console.pic_path').$banner['src'],
- 'url' => $banner['url']
- ];
- }
- $result->banner = $newBanner;
- }
-
- return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
- }
-
- public function create(array $data)
- {
- $result = SpecialistCloumn::create($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function updateBy(array $conditions, array $data)
- {
- $result = SpecialistCloumn::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->update($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function deleteBy(array $conditions)
- {
- $result = SpecialistCloumn::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->delete();
- return $result ? $this->response($result) : $this->error()->fail();
- }
- }
|