ChapterController.php 26 KB

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