PmsRepository.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/12/4
  6. * Time: 13:47
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Pms;
  10. use Prettus\Repository\Eloquent\BaseRepository;
  11. use Prettus\Repository\Criteria\RequestCriteria;
  12. use Encore\Admin\Facades\Admin;
  13. class PmsRepository extends BaseRepository
  14. {
  15. public function model()
  16. {
  17. return Pms::class;
  18. }
  19. /**
  20. * Boot up the repository, pushing criteria
  21. */
  22. public function boot()
  23. {
  24. $this->pushCriteria(app(RequestCriteria::class));
  25. }
  26. public function comPms($where)
  27. {
  28. return $this->model->where($where)->where(function ($query) {
  29. $query->where('started_at', '<=', strtotime(date("Y-m-d", time())))->where('ended_at', '>', strtotime(date("Y-m-d", time()))+60*60*24);
  30. $query->orwhere(['started_at'=>0,'ended_at'=>0]);
  31. })->orderBy('created_at', 'desc')->paginate(10, ['*']);
  32. }
  33. //弹窗消息
  34. public function findFirstPms($where)
  35. {
  36. return $this->model->where($where)->orderBy('started_at', 'asc')->first();
  37. }
  38. public function findMsg($ids)
  39. {
  40. return $this->model->whereIn('id', $ids)->first();
  41. }
  42. public function updateNew($ids, $where, $data)
  43. {
  44. return $this->model->whereIn('id', $ids)->where($where)->update($data);
  45. }
  46. public function writePmsNotice($user, $message)
  47. {
  48. $insert_data = array(
  49. 'utype' => $user->utype,
  50. 'msgtype' => 1,
  51. 'msgfromuid'=> Admin::user()->id,
  52. 'msgfrom' => Admin::user()->username,
  53. 'msgtoname' => $user->username,
  54. 'msgtouid' => $user->uid,
  55. 'message' => $message,
  56. 'new' => 1
  57. );
  58. return $this->model->create($insert_data);
  59. }
  60. public function deleteAll($ids,$company_id = null)
  61. {
  62. if($company_id){
  63. return $this->model->where("msgtouid",$company_id)->whereIn("id",$ids)->delete();
  64. }else{
  65. return $this->model->whereIn("id",$ids)->delete();
  66. }
  67. }
  68. public function getPms($where)
  69. {
  70. return $this->model->where($where)->where(function ($query){
  71. $query->where('started_at','<=',strtotime(date("Y-m-d", time())))->where('ended_at','>',strtotime(date("Y-m-d", time()))+60*60*24);
  72. $query->orwhere(['started_at'=>0,'ended_at'=>0]);
  73. })->orderBy('id', 'desc')->paginate(10);
  74. }
  75. public function getPmsCount($where)
  76. {
  77. return $this->model->where($where)->where(function ($query) {
  78. $query->where('started_at', '<=', strtotime(date("Y-m-d", time())))->where('ended_at', '>', strtotime(date("Y-m-d", time()))+60*60*24);
  79. $query->orwhere(['started_at'=>0,'ended_at'=>0]);
  80. })->count();
  81. }
  82. public function getPmsById($id)
  83. {
  84. return $this->model->find($id);
  85. }
  86. public function updateNewById($id, $data)
  87. {
  88. return $this->model->where('id', $id)->update($data);
  89. }
  90. public function getPmsCountByUid($where)
  91. {
  92. return $this->model->where($where)->count();
  93. }
  94. public function getNewestPms($where)
  95. {
  96. return $this->model->withTrashed()->where($where)->orderBy('id', 'desc')->first();
  97. }
  98. public function insertData($data)
  99. {
  100. return $this->model->insert($data);
  101. }
  102. }