12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\Repositories\Eloquent;
- use App\Repositories\Eloquent\BaseRepository;
- use App\Repositories\Contracts\DiaryLetterInterface;
- use App\Models\DiaryLetter;
- /**
- *
- * @author lilin
- *
- */
- class DiaryLetterFacadeRepository extends BaseRepository implements DiaryLetterInterface
- {
- public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
- {
- $result = DiaryLetter::where(function($query) use($conditions){
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- if (isset($conditions['send_time'])){
- $query->where('send_time', '<=' , $conditions['send_time']);
- }
- })->orderByRaw($sort)->paginate($limit, $fields);
-
- return $this->response($result);
- }
-
- public function findBy(array $conditions, array $fields){
- $result = DiaryLetter::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 = DiaryLetter::create($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function updateBy(array $conditions, array $data)
- {
- $result = DiaryLetter::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- if (isset($conditions['send_time'])){
- $query->where('send_time', '<=' , $conditions['send_time']);
- }
- })->update($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
-
- public function deleteBy(array $conditions)
- {
- $result = DiaryLetter::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();
- }
- }
|