MsgRepository.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/22
  6. * Time: 15:25
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Msg;
  10. use App\Models\MemberMsgtip;
  11. use Prettus\Repository\Eloquent\BaseRepository;
  12. /**
  13. * Class MsgRepositoryEloquent.
  14. *
  15. * @package namespace App\Repositories;
  16. */
  17. class MsgRepository extends BaseRepository
  18. {
  19. /**
  20. * Specify Model class name
  21. *
  22. * @return string
  23. */
  24. public function model()
  25. {
  26. return Msg::class;
  27. }
  28. public function addData($data)
  29. {
  30. return Msg::insertGetId($data);
  31. }
  32. public function update(array $data, $id)
  33. {
  34. return $this->model->where('id', $id)->update($data);
  35. }
  36. public function getMemberMsgtipInfo($where)
  37. {
  38. return MemberMsgtip::where($where)->first();
  39. }
  40. public function updateMemberMsgtipInfo($where, $data)
  41. {
  42. return MemberMsgtip::where($where)->update($data);
  43. }
  44. public function addMemberMsgtipInfo($data)
  45. {
  46. return MemberMsgtip::insert($data);
  47. }
  48. public function msg($utype, $uid)
  49. {
  50. if ($utype==1) {
  51. $res = $this->model->orWhere(function ($query) use ($utype, $uid) {
  52. $query->where(['from_uid'=>$uid, 'utype'=>$utype]);
  53. })->orWhere(function ($query) use ($utype, $uid) {
  54. $query->where(['to_uid' => $uid, 'utype' => 2]);
  55. })->select(
  56. [
  57. 'parent_id',
  58. \DB::raw('group_concat(utype,":",from_uid,":",to_uid,":",message) as result'),
  59. 'created_at'
  60. ]
  61. )->orderBy('id', 'desc')
  62. ->groupBy('parent_id')->paginate(10);
  63. } else {
  64. $res = $this->model->orWhere(function ($query) use ($utype, $uid) {
  65. $query->where(['from_uid'=>$uid, 'utype'=>$utype]);
  66. })->orWhere(function ($query) use ($utype, $uid) {
  67. $query->where(['to_uid' => $uid, 'utype' => 1]);
  68. })->select(
  69. [
  70. 'parent_id',
  71. \DB::raw('group_concat(utype,":",from_uid,":",to_uid,":",message) as result'),
  72. 'created_at'
  73. ]
  74. )->orderBy('id', 'desc')
  75. ->groupBy('parent_id')->paginate(10);
  76. }
  77. return $res;
  78. }
  79. public function mobileMsg($utype, $uid)
  80. {
  81. $res = $this->model->Where(function ($query) use ($utype, $uid) {
  82. if ($utype == 1) {
  83. $query->Where(['to_uid'=>$uid,'utype'=>2]);
  84. } else {
  85. $query->Where(['from_uid'=>$uid,'utype'=>$utype]);
  86. }
  87. })->with('company')->whereHas('company')->orderBy('id', 'desc')
  88. ->groupBy('parent_id')->paginate(10);
  89. return $res;
  90. }
  91. public function mobileMsgShow($parent_id)
  92. {
  93. return $this->model->where('parent_id', $parent_id)->orderBy('id', 'desc')->paginate(10);
  94. }
  95. /**企业用
  96. * @param $parent_id
  97. * @return mixed
  98. */
  99. public function mobileMsgShows($parent_id)
  100. {
  101. return $this->model->where('parent_id', $parent_id)->orderBy('id', 'desc')->paginate(10);
  102. }
  103. public function findCompanyByPar($utype, $uid, $parent_id)
  104. {
  105. if ($utype == 1) {
  106. return $this->model->where('parent_id', $parent_id)->where(['from_uid'=>$uid, 'utype'=>$utype])->with(['memberInfoMsg','resumes'])
  107. ->whereHas('memberInfoMsg')->first();
  108. } else {
  109. return $this->model->where('parent_id', $parent_id)->where(['from_uid'=>$uid, 'utype'=>$utype])->with('company')
  110. ->whereHas('company')->first();
  111. }
  112. }
  113. public function msgSend($data)
  114. {
  115. return $this->model->create($data);
  116. }
  117. public function msgDelete($parent_id)
  118. {
  119. return $this->model->where('parent_id', $parent_id)->delete();
  120. }
  121. }