ChapterController.php 24 KB

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