123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Repositories\Eloquent;
- use App\Models\ScaleCategory;
- use App\Repositories\Contracts\ScaleCategoryInterface;
- /**
- * 量表分类
- * @author lilin
- *
- */
- class ScaleCategoryFacadeRepository extends BaseRepository implements ScaleCategoryInterface
- {
- public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
- {
- $result = ScaleCategory::where(function($query) use($conditions){
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- })->orderByRaw($sort)->paginate($limit, $fields);
-
- return $this->response($result);
- }
-
- public function findBy(array $conditions, array $fields){
- $result = ScaleCategory::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- })->first($fields);
- return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
- }
-
- public function create(array $data)
- {
- $result = ScaleCategory::create($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function updateBy(array $conditions, array $data)
- {
- $result = ScaleCategory::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- })->update($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function deleteBy(array $conditions)
- {
- $result = ScaleCategory::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- })->delete();
- return $result ? $this->response($result) : $this->error()->fail();
- }
- }
|