123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace App\Repositories\Eloquent;
- use App\Repositories\Contracts\CollectInterface;
- use App\Models\BrowseRecord;
- /**
- * 浏览记录
- * @author lilin
- *
- */
- class BrowseRecordFacadeRepository extends BaseRepository implements CollectInterface
- {
- public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
- {
- $result = BrowseRecord::with(['scale', 'drill', 'specialist'])
- ->where(function($query) use($conditions){
- if (isset($conditions['uid'])){
- $query->where('uid', $conditions['uid']);
- }
- if (isset($conditions['column'])){
- if ($conditions['column']==2){
- $query->where('column', 3);
- $query->whereRaw("
- object_id in ( select id from specialist_infos where second_id in (12,13) )
- ");
- }elseif ($conditions['column']==3){
- $query->where('column', 3);
- $query->whereRaw("
- object_id NOT IN ( select id from specialist_infos where second_id in (12,13) )
- ");
- }elseif ($conditions['column']==1){
- $query->where('column', 1);
- }
- }
- if (isset($conditions['object_id'])){
- $query->where('object_id', $conditions['object_id']);
- }
- })->groupBy("object_id")
- ->orderByRaw($sort)
- ->paginate($limit, $fields);
- return $this->response($result);
- }
- public function sign(string $op, string $task, string $version, array $parameter)
- {
- $appid = config('console.thirdScale.appid');
- $key = config('console.thirdScale.key');
- ksort($parameter);
- $pStr = '';
- foreach ($parameter as $v) {
- $pStr .= $v;
- }
- $str = $parameter['appid'] . $op . $task . $version . $pStr . $key;
- return md5($str);
- }
- public function findBy(array $conditions, array $fields){
- $result = BrowseRecord::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['column'])){
- $query->where('column', $conditions['column']);
- }
- if (isset($conditions['object_id'])){
- $query->where('object_id', $conditions['object_id']);
- }
- })->first($fields);
- return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
- }
- public function create(array $data)
- {
- $result = BrowseRecord::create($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
- public function updateBy(array $conditions, array $data)
- {
- $result = BrowseRecord::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['column'])){
- $query->where('column', $conditions['column']);
- }
- if (isset($conditions['object_id'])){
- $query->where('object_id', $conditions['object_id']);
- }
- })->update($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
- public function deleteBy(array $conditions)
- {
- $result = BrowseRecord::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();
- }
- }
|