12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Elton
- * Date: 2019/4/28
- * Time: 18:17
- */
- namespace app\clientwebapi\controller;
- use app\common\controller\ClientWebApi;
- use app\main\service\LogService;
- use app\main\service\UserService;
- use think\Cookie;
- class Checkin extends ClientWebApi
- {
- //加入书架
- public function bookshelf()
- {
- LogService::info('[ Checkin ] 全部加入书架');
- //获取当前登录用户ID
- $uid =Cookie::get('user_id');
- //如果用户UID为空,不做处理
- if(empty($uid)){
- $this->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;
- }
- }
- }
- }
|