public function getNot($id)
 {
     $u_id = Input::get('u_id', 0);
     $token = Input::get('token', '');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $not = Notification::find($id);
         if (empty($not)) {
             throw new Exception("没有找到请求的数据", 2001);
         }
         $data = $not->showDetail();
         $read = NotificationRead::where('u_id', '=', $u_id)->where('n_id', '=', $id)->first();
         if (empty($read)) {
             $read = new NotificationRead();
             $read->n_id = $id;
             $read->u_id = $u_id;
             $read->is_read = 1;
             $read->is_del = 0;
         } else {
             $read->is_read = 1;
         }
         $read->save();
         $re = Tools::reTrue('获取消息成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取消息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNotificationReads()
 {
     return $this->hasMany(NotificationRead::className(), ['user_id' => 'id']);
 }