redis = Redis::instance();
//parent::_initialize();
}
public function test(){
//$ur = new UserRecentlyRead();
//$ur->getOneReadRecord('U1B11000000039');
//$res = $ur->getRecentlyRead(1);
//$pp = $this->redis->hgetall('U1B11000000029');
//dump($pp);
// $thismodel = new UserRecentlyRead();
// $read = $thismodel->getRecentlyRead();
// dump($read);die;
$book_id = 11000000039;
//echo $this->redis->get('hello');die;
//$chapters = model('Book')::getChapterList($book_id);
$bookinfo = model('Book')->bookinfo($book_id);
dump($bookinfo);die;
// echo "
";
// print_r($chapters);
echo(microtime());
$res = $this->bookfee(3,$bookinfo,'测试章节1',142,196511666,1);
dump($res);
echo(microtime());
}
/**
* 点击下一章
* @param $userId $this->user->id; 如果没有userid 就写到cookie里(最多5本)
* @param $bookId url上传的
* @param $chapter_id url上带的chapter_id ,cookie里的chaper_id 和 sid 优先级低(高于)
* @param $chapter_name
* @param $idx 第几章
* @param int $kandian config('site.book_chapter_price')
* @return array $returnArr['type'] = 4; // type:1扣书币成功 2.书币不足,3扣书币失败,4缺少参数,5获取书籍信息失败,6未登录,7,游客到了计费章节 $returnArr['isRecharge']=1,扣费,返回数组里没有isRecharge这个参数是免费的
* @throws \Exception
*/
public function bookfee($admin_id,$book,$chapter_name,$idx,$chapter_id,$user){
$freeChapter = config('site.book_free_chapter_num'); //全局免费章节数
if(intval($book['free_chapter_num'])>0){ //如果本书籍设置了免费章节数,以本书籍的免费章节数为准
$freeChapter = $book['free_chapter_num'];
}
//维护书阅读数量
$bookNumKey = 'B-N';
$this->redis->hincrby($bookNumKey, $book['id'], 1);
$bookKey = 'B:'.$book['id'];
if($this->redis->exists($bookKey)){ //判断有没有这个key
$this->redis->hincrby($bookKey,'read_num',1);
}
$kandian = config('site.book_chapter_price'); //全局每章节书币数
$returnArr = [];
if(!$book || !$admin_id || !$chapter_id || !$chapter_name || !$idx){ //必传参数
$returnArr['error'] = 1;
$returnArr['type'] = 4;
$returnArr['msg'] = '缺少参数';
return $returnArr;
}
if(!empty($user)) {
$userId = $user['id'];
}else{
$userId = null;
}
if(Config::get("site.free")==1){ //容灾处理,如果计费出现问题在后台配置read_free=true则所有书籍都免费
$this->recentlyRead($chapter_name,$chapter_id,$book,$userId); //记录最近阅读
$returnArr['error'] = 0;
$returnArr['type'] = 1;
$returnArr['msg'] = '免费章节';
return $returnArr;
}
if(intval($book['free_stime'])