ChapterController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. Redis::sadd('qapp:free:virtual:uids'.$now.$free->id,$this->uid);
  198. Redis::sadd('qapp:free:virtual:uids'.$free->id,$this->uid);
  199. }
  200. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  201. }
  202. //已经付费
  203. if ($this->getOrderRecord($bid, $cid)) {
  204. ReadRecordService::addReadLog($this->uid, [
  205. 'distribution_channel_id' => $this->distribution_channel_id,
  206. 'bid' => $bid,
  207. 'cid' => $chapter->id,
  208. 'uid' => $this->uid,
  209. 'send_order_id' => $this->send_order_id,
  210. 'sequence' => $chapter->sequence,
  211. ]);
  212. ReadRecordService::addReadRecord([
  213. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  214. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  215. ]);
  216. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  217. }
  218. //未付费 要提醒
  219. $user_info = $this->user_info;
  220. //未付费 余额不足
  221. $fee = $this->getPrice($book_info, $chapter->size);
  222. $data = [
  223. 'book_id' => $oldbid,
  224. 'book_name' => $book_info->book_name,
  225. 'chapter_name' => $chapter->name,
  226. 'chapter_id' => $cid,
  227. 'pay_type' => $book_info->charge_type,
  228. 'fee' => $fee,
  229. 'user_balance' => $user_info->balance,
  230. 'product_id' => $book_info->product_id,
  231. 'uid' => $this->uid,
  232. 'distribution_channel_id' => $this->distribution_channel_id,
  233. 'is_discount' => 0,
  234. 'discount_fee' => '',
  235. 'discount' => ''
  236. ];
  237. if ($user_info['balance'] < $fee) {
  238. if ($book_info->charge_type == 'BOOK') {
  239. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  240. } elseif ($book_info->charge_type == 'CHAPTER') {
  241. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  242. } else {
  243. return response()->error('QAPP_SYS_ERROR');
  244. }
  245. }
  246. //付费 不提醒
  247. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
  248. UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
  249. ReadRecordService::addReadLog($this->uid, [
  250. 'distribution_channel_id' => $this->distribution_channel_id,
  251. 'bid' => $bid,
  252. 'cid' => $chapter->id,
  253. 'uid' => $this->uid,
  254. 'send_order_id' => $this->send_order_id,
  255. 'sequence' => $chapter->sequence,
  256. ]);
  257. ReadRecordService::addReadRecord([
  258. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  259. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  260. ]);
  261. //限免统计
  262. $free_book = BookConfigService::getByBidNoFilter($bid);
  263. if($free_book) {
  264. if(strtotime($free_book->end_time)+7*86400 >= strtotime(date('Y-m-d'))) {
  265. if(Redis::Sismember('qapp:free:virtual:uids'.$free_book->id,$this->uid)){
  266. $now = date('Y-m-d');
  267. Redis::hincrby('qapp:book:free:actuality:' . $free_book->id, $now, $fee);
  268. Redis::sadd('qapp:free:actuality' . $now, $free_book->id);
  269. Redis::sadd('qapp:free:actuality:uids'.$now.$free_book->id,$this->uid);
  270. }
  271. }
  272. }
  273. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  274. } else {
  275. if ($book_info->charge_type == 'BOOK') {
  276. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  277. } elseif ($book_info->charge_type == 'CHAPTER') {
  278. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  279. } else {
  280. return response()->error('QAPP_SYS_ERROR');
  281. }
  282. }
  283. }
  284. public function pay(Request $request, $bid, $cid)
  285. {
  286. $remind = (int)$request->input('remind');
  287. $oldbid = $bid;
  288. $bid = BookService::decodeBidStatic($bid);
  289. $book_info = BookConfigService::getBookById($bid);;
  290. if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
  291. if($this->distribution_channel_id == 7477 && $bid == 13765){
  292. $book_info->is_on_shelf = 2;
  293. }
  294. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  295. if (!$this->isBookOrdered($bid)) {
  296. response()->error('QAPP_OFF_SHELF');
  297. }
  298. }
  299. //获取章节
  300. $chapter = ChapterService::getChapterNameById($cid, $bid);
  301. if (!$chapter) {
  302. $combination_chapter = $this->chapterNotExists($bid,$cid);
  303. if($combination_chapter){
  304. $chapter = $combination_chapter;
  305. $bid = $chapter->bid;
  306. $book_info = BookConfigService::getBookById($bid);
  307. $oldbid = \Hashids::encode($bid);
  308. $this->book_info = $book_info;
  309. }else{
  310. return response()->error('QAPP_SYS_ERROR');
  311. }
  312. }
  313. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, $remind)) {
  314. ReadRecordService::addReadRecord([
  315. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  316. 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
  317. ]);
  318. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  319. } else {
  320. $fee = $this->getPrice($book_info, $chapter->size);
  321. $data = [
  322. 'book_id' => $oldbid,
  323. 'book_name' => $book_info->book_name,
  324. 'chapter_name' => $chapter->name,
  325. 'chapter_id' => $cid,
  326. 'pay_type' => $book_info->charge_type,
  327. 'fee' => $fee,
  328. 'user_balance' => $this->user_info['balance'],
  329. 'product_id' => $book_info->product_id,
  330. 'uid' => $this->uid,
  331. 'distribution_channel_id' => $this->distribution_channel_id,
  332. 'is_discount' => 0,
  333. 'discount_fee' => '',
  334. 'discount' => ''
  335. ];
  336. if ($book_info->charge_type == 'BOOK') {
  337. return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
  338. } elseif ($book_info->charge_type == 'CHAPTER') {
  339. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  340. } else {
  341. return response()->error('QAPP_SYS_ERROR');
  342. }
  343. }
  344. }
  345. /**
  346. * 余额支付
  347. * @param $book_info
  348. * @param $chapter_id
  349. * @param $chapter_size
  350. * @return bool
  351. */
  352. protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
  353. {
  354. $fee = $this->getPrice($book_info, $chapter_size);
  355. if ((int)$this->user_info['balance'] >= $fee) {
  356. if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
  357. return true;
  358. }
  359. return false;
  360. } else {
  361. return false;
  362. }
  363. }
  364. /**
  365. * 获取章节内容
  366. * @param $bid
  367. * @param $cid
  368. * @return bool|mixed
  369. */
  370. protected function getChapter($bid, $cid, $chapter)
  371. {
  372. $chapter_content = ChapterService::getChapter($bid, $cid);
  373. if (!$chapter_content) return false;
  374. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  375. //统计点击率
  376. $key = 'book_click_num_bid_' . $bid;
  377. $field = date('Y-m-d');
  378. $old = Redis::hget($key, $field);
  379. if (!$old) $old = 0;
  380. Redis::hset($key, $field, $old + 1);
  381. $force_add_desk_type = $this->addDesktopType($bid, $chapter->sequence);
  382. $chapter->force_add_desk_type = $force_add_desk_type;
  383. //统计
  384. $this->stats();
  385. $this->userBookCombination($chapter);
  386. return $chapter;
  387. }
  388. //短续长
  389. private function userBookCombination($chapter){
  390. if($chapter->prev_cid && $chapter->next_cid){
  391. return ;
  392. }
  393. if($chapter->next_cid == 0 && $this->book_info->charge_type == 'BOOK'){
  394. $bid = UserBookCombinationConfigService::selectAndSave($this->uid,$this->book_info->bid);
  395. if($bid){
  396. $bookInfo = BookConfigService::getBookById($bid);
  397. $chapter->next_cid = $bookInfo->first_cid;
  398. }
  399. }
  400. if($chapter->prev_cid == 0 && $this->book_info->charge_type == 'CHAPTER'){
  401. $bid = UserBookCombinationConfigService::getShortBookFromLongBid($this->uid,$this->book_info->bid);
  402. if($bid){
  403. $bookInfo = BookConfigService::getBookById($bid);
  404. $chapter->prev_cid = $bookInfo->last_cid;
  405. }
  406. }
  407. }
  408. private function chapterNotExists($bid,$cid)
  409. {
  410. //1.全局图书组合配置
  411. $combination = BookConfigService::getCombinationInfo($bid);
  412. if($combination){
  413. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  414. if($chapter){
  415. return $chapter;
  416. }
  417. return false;
  418. }
  419. //2.用户图书组合配置
  420. if($this->book_info->charge_type == 'CHAPTER'){
  421. $user_combination = UserBookCombinationConfigService::getShortBookFromLongBook($this->uid,$bid);
  422. }else{
  423. $user_combination = UserBookCombinationConfigService::getLongBookFromShortBook($this->uid,$bid);
  424. }
  425. if($user_combination){
  426. $chapter = ChapterService::getChapterNameByIdNoCheck($cid);
  427. if($chapter){
  428. return $chapter;
  429. }
  430. return false;
  431. }
  432. return false;
  433. }
  434. /**
  435. * 添加订购记录
  436. * @param $book_info
  437. * @param $chapter_id
  438. * @param $fee
  439. * @return bool
  440. */
  441. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  442. {
  443. if ($book_info['charge_type'] == 'BOOK') {
  444. $data = [
  445. 'uid' => $this->uid,
  446. 'fee' => $fee,
  447. 'u' => $this->send_order_id,
  448. 'distribution_channel_id' => $this->distribution_channel_id,
  449. 'bid' => $book_info->bid,
  450. 'book_name' => $book_info->book_name,
  451. 'send_order_id' => $this->send_order_id,
  452. ];
  453. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  454. } else {
  455. $data = [
  456. 'uid' => $this->uid,
  457. 'fee' => $fee,
  458. 'cid' => $chapter_id,
  459. 'bid' => $book_info->bid,
  460. 'distribution_channel_id' => $this->distribution_channel_id,
  461. 'book_name' => $book_info->book_name,
  462. 'chapter_name' => $chapter_name,
  463. 'send_order_id' => $this->send_order_id,
  464. 'is_remind' => $is_remind
  465. ];
  466. if ($is_remind) {
  467. $this->addOrderRemind($book_info->bid);
  468. }
  469. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  470. }
  471. }
  472. protected function addOrderRemind($bid)
  473. {
  474. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  475. return true;
  476. } else {
  477. ChapterReminderService::add($this->uid, $bid);
  478. return true;
  479. }
  480. }
  481. /**
  482. * 是否订购提醒
  483. * @param $chapter_id
  484. * @return bool
  485. */
  486. protected function isOrderRemind($bid)
  487. {
  488. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  489. return $is_no_reminder == 0;
  490. }
  491. /**
  492. * 用户是否关注
  493. * @param $uid
  494. * @return bool
  495. */
  496. protected function getSubscribe()
  497. {
  498. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  499. if ($res) return true;
  500. return false;
  501. }
  502. /**
  503. * 获取订购记录
  504. * @param $book_info
  505. * @param $chapter_id
  506. * @return bool
  507. */
  508. protected function getOrderRecord($bid, $chapter_id)
  509. {
  510. //包年记录
  511. $uid = $this->uid;
  512. $res = YearOrderService::getRecord($uid);
  513. if ($res) return true;
  514. $res = null;
  515. //单本订购记录
  516. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  517. if ($res) return true;
  518. $res = null;
  519. //章节订购记录
  520. $chapterOrder = new ChapterOrderService();
  521. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  522. return false;
  523. }
  524. /**
  525. * 计算价格
  526. * @param $book_info
  527. * @param $chapter_size
  528. * @return float
  529. */
  530. private function getPrice($book_info, $chapter_size = 0)
  531. {
  532. if ($book_info->charge_type == 'BOOK') {
  533. if (BookOrderService::isHasBookOrder($this->uid)) {
  534. $this->is_first_book_order = 0;
  535. return 1399;
  536. } else {
  537. $this->is_first_book_order = 1;
  538. return 899;
  539. }
  540. } else {
  541. // 获取投放后台账号,
  542. $account = '';
  543. if(isset($this->user_info->send_order_id) && $this->user_info->send_order_id){
  544. $account_send_order = QappSendOrder::getSendOrderById($this->user_info->send_order_id);
  545. $account = isset($account_send_order['account'])?$account_send_order['account']:'';
  546. \Log::info('getPrice:'.$this->uid.' account:'.$account.' send_order_id:'.$this->user_info->send_order_id);
  547. }
  548. $fee = BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size,$account);
  549. return $fee;
  550. }
  551. }
  552. /**
  553. * 用户添加标签
  554. * @param $book_info
  555. */
  556. protected function addTag($book_info)
  557. {
  558. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  559. try {
  560. UserDeepReadTagService::addTag([
  561. 'uid' => $this->uid,
  562. 'bid' => $book_info->bid,
  563. 'book_name' => $book_info->book_name,
  564. 'category_id' => $book_info->category_id,
  565. 'category_name' => $book_info->category_name,
  566. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  567. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  568. 'send_order_id' => $this->send_order_id,
  569. ]);
  570. } catch (\Exception $e) {
  571. }
  572. }
  573. }
  574. protected function isBookOrdered($bid)
  575. {
  576. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  577. if ($chapter_order) return true;
  578. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  579. if ($res) return true;
  580. return false;
  581. }
  582. /**
  583. * 判断是否需要充值
  584. */
  585. private function isBookNeedCharge(int $bid, float $price)
  586. {
  587. $book_order = $this->getOrderRecord($bid, 0);
  588. if ($book_order) {
  589. return false;
  590. } else {
  591. $user_info = $this->user_info;
  592. return $user_info['balance'] < $price;
  593. }
  594. }
  595. /**
  596. * 判断章节是否需要充值
  597. */
  598. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  599. {
  600. $book_order = $this->getOrderRecord($bid, $cid);
  601. if ($book_order) {
  602. return false;
  603. } else {
  604. $user_info = $this->user_info;
  605. return $user_info['balance'] < $price;
  606. }
  607. }
  608. private function stats()
  609. {
  610. //阅读器统计
  611. WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
  612. }
  613. //加桌类型
  614. private function addDesktopType($bid, $sequence)
  615. {
  616. $force_add_desk_type = 0;
  617. $send_order_id = ReadRecordService::getSendOrderId($this->uid);
  618. if (!$send_order_id) return $force_add_desk_type;
  619. $send_order_info = SendOrderService::getById($send_order_id);
  620. if (!$send_order_info) return $force_add_desk_type;
  621. if ($send_order_info->book_id == $bid) {
  622. if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
  623. if ($sequence >= $send_order_info->force_add_desk_seq) {
  624. $force_add_desk_type = $send_order_info->force_add_desk_type;
  625. }
  626. }
  627. if ($send_order_info->force_add_desk_type == 2) {
  628. if ($sequence >= $this->book_info->force_subscribe_chapter_seq && $sequence <= $this->book_info->force_subscribe_chapter_seq + 3) {
  629. $force_add_desk_type = $send_order_info->force_add_desk_type;
  630. }
  631. }
  632. }
  633. return $force_add_desk_type;
  634. }
  635. }