ChapterController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. namespace App\Http\Controllers\KuaiYingYong\Book;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\KuaiYingYong\BaseController;
  5. use Redis;
  6. use App\Modules\Book\Services\ChapterService;
  7. use App\Modules\User\Services\ReadRecordService;
  8. use App\Http\Controllers\KuaiYingYong\Book\Transformers\ChapterTransformer;
  9. use App\Modules\Book\Services\BookConfigService;
  10. use App\Http\Controllers\KuaiYingYong\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. if(!$this->checkUid()){
  216. return response()->error('XCX_NOT_LOGIN');
  217. }
  218. $oldbid = $bid;
  219. $bid = Hashids::decode($bid)[0];
  220. //获取图书信息
  221. $book_info = BookConfigService::getBookById($bid);
  222. if(empty($book_info)) return response()->error('XCX_SYS_ERROR');
  223. if($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3){
  224. //return response()->error('XCX_OFF_SHELF');
  225. }
  226. //获取章节信息
  227. $chapter = ChapterService::getChapterNameById($cid,$bid);
  228. if(!$chapter){
  229. return response()->error('XCX_SYS_ERROR');
  230. }
  231. if($chapter->is_vip == 0){
  232. ReadRecordService::addReadRecord(['uid'=>$this->uid,'bid'=>$bid,'book_name'=>$book_info->book_name,
  233. 'cid'=>$cid,'chapter_name'=>$chapter->name ]);
  234. //用户标签
  235. if($chapter->sequence >= 20){
  236. $this->addTag($book_info);
  237. }
  238. return response()->item(new ChapterTransformer,$this->getChapter($bid,$cid,$chapter));
  239. }
  240. //已经付费
  241. if($this->getOrderRecord($bid,$cid)){
  242. ReadRecordService::addReadRecord(['uid'=>$this->uid,'bid'=>$bid,'book_name'=>$book_info->book_name,
  243. 'cid'=>$cid,'chapter_name'=>$chapter->name ]);
  244. //用户标签
  245. if($chapter->sequence >= 20){
  246. $this->addTag($book_info);
  247. }
  248. return response()->item(new ChapterTransformer,$this->getChapter($bid,$cid,$chapter));
  249. }
  250. //未付费 要提醒
  251. $user_info = $this->_user_info;
  252. //未付费 余额不足
  253. $fee = $this->getPrice($book_info,$chapter->size);
  254. $data = [
  255. 'book_id'=>$oldbid,
  256. 'book_name'=>$book_info->book_name,
  257. 'chapter_name'=>$chapter->name,
  258. 'chapter_id'=>$cid,
  259. 'pay_type'=>$book_info->charge_type,
  260. 'fee'=>$fee,
  261. 'user_balance'=>$user_info->balance,
  262. 'product_id'=>$book_info->product_id,
  263. 'uid'=>$this->uid,
  264. 'distribution_channel_id'=>$this->distribution_channel_id,
  265. 'is_discount'=>0,
  266. 'discount_fee' => '',
  267. 'discount'=>''
  268. ];
  269. if($user_info['balance'] < $fee){
  270. //需要提箱
  271. if($this->isOrderRemind($bid)){
  272. if($book_info->charge_type == 'BOOK'){
  273. return response()->error('XCX_BOOK_BALANCE_PAY',$data);
  274. }else
  275. if($book_info->charge_type == 'CHAPTER'){
  276. return response()->error('XCX_CHAPTER_INSUFFICIENT_BALANCE',$data);
  277. }else{
  278. return response()->error('XCX_SYS_ERROR');
  279. }
  280. }else{
  281. //不需要提醒
  282. if($book_info->charge_type == 'BOOK'){
  283. return response()->error('XCX_BOOK_SECOND_BALANCE_PAY',$data);
  284. }elseif($book_info->charge_type == 'CHAPTER'){
  285. return response()->error('XCX_CHAPTER_SECOND_BALANCE_PAY',$data);
  286. }else{
  287. return response()->error('XCX_SYS_ERROR');
  288. }
  289. }
  290. }
  291. if($this->isOrderRemind($bid)){
  292. //return response()->error('INSUFFICIENT_BALANCE',$data);
  293. if($book_info->charge_type == 'BOOK'){
  294. return response()->error('XCX_BOOK_BUY',$data);
  295. }else
  296. if($book_info->charge_type == 'CHAPTER'){
  297. return response()->error('XCX_CHAPTER_BUY',$data);
  298. }else{
  299. return response()->error('XCX_SYS_ERROR');
  300. }
  301. }
  302. //付费 不提醒
  303. if($this->balancePay($book_info,$cid,$chapter->size,$chapter->name,0)){
  304. ReadRecordService::addReadRecord(['uid'=>$this->uid,'bid'=>$bid,'book_name'=>$book_info->book_name,
  305. 'cid'=>$cid,'chapter_name'=>$chapter->name ]);
  306. //用户标签
  307. if($chapter->sequence >= 20){
  308. $this->addTag($book_info);
  309. }
  310. return response()->item(new ChapterTransformer,$this->getChapter($bid,$cid,$chapter));
  311. }else{
  312. //不需要提醒
  313. if($book_info->charge_type == 'BOOK'){
  314. return response()->error('XCX_BOOK_SECOND_BALANCE_PAY',$data);
  315. }elseif($book_info->charge_type == 'CHAPTER'){
  316. return response()->error('XCX_CHAPTER_SECOND_BALANCE_PAY',$data);
  317. }else{
  318. return response()->error('XCX_SYS_ERROR');
  319. }
  320. }
  321. }
  322. /**
  323. * @apiVersion 1.0.0
  324. * @apiDescription 余额支付
  325. * @api {get} books/{bid}/balance/chapterOrders/{cid} 余额支付
  326. * @apiParam {String} [token] token
  327. * @apiHeader {String} [Authorization] token 两个token任选其一
  328. * @apiGroup Chapter
  329. * @apiName pay
  330. * @apiParam (Int) remind 提醒
  331. * @apiSuccess {int} code 状态码
  332. * @apiSuccess {String} msg 信息
  333. * @apiSuccess {object} data 结果集
  334. * @apiSuccess {Int} data.chapter_id 章节id
  335. * @apiSuccess {String} data.chapter_name 章节名称
  336. * @apiSuccess {Int} data.chapter_sequence 序号
  337. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  338. * @apiSuccess {Int} data.chapter_size 章节大小
  339. * @apiSuccess {Int} data.prev_cid 上一章节id
  340. * @apiSuccess {Int} data.next_cid 下一章节
  341. * @apiSuccess {String} data.recent_update_at 更新时间
  342. * @apiSuccess {String} data.chapter_content 章节内容
  343. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  344. * @apiSuccessExample {json} Success-Response:
  345. * HTTP/1.1 200 OK
  346. * {
  347. * code: 0,
  348. * msg: "",
  349. * data: {
  350. * chapter_id: 5,
  351. * chapter_name: "第1240章 不是我",
  352. * chapter_sequence: 1239,
  353. * chapter_is_vip: 1,
  354. * chapter_size: 2422,
  355. * prev_cid: 0,
  356. * next_cid: 0,
  357. * recent_update_at: 2017-11-20 15:01:56,
  358. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  359. * }
  360. * }
  361. */
  362. public function pay(Request $request,$bid,$cid){
  363. if(!$this->checkUid()){
  364. return response()->error('XCX_NOT_LOGIN');
  365. }
  366. $remind = (int)$request->input('remind');
  367. $oldbid = $bid;
  368. $bid = Hashids::decode($bid)[0];
  369. $book_info = BookConfigService::getBookById($bid);;
  370. if(empty($book_info)) response()->error('XCX_SYS_ERROR');
  371. if($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3){
  372. if(!$this->isBookOrdered($bid)){
  373. response()->error('XCX_OFF_SHELF');
  374. }
  375. }
  376. //获取章节
  377. $chapter = ChapterService::getChapterNameById($cid,$bid);
  378. if(!$chapter){
  379. return response()->error('XCX_SYS_ERROR');
  380. }
  381. if($this->balancePay($book_info,$cid,$chapter->size,$chapter->name,$remind)){
  382. ReadRecordService::addReadRecord(['uid'=>$this->uid,'bid'=>$bid,'book_name'=>$book_info->book_name,
  383. 'cid'=>$cid,'chapter_name'=>$chapter->name ]);
  384. //用户标签
  385. if($chapter->sequence >= 20){
  386. $this->addTag($book_info);
  387. }
  388. return response()->item(new ChapterTransformer,$this->getChapter($bid,$cid,$chapter));
  389. }else{
  390. $fee = $this->getPrice($book_info,$chapter->size);
  391. $data = [
  392. 'book_id'=>$oldbid,
  393. 'book_name'=>$book_info->book_name,
  394. 'chapter_name'=>$chapter->name,
  395. 'chapter_id'=>$cid,
  396. 'pay_type'=>$book_info->charge_type,
  397. 'fee'=>$fee,
  398. 'user_balance'=>$this->_user_info['balance'],
  399. 'product_id'=>$book_info->product_id,
  400. 'uid'=>$this->uid,
  401. 'distribution_channel_id'=>$this->distribution_channel_id,
  402. 'is_discount'=>0,
  403. 'discount_fee' => '',
  404. 'discount'=>''
  405. ];
  406. //不需要提醒
  407. if($book_info->charge_type == 'BOOK'){
  408. return response()->error('XCX_BOOK_SECOND_BALANCE_PAY',$data);
  409. }elseif($book_info->charge_type == 'CHAPTER'){
  410. return response()->error('XCX_CHAPTER_SECOND_BALANCE_PAY',$data);
  411. }else{
  412. return response()->error('XCX_SYS_ERROR');
  413. }
  414. }
  415. }
  416. /**
  417. * 余额支付
  418. * @param $book_info
  419. * @param $chapter_id
  420. * @param $chapter_size
  421. * @return bool
  422. */
  423. protected function balancePay($book_info,$chapter_id,$chapter_size,$chapter_name,$is_remind){
  424. $fee = $this->getPrice($book_info,$chapter_size);
  425. if((int)$this->_user_info['balance'] >= $fee){
  426. if($this->bookOrderOrChapterOrder($book_info,$chapter_id,$fee,$chapter_name,$is_remind)){
  427. return true;
  428. }
  429. return false;
  430. }else{
  431. return false;
  432. }
  433. }
  434. /**
  435. * 获取章节内容
  436. * @param $bid
  437. * @param $cid
  438. * @return bool|mixed
  439. */
  440. protected function getChapter($bid,$cid,$chapter){
  441. $chapter_content = ChapterService::getChapter($bid,$cid);
  442. if(!$chapter_content) return false;
  443. //$chapter->content = $chapter_content->content;
  444. $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
  445. //统计点击率
  446. $key = 'book_click_num_bid_'.$bid;
  447. $field = date('Y-m-d');
  448. $old = Redis::hget($key,$field);
  449. if(!$old) $old = 0;
  450. Redis::hset($key,$field,$old+1);
  451. //签到奖励
  452. /*
  453. $sign_key = 'sign-'.date('Y-m-d');
  454. $sign_status = 0;
  455. if(!Redis::hexists($sign_key,$this->uid)){
  456. Redis::hset($sign_key,$this->uid,time());
  457. $sign_status = 1;
  458. }*/
  459. $sign_status = $this->userSign($this->uid);
  460. $chapter->sign_status = $sign_status;
  461. return $chapter;
  462. }
  463. /**
  464. * 签到
  465. * @param $uid
  466. * @return int
  467. */
  468. protected function userSign($uid){
  469. if($this->distribution_channel_id != 5){
  470. return 0;
  471. }
  472. $day = date('Y-m-d');
  473. if(UserSignService::isSign($uid,$day)){
  474. return 0;
  475. }
  476. if(UserSignService::sign($uid,$day)){
  477. return 1;
  478. }
  479. return 0;
  480. }
  481. /**
  482. * 添加订购记录
  483. * @param $book_info
  484. * @param $chapter_id
  485. * @param $fee
  486. * @return bool
  487. */
  488. protected function bookOrderOrChapterOrder($book_info,$chapter_id,$fee,$chapter_name,$is_remind){
  489. $send_order_id = 0;
  490. if($book_info['charge_type'] == 'BOOK'){
  491. $data = [
  492. 'uid'=>$this->uid,
  493. 'fee'=>$fee,
  494. 'u'=>$send_order_id,
  495. 'distribution_channel_id'=>$this->distribution_channel_id,
  496. 'bid'=>$book_info->bid,
  497. 'book_name'=>$book_info->book_name,
  498. 'send_order_id'=>$send_order_id,
  499. ];
  500. return BookOrderService::addOrderRecodeAndDecrUserBalance($data,$this->uid);
  501. }
  502. else{
  503. $data = [
  504. 'uid'=>$this->uid,
  505. 'fee'=>$fee,
  506. 'cid'=>$chapter_id,
  507. 'bid'=>$book_info->bid,
  508. 'distribution_channel_id'=>$this->distribution_channel_id,
  509. 'book_name'=>$book_info->book_name,
  510. 'chapter_name'=>$chapter_name,
  511. 'send_order_id'=>$send_order_id,
  512. 'is_remind'=>$is_remind
  513. ];
  514. //print_r($data);
  515. if($is_remind){
  516. $this->addOrderRemind($book_info->bid);
  517. }
  518. return ChapterOrderService::addOrderAndDecrUserBalance($data,$this->uid);
  519. }
  520. }
  521. protected function addOrderRemind($bid){
  522. if(ChapterReminderService::checkIsNoReminder($this->uid,$bid)){
  523. return true;
  524. }else{
  525. ChapterReminderService::add($this->uid,$bid);
  526. return true;
  527. }
  528. }
  529. /**
  530. * 是否订购提醒
  531. * @param $chapter_id
  532. * @return bool
  533. */
  534. protected function isOrderRemind($bid){
  535. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid,$bid) ? 1 : 0;
  536. return $is_no_reminder == 0;
  537. }
  538. /**
  539. * 用户是否关注
  540. * @param $uid
  541. * @return bool
  542. */
  543. protected function getSubscribe(){
  544. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid'=>$this->uid]);
  545. if($res) return true;
  546. return false;
  547. }
  548. /**
  549. * 获取订购记录
  550. * @param $book_info
  551. * @param $chapter_id
  552. * @return bool
  553. */
  554. protected function getOrderRecord($bid,$chapter_id){
  555. //包年记录
  556. $uid = $this->uid;
  557. $res = YearOrderService::getRecord($uid);
  558. if($res) return true;
  559. $res = null;
  560. //单本订购记录
  561. $res = BookOrderService::getRecordByuidBid($uid,$bid);
  562. if($res) return true;
  563. $res = null;
  564. //章节订购记录
  565. $chapterOrder = new ChapterOrderService();
  566. if($chapterOrder->checkIsOrdered($uid,$bid,$chapter_id)) return true;
  567. return false;
  568. }
  569. /**
  570. * 计算价格
  571. * @param $book_info
  572. * @param $chapter_size
  573. * @return float
  574. */
  575. protected function getPrice($book_info,$chapter_size){
  576. if($book_info->charge_type == 'BOOK')
  577. return $book_info->price*100;
  578. return ceil($chapter_size/100);
  579. }
  580. /**
  581. * 用户添加标签
  582. * @param $book_info
  583. */
  584. protected function addTag($book_info){
  585. $send_order_id = 0;
  586. if(!UserDeepReadTagService::isAddTag($this->uid,$book_info->bid)){
  587. try{
  588. UserDeepReadTagService::addTag([
  589. 'uid'=>$this->uid,
  590. 'bid'=>$book_info->bid,
  591. 'book_name'=>$book_info->book_name,
  592. 'category_id'=>$book_info->category_id,
  593. 'category_name'=>$book_info->category_name,
  594. 'sex_preference'=>$book_info->channel_name?$book_info->channel_name:'',
  595. 'distribution_channel_id'=>$this->distribution_channel_id?$this->distribution_channel_id:'0',
  596. 'send_order_id'=>$send_order_id,
  597. ]);
  598. }catch (\Exception $e){
  599. }
  600. }
  601. }
  602. protected function isBookOrdered($bid){
  603. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid,$bid);
  604. if($chapter_order) return true;
  605. $res = BookOrderService::getRecordByuidBid($this->uid,$bid);
  606. if($res) return true;
  607. return false;
  608. }
  609. }