error('请先登录'); } if($this->request->isPost()){ $bookshelf = $this->request->param('bookshelf'); LogService::info('[ Checkin ] bookshelf:'.$bookshelf); $bookshelf = json_decode($bookshelf, true); $data = []; foreach ($bookshelf as $k => $v){ //保存到书架即保存到最近阅读记录 $data[] = [ 'user_id' => $uid, 'book_id' => $v['book_id'], 'chapter_id' => $v['first_chapter_id'], 'chapter_name' => $v['first_chapter_name'] ]; } if($data){ model('UserRecentlyRead')->setConnect($uid)->saveAll($data); } LogService::info('[ Checkin ] 全部加入书架 成功'); $this->success('成功'); } } // APP 签到 public function appSign() { LogService::info('[ Checkin ] 执行签到'); //判断用户是否已经登录 $uid =Cookie::get('user_id'); if(empty($uid)){ $this->error('请先登录'); } //判断今天是否已经签到 //$todayDate = Date('Ymd',time()); $isSign = $this->isSign(); if($isSign){ $this->error('今日已经签到了,不用重复签到'); } //没有签到,执行签到 | Sign表中写数据 | 签到送积分 | 修改今日签到的标记 UserService::instance()->getSignModel()->setConnect($uid)->writeSignLog(); LogService::info('[ Checkin ] 签到完成'); } /** * 判断当前用户今日有没有签到 * @return bool */ public function isSign(){ $uid = Cookie::get('user_id'); $todayDate = Date('Ymd',time()); if(Cookie::get('sign'.$todayDate)=='1'){ return true; }else{ $isSign = model('Sign')->setConnect($uid)->where(['uid'=>$uid,'createdate'=>$todayDate])->find(); if(empty($isSign)){ return false; }else{ Cookie::set('sign'.$todayDate,'1',86400); //已经签到了,存cookie里 return true; } } } }