| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Module\Ulogic;
- use App\Module\Ulogic\Enum\INTERNAL_TYPE;
- /**
- * 站内信
- *
- */
- class Internal
- {
- /**
- * 列表
- *
- * @param $page
- * @param $limit
- * @param $w
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
- */
- public static function list1($page, $limit, $w, $order ='')
- {
- $q = \App\Module\Ulogic\Model\Internal::query();
- if($order){
- $q = $q->orderBy($order);
- }else{
- $q = $q->orderBy('id','desc');
- }
- if ($w['user_id'] ?? 0) {
- $q = $q->where('user_id', '=', $w['user_id']);
- }
- if ($w['is_read'] ?? '') {
- $q = $q->where('is_read', '=', $w['is_read']);
- }
- return $q->paginate($limit, [ '*' ], '', $page);
- }
- /**
- * 发送消息
- *
- * @param $user_id
- * @param $to_user_id
- * @param $content
- * @param $app_data
- * @param $cate
- * @return bool
- */
- static public function send($user_id, $to_user_id, $content, $app_data, $cate = 0,$admin_id = 0)
- {
- $model = new \App\Module\Ulogic\Model\Internal();
- $model->status = 0;
- $model->is_read = 0;
- $model->content = $content;
- $model->cate = $cate;
- $model->from_id = $user_id;
- if($user_id){
- $model->type1= INTERNAL_TYPE::USER;
- }
- if(!$user_id){
- if($admin_id){
- $model->type1= INTERNAL_TYPE::ADMIN;
- }else{
- $model->type1= INTERNAL_TYPE::SYSTEM;
- }
- }
- $model->admin_id = $admin_id;
- $model->user_id = $to_user_id;
- $model->data = serialize($app_data);
- $model->save();
- $model->refresh();
- // $model->at_users = '';
- if ($model->id > 0) {
- return true;
- }
- return false;
- }
- /**
- * 单条信息
- * @param $where
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
- */
- static public function info($where)
- {
- return \App\Module\Ulogic\Model\Internal::query()->where($where)->first();
- }
- /**
- * 设置已读
- *
- * @param $ids
- * @return void
- */
- static public function reads($ids, $user_id = null)
- {
- $q = \App\Module\Ulogic\Model\Internal::query()->whereIn('id', $ids);
- if ($user_id) {
- $q = $q->where('user_id', $user_id);
- }
- $q->update([
- 'is_read' => 1
- ]);
- }
- }
|