www.wdadmin.cn // +---------------------------------------------------------------------- namespace app\api\controller\wdsxh\message; use app\admin\model\wdsxh\message\MessageNotification; use app\api\model\wdsxh\member\Member; use app\api\model\wdsxh\UserWechat; use app\common\controller\Api; class MemberNotification extends Api { protected $noNeedLogin = ['']; protected $noNeedRight = ['*']; protected $model = null; protected $member_id = null; public function _initialize() { parent::_initialize(); $this->model = new \app\api\model\wdsxh\message\MemberNotification(); $wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id'); if (!$wechat_id) { $this->error('用户信息不存在'); } $memberObj = (new Member())->where('wechat_id',$wechat_id)->find(); if (!$memberObj) { $this->member_id = '-1'; } else { $this->member_id = $memberObj['id']; } } /** * Desc 消息通知列表 * Create on 2025/11/17 下午2:57 * Create by wangyafang */ public function index() { if(!$this->request->isGet()) { $this->error('请求类型错误'); } $param = $this->request->get(); $page = isset($param['page']) ? $param['page'] : ''; $limit = isset($param['limit']) ? $param['limit'] : 10; $where = []; $where['member_id'] = array('eq',$this->member_id); $total = $this->model->where($where)->count(); $data = $this->model ->where($where) ->field('id,createtime,is_read,notification_id') ->page($page,$limit) ->order('is_read asc,createtime desc,id desc') ->select(); foreach ($data as $key => $value) { $value->hidden(['notification_id']); } $this->success('请求成功',['total' => $total,'data' => $data]); } /** * Desc 详情 * Create on 2025/11/17 下午2:59 * Create by wangyafang */ public function detail() { if (!$this->request->isGet()) { $this->error('请求类型错误'); } $param = $this->request->get(); $id = isset($param['id']) ? $param['id'] : ''; if (!$id) { $this->error('参数错误'); } $where = []; $where['member_id'] = array('eq', $this->member_id); $where['id'] = array('eq', $id); $data = $this->model ->where($where) ->field('createtime,is_read,notification_id') ->find(); if (!$data) { $this->error('消息不存在'); } if ($data['is_read'] == '0') { $this->model->where('id', $id)->update(['is_read' => '1']); } $data['content'] = (new MessageNotification())->where('id',$data['notification_id'])->value('content'); $data->hidden(['is_read','notification_id']); $this->success('请求成功', $data); } }