ChapterController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\QuickApp\BaseController;
  5. use Redis;
  6. use App\Modules\Book\Services\ChapterService;
  7. use App\Modules\User\Services\ReadRecordService;
  8. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterTransformer;
  9. use App\Modules\Book\Services\BookConfigService;
  10. use App\Http\Controllers\QuickApp\Book\Transformers\ChapterListTransformer;
  11. use App\Modules\Book\Services\BookService;
  12. use App\Modules\Subscribe\Services\BookOrderService;
  13. use App\Modules\Subscribe\Services\ChapterOrderService;
  14. use App\Modules\Subscribe\Services\YearOrderService;
  15. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  16. use App\Modules\Subscribe\Services\ChapterReminderService;
  17. use Hashids;
  18. use App\Modules\User\Services\UserSignService;
  19. use App\Modules\User\Services\UserDeepReadTagService;
  20. class ChapterController extends BaseController
  21. {
  22. /**
  23. * @apiDefine Chapter 章节
  24. */
  25. /**
  26. * @apiVersion 1.0.0
  27. * @apiDescription 章节列表不分页
  28. * @api {get} books/{bid}/allcatalog 章节列表不分页
  29. * @apiParam {String} [token] token
  30. * @apiHeader {String} [Authorization] token 两个token任选其一
  31. * @apiGroup Chapter
  32. * @apiName getCatalog
  33. * @apiSuccess {int} code 状态码
  34. * @apiSuccess {String} msg 信息
  35. * @apiSuccess {object} data 结果集
  36. * @apiSuccess {Array} data.list 分页结果集
  37. * @apiSuccess {Int} data.list.bid bid
  38. * @apiSuccess {Int} data.list.chapter_id 章节id
  39. * @apiSuccess {String} data.list.chapter_name 章节名称
  40. * @apiSuccess {Int} data.list.chapter_sequence 序号
  41. * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
  42. * @apiSuccess {Int} data.list.chapter_size 章节大小
  43. * @apiSuccess {Int} data.list.prev_cid 上一章节id
  44. * @apiSuccess {Int} data.list.next_cid 下一章节
  45. * @apiSuccess {String} data.list.recent_update_at 更新时间
  46. * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
  47. * @apiSuccess {object} data.meta 分页信息
  48. * @apiSuccess {Int} data.meta.total 总条数
  49. * @apiSuccess {Int} data.meta.per_page 每页条数
  50. * @apiSuccess {Int} data.meta.current_page 当前页
  51. * @apiSuccess {Int} data.meta.last_page 最后页
  52. * @apiSuccess {String} data.meta.next_page_url 下一页
  53. * @apiSuccess {String} data.meta.prev_page_url 上一页
  54. * @apiSuccessExample {json} Success-Response:
  55. * HTTP/1.1 200 OK
  56. * {
  57. * code: 0,
  58. * msg: "",
  59. * data:
  60. * [
  61. * {
  62. * bid: 5,
  63. * chapter_id: 5,
  64. * chapter_name: "第1240章 不是我",
  65. * chapter_sequence: 1239,
  66. * chapter_is_vip: 1,
  67. * chapter_size: 2422,
  68. * prev_cid: 0,
  69. * next_cid: 0,
  70. * recent_update_at: 2017-11-20 15:01:56,
  71. * is_need_subscirbe: 1,
  72. * },
  73. * {
  74. * bid: 5,
  75. * chapter_id: 5,
  76. * chapter_name: "第1240章 不是我",
  77. * chapter_sequence: 1239,
  78. * chapter_is_vip: 1,
  79. * chapter_size: 2422,
  80. * prev_cid: 0,
  81. * next_cid: 0,
  82. * recent_update_at: 2017-11-20 15:01:56,
  83. * is_need_subscirbe: 1,
  84. * },
  85. * ]
  86. * }
  87. */
  88. public function getCatalog(Request $request, $bid)
  89. {
  90. $bid = BookService::decodeBidStatic($bid);
  91. $lists = ChapterService::getChapterLists($bid);
  92. $book_info = BookConfigService::getBookById($bid);
  93. if (!$book_info) {
  94. return response()->error('PARAM_ERROR');
  95. }
  96. $this->book_info = $book_info;
  97. $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
  98. foreach ($lists as $v) {
  99. $v->is_show_price = $is_show_price;
  100. $v->price = '';
  101. if ($is_show_price) {
  102. $v->price = $this->getPrice($book_info, $v);
  103. }
  104. if ($v->sequence == $book_info->force_subscribe_chapter_seq) {
  105. $v->is_need_subscirb = 1;
  106. } else {
  107. $v->is_need_subscirb = 0;
  108. }
  109. }
  110. return response()->collection(new ChapterListTransformer, $lists);
  111. }
  112. /**
  113. * @apiVersion 1.0.0
  114. * @apiDescription 章节列表分页
  115. * @api {get} books/{bid}/catalog 章节列表分页
  116. * @apiParam {String} [token] token
  117. * @apiHeader {String} [Authorization] token 两个token任选其一
  118. * @apiGroup Chapter
  119. * @apiName getCatalogPerPage
  120. * @apiParam {Int} page_size 分页大小(默认15)
  121. * @apiParam {Int} page 页码(默认1)
  122. * @apiSuccess {int} code 状态码
  123. * @apiSuccess {String} msg 信息
  124. * @apiSuccess {object} data 结果集
  125. * @apiSuccess {Array} data.list 分页结果集
  126. * @apiSuccess {Int} data.list.bid bid
  127. * @apiSuccess {Int} data.list.chapter_id 章节id
  128. * @apiSuccess {String} data.list.chapter_name 章节名称
  129. * @apiSuccess {Int} data.list.chapter_sequence 序号
  130. * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
  131. * @apiSuccess {Int} data.list.chapter_size 章节大小
  132. * @apiSuccess {Int} data.list.prev_cid 上一章节id
  133. * @apiSuccess {Int} data.list.next_cid 下一章节
  134. * @apiSuccess {String} data.list.recent_update_at 更新时间
  135. * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
  136. * @apiSuccess {object} data.meta 分页信息
  137. * @apiSuccess {Int} data.meta.total 总条数
  138. * @apiSuccess {Int} data.meta.per_page 每页条数
  139. * @apiSuccess {Int} data.meta.current_page 当前页
  140. * @apiSuccess {Int} data.meta.last_page 最后页
  141. * @apiSuccess {String} data.meta.next_page_url 下一页
  142. * @apiSuccess {String} data.meta.prev_page_url 上一页
  143. * @apiSuccessExample {json} Success-Response:
  144. * HTTP/1.1 200 OK
  145. * {
  146. * code: 0,
  147. * msg: "",
  148. * data:
  149. * list:[
  150. * {
  151. * bid: 5,
  152. * chapter_id: 5,
  153. * chapter_name: "第1240章 不是我",
  154. * chapter_sequence: 1239,
  155. * chapter_is_vip: 1,
  156. * chapter_size: 2422,
  157. * prev_cid: 0,
  158. * next_cid: 0,
  159. * recent_update_at: 2017-11-20 15:01:56,
  160. * is_need_subscirbe: 1,
  161. * },
  162. * {
  163. * bid: 5,
  164. * chapter_id: 5,
  165. * chapter_name: "第1240章 不是我",
  166. * chapter_sequence: 1239,
  167. * chapter_is_vip: 1,
  168. * chapter_size: 2422,
  169. * prev_cid: 0,
  170. * next_cid: 0,
  171. * recent_update_at: 2017-11-20 15:01:56,
  172. * is_need_subscirbe: 1,
  173. * },
  174. * ]
  175. * meta:{
  176. * total: 1253,
  177. * per_page: 15,
  178. * current_page: 1,
  179. * last_page: 84,
  180. * next_page_url: "http://myapi.cn/api/books/1/chapter?page=2",
  181. * prev_page_url: ""
  182. * }
  183. * }
  184. */
  185. public function getCatalogPerPage(Request $request, $bid)
  186. {
  187. $bid = BookService::decodeBidStatic($bid);
  188. $book_info = BookConfigService::getBookById($bid);
  189. if (!$book_info) {
  190. return response()->error('PARAM_ERROR');
  191. }
  192. $this->book_info = $book_info;
  193. $page_size = $request->input('page_size', 15);
  194. if ($page_size >= 100) $page_size = 100;
  195. $res = ChapterService::getChapterListsPage($bid, $page_size);
  196. $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
  197. foreach ($res as $v) {
  198. $v->is_show_price = $is_show_price;
  199. $v->price = '';
  200. if ($is_show_price) {
  201. $v->price = $this->getPrice($book_info, $v);
  202. }
  203. if ($v->sequence == $book_info->force_subscribe_chapter_seq) {
  204. $v->is_need_subscirb = 1;
  205. } else {
  206. $v->is_need_subscirb = 0;
  207. }
  208. }
  209. return response()->pagination(new ChapterListTransformer, $res);
  210. }
  211. /**
  212. * @apiVersion 1.0.0
  213. * @apiDescription 章节内容
  214. * @api {get} books/{bid}/chapters/{chapter_id} 章节内容
  215. * @apiParam {String} [token] token
  216. * @apiHeader {String} [Authorization] token 两个token任选其一
  217. * @apiGroup Chapter
  218. * @apiName index
  219. * @apiSuccess {int} code 状态码
  220. * @apiSuccess {String} msg 信息
  221. * @apiSuccess {object} data 结果集
  222. * @apiSuccess {Int} data.chapter_id 章节id
  223. * @apiSuccess {String} data.chapter_name 章节名称
  224. * @apiSuccess {Int} data.chapter_sequence 序号
  225. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  226. * @apiSuccess {Int} data.chapter_size 章节大小
  227. * @apiSuccess {Int} data.prev_cid 上一章节id
  228. * @apiSuccess {Int} data.next_cid 下一章节
  229. * @apiSuccess {String} data.recent_update_at 更新时间
  230. * @apiSuccess {String} data.chapter_content 章节内容
  231. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  232. * @apiSuccessExample {json} Success-Response:
  233. * HTTP/1.1 200 OK
  234. * {
  235. * code: 0,
  236. * msg: "",
  237. * data: {
  238. * chapter_id: 5,
  239. * chapter_name: "第1240章 不是我",
  240. * chapter_sequence: 1239,
  241. * chapter_is_vip: 1,
  242. * chapter_size: 2422,
  243. * prev_cid: 0,
  244. * next_cid: 0,
  245. * recent_update_at: 2017-11-20 15:01:56,
  246. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  247. * }
  248. * }
  249. */
  250. public function index(Request $request, $bid, $cid)
  251. {
  252. $oldbid = $bid;
  253. $bid = BookService::decodeBidStatic($bid);
  254. //获取图书信息
  255. $book_info = BookConfigService::getBookById($bid);
  256. if (empty($book_info))
  257. return response()->error('QAPP_SYS_ERROR');
  258. //获取章节信息
  259. $chapter = ChapterService::getChapterNameById($cid, $bid);
  260. if (!$chapter) {
  261. return response()->error('QAPP_SYS_ERROR');
  262. }
  263. if ($chapter->is_vip == 0) {
  264. ReadRecordService::addReadRecord([
  265. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  266. 'cid' => $cid, 'chapter_name' => $chapter->name
  267. ]);
  268. //用户标签
  269. if ($chapter->sequence >= 20) {
  270. $this->addTag($book_info);
  271. }
  272. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  273. }
  274. //已经付费
  275. if ($this->getOrderRecord($bid, $cid)) {
  276. ReadRecordService::addReadRecord([
  277. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  278. 'cid' => $cid, 'chapter_name' => $chapter->name
  279. ]);
  280. //用户标签
  281. if ($chapter->sequence >= 20) {
  282. $this->addTag($book_info);
  283. }
  284. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  285. }
  286. //未付费 要提醒
  287. $user_info = $this->_user_info;
  288. //未付费 余额不足
  289. $fee = $this->getPrice($book_info, $chapter->size);
  290. $data = [
  291. 'book_id' => $oldbid,
  292. 'book_name' => $book_info->book_name,
  293. 'chapter_name' => $chapter->name,
  294. 'chapter_id' => $cid,
  295. 'pay_type' => $book_info->charge_type,
  296. 'fee' => $fee,
  297. 'user_balance' => $user_info->balance,
  298. 'product_id' => $book_info->product_id,
  299. 'uid' => $this->uid,
  300. 'distribution_channel_id' => $this->distribution_channel_id,
  301. 'is_discount' => 0,
  302. 'discount_fee' => '',
  303. 'discount' => ''
  304. ];
  305. if ($user_info['balance'] < $fee) {
  306. //需要提箱
  307. if ($this->isOrderRemind($bid)) {
  308. if ($book_info->charge_type == 'BOOK') {
  309. return response()->error('QAPP_BOOK_BALANCE_PAY', $data);
  310. } else
  311. if ($book_info->charge_type == 'CHAPTER') {
  312. return response()->error('QAPP_CHAPTER_INSUFFICIENT_BALANCE', $data);
  313. } else {
  314. return response()->error('QAPP_SYS_ERROR');
  315. }
  316. } else {
  317. //不需要提醒
  318. if ($book_info->charge_type == 'BOOK') {
  319. return response()->error('QAPP_BOOK_SECOND_BALANCE_PAY', $data);
  320. } elseif ($book_info->charge_type == 'CHAPTER') {
  321. return response()->error('QAPP_CHAPTER_SECOND_BALANCE_PAY', $data);
  322. } else {
  323. return response()->error('QAPP_SYS_ERROR');
  324. }
  325. }
  326. }
  327. if ($this->isOrderRemind($bid)) {
  328. if ($book_info->charge_type == 'BOOK') {
  329. return response()->error('QAPP_BOOK_BUY', $data);
  330. } else
  331. if ($book_info->charge_type == 'CHAPTER') {
  332. return response()->error('QAPP_CHAPTER_BUY', $data);
  333. } else {
  334. return response()->error('QAPP_SYS_ERROR');
  335. }
  336. }
  337. //付费 不提醒
  338. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
  339. ReadRecordService::addReadRecord([
  340. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  341. 'cid' => $cid, 'chapter_name' => $chapter->name
  342. ]);
  343. //用户标签
  344. if ($chapter->sequence >= 20) {
  345. $this->addTag($book_info);
  346. }
  347. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  348. } else {
  349. //不需要提醒
  350. if ($book_info->charge_type == 'BOOK') {
  351. return response()->error('QAPP_BOOK_SECOND_BALANCE_PAY', $data);
  352. } elseif ($book_info->charge_type == 'CHAPTER') {
  353. return response()->error('QAPP_CHAPTER_SECOND_BALANCE_PAY', $data);
  354. } else {
  355. return response()->error('QAPP_SYS_ERROR');
  356. }
  357. }
  358. }
  359. /**
  360. * @apiVersion 1.0.0
  361. * @apiDescription 余额支付
  362. * @api {get} books/{bid}/balance/chapterOrders/{cid} 余额支付
  363. * @apiParam {String} [token] token
  364. * @apiHeader {String} [Authorization] token 两个token任选其一
  365. * @apiGroup Chapter
  366. * @apiName pay
  367. * @apiParam (Int) remind 提醒
  368. * @apiSuccess {int} code 状态码
  369. * @apiSuccess {String} msg 信息
  370. * @apiSuccess {object} data 结果集
  371. * @apiSuccess {Int} data.chapter_id 章节id
  372. * @apiSuccess {String} data.chapter_name 章节名称
  373. * @apiSuccess {Int} data.chapter_sequence 序号
  374. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  375. * @apiSuccess {Int} data.chapter_size 章节大小
  376. * @apiSuccess {Int} data.prev_cid 上一章节id
  377. * @apiSuccess {Int} data.next_cid 下一章节
  378. * @apiSuccess {String} data.recent_update_at 更新时间
  379. * @apiSuccess {String} data.chapter_content 章节内容
  380. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  381. * @apiSuccessExample {json} Success-Response:
  382. * HTTP/1.1 200 OK
  383. * {
  384. * code: 0,
  385. * msg: "",
  386. * data: {
  387. * chapter_id: 5,
  388. * chapter_name: "第1240章 不是我",
  389. * chapter_sequence: 1239,
  390. * chapter_is_vip: 1,
  391. * chapter_size: 2422,
  392. * prev_cid: 0,
  393. * next_cid: 0,
  394. * recent_update_at: 2017-11-20 15:01:56,
  395. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  396. * }
  397. * }
  398. */
  399. public function pay(Request $request, $bid, $cid)
  400. {
  401. $remind = (int) $request->input('remind');
  402. $oldbid = $bid;
  403. $bid = BookService::decodeBidStatic($bid);
  404. $book_info = BookConfigService::getBookById($bid);;
  405. if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
  406. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  407. if (!$this->isBookOrdered($bid)) {
  408. response()->error('QAPP_OFF_SHELF');
  409. }
  410. }
  411. //获取章节
  412. $chapter = ChapterService::getChapterNameById($cid, $bid);
  413. if (!$chapter) {
  414. return response()->error('QAPP_SYS_ERROR');
  415. }
  416. if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, $remind)) {
  417. ReadRecordService::addReadRecord([
  418. 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  419. 'cid' => $cid, 'chapter_name' => $chapter->name
  420. ]);
  421. //用户标签
  422. if ($chapter->sequence >= 20) {
  423. $this->addTag($book_info);
  424. }
  425. return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
  426. } else {
  427. $fee = $this->getPrice($book_info, $chapter->size);
  428. $data = [
  429. 'book_id' => $oldbid,
  430. 'book_name' => $book_info->book_name,
  431. 'chapter_name' => $chapter->name,
  432. 'chapter_id' => $cid,
  433. 'pay_type' => $book_info->charge_type,
  434. 'fee' => $fee,
  435. 'user_balance' => $this->_user_info['balance'],
  436. 'product_id' => $book_info->product_id,
  437. 'uid' => $this->uid,
  438. 'distribution_channel_id' => $this->distribution_channel_id,
  439. 'is_discount' => 0,
  440. 'discount_fee' => '',
  441. 'discount' => ''
  442. ];
  443. //不需要提醒
  444. if ($book_info->charge_type == 'BOOK') {
  445. return response()->error('QAPP_BOOK_SECOND_BALANCE_PAY', $data);
  446. } elseif ($book_info->charge_type == 'CHAPTER') {
  447. return response()->error('QAPP_CHAPTER_SECOND_BALANCE_PAY', $data);
  448. } else {
  449. return response()->error('QAPP_SYS_ERROR');
  450. }
  451. }
  452. }
  453. /**
  454. * 余额支付
  455. * @param $book_info
  456. * @param $chapter_id
  457. * @param $chapter_size
  458. * @return bool
  459. */
  460. protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
  461. {
  462. $fee = $this->getPrice($book_info, $chapter_size);
  463. if ((int) $this->_user_info['balance'] >= $fee) {
  464. if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
  465. return true;
  466. }
  467. return false;
  468. } else {
  469. return false;
  470. }
  471. }
  472. /**
  473. * 获取章节内容
  474. * @param $bid
  475. * @param $cid
  476. * @return bool|mixed
  477. */
  478. protected function getChapter($bid, $cid, $chapter)
  479. {
  480. $chapter_content = ChapterService::getChapter($bid, $cid);
  481. if (!$chapter_content) return false;
  482. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  483. //统计点击率
  484. $key = 'book_click_num_bid_' . $bid;
  485. $field = date('Y-m-d');
  486. $old = Redis::hget($key, $field);
  487. if (!$old) $old = 0;
  488. Redis::hset($key, $field, $old + 1);
  489. return $chapter;
  490. }
  491. /**
  492. * 添加订购记录
  493. * @param $book_info
  494. * @param $chapter_id
  495. * @param $fee
  496. * @return bool
  497. */
  498. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  499. {
  500. $send_order_id = 0;
  501. if ($book_info['charge_type'] == 'BOOK') {
  502. $data = [
  503. 'uid' => $this->uid,
  504. 'fee' => $fee,
  505. 'u' => $send_order_id,
  506. 'distribution_channel_id' => $this->distribution_channel_id,
  507. 'bid' => $book_info->bid,
  508. 'book_name' => $book_info->book_name,
  509. 'send_order_id' => $send_order_id,
  510. ];
  511. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  512. } else {
  513. $data = [
  514. 'uid' => $this->uid,
  515. 'fee' => $fee,
  516. 'cid' => $chapter_id,
  517. 'bid' => $book_info->bid,
  518. 'distribution_channel_id' => $this->distribution_channel_id,
  519. 'book_name' => $book_info->book_name,
  520. 'chapter_name' => $chapter_name,
  521. 'send_order_id' => $send_order_id,
  522. 'is_remind' => $is_remind
  523. ];
  524. //print_r($data);
  525. if ($is_remind) {
  526. $this->addOrderRemind($book_info->bid);
  527. }
  528. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  529. }
  530. }
  531. protected function addOrderRemind($bid)
  532. {
  533. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  534. return true;
  535. } else {
  536. ChapterReminderService::add($this->uid, $bid);
  537. return true;
  538. }
  539. }
  540. /**
  541. * 是否订购提醒
  542. * @param $chapter_id
  543. * @return bool
  544. */
  545. protected function isOrderRemind($bid)
  546. {
  547. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  548. return $is_no_reminder == 0;
  549. }
  550. /**
  551. * 用户是否关注
  552. * @param $uid
  553. * @return bool
  554. */
  555. protected function getSubscribe()
  556. {
  557. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  558. if ($res) return true;
  559. return false;
  560. }
  561. /**
  562. * 获取订购记录
  563. * @param $book_info
  564. * @param $chapter_id
  565. * @return bool
  566. */
  567. protected function getOrderRecord($bid, $chapter_id)
  568. {
  569. //包年记录
  570. $uid = $this->uid;
  571. $res = YearOrderService::getRecord($uid);
  572. if ($res) return true;
  573. $res = null;
  574. //单本订购记录
  575. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  576. if ($res) return true;
  577. $res = null;
  578. //章节订购记录
  579. $chapterOrder = new ChapterOrderService();
  580. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  581. return false;
  582. }
  583. /**
  584. * 计算价格
  585. * @param $book_info
  586. * @param $chapter_size
  587. * @return float
  588. */
  589. protected function getPrice($book_info, $chapter_size)
  590. {
  591. if ($book_info->charge_type == 'BOOK')
  592. return $book_info->price * 100;
  593. return ceil($chapter_size / 100);
  594. }
  595. /**
  596. * 用户添加标签
  597. * @param $book_info
  598. */
  599. protected function addTag($book_info)
  600. {
  601. $send_order_id = 0;
  602. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  603. try {
  604. UserDeepReadTagService::addTag([
  605. 'uid' => $this->uid,
  606. 'bid' => $book_info->bid,
  607. 'book_name' => $book_info->book_name,
  608. 'category_id' => $book_info->category_id,
  609. 'category_name' => $book_info->category_name,
  610. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  611. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  612. 'send_order_id' => $send_order_id,
  613. ]);
  614. } catch (\Exception $e) { }
  615. }
  616. }
  617. protected function isBookOrdered($bid)
  618. {
  619. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  620. if ($chapter_order) return true;
  621. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  622. if ($res) return true;
  623. return false;
  624. }
  625. private function showChapterPrice($bid, $charge_type)
  626. {
  627. if ($charge_type == 'BOOK') {
  628. return false;
  629. }
  630. $show_chapter_price_bid = env('SHOW_CHAPTER_PRICE_BID', 'all');
  631. if ($show_chapter_price_bid != 'all') {
  632. $show_chapter_price_bid_array = explode(',', $show_chapter_price_bid);
  633. if (!in_array($bid, $show_chapter_price_bid_array)) {
  634. return false;
  635. }
  636. }
  637. $show_chapter_price_channel = env('SHOW_CHAPTER_PRICE_CHANNEL', '');
  638. if (!$show_chapter_price_channel) {
  639. return false;
  640. }
  641. if ($show_chapter_price_channel == 'all') {
  642. return true;
  643. }
  644. $show_chapter_price_channel_array = explode(',', $show_chapter_price_channel);
  645. if (in_array($this->distribution_channel_id, $show_chapter_price_channel_array)) {
  646. return true;
  647. }
  648. return false;
  649. }
  650. }