ChapterController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. namespace App\Http\Controllers\Wap\Book;
  3. use App\Modules\Book\Services\BookService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Wap\BaseController;
  6. use Cookie;
  7. use Redis;
  8. use App\Modules\Book\Services\ChapterService;
  9. use App\Modules\User\Services\ReadRecordService;
  10. use App\Http\Controllers\Wap\Book\Transformers\ChapterTransformer;
  11. use App\Modules\Book\Services\BookConfigService;
  12. use App\Http\Controllers\Wap\Book\Transformers\ChapterListTransformer;
  13. use App\Modules\Subscribe\Services\BookOrderService;
  14. use App\Modules\Subscribe\Services\ChapterOrderService;
  15. use App\Modules\Subscribe\Services\YearOrderService;
  16. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  17. use App\Modules\Subscribe\Services\ChapterReminderService;
  18. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  19. use Hashids;
  20. use GuzzleHttp\Client;
  21. use Log;
  22. use DB;
  23. use App\Modules\User\Services\UserSignService;
  24. use App\Modules\SendOrder\Services\SendOrderService;
  25. use App\Modules\User\Services\UserDeepReadTagService;
  26. use App\Modules\Book\Services\BookSubscribleChapterService;
  27. use App\Modules\Channel\Services\ChannelSubscribeSettingService;
  28. class ChapterController extends BaseController
  29. {
  30. /**
  31. * @apiDefine Chapter 章节
  32. */
  33. /**
  34. * @apiVersion 1.0.0
  35. * @apiDescription 章节列表不分页
  36. * @api {get} books/{bid}/allcatalog 章节列表不分页
  37. * @apiGroup Chapter
  38. * @apiName getCatalog
  39. * @apiSuccess {int} code 状态码
  40. * @apiSuccess {String} msg 信息
  41. * @apiSuccess {object} data 结果集
  42. * @apiSuccess {Array} data.list 分页结果集
  43. * @apiSuccess {Int} data.list.bid bid
  44. * @apiSuccess {Int} data.list.chapter_id 章节id
  45. * @apiSuccess {String} data.list.chapter_name 章节名称
  46. * @apiSuccess {Int} data.list.chapter_sequence 序号
  47. * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
  48. * @apiSuccess {Int} data.list.chapter_size 章节大小
  49. * @apiSuccess {Int} data.list.prev_cid 上一章节id
  50. * @apiSuccess {Int} data.list.next_cid 下一章节
  51. * @apiSuccess {String} data.list.recent_update_at 更新时间
  52. * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
  53. * @apiSuccess {String} data.list.is_show_price 是否显示价格
  54. * @apiSuccess {String} data.list.price 价格
  55. * @apiSuccess {object} data.meta 分页信息
  56. * @apiSuccess {Int} data.meta.total 总条数
  57. * @apiSuccess {Int} data.meta.per_page 每页条数
  58. * @apiSuccess {Int} data.meta.current_page 当前页
  59. * @apiSuccess {Int} data.meta.last_page 最后页
  60. * @apiSuccess {String} data.meta.next_page_url 下一页
  61. * @apiSuccess {String} data.meta.prev_page_url 上一页
  62. * @apiSuccessExample {json} Success-Response:
  63. * HTTP/1.1 200 OK
  64. * {
  65. * code: 0,
  66. * msg: "",
  67. * data:
  68. * [
  69. * {
  70. * bid: 5,
  71. * chapter_id: 5,
  72. * chapter_name: "第1240章 不是我",
  73. * chapter_sequence: 1239,
  74. * chapter_is_vip: 1,
  75. * chapter_size: 2422,
  76. * prev_cid: 0,
  77. * next_cid: 0,
  78. * recent_update_at: 2017-11-20 15:01:56,
  79. * is_need_subscirbe: 1,
  80. * },
  81. * {
  82. * bid: 5,
  83. * chapter_id: 5,
  84. * chapter_name: "第1240章 不是我",
  85. * chapter_sequence: 1239,
  86. * chapter_is_vip: 1,
  87. * chapter_size: 2422,
  88. * prev_cid: 0,
  89. * next_cid: 0,
  90. * recent_update_at: 2017-11-20 15:01:56,
  91. * is_need_subscirbe: 1,
  92. * },
  93. * ]
  94. * }
  95. */
  96. public function getCatalog(Request $request, $t, $domain, $bid)
  97. {
  98. $bid = Hashids::decode($bid)[0];
  99. $lists = ChapterService::getChapterLists($bid);
  100. $book_info = BookConfigService::getBookById($bid);
  101. if(!$book_info){
  102. return response()->error('PARAM_ERROR');
  103. }
  104. $is_show_price = $this->showChapterPrice($bid,$book_info->charge_type);
  105. foreach ($lists as $v) {
  106. $v->is_show_price = $is_show_price;
  107. $v->price = '';
  108. if($is_show_price){
  109. $v->price = $this->getPrice($book_info,$v);
  110. }
  111. }
  112. return response()->collection(new ChapterListTransformer, $lists);
  113. }
  114. /**
  115. * @apiVersion 1.0.0
  116. * @apiDescription 章节列表分页
  117. * @api {get} books/{bid}/catalog 章节列表分页
  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 {String} data.list.is_show_price 是否显示价格
  137. * @apiSuccess {String} data.list.price 价格
  138. * @apiSuccess {object} data.meta 分页信息
  139. * @apiSuccess {Int} data.meta.total 总条数
  140. * @apiSuccess {Int} data.meta.per_page 每页条数
  141. * @apiSuccess {Int} data.meta.current_page 当前页
  142. * @apiSuccess {Int} data.meta.last_page 最后页
  143. * @apiSuccess {String} data.meta.next_page_url 下一页
  144. * @apiSuccess {String} data.meta.prev_page_url 上一页
  145. * @apiSuccessExample {json} Success-Response:
  146. * HTTP/1.1 200 OK
  147. * {
  148. * code: 0,
  149. * msg: "",
  150. * data:
  151. * list:[
  152. * {
  153. * bid: 5,
  154. * chapter_id: 5,
  155. * chapter_name: "第1240章 不是我",
  156. * chapter_sequence: 1239,
  157. * chapter_is_vip: 1,
  158. * chapter_size: 2422,
  159. * prev_cid: 0,
  160. * next_cid: 0,
  161. * recent_update_at: 2017-11-20 15:01:56,
  162. * is_need_subscirbe: 1,
  163. * },
  164. * {
  165. * bid: 5,
  166. * chapter_id: 5,
  167. * chapter_name: "第1240章 不是我",
  168. * chapter_sequence: 1239,
  169. * chapter_is_vip: 1,
  170. * chapter_size: 2422,
  171. * prev_cid: 0,
  172. * next_cid: 0,
  173. * recent_update_at: 2017-11-20 15:01:56,
  174. * is_need_subscirbe: 1,
  175. * },
  176. * ]
  177. * meta:{
  178. * total: 1253,
  179. * per_page: 15,
  180. * current_page: 1,
  181. * last_page: 84,
  182. * next_page_url: "http://myapi.cn/api/books/1/chapter?page=2",
  183. * prev_page_url: ""
  184. * }
  185. * }
  186. */
  187. public function getCatalogPerPage(Request $request, $t, $domain, $bid)
  188. {
  189. $bid_array = Hashids::decode($bid);
  190. if (isset($bid_array[0])) {
  191. $bid = $bid_array[0];
  192. } else {
  193. return response()->error('PARAM_ERROR');
  194. }
  195. $book_info = BookConfigService::getBookById($bid);
  196. if (!$book_info) {
  197. return response()->error('PARAM_ERROR');
  198. }
  199. $page_size = $request->input('page_size', 15);
  200. $res = ChapterService::getChapterListsPage($bid, $page_size);
  201. $is_show_price = $this->showChapterPrice($bid,$book_info->charge_type);
  202. foreach ($res as $v) {
  203. $v->is_show_price = $is_show_price;
  204. $v->price = '';
  205. if($is_show_price){
  206. $v->price = $this->getPrice($book_info,$v);
  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. * @apiGroup Chapter
  216. * @apiName index
  217. * @apiSuccess {int} code 状态码
  218. * @apiSuccess {String} msg 信息
  219. * @apiSuccess {object} data 结果集
  220. * @apiSuccess {Int} data.chapter_id 章节id
  221. * @apiSuccess {String} data.chapter_name 章节名称
  222. * @apiSuccess {Int} data.chapter_sequence 序号
  223. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  224. * @apiSuccess {Int} data.chapter_size 章节大小
  225. * @apiSuccess {Int} data.prev_cid 上一章节id
  226. * @apiSuccess {Int} data.next_cid 下一章节
  227. * @apiSuccess {String} data.recent_update_at 更新时间
  228. * @apiSuccess {String} data.chapter_content 章节内容
  229. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  230. * @apiSuccess {Int} data.is_show_subscribe_link 是否显示底部强关链接
  231. * @apiSuccessExample {json} Success-Response:
  232. * HTTP/1.1 200 OK
  233. * {
  234. * code: 0,
  235. * msg: "",
  236. * data: {
  237. * chapter_id: 5,
  238. * chapter_name: "第1240章 不是我",
  239. * chapter_sequence: 1239,
  240. * chapter_is_vip: 1,
  241. * chapter_size: 2422,
  242. * prev_cid: 0,
  243. * next_cid: 0,
  244. * recent_update_at: 2017-11-20 15:01:56,
  245. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  246. * }
  247. * }
  248. */
  249. public function index(Request $request, $t, $domain, $bid, $cid)
  250. {
  251. if (!$this->checkUid()) {
  252. return response()->error('WAP_NOT_LOGIN');
  253. }
  254. $oldbid = $bid;
  255. $bid = Hashids::decode($bid)[0];
  256. //获取图书信息
  257. $book_info = BookConfigService::getBookById($bid);
  258. if (empty($book_info)) return response()->error('WAP_SYS_ERROR');
  259. //图书域名,book_configs表的promotion_domain 要跟当前的主机名匹配
  260. if ($this->isVisitDomainEqualBookDomain($book_info->promotion_domain)) {
  261. $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0;
  262. //promotion_domain可以是多个,以逗号隔开
  263. $domain_head = explode('.', _domain());
  264. $book_domain = explode(',', $book_info->promotion_domain);
  265. $from_type = Cookie::get('from') ? Cookie::get('from') : 'main';
  266. $url = 'https://' . $domain_head[0] . '.' . $book_domain[0] . '/reader?bid=' . $oldbid . '&cid=' . $cid . '&send_order_id=' . $send_order_id . '&fromtype=' . $from_type;
  267. return response()->error('WAP_DOMAIN_NOT_MATCH', [
  268. 'url' => $url
  269. ]);
  270. }
  271. //下架图书不能看
  272. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  273. return response()->error('WAP_OFF_SHELF');
  274. }
  275. //屏蔽一本书
  276. if ($bid == 1042 && $this->distribution_channel_id == 123) {
  277. return response()->error('WAP_OFF_SHELF');
  278. }
  279. if ($book_info->is_on_shelf == 4) {
  280. //版权到期,有阅读记录还可以继续阅读,订购
  281. if (!ReadRecordService::getRecordByUidBid($this->uid, $bid)) {
  282. return response()->error('WAP_OFF_SHELF');
  283. }
  284. //版权到期 只可以阅读订购过的章节
  285. /*if (!$this->getOrderRecord($bid, $cid)) {
  286. return response()->error('WAP_OFF_SHELF');
  287. }*/
  288. }
  289. //获取章节信息
  290. $chapter = ChapterService::getChapterNameById($cid, $bid);
  291. if (!$chapter) {
  292. return response()->error('WAP_SYS_ERROR');
  293. }
  294. //阅读记录
  295. ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  296. 'cid' => $cid, 'chapter_name' => $chapter->name]);
  297. if ( $chapter->is_vip == 0) {
  298. $content = $this->getChapter($bid, $cid, $chapter, 0, 1);
  299. $content->is_had_subscribe = 0;
  300. return response()->item(new ChapterTransformer, $content);
  301. }
  302. //已经付费
  303. if ($this->getOrderRecord($bid, $cid)) {
  304. $content = $this->getChapter($bid, $cid, $chapter, 0, 0);
  305. $content->is_had_subscribe = 0;
  306. return response()->item(new ChapterTransformer, $content);
  307. }
  308. //以上都是不用付费的情况******************************************************
  309. //未付费
  310. $user_info = $this->_user_info;
  311. //获取价格
  312. $fee = $this->getPrice($book_info, $chapter);
  313. //返回的价格信息
  314. $data = [
  315. 'book_id' => $oldbid,
  316. 'book_name' => $book_info->book_name,
  317. 'chapter_name' => $chapter->name,
  318. 'chapter_id' => $cid,
  319. 'pay_type' => $book_info->charge_type,
  320. 'fee' => $fee,
  321. 'user_balance' => $user_info->balance,
  322. 'product_id' => $book_info->product_id,
  323. 'uid' => $this->uid,
  324. 'distribution_channel_id' => $this->distribution_channel_id,
  325. 'is_discount' => 0,
  326. 'discount_fee' => '',
  327. 'discount' => ''
  328. ];
  329. //余额不足 弹窗提醒
  330. if ($user_info['balance'] < $fee) {
  331. if ($book_info->charge_type == 'BOOK') {
  332. return response()->error('WAP_BOOK_BALANCE_PAY', $data);
  333. //return response()->error('WAP_BOOK_SECOND_BALANCE_PAY',$data);
  334. } else if ($book_info->charge_type == 'CHAPTER') {
  335. //return response()->error('WAP_CHAPTER_INSUFFICIENT_BALANCE',$data);
  336. return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
  337. } else {
  338. return response()->error('WAP_SYS_ERROR');
  339. }
  340. }
  341. //余额充足 单本弹窗提醒,章节直接扣费
  342. if ($this->isOrderRemind($bid) && $book_info->charge_type == 'BOOK') {
  343. return response()->error('WAP_BOOK_BUY', $data);
  344. }
  345. //付费 不提醒
  346. if ($this->balancePay($book_info, $chapter, 0)) {
  347. $content = $this->getChapter($bid, $cid, $chapter, 0, 1);
  348. $content->is_had_subscribe = 1;
  349. return response()->item(new ChapterTransformer, $content);
  350. } else {
  351. //不需要提醒
  352. if ($book_info->charge_type == 'BOOK') {
  353. return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
  354. } elseif ($book_info->charge_type == 'CHAPTER') {
  355. return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
  356. } else {
  357. return response()->error('WAP_SYS_ERROR');
  358. }
  359. }
  360. }
  361. /**
  362. * @apiVersion 1.0.0
  363. * @apiDescription 余额支付
  364. * @api {get} books/{bid}/balance/chapterOrders/{cid} 余额支付
  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, $t, $domain, $bid, $cid)
  400. {
  401. if (!$this->checkUid()) {
  402. return response()->error('NOT_LOGIN');
  403. }
  404. $remind = (int)$request->input('remind');
  405. $oldbid = $bid;
  406. $bid = Hashids::decode($bid)[0];
  407. $book_info = BookConfigService::getBookById($bid);;
  408. if (empty($book_info)) response()->error('WAP_SYS_ERROR');
  409. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  410. if (!$this->isBookOrdered($bid)) {
  411. response()->error('WAP_OFF_SHELF');
  412. }
  413. }
  414. //获取章节
  415. $chapter = ChapterService::getChapterNameById($cid, $bid);
  416. if (!$chapter) {
  417. return response()->error('WAP_SYS_ERROR');
  418. }
  419. if ($this->balancePay($book_info, $chapter, $remind)) {
  420. ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  421. 'cid' => $cid, 'chapter_name' => $chapter->name]);
  422. $content = $this->getChapter($bid, $cid, $chapter, 0, 1);
  423. $content->is_had_subscribe = 0;
  424. return response()->item(new ChapterTransformer, $content);
  425. } else {
  426. $fee = $this->getPrice($book_info, $chapter);
  427. $data = [
  428. 'book_id' => $oldbid,
  429. 'book_name' => $book_info->book_name,
  430. 'chapter_name' => $chapter->name,
  431. 'chapter_id' => $cid,
  432. 'pay_type' => $book_info->charge_type,
  433. 'fee' => $fee,
  434. 'user_balance' => $this->_user_info['balance'],
  435. 'product_id' => $book_info->product_id,
  436. 'uid' => $this->uid,
  437. 'distribution_channel_id' => $this->distribution_channel_id,
  438. 'is_discount' => 0,
  439. 'discount_fee' => '',
  440. 'discount' => ''
  441. ];
  442. //不需要提醒
  443. if ($book_info->charge_type == 'BOOK') {
  444. return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
  445. } elseif ($book_info->charge_type == 'CHAPTER') {
  446. return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
  447. } else {
  448. return response()->error('WAP_SYS_ERROR');
  449. }
  450. }
  451. }
  452. /**
  453. * 余额支付
  454. * @param $book_info
  455. * @param $chapter_id
  456. * @param $chapter_size
  457. * @return bool
  458. */
  459. protected function balancePay($book_info, $chapter, $is_remind)
  460. {
  461. $fee = $this->getPrice($book_info, $chapter);
  462. if ($this->_user_info->is_new == 1) {
  463. //$fee = ceil($fee*0.3);
  464. }
  465. if ((int)$this->_user_info['balance'] >= $fee) {
  466. if ($this->bookOrderOrChapterOrder($book_info, $chapter->id, $fee, $chapter->name, $is_remind)) {
  467. try {
  468. $day = date('Y--m-d');
  469. Redis::hincrby('wap:chapterandbookorder:bid:' . $book_info->bid, $day, $fee);
  470. } catch (\Exception $e) {
  471. }
  472. return true;
  473. }
  474. return false;
  475. } else {
  476. return false;
  477. }
  478. }
  479. /**
  480. * 获取章节内容
  481. * @param $bid
  482. * @param $cid
  483. * @return bool|mixed
  484. */
  485. protected function getChapter($bid, $cid, $chapter, $is_show_subscribe_link = 0, $is_subscribe = 0)
  486. {
  487. //$this->readRecordOther($chapter);
  488. $chapter_content = ChapterService::getChapter($bid, $cid);
  489. if (!$chapter_content) return false;
  490. $chapter->content = str_replace($chapter_content->name, '', $chapter_content->content);
  491. $sign_status = $this->userSign($this->uid);
  492. $chapter->sign_status = $sign_status ? 1 : 0;
  493. $chapter->sign_reard = $sign_status;
  494. $chapter->is_show_subscribe_link = $is_show_subscribe_link;
  495. return $chapter;
  496. }
  497. /**
  498. * 签到
  499. * @param $uid
  500. * @return int
  501. */
  502. protected function userSign($uid)
  503. {
  504. if ($this->distribution_channel_id != 5) {
  505. //return 0;
  506. }
  507. $day = date('Y-m-d');
  508. $sign_stat = UserSignService::isSigni($uid, $day);
  509. if (!$sign_stat) {
  510. return 0;
  511. }
  512. if (UserSignService::sign($uid, $day, $sign_stat)) {
  513. $sign_key = 'leyuee:wap:usersigni';
  514. Redis::hset($sign_key, $uid, $sign_stat);
  515. return $sign_stat;
  516. }
  517. return 0;
  518. }
  519. /**
  520. * 添加订购记录
  521. * @param $book_info
  522. * @param $chapter_id
  523. * @param $fee
  524. * @return bool
  525. */
  526. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  527. {
  528. if ($book_info['charge_type'] == 'BOOK') {
  529. $data = [
  530. 'uid' => $this->uid,
  531. 'fee' => $fee,
  532. 'u' => Cookie::get('send_order_id'),
  533. 'distribution_channel_id' => $this->distribution_channel_id,
  534. 'bid' => $book_info->bid,
  535. 'book_name' => $book_info->book_name,
  536. 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
  537. ];
  538. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  539. } else {
  540. $data = [
  541. 'uid' => $this->uid,
  542. 'fee' => $fee,
  543. 'cid' => $chapter_id,
  544. 'bid' => $book_info->bid,
  545. 'distribution_channel_id' => $this->distribution_channel_id,
  546. 'book_name' => $book_info->book_name,
  547. 'chapter_name' => $chapter_name,
  548. 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
  549. 'is_remind' => $is_remind
  550. ];
  551. //print_r($data);
  552. if ($is_remind) {
  553. $this->addOrderRemind($book_info->bid);
  554. }
  555. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  556. }
  557. }
  558. protected function addOrderRemind($bid)
  559. {
  560. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  561. return true;
  562. } else {
  563. ChapterReminderService::add($this->uid, $bid);
  564. return true;
  565. }
  566. }
  567. /**
  568. * 是否订购提醒
  569. * @param $chapter_id
  570. * @return bool
  571. */
  572. protected function isOrderRemind($bid)
  573. {
  574. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  575. return $is_no_reminder == 0;
  576. }
  577. /**
  578. * 获取订购记录
  579. * @param $book_info
  580. * @param $chapter_id
  581. * @return bool
  582. */
  583. protected function getOrderRecord($bid, $chapter_id)
  584. {
  585. //包年记录
  586. $uid = $this->uid;
  587. $res = YearOrderService::getRecord($uid);
  588. if ($res) return true;
  589. $res = null;
  590. //单本订购记录
  591. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  592. if ($res) return true;
  593. $res = null;
  594. //章节订购记录
  595. $chapterOrder = new ChapterOrderService();
  596. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  597. return false;
  598. }
  599. /**
  600. * 计算价格
  601. * @param $book_info
  602. * @param $chapter_size
  603. * @return float
  604. */
  605. protected function getPrice($book_info, $chapter)
  606. {
  607. if ($book_info->charge_type == 'BOOK') {
  608. $fee = $book_info->price * 100;
  609. } else {
  610. //$fee = ceil($chapter->size/100);
  611. //$channel_fee = BookService::getChapterPrice()
  612. $channel_fee = BookService::getChapterPrice($this->distribution_channel_id);
  613. if ($channel_fee) {
  614. $price_rate = $channel_fee / 100;
  615. } else {
  616. //$price_rate = 0.012;
  617. $price_rate = env('DEFAULT_CHAPTER_PRICE', 0.015);
  618. }
  619. //Log::info($price_rate);
  620. $fee = ceil($chapter->size * $price_rate);
  621. }
  622. //首个计费章节书币价格以35书币为基准,低于35提升至35,原价高于35书币,维持原价
  623. if (isset($chapter->sequence) && isset($book_info->vip_seq)) {
  624. if ($chapter->sequence == $book_info->vip_seq) {
  625. if ($fee < 35) {
  626. $fee = 35;
  627. }
  628. }
  629. }
  630. return $fee;
  631. }
  632. /**
  633. * 判断访问的域名和数据库指定的域名是否一致,一致返回false ,不一致 true
  634. * @param $book_domain
  635. * @return bool
  636. */
  637. protected function isVisitDomainEqualBookDomain($book_domain)
  638. {
  639. return stripos(_domain(), $book_domain) === false;
  640. }
  641. protected function isBookOrdered($bid)
  642. {
  643. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  644. if ($chapter_order) return true;
  645. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  646. if ($res) return true;
  647. return false;
  648. }
  649. private function showChapterPrice($bid, $charge_type)
  650. {
  651. if ($charge_type == 'BOOK') {
  652. return false;
  653. }
  654. $show_chapter_price_bid = env('SHOW_CHAPTER_PRICE_BID', 'all');
  655. if ($show_chapter_price_bid != 'all') {
  656. $show_chapter_price_bid_array = explode(',', $show_chapter_price_bid);
  657. if (!in_array($bid, $show_chapter_price_bid_array)) {
  658. return false;
  659. }
  660. }
  661. $show_chapter_price_channel = env('SHOW_CHAPTER_PRICE_CHANNEL', '');
  662. if (!$show_chapter_price_channel) {
  663. return false;
  664. }
  665. if ($show_chapter_price_channel == 'all') {
  666. return true;
  667. }
  668. $show_chapter_price_channel_array = explode(',', $show_chapter_price_channel);
  669. if (in_array($this->distribution_channel_id, $show_chapter_price_channel_array)) {
  670. return true;
  671. }
  672. return false;
  673. }
  674. }