ChapterController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use App\Modules\SendOrder\Services\SendOrderService;
  4. use App\Modules\Statistic\Services\WapVisitStatService;
  5. use App\Modules\User\Services\UserBookCombinationConfigService;
  6. use Illuminate\Http\Request;
  7. use App\Http\Controllers\QuickApp\BaseController;
  8. use Redis;
  9. use App\Modules\Book\Services\ChapterService;
  10. use App\Modules\User\Services\ReadRecordService;
  11. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterTransformer;
  12. use App\Modules\Book\Services\BookConfigService;
  13. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterListTransformer;
  14. use App\Jobs\UserRententionJob;
  15. use App\Modules\Book\Services\BookService;
  16. use App\Modules\Subscribe\Services\BookOrderService;
  17. use App\Modules\Subscribe\Services\ChapterOrderService;
  18. use App\Modules\Subscribe\Services\YearOrderService;
  19. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  20. use App\Modules\Subscribe\Services\ChapterReminderService;
  21. use App\Modules\User\Services\UserDeepReadTagService;
  22. use App\Modules\UserTask\Services\BaseTask;
  23. use App\Modules\UserTask\Services\UserTaskService;
  24. class ChapterController extends BaseController
  25. {
  26. private $book_info;
  27. public function getCatalog(Request $request, $bid)
  28. {
  29. $bid = BookService::decodeBidStatic($bid);
  30. $lists = ChapterService::getChapterLists($bid);
  31. $book_info = BookConfigService::getBookById($bid);
  32. if (!$book_info) {
  33. return response()->error('PARAM_ERROR');
  34. }
  35. $lists = $this->getChapterCatalog($bid, $lists, $book_info);
  36. return response()->collection(new ChapterListTransformer, $lists);
  37. }
  38. public function getCatalogPerPage(Request $request, $bid)
  39. {
  40. $bid = BookService::decodeBidStatic($bid);
  41. $book_info = BookConfigService::getBookById($bid);
  42. if (!$book_info) {
  43. return response()->error('PARAM_ERROR');
  44. }
  45. $page_size = $request->input('page_size', 15);
  46. if ($page_size >= 100) $page_size = 100;
  47. $res = ChapterService::getChapterListsPage($bid, $page_size);
  48. $lists = $this->getChapterCatalog($bid, $res, $book_info);
  49. return response()->pagination(new ChapterListTransformer, $lists);
  50. }
  51. private function getChapterCatalog(int $bid, $chapters, $book_info)
  52. {
  53. // 查询书籍是否限免
  54. $isFree = BookConfigService::judgeBookIsFree($bid);
  55. //渠道自定义vip章节
  56. $vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  57. list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
  58. $change_chapter_name = 0;
  59. if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
  60. $change_chapter_name = 1;
  61. }
  62. switch ($book_info->charge_type) {
  63. case 'BOOK':
  64. $price = $this->getPrice($book_info);
  65. $is_need_charge = $this->isBookNeedCharge($bid, $price);
  66. foreach ($chapters as $v) {
  67. $v->is_need_charge = $v->is_vip ? $is_need_charge : false;
  68. $v->price = $price;
  69. // 限免判断
  70. if ($isFree) {
  71. $v->is_need_charge = false;
  72. $v->price = 0;
  73. }
  74. if($vip_sequence){
  75. if($v->sequence >= $vip_sequence){
  76. $v->is_vip = 1;
  77. }else{
  78. $v->is_vip = 0;
  79. }
  80. }
  81. //拆章
  82. if($change_chapter_name){
  83. $v->name = '第'.$v->sequence.'章';
  84. }
  85. }
  86. break;
  87. default:
  88. foreach ($chapters as $v) {
  89. // 限免判断
  90. if ($isFree) {
  91. $v->is_need_charge = false;
  92. $v->price = 0;
  93. } else {
  94. $v->price = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
  95. $v->is_need_charge = $v->is_vip ? $this->isChapterNeedCharge($bid, $v->id, $v->price) : false;
  96. }
  97. if($vip_sequence){
  98. if($v->sequence >= $vip_sequence){
  99. $v->is_vip = 1;
  100. }else{
  101. $v->is_vip = 0;
  102. }
  103. }
  104. //拆章
  105. if($change_chapter_name){
  106. $v->name = '第'.$v->sequence.'章';
  107. }
  108. }
  109. break;
  110. }
  111. return $chapters;
  112. }
  113. public function index(Request $request, $bid, $cid)
  114. {
  115. $oldbid = $bid;
  116. $bid = BookService::decodeBidStatic($bid);
  117. //获取图书信息
  118. $book_info = BookConfigService::getBookById($bid);
  119. if (empty($book_info))
  120. return response()->error('QAPP_SYS_ERROR');
  121. $this->book_info = $book_info;
  122. //获取章节信息
  123. $chapter = ChapterService::getChapterNameById($cid, $bid);
  124. if (!$chapter) {
  125. //短推长
  126. $combination_chapter = $this->chapterNotExists($bid,$cid);
  127. if($combination_chapter){
  128. $chapter = $combination_chapter;
  129. $bid = $chapter->bid;
  130. $book_info = BookConfigService::getBookById($bid);
  131. $oldbid = \Hashids::encode($bid);
  132. $this->book_info = $book_info;
  133. }else{
  134. return response()->error('QAPP_SYS_ERROR');
  135. }
  136. }
  137. list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
  138. if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
  139. $chapter->name = '第'.$chapter->sequence.'章';
  140. }
  141. $is_next_day = date('Y-m-d', strtotime($this->user_info->created_at)) == date('Y-m-d', strtotime('-1 days'));
  142. if ($is_next_day) {
  143. $job = new UserRententionJob($this->uid, now(), $this->user_info->created_at);
  144. dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
  145. }
  146. //自定义vip章节
  147. $vip_sequence = Redis::hget('channel:chapterfee:setting:' . $this->distribution_channel_id, $bid);
  148. if($vip_sequence){
  149. if($chapter->sequence >= $vip_sequence){
  150. $chapter->is_vip = 1;
  151. }else{
  152. $chapter->is_vip = 0;
  153. }
  154. }
  155. if ($chapter->is_vip == 0) {
  156. ReadRecordService::addReadLog($this->uid, [
  157. 'distribution_channel_id' => $this->distribution_channel_id,
  158. 'bid' => $bid,
  159. 'cid' => $chapter->id,
  160. 'uid' => $this->uid,
  161. 'send_order_id' => $this->send_order_id,
  162. 'sequence' => $chapter->sequence,
  163. ]);
  164. ReadRecordService::addReadRecord([
  165. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  166. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  167. ]);
  168. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  169. }
  170. // 书籍是否限免
  171. $free = BookConfigService::judgeBookIsFree($bid);
  172. if ($free) {
  173. ReadRecordService::addReadLog($this->uid, [
  174. 'distribution_channel_id' => $this->distribution_channel_id,
  175. 'bid' => $bid,
  176. 'cid' => $chapter->id,
  177. 'uid' => $this->uid,
  178. 'send_order_id' => $this->send_order_id,
  179. 'sequence' => $chapter->sequence,
  180. ]);
  181. ReadRecordService::addReadRecord([
  182. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  183. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  184. ]);
  185. if ($chapter->is_vip == 1) {
  186. $fee = $this->getPrice($book_info, $chapter->size);
  187. $now = date('Y-m-d');
  188. Redis::hincrby('qapp:book:free:virtual:' . $free->id, $now, $fee);
  189. Redis::sadd('qapp:free:virtual' . $now, $free->id);
  190. }
  191. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  192. }
  193. //已经付费
  194. if ($this->getOrderRecord($bid, $cid)) {
  195. ReadRecordService::addReadLog($this->uid, [
  196. 'distribution_channel_id' => $this->distribution_channel_id,
  197. 'bid' => $bid,
  198. 'cid' => $chapter->id,
  199. 'uid' => $this->uid,
  200. 'send_order_id' => $this->send_order_id,
  201. 'sequence' => $chapter->sequence,
  202. ]);
  203. ReadRecordService::addReadRecord([
  204. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  205. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  206. ]);
  207. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  208. }
  209. //未付费 要提醒
  210. $user_info = $this->user_info;
  211. //未付费 余额不足
  212. $fee = $this->getPrice($book_info, $chapter->size);
  213. $data = [
  214. 'book_id' => $oldbid,
  215. 'book_name' => $book_info->book_name,
  216. 'chapter_name' => $chapter->name,
  217. 'chapter_id' => $cid,
  218. 'pay_type' => $book_info->charge_type,
  219. 'fee' => $fee,
  220. 'user_balance' => $user_info->balance,
  221. 'product_id' => $book_info->product_id,
  222. 'uid' => $this->uid,
  223. 'distribution_channel_id' => $this->distribution_channel_id,
  224. 'is_discount' => 0,
  225. 'discount_fee' => '',
  226. 'discount' => ''
  227. ];
  228. if ($user_info['balance'] < $fee) {
  229. if ($book_info->charge_type == 'BOOK') {
  230. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  231. } elseif ($book_info->charge_type == 'CHAPTER') {
  232. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  233. } else {
  234. return response()->error('QAPP_SYS_ERROR');
  235. }
  236. }
  237. //付费 不提醒
  238. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
  239. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  240. ReadRecordService::addReadLog($this->uid, [
  241. 'distribution_channel_id' => $this->distribution_channel_id,
  242. 'bid' => $bid,
  243. 'cid' => $chapter->id,
  244. 'uid' => $this->uid,
  245. 'send_order_id' => $this->send_order_id,
  246. 'sequence' => $chapter->sequence,
  247. ]);
  248. ReadRecordService::addReadRecord([
  249. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  250. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  251. ]);
  252. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  253. } else {
  254. if ($book_info->charge_type == 'BOOK') {
  255. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  256. } elseif ($book_info->charge_type == 'CHAPTER') {
  257. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  258. } else {
  259. return response()->error('QAPP_SYS_ERROR');
  260. }
  261. }
  262. }
  263. public function pay(Request $request, $bid, $cid)
  264. {
  265. $remind = (int)$request->input('remind');
  266. $oldbid = $bid;
  267. $bid = BookService::decodeBidStatic($bid);
  268. $book_info = BookConfigService::getBookById($bid);;
  269. if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
  270. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  271. if (!$this->isBookOrdered($bid)) {
  272. response()->error('QAPP_OFF_SHELF');
  273. }
  274. }
  275. //获取章节
  276. $chapter = ChapterService::getChapterNameById($cid, $bid);
  277. if (!$chapter) {
  278. $combination_chapter = $this->chapterNotExists($bid,$cid);
  279. if($combination_chapter){
  280. $chapter = $combination_chapter;
  281. $bid = $chapter->bid;
  282. $book_info = BookConfigService::getBookById($bid);
  283. $oldbid = \Hashids::encode($bid);
  284. $this->book_info = $book_info;
  285. }else{
  286. return response()->error('QAPP_SYS_ERROR');
  287. }
  288. }
  289. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, $remind)) {
  290. ReadRecordService::addReadRecord([
  291. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  292. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  293. ]);
  294. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  295. } else {
  296. $fee = $this->getPrice($book_info, $chapter->size);
  297. $data = [
  298. 'book_id' => $oldbid,
  299. 'book_name' => $book_info->book_name,
  300. 'chapter_name' => $chapter->name,
  301. 'chapter_id' => $cid,
  302. 'pay_type' => $book_info->charge_type,
  303. 'fee' => $fee,
  304. 'user_balance' => $this->user_info['balance'],
  305. 'product_id' => $book_info->product_id,
  306. 'uid' => $this->uid,
  307. 'distribution_channel_id' => $this->distribution_channel_id,
  308. 'is_discount' => 0,
  309. 'discount_fee' => '',
  310. 'discount' => ''
  311. ];
  312. if ($book_info->charge_type == 'BOOK') {
  313. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  314. } elseif ($book_info->charge_type == 'CHAPTER') {
  315. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  316. } else {
  317. return response()->error('QAPP_SYS_ERROR');
  318. }
  319. }
  320. }
  321. /**
  322. * 余额支付
  323. * @param $book_info
  324. * @param $chapter_id
  325. * @param $chapter_size
  326. * @return bool
  327. */
  328. protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
  329. {
  330. $fee = $this->getPrice($book_info, $chapter_size);
  331. if ((int)$this->user_info['balance'] >= $fee) {
  332. if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
  333. return true;
  334. }
  335. return false;
  336. } else {
  337. return false;
  338. }
  339. }
  340. /**
  341. * 获取章节内容
  342. * @param $bid
  343. * @param $cid
  344. * @return bool|mixed
  345. */
  346. protected function getChapter($bid, $cid, $chapter)
  347. {
  348. $chapter_content = ChapterService::getChapter($bid, $cid);
  349. if (!$chapter_content) return false;
  350. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  351. //统计点击率
  352. $key = 'book_click_num_bid_' . $bid;
  353. $field = date('Y-m-d');
  354. $old = Redis::hget($key, $field);
  355. if (!$old) $old = 0;
  356. Redis::hset($key, $field, $old + 1);
  357. $force_add_desk_type = $this->addDesktopType($bid, $chapter->sequence);
  358. $chapter->force_add_desk_type = $force_add_desk_type;
  359. //统计
  360. $this->stats();
  361. $this->userBookCombination($chapter);
  362. return $chapter;
  363. }
  364. //短续长
  365. private function userBookCombination($chapter){
  366. if($chapter->prev_cid && $chapter->next_cid){
  367. return ;
  368. }
  369. if($chapter->next_cid == 0 && $this->book_info->charge_type == 'BOOK'){
  370. $bid = UserBookCombinationConfigService::selectAndSave($this->uid,$this->book_info->bid);
  371. if($bid){
  372. $bookInfo = BookConfigService::getBookById($bid);
  373. $chapter->next_cid = $bookInfo->first_cid;
  374. }
  375. }
  376. if($chapter->prev_cid == 0 && $this->book_info->charge_type == 'CHAPTER'){
  377. $bid = UserBookCombinationConfigService::getShortBookFromLongBid($this->uid,$this->book_info->bid);
  378. if($bid){
  379. $bookInfo = BookConfigService::getBookById($bid);
  380. $chapter->prev_cid = $bookInfo->last_cid;
  381. }
  382. }
  383. }
  384. private function chapterNotExists($bid,$cid)
  385. {
  386. //1.全局图书组合配置
  387. $combination = BookConfigService::getCombinationInfo($bid);
  388. if($combination){
  389. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  390. if($chapter){
  391. return $chapter;
  392. }
  393. return false;
  394. }
  395. //2.用户图书组合配置
  396. if($this->book_info->charge_type == 'CHAPTER'){
  397. $user_combination = UserBookCombinationConfigService::getShortBookFromLongBook($this->uid,$bid);
  398. }else{
  399. $user_combination = UserBookCombinationConfigService::getLongBookFromShortBook($this->uid,$bid);
  400. }
  401. if($user_combination){
  402. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  403. if($chapter){
  404. return $chapter;
  405. }
  406. return false;
  407. }
  408. return false;
  409. }
  410. /**
  411. * 添加订购记录
  412. * @param $book_info
  413. * @param $chapter_id
  414. * @param $fee
  415. * @return bool
  416. */
  417. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  418. {
  419. if ($book_info['charge_type'] == 'BOOK') {
  420. $data = [
  421. 'uid' => $this->uid,
  422. 'fee' => $fee,
  423. 'u' => $this->send_order_id,
  424. 'distribution_channel_id' => $this->distribution_channel_id,
  425. 'bid' => $book_info->bid,
  426. 'book_name' => $book_info->book_name,
  427. 'send_order_id' => $this->send_order_id,
  428. ];
  429. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  430. } else {
  431. $data = [
  432. 'uid' => $this->uid,
  433. 'fee' => $fee,
  434. 'cid' => $chapter_id,
  435. 'bid' => $book_info->bid,
  436. 'distribution_channel_id' => $this->distribution_channel_id,
  437. 'book_name' => $book_info->book_name,
  438. 'chapter_name' => $chapter_name,
  439. 'send_order_id' => $this->send_order_id,
  440. 'is_remind' => $is_remind
  441. ];
  442. if ($is_remind) {
  443. $this->addOrderRemind($book_info->bid);
  444. }
  445. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  446. }
  447. }
  448. protected function addOrderRemind($bid)
  449. {
  450. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  451. return true;
  452. } else {
  453. ChapterReminderService::add($this->uid, $bid);
  454. return true;
  455. }
  456. }
  457. /**
  458. * 是否订购提醒
  459. * @param $chapter_id
  460. * @return bool
  461. */
  462. protected function isOrderRemind($bid)
  463. {
  464. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  465. return $is_no_reminder == 0;
  466. }
  467. /**
  468. * 用户是否关注
  469. * @param $uid
  470. * @return bool
  471. */
  472. protected function getSubscribe()
  473. {
  474. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  475. if ($res) return true;
  476. return false;
  477. }
  478. /**
  479. * 获取订购记录
  480. * @param $book_info
  481. * @param $chapter_id
  482. * @return bool
  483. */
  484. protected function getOrderRecord($bid, $chapter_id)
  485. {
  486. //包年记录
  487. $uid = $this->uid;
  488. $res = YearOrderService::getRecord($uid);
  489. if ($res) return true;
  490. $res = null;
  491. //单本订购记录
  492. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  493. if ($res) return true;
  494. $res = null;
  495. //章节订购记录
  496. $chapterOrder = new ChapterOrderService();
  497. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  498. return false;
  499. }
  500. /**
  501. * 计算价格
  502. * @param $book_info
  503. * @param $chapter_size
  504. * @return float
  505. */
  506. private function getPrice($book_info, $chapter_size = 0)
  507. {
  508. if ($book_info->charge_type == 'BOOK') {
  509. if (BookOrderService::isHasBookOrder($this->uid)) {
  510. $this->is_first_book_order = 0;
  511. return 1399;
  512. } else {
  513. $this->is_first_book_order = 1;
  514. return 899;
  515. }
  516. } else {
  517. $fee = BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size);
  518. return $fee;
  519. }
  520. }
  521. /**
  522. * 用户添加标签
  523. * @param $book_info
  524. */
  525. protected function addTag($book_info)
  526. {
  527. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  528. try {
  529. UserDeepReadTagService::addTag([
  530. 'uid' => $this->uid,
  531. 'bid' => $book_info->bid,
  532. 'book_name' => $book_info->book_name,
  533. 'category_id' => $book_info->category_id,
  534. 'category_name' => $book_info->category_name,
  535. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  536. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  537. 'send_order_id' => $this->send_order_id,
  538. ]);
  539. } catch (\Exception $e) {
  540. }
  541. }
  542. }
  543. protected function isBookOrdered($bid)
  544. {
  545. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  546. if ($chapter_order) return true;
  547. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  548. if ($res) return true;
  549. return false;
  550. }
  551. /**
  552. * 判断是否需要充值
  553. */
  554. private function isBookNeedCharge(int $bid, float $price)
  555. {
  556. $book_order = $this->getOrderRecord($bid, 0);
  557. if ($book_order) {
  558. return false;
  559. } else {
  560. $user_info = $this->user_info;
  561. return $user_info['balance'] < $price;
  562. }
  563. }
  564. /**
  565. * 判断章节是否需要充值
  566. */
  567. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  568. {
  569. $book_order = $this->getOrderRecord($bid, $cid);
  570. if ($book_order) {
  571. return false;
  572. } else {
  573. $user_info = $this->user_info;
  574. return $user_info['balance'] < $price;
  575. }
  576. }
  577. private function stats()
  578. {
  579. //阅读器统计
  580. WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
  581. }
  582. //加桌类型
  583. private function addDesktopType($bid, $sequence)
  584. {
  585. $force_add_desk_type = 0;
  586. $send_order_id = ReadRecordService::getSendOrderId($this->uid);
  587. if (!$send_order_id) return $force_add_desk_type;
  588. $send_order_info = SendOrderService::getById($send_order_id);
  589. if (!$send_order_info) return $force_add_desk_type;
  590. if ($send_order_info->book_id == $bid) {
  591. if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
  592. if ($sequence >= $send_order_info->force_add_desk_seq) {
  593. $force_add_desk_type = $send_order_info->force_add_desk_type;
  594. }
  595. }
  596. if ($send_order_info->force_add_desk_type == 2) {
  597. if ($sequence >= $this->book_info->force_subscribe_chapter_seq && $sequence <= $this->book_info->force_subscribe_chapter_seq + 3) {
  598. $force_add_desk_type = $send_order_info->force_add_desk_type;
  599. }
  600. }
  601. }
  602. return $force_add_desk_type;
  603. }
  604. }