| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | <?php/** * Created by PhpStorm. * User: wuzhenke * Date: 2018/12/4 * Time: 13:47 */namespace App\Repositories;use App\Models\Pms;use Prettus\Repository\Eloquent\BaseRepository;use Prettus\Repository\Criteria\RequestCriteria;use Encore\Admin\Facades\Admin;class PmsRepository extends BaseRepository{    public function model()    {        return Pms::class;    }    /**     * Boot up the repository, pushing criteria     */    public function boot()    {        $this->pushCriteria(app(RequestCriteria::class));    }    public function comPms($where)    {        return $this->model->where($where)->where(function ($query) {            $query->where('started_at', '<=', strtotime(date("Y-m-d", time())))->where('ended_at', '>', strtotime(date("Y-m-d", time()))+60*60*24);            $query->orwhere(['started_at'=>0,'ended_at'=>0]);        })->orderBy('created_at', 'desc')->paginate(10, ['*']);    }    //弹窗消息    public function findFirstPms($where)    {        return $this->model->where($where)->orderBy('started_at', 'asc')->first();    }    public function findMsg($ids)    {        return $this->model->whereIn('id', $ids)->first();    }    public function updateNew($ids, $where, $data)    {        return $this->model->whereIn('id', $ids)->where($where)->update($data);    }    public function writePmsNotice($user, $message)    {        $insert_data = array(            'utype'      => $user->utype,            'msgtype'    => 1,            'msgfromuid'=> Admin::user()->id,            'msgfrom'   => Admin::user()->username,            'msgtoname' => $user->username,            'msgtouid'  => $user->uid,            'message'   => $message,            'new'       => 1        );        return $this->model->create($insert_data);    }    public function deleteAll($ids,$company_id)    {        return $this->model->where("msgtouid",$company_id)->whereIn("id",$ids)->delete();    }    public function getPms($where)    {        return $this->model->where($where)->where(function ($query){            $query->where('started_at','<=',strtotime(date("Y-m-d", time())))->where('ended_at','>',strtotime(date("Y-m-d", time()))+60*60*24);            $query->orwhere(['started_at'=>0,'ended_at'=>0]);        })->orderBy('id', 'desc')->paginate(10);    }    public function getPmsCount($where)    {        return $this->model->where($where)->where(function ($query) {            $query->where('started_at', '<=', strtotime(date("Y-m-d", time())))->where('ended_at', '>', strtotime(date("Y-m-d", time()))+60*60*24);            $query->orwhere(['started_at'=>0,'ended_at'=>0]);        })->count();    }    public function getPmsById($id)    {        return $this->model->find($id);    }    public function updateNewById($id, $data)    {        return $this->model->where('id', $id)->update($data);    }    public function getPmsCountByUid($where)    {        return $this->model->where($where)->count();    }    public function getNewestPms($where)    {        return $this->model->withTrashed()->where($where)->orderBy('id', 'desc')->first();    }    public function insertData($data)    {        return $this->model->insert($data);    }}
 |