ChapterController.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  1. <?php
  2. namespace App\Http\Controllers\Wap\Book;
  3. use App\Console\Commands\YqBook;
  4. use App\Modules\Book\Models\DataAnalysisBookConfig;
  5. use App\Modules\Book\Services\BookService;
  6. use App\Modules\Book\Services\ChapterCommentsService;
  7. use App\Modules\Book\Services\ChapterShareWechatConfigService;
  8. use App\Modules\Statistic\Models\DataAnalysisSelectUser;
  9. use App\Modules\Statistic\Services\AdVisitStatService;
  10. use App\Modules\Statistic\Services\DataAnalysisChapterService;
  11. use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
  12. use App\Modules\Statistic\Services\WapVisitStatService;
  13. use App\Modules\Subscribe\Services\OrderService;
  14. use App\Modules\User\Services\ReadRecordStatsService;
  15. use App\Modules\YunQi\Services\BookUserService;
  16. use Illuminate\Http\Request;
  17. use App\Http\Controllers\Wap\BaseController;
  18. use Cookie;
  19. use Redis;
  20. use App\Modules\Book\Services\ChapterService;
  21. use App\Modules\User\Services\ReadRecordService;
  22. use App\Http\Controllers\Wap\Book\Transformers\ChapterTransformer;
  23. use App\Modules\Book\Services\BookConfigService;
  24. use App\Http\Controllers\Wap\Book\Transformers\ChapterListTransformer;
  25. use App\Modules\Subscribe\Services\BookOrderService;
  26. use App\Modules\Subscribe\Services\ChapterOrderService;
  27. use App\Modules\Subscribe\Services\YearOrderService;
  28. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  29. use App\Modules\Subscribe\Services\ChapterReminderService;
  30. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  31. use Hashids;
  32. use GuzzleHttp\Client;
  33. use Log;
  34. use DB;
  35. use App\Modules\User\Services\UserSignService;
  36. use App\Modules\SendOrder\Services\SendOrderService;
  37. use App\Modules\User\Services\UserDeepReadTagService;
  38. use App\Modules\Book\Services\BookSubscribleChapterService;
  39. use App\Modules\Channel\Services\ChannelSubscribeSettingService;
  40. class ChapterController extends BaseController
  41. {
  42. /**
  43. * @apiDefine Chapter 章节
  44. */
  45. //用户是否强关
  46. private $is_had_subscribe = false;
  47. //章节是否需要强关
  48. private $is_need_subscribe;
  49. //用户信息
  50. private $user;
  51. //图书信息
  52. private $book_info;
  53. //cid
  54. private $cid;
  55. //加密的bid
  56. private $en_bid;
  57. //章节信息
  58. private $chapter;
  59. //强关时间
  60. private $force_subscribe_time = null;
  61. /**
  62. * @apiVersion 1.0.0
  63. * @apiDescription 章节列表不分页
  64. * @api {get} books/{bid}/allcatalog 章节列表不分页
  65. * @apiGroup Chapter
  66. * @apiName getCatalog
  67. * @apiSuccess {int} code 状态码
  68. * @apiSuccess {String} msg 信息
  69. * @apiSuccess {object} data 结果集
  70. * @apiSuccess {Array} data.list 分页结果集
  71. * @apiSuccess {Int} data.list.bid bid
  72. * @apiSuccess {Int} data.list.chapter_id 章节id
  73. * @apiSuccess {String} data.list.chapter_name 章节名称
  74. * @apiSuccess {Int} data.list.chapter_sequence 序号
  75. * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
  76. * @apiSuccess {Int} data.list.chapter_size 章节大小
  77. * @apiSuccess {Int} data.list.prev_cid 上一章节id
  78. * @apiSuccess {Int} data.list.next_cid 下一章节
  79. * @apiSuccess {String} data.list.recent_update_at 更新时间
  80. * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
  81. * @apiSuccess {String} data.list.is_show_price 是否显示价格
  82. * @apiSuccess {String} data.list.price 价格
  83. * @apiSuccess {object} data.meta 分页信息
  84. * @apiSuccess {Int} data.meta.total 总条数
  85. * @apiSuccess {Int} data.meta.per_page 每页条数
  86. * @apiSuccess {Int} data.meta.current_page 当前页
  87. * @apiSuccess {Int} data.meta.last_page 最后页
  88. * @apiSuccess {String} data.meta.next_page_url 下一页
  89. * @apiSuccess {String} data.meta.prev_page_url 上一页
  90. * @apiSuccessExample {json} Success-Response:
  91. * HTTP/1.1 200 OK
  92. * {
  93. * code: 0,
  94. * msg: "",
  95. * data:
  96. * [
  97. * {
  98. * bid: 5,
  99. * chapter_id: 5,
  100. * chapter_name: "第1240章 不是我",
  101. * chapter_sequence: 1239,
  102. * chapter_is_vip: 1,
  103. * chapter_size: 2422,
  104. * prev_cid: 0,
  105. * next_cid: 0,
  106. * recent_update_at: 2017-11-20 15:01:56,
  107. * is_need_subscirbe: 1,
  108. * },
  109. * {
  110. * bid: 5,
  111. * chapter_id: 5,
  112. * chapter_name: "第1240章 不是我",
  113. * chapter_sequence: 1239,
  114. * chapter_is_vip: 1,
  115. * chapter_size: 2422,
  116. * prev_cid: 0,
  117. * next_cid: 0,
  118. * recent_update_at: 2017-11-20 15:01:56,
  119. * is_need_subscirbe: 1,
  120. * },
  121. * ]
  122. * }
  123. */
  124. public function getCatalog(Request $request, $t, $domain, $bid)
  125. {
  126. $this->en_bid = $bid;
  127. $bid = Hashids::decode($bid)[0];
  128. $lists = ChapterService::getChapterLists($bid);
  129. $book_info = BookConfigService::getBookById($bid);
  130. if (!$book_info) {
  131. return response()->error('PARAM_ERROR');
  132. }
  133. $this->book_info = $book_info;
  134. $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
  135. foreach ($lists as $v) {
  136. $v->is_show_price = $is_show_price;
  137. $v->price = '';
  138. if ($is_show_price) {
  139. $v->price = $this->getPrice($book_info, $v);
  140. }
  141. }
  142. return response()->collection(new ChapterListTransformer, $lists);
  143. }
  144. /**
  145. * @apiVersion 1.0.0
  146. * @apiDescription 章节列表分页
  147. * @api {get} books/{bid}/catalog 章节列表分页
  148. * @apiGroup Chapter
  149. * @apiName getCatalogPerPage
  150. * @apiParam {Int} page_size 分页大小(默认15)
  151. * @apiParam {Int} page 页码(默认1)
  152. * @apiSuccess {int} code 状态码
  153. * @apiSuccess {String} msg 信息
  154. * @apiSuccess {object} data 结果集
  155. * @apiSuccess {Array} data.list 分页结果集
  156. * @apiSuccess {Int} data.list.bid bid
  157. * @apiSuccess {Int} data.list.chapter_id 章节id
  158. * @apiSuccess {String} data.list.chapter_name 章节名称
  159. * @apiSuccess {Int} data.list.chapter_sequence 序号
  160. * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
  161. * @apiSuccess {Int} data.list.chapter_size 章节大小
  162. * @apiSuccess {Int} data.list.prev_cid 上一章节id
  163. * @apiSuccess {Int} data.list.next_cid 下一章节
  164. * @apiSuccess {String} data.list.recent_update_at 更新时间
  165. * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
  166. * @apiSuccess {String} data.list.is_show_price 是否显示价格
  167. * @apiSuccess {String} data.list.price 价格
  168. * @apiSuccess {object} data.meta 分页信息
  169. * @apiSuccess {Int} data.meta.total 总条数
  170. * @apiSuccess {Int} data.meta.per_page 每页条数
  171. * @apiSuccess {Int} data.meta.current_page 当前页
  172. * @apiSuccess {Int} data.meta.last_page 最后页
  173. * @apiSuccess {String} data.meta.next_page_url 下一页
  174. * @apiSuccess {String} data.meta.prev_page_url 上一页
  175. * @apiSuccessExample {json} Success-Response:
  176. * HTTP/1.1 200 OK
  177. * {
  178. * code: 0,
  179. * msg: "",
  180. * data:
  181. * list:[
  182. * {
  183. * bid: 5,
  184. * chapter_id: 5,
  185. * chapter_name: "第1240章 不是我",
  186. * chapter_sequence: 1239,
  187. * chapter_is_vip: 1,
  188. * chapter_size: 2422,
  189. * prev_cid: 0,
  190. * next_cid: 0,
  191. * recent_update_at: 2017-11-20 15:01:56,
  192. * is_need_subscirbe: 1,
  193. * },
  194. * {
  195. * bid: 5,
  196. * chapter_id: 5,
  197. * chapter_name: "第1240章 不是我",
  198. * chapter_sequence: 1239,
  199. * chapter_is_vip: 1,
  200. * chapter_size: 2422,
  201. * prev_cid: 0,
  202. * next_cid: 0,
  203. * recent_update_at: 2017-11-20 15:01:56,
  204. * is_need_subscirbe: 1,
  205. * },
  206. * ]
  207. * meta:{
  208. * total: 1253,
  209. * per_page: 15,
  210. * current_page: 1,
  211. * last_page: 84,
  212. * next_page_url: "http://myapi.cn/api/books/1/chapter?page=2",
  213. * prev_page_url: ""
  214. * }
  215. * }
  216. */
  217. public function getCatalogPerPage(Request $request, $t, $domain, $bid)
  218. {
  219. $this->en_bid = $bid;
  220. $bid_array = Hashids::decode($bid);
  221. if (isset($bid_array[0])) {
  222. $bid = $bid_array[0];
  223. } else {
  224. return response()->error('PARAM_ERROR');
  225. }
  226. $book_info = BookConfigService::getBookById($bid);
  227. if (!$book_info) {
  228. return response()->error('PARAM_ERROR');
  229. }
  230. $this->book_info = $book_info;
  231. $page_size = $request->input('page_size', 15);
  232. $res = ChapterService::getChapterListsPage($bid, $page_size);
  233. $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
  234. foreach ($res as $v) {
  235. $v->is_show_price = $is_show_price;
  236. $v->price = '';
  237. if ($is_show_price) {
  238. $v->price = $this->getPrice($book_info, $v);
  239. }
  240. }
  241. return response()->pagination(new ChapterListTransformer, $res);
  242. }
  243. /**
  244. * @apiVersion 1.0.0
  245. * @apiDescription 章节内容
  246. * @api {get} books/{bid}/chapters/{chapter_id} 章节内容
  247. * @apiGroup Chapter
  248. * @apiName index
  249. * @apiSuccess {int} code 状态码
  250. * @apiSuccess {String} msg 信息
  251. * @apiSuccess {object} data 结果集
  252. * @apiSuccess {Int} data.chapter_id 章节id
  253. * @apiSuccess {String} data.chapter_name 章节名称
  254. * @apiSuccess {Int} data.chapter_sequence 序号
  255. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  256. * @apiSuccess {Int} data.chapter_size 章节大小
  257. * @apiSuccess {Int} data.prev_cid 上一章节id
  258. * @apiSuccess {Int} data.next_cid 下一章节
  259. * @apiSuccess {String} data.recent_update_at 更新时间
  260. * @apiSuccess {String} data.chapter_content 章节内容
  261. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  262. * @apiSuccess {Int} data.is_show_subscribe_link 是否显示底部强关链接
  263. * @apiSuccessExample {json} Success-Response:
  264. * HTTP/1.1 200 OK
  265. * {
  266. * code: 0,
  267. * msg: "",
  268. * data: {
  269. * chapter_id: 5,
  270. * chapter_name: "第1240章 不是我",
  271. * chapter_sequence: 1239,
  272. * chapter_is_vip: 1,
  273. * chapter_size: 2422,
  274. * prev_cid: 0,
  275. * next_cid: 0,
  276. * recent_update_at: 2017-11-20 15:01:56,
  277. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  278. * }
  279. * }
  280. */
  281. public function index(Request $request, $t, $domain, $bid, $cid)
  282. {
  283. myLog('special')->info('in chapter index controller----------');
  284. myLog('special')->info('everyone uid');
  285. myLog('special')->info($this->uid);
  286. $special_user_log = env('SPECIAL_USER_LOG');
  287. //注意:内部约定用 有此参数不需要强关
  288. $inter_not_need_sub = $request->has('inter_not_need_sub') ? true : false;
  289. myLog('special')->info('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
  290. $ad_status = $request->get('ad_status');
  291. //$ad_status = 0;
  292. $has_force_show_qrcode_cookie = Cookie::get('force_show_qrcode');
  293. Cookie::queue('force_show_qrcode', 1, -1);
  294. myLog('special')->info('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
  295. if (!$this->checkUid()) {
  296. myLog('special')->info('chapter index controller---$this->checkUid() fail-------');
  297. return response()->error('WAP_NOT_LOGIN');
  298. }
  299. myLog('special')->info('cccccccccccccccccccccccccccc');
  300. if($special_user_log && $special_user_log == $this->uid){
  301. $my_log = myLog('special');
  302. $my_log->info('in chapters--------------------------');
  303. $my_log->info('param is');
  304. $my_log->info($request->all());
  305. $my_log->info('$t is: '.$t);
  306. $my_log->info('$domain is: '.$domain);
  307. $my_log->info('$bid is: '.$bid);
  308. $my_log->info('$cid is: '.$cid);
  309. $my_log->info('$uri is: '. $request->path());
  310. }
  311. $this->en_bid = $bid;
  312. $bid = explode(',',$bid)[0];
  313. $bid = Hashids::decode($bid)[0];
  314. if($special_user_log && $special_user_log == $this->uid){
  315. myLog('special')->info('decode bid is: '.$bid);
  316. }
  317. //获取图书信息
  318. $book_info = BookConfigService::getBookById($bid);
  319. if($special_user_log && $special_user_log == $this->uid){
  320. $my_log = myLog('special');
  321. $my_log->info('book_info is ');
  322. $my_log->info($book_info);
  323. }
  324. //是否开启全站按章模式
  325. $global_charge_by_chapter_channels = explode(',',env('GLOBAL_CHARGE_BY_CHAPTER_CHANNEL'));
  326. if(in_array($this->distribution_channel_id,$global_charge_by_chapter_channels))
  327. {
  328. $book_info->charge_type = 'CHAPTER';
  329. }
  330. if (empty($book_info)) return response()->error('WAP_SYS_ERROR');
  331. if($special_user_log && $special_user_log == $this->uid){
  332. $my_log = myLog('special');
  333. $my_log->info('book info ok--------------------------');
  334. }
  335. $this->book_info = $book_info;
  336. $this->cid = $cid;
  337. //下架图书不能看
  338. if ($this->isOffShelf()) {
  339. return response()->error('WAP_OFF_SHELF');
  340. }
  341. if($special_user_log && $special_user_log == $this->uid){
  342. $my_log = myLog('special');
  343. $my_log->info('on shelf ok--------------------------');
  344. }
  345. //获取章节信息
  346. $chapter = ChapterService::getChapterNameById($cid, $bid);
  347. $this->chapter = $chapter;
  348. if($special_user_log && $special_user_log == $this->uid){
  349. $my_log = myLog('special');
  350. $my_log->info('chapters-info--is-----------------------');
  351. $my_log->info($chapter);
  352. }
  353. //章节被删除
  354. if (($is_delete = $this->chapterNotExists())) {
  355. if($special_user_log && $special_user_log == $this->uid){
  356. $my_log = myLog('special');
  357. $my_log->info('chapters-----delete---------------------');
  358. }
  359. return response()->error('WAP_DOMAIN_NOT_MATCH', [
  360. 'url' => $is_delete
  361. ]);
  362. }
  363. if($special_user_log && $special_user_log == $this->uid){
  364. $my_log = myLog('special');
  365. $my_log->info('chapters-----ok---------------------');
  366. }
  367. //获取强关章节数
  368. $subscribe_seq = $this->getSubscribeChapterNum($book_info);
  369. //章节是否需要强关 TRUE:不需要,false:需要
  370. $force_subscribe = $subscribe_seq > $chapter->sequence;
  371. $this->is_need_subscribe = !$force_subscribe;
  372. //图书域名,book_configs表的promotion_domain 要跟当前的主机名匹配 在强关章节后
  373. if ($this->is_need_subscribe && $this->isVisitDomainEqualBookDomain($domain)) {
  374. if($special_user_log && $special_user_log == $this->uid){
  375. $my_log = myLog('special');
  376. $my_log->info('book domain not match------------------------');
  377. }
  378. return response()->error('WAP_DOMAIN_NOT_MATCH', [
  379. 'url' => $this->getCorrespondBookUrl()
  380. ]);
  381. }
  382. if($special_user_log && $special_user_log == $this->uid){
  383. $my_log = myLog('special');
  384. $my_log->info('book domain jump--------------------------');
  385. }
  386. $user_info = $this->_user_info;
  387. $this->user = $user_info;
  388. //用户是否强关
  389. $this->is_had_subscribe = $is_had_subscribe = $inter_not_need_sub ? true : $this->getSubscribe();
  390. //阅读记录
  391. ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  392. 'cid' => $cid, 'chapter_name' => $chapter->name]);
  393. //判断当前是否有强制显示服务号信息的cookie、已经关注 跳转到服务号信息引导页
  394. if($has_force_show_qrcode_cookie && $is_had_subscribe)
  395. {
  396. if($special_user_log && $special_user_log == $this->uid){
  397. $my_log = myLog('special');
  398. $my_log->info('do not have force show qrcode cookie-------------------------');
  399. }
  400. $force_read_url = '/subscribe/getFromUser';//服务号信息引导页
  401. $force_read_data = ['src' => $force_read_url];
  402. return response()->error('WAP_NOT_SUBSCRIBE', $force_read_data);
  403. }
  404. if($special_user_log && $special_user_log == $this->uid){
  405. $my_log = myLog('special');
  406. $my_log->info('has force show qrcode cookie-ok-------------------------');
  407. }
  408. if ($force_subscribe || $chapter->is_vip == 0) {
  409. //vip前一张和枪管前一张的访问统计
  410. $this->beforeForceSubAndBeforeVipUvAndPv($book_info, $subscribe_seq, $chapter);
  411. }
  412. //不用关注且不是vip章节
  413. if ($force_subscribe && $chapter->is_vip == 0) {
  414. //获取公共号
  415. $officialAccount = $this->getOfficialAccount();
  416. $this->chapter->is_show_subscribe_link = 0;
  417. //非强关,但是设置了弱关,阅读页底部显示强关链接
  418. if ($officialAccount && isset($officialAccount->appid) && !empty($officialAccount->appid)) {
  419. $sub_type = $this->getSubscribeType($officialAccount->appid, $bid);
  420. if (in_array(2, $sub_type['type']) && !$is_had_subscribe) {
  421. $this->chapter->is_show_subscribe_link = 1;
  422. }
  423. }
  424. if($special_user_log && $special_user_log == $this->uid){
  425. $my_log = myLog('special');
  426. $my_log->info('do not force subscribe-and is not vip-------------------------');
  427. }
  428. $this->getChapter();
  429. return response()->item(new ChapterTransformer, $this->chapter);
  430. }
  431. if($special_user_log && $special_user_log == $this->uid){
  432. $my_log = myLog('special');
  433. $my_log->info('11111111111111111111111111111111111111111');
  434. }
  435. //需要强制关注 不是vip章节 已经关注了
  436. if (!$force_subscribe && $chapter->is_vip == 0 && $is_had_subscribe) {
  437. $this->getChapter();
  438. return response()->item(new ChapterTransformer, $this->chapter);
  439. }
  440. if($special_user_log && $special_user_log == $this->uid){
  441. $my_log = myLog('special');
  442. $my_log->info('222222222222222222222222222222222222222');
  443. }
  444. //需要强制关注 没关注
  445. if ((!$force_subscribe) && !$is_had_subscribe) {
  446. $force_data = $this->forceSubscribe();
  447. if ($force_data) {
  448. $this->subscribeStats();
  449. if($special_user_log && $special_user_log == $this->uid){
  450. $my_log = myLog('special');
  451. $my_log->info('need subscribe-------------------------');
  452. }
  453. return response()->error($force_data['error_type'], $force_data['data']);
  454. }
  455. //取不到公众号则不用强关
  456. if ($chapter->is_vip == 0) {
  457. $this->getChapter();
  458. if($special_user_log && $special_user_log == $this->uid){
  459. $my_log = myLog('special');
  460. $my_log->info('official fail--------------------------');
  461. }
  462. return response()->item(new ChapterTransformer, $this->chapter);
  463. }
  464. }
  465. if($special_user_log && $special_user_log == $this->uid){
  466. $my_log = myLog('special');
  467. $my_log->info('33333333333333333333333333333333333333333');
  468. }
  469. //已经付费
  470. if ($this->getOrderRecord($bid, $cid)) {
  471. $this->getChapter();
  472. if($special_user_log && $special_user_log == $this->uid){
  473. $my_log = myLog('special');
  474. $my_log->info('had order order record--------------------------');
  475. }
  476. return response()->item(new ChapterTransformer, $this->chapter);
  477. }
  478. if($special_user_log && $special_user_log == $this->uid){
  479. $my_log = myLog('special');
  480. $my_log->info('4444444444444444444444444444444444444444444');
  481. }
  482. //获取价格
  483. $fee = $this->getPrice($book_info, $chapter);
  484. //广告
  485. if($this->isUserInAdSample() && $ad_status && $ad_status == 1 && $user_info->balance < $fee){
  486. $this->getChapter();
  487. if($special_user_log && $special_user_log == $this->uid){
  488. $my_log = myLog('special');
  489. $my_log->info('ad-----in--------------------');
  490. }
  491. //广告解锁2张
  492. if($this->chapter->next_cid){
  493. $next_chapter = ChapterService::getChapterNameById($this->chapter->next_cid, $bid);
  494. if($next_chapter){
  495. $next_chapter_name = $next_chapter->name;
  496. $this->bookOrderOrChapterOrder($book_info, $this->chapter->next_cid, 0, $next_chapter_name, 1);
  497. AdVisitStatService::create($this->uid,$this->book_info->bid,$this->chapter->next_cid,'UNLOCK_2');
  498. }
  499. }
  500. $this->chapter->is_show_ad = 0;
  501. $this->bookOrderOrChapterOrder($book_info, $cid, 0, $chapter->name, 1);
  502. return response()->item(new ChapterTransformer, $this->chapter);
  503. }
  504. if($special_user_log && $special_user_log == $this->uid){
  505. $my_log = myLog('special');
  506. $my_log->info('5555555555555555555555555555555555');
  507. }
  508. //以上都是不用付费的情况******************************************************
  509. //未付费
  510. //返回的价格信息
  511. $data = [
  512. 'book_id' => $this->en_bid,
  513. 'book_name' => $book_info->book_name,
  514. 'chapter_name' => $chapter->name,
  515. 'chapter_id' => $cid,
  516. 'pay_type' => $book_info->charge_type,
  517. 'fee' => $fee,
  518. 'user_balance' => $user_info->balance,
  519. 'product_id' => $book_info->product_id,
  520. 'uid' => $this->uid,
  521. 'distribution_channel_id' => $this->distribution_channel_id,
  522. 'is_discount' => 0,
  523. 'discount_fee' => '',
  524. 'discount' => ''
  525. ];
  526. if($special_user_log && $special_user_log == $this->uid){
  527. $my_log = myLog('special');
  528. $my_log->info('data is:');
  529. $my_log->info($data);
  530. }
  531. //余额不足 弹窗提醒
  532. if ($user_info['balance'] < $fee) {
  533. if($special_user_log && $special_user_log == $this->uid){
  534. $my_log = myLog('special');
  535. $my_log->info('balance is lack');
  536. $my_log->info('user balance is: '.$user_info['balance']);
  537. $my_log->info('fee is: '.$fee);
  538. }
  539. $this->smartPushTestBookPayPageUv($bid);
  540. //$this->sendOrderPayPageUv($bid);
  541. //除了单本订购 其他的都不提醒,直接跳转到充值页面
  542. if ($book_info->charge_type == 'CHAPTER') {
  543. if($special_user_log && $special_user_log == $this->uid){
  544. $my_log = myLog('special');
  545. $my_log->info('chapter order balance lack');
  546. }
  547. return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
  548. }
  549. //需要提箱
  550. if ($this->isOrderRemind($bid)) {
  551. if($special_user_log && $special_user_log == $this->uid){
  552. $my_log = myLog('special');
  553. $my_log->info('balance lack remind');
  554. }
  555. return response()->error('WAP_BOOK_BALANCE_PAY', $data);
  556. } else {
  557. if($special_user_log && $special_user_log == $this->uid){
  558. $my_log = myLog('special');
  559. $my_log->info('balance lack not remind');
  560. }
  561. return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
  562. }
  563. }
  564. if($special_user_log && $special_user_log == $this->uid){
  565. $my_log = myLog('special');
  566. $my_log->info('6666666666666666666666666666666666666');
  567. }
  568. //余额充足 单本弹窗提醒,章节直接扣费
  569. if ($this->isOrderRemind($bid) && $book_info->charge_type == 'BOOK') {
  570. if($special_user_log && $special_user_log == $this->uid){
  571. $my_log = myLog('special');
  572. $my_log->info('balance enough remind');
  573. }
  574. return response()->error('WAP_BOOK_BUY', $data);
  575. }
  576. if($special_user_log && $special_user_log == $this->uid){
  577. $my_log = myLog('special');
  578. $my_log->info('77777777777777777777777777777');
  579. }
  580. //付费 不提醒
  581. if ($this->balancePay($book_info, $chapter, 0)) {
  582. if($special_user_log && $special_user_log == $this->uid){
  583. $my_log = myLog('special');
  584. $my_log->info('balance pay ok-----');
  585. }
  586. $this->getChapter();
  587. return response()->item(new ChapterTransformer, $this->chapter);
  588. } else {
  589. if($special_user_log && $special_user_log == $this->uid){
  590. $my_log = myLog('special');
  591. $my_log->info('balance pay fails!!!!!!!!!!!!!!!!');
  592. }
  593. //付费 异常
  594. return response()->error('WAP_SYS_ERROR');
  595. }
  596. }
  597. /**
  598. * @apiVersion 1.0.0
  599. * @apiDescription 余额支付
  600. * @api {get} books/{bid}/balance/chapterOrders/{cid} 余额支付
  601. * @apiGroup Chapter
  602. * @apiName pay
  603. * @apiParam (Int) remind 提醒
  604. * @apiSuccess {int} code 状态码
  605. * @apiSuccess {String} msg 信息
  606. * @apiSuccess {object} data 结果集
  607. * @apiSuccess {Int} data.chapter_id 章节id
  608. * @apiSuccess {String} data.chapter_name 章节名称
  609. * @apiSuccess {Int} data.chapter_sequence 序号
  610. * @apiSuccess {Int} data.chapter_is_vip 是否vip
  611. * @apiSuccess {Int} data.chapter_size 章节大小
  612. * @apiSuccess {Int} data.prev_cid 上一章节id
  613. * @apiSuccess {Int} data.next_cid 下一章节
  614. * @apiSuccess {String} data.recent_update_at 更新时间
  615. * @apiSuccess {String} data.chapter_content 章节内容
  616. * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
  617. * @apiSuccessExample {json} Success-Response:
  618. * HTTP/1.1 200 OK
  619. * {
  620. * code: 0,
  621. * msg: "",
  622. * data: {
  623. * chapter_id: 5,
  624. * chapter_name: "第1240章 不是我",
  625. * chapter_sequence: 1239,
  626. * chapter_is_vip: 1,
  627. * chapter_size: 2422,
  628. * prev_cid: 0,
  629. * next_cid: 0,
  630. * recent_update_at: 2017-11-20 15:01:56,
  631. * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
  632. * }
  633. * }
  634. */
  635. public function pay(Request $request, $t, $domain, $bid, $cid)
  636. {
  637. if (!$this->checkUid()) {
  638. return response()->error('NOT_LOGIN');
  639. }
  640. $remind = (int)$request->input('remind');
  641. $this->en_bid = $bid;
  642. $oldbid = $bid;
  643. $bid = Hashids::decode($bid)[0];
  644. $book_info = BookConfigService::getBookById($bid);;
  645. if (empty($book_info)) response()->error('WAP_SYS_ERROR');
  646. //获取章节
  647. $chapter = ChapterService::getChapterNameById($cid, $bid);
  648. if (!$chapter) {
  649. return response()->error('WAP_SYS_ERROR');
  650. }
  651. $this->chapter = $chapter;
  652. $this->book_info = $book_info;
  653. $this->cid = $cid;
  654. if ($this->balancePay($book_info, $chapter, $remind)) {
  655. ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
  656. 'cid' => $cid, 'chapter_name' => $chapter->name]);
  657. $this->getChapter();
  658. return response()->item(new ChapterTransformer, $this->chapter);
  659. } else {
  660. $fee = $this->getPrice($book_info, $chapter);
  661. $data = [
  662. 'book_id' => $oldbid,
  663. 'book_name' => $book_info->book_name,
  664. 'chapter_name' => $chapter->name,
  665. 'chapter_id' => $cid,
  666. 'pay_type' => $book_info->charge_type,
  667. 'fee' => $fee,
  668. 'user_balance' => $this->_user_info['balance'],
  669. 'product_id' => $book_info->product_id,
  670. 'uid' => $this->uid,
  671. 'distribution_channel_id' => $this->distribution_channel_id,
  672. 'is_discount' => 0,
  673. 'discount_fee' => '',
  674. 'discount' => ''
  675. ];
  676. //不需要提醒
  677. if ($book_info->charge_type == 'BOOK') {
  678. return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
  679. } elseif ($book_info->charge_type == 'CHAPTER') {
  680. return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
  681. } else {
  682. return response()->error('WAP_SYS_ERROR');
  683. }
  684. }
  685. }
  686. /**
  687. * 余额支付
  688. * @param $book_info
  689. * @param $chapter_id
  690. * @param $chapter_size
  691. * @return bool
  692. */
  693. protected function balancePay($book_info, $chapter, $is_remind)
  694. {
  695. $fee = $this->getPrice($book_info, $chapter);
  696. if ((int)$this->_user_info['balance'] >= $fee) {
  697. if ($this->bookOrderOrChapterOrder($book_info, $chapter->id, $fee, $chapter->name, $is_remind)) {
  698. $this->chapterOrderStats($fee);
  699. if($this->user){
  700. $this->user->balance -= $fee;
  701. }
  702. return true;
  703. }
  704. }
  705. return false;
  706. }
  707. /**
  708. * 获取章节内容
  709. * @param $bid
  710. * @param $cid
  711. * @return bool|mixed
  712. */
  713. private function getChapter()
  714. {
  715. //初始化 默认字段
  716. $this->initChapterDefaultField();
  717. //章节内容
  718. $chapter_content = ChapterService::getChapter($this->book_info->bid, $this->cid);
  719. $this->chapter->content = str_replace($chapter_content->name, '', $chapter_content->content);
  720. //统计
  721. $this->chapterStats();
  722. //123特殊强关
  723. $this->specialSubscribeFlag();
  724. //签到奖励
  725. $this->sign();
  726. //#短篇推送长篇需求#
  727. //$this->shortPushLong();
  728. //#短推长、短推短对比
  729. $this->shortPushshort();
  730. //阅读器分享
  731. $this->share();
  732. //广告
  733. $this->isShowAd();
  734. //完整阅读纪录 阅读纪录
  735. $this->readRecordOther();
  736. }
  737. /**
  738. * 章节阅读接口需要配置返回的字段
  739. */
  740. private function initChapterDefaultField()
  741. {
  742. if (!$this->chapter) {
  743. return;
  744. }
  745. //内容
  746. $this->chapter->content = '';
  747. //签到默认字段
  748. $this->chapter->sign_days = 1;
  749. $this->chapter->sign_status = 0;
  750. $this->chapter->sign_reard = 0;
  751. //#短篇推送长篇需求#
  752. $this->chapter->next_jump = 0;
  753. $this->chapter->next_jump_url = '';
  754. $this->chapter->show_push_title = 0;
  755. $this->chapter->push_title_url = '';
  756. $this->chapter->push_title = [];
  757. //分享
  758. $this->chapter->is_show_share_button = 0;
  759. //阅读底部强关图片 只有123有
  760. $this->chapter->is_had_subscribe = 0;
  761. //广告
  762. $this->chapter->is_show_ad = 0;
  763. }
  764. private function sign()
  765. {
  766. //渠道123 未关注的签到放到强关前一章
  767. if ($this->distribution_channel_id == 123 && !$this->is_had_subscribe) {
  768. if ($this->book_info->force_subscribe_chapter_seq - 1 == $this->chapter->sequence) {
  769. $sign_status = $this->userSign($this->uid);
  770. //$sign_status = 0;
  771. $this->chapter->sign_status = $sign_status ? 1 : 0;
  772. $this->chapter->sign_reard = $sign_status;
  773. $this->chapter->sign_days = ReadRecordService::getSignCount($this->uid);
  774. }
  775. } else {
  776. $sign_status = $this->userSign($this->uid);
  777. //$sign_status =0;
  778. $this->chapter->sign_status = $sign_status ? 1 : 0;
  779. $this->chapter->sign_reard = $sign_status;
  780. $this->chapter->sign_days = ReadRecordService::getSignCount($this->uid);
  781. }
  782. }
  783. private function forceSubscribe()
  784. {
  785. //获取公众号信息
  786. $officialAccount = $this->getOfficialAccount();
  787. if (!$officialAccount || empty($officialAccount->appid)) {
  788. return false;
  789. }
  790. //如果是链接强关,则跳转
  791. $sub_type = $this->getSubscribeType($officialAccount->appid, $this->book_info->bid);
  792. if (in_array(3, $sub_type['type']) && $sub_type['url']) {
  793. return ['error_type' => 'WAP_LINK_SUBSCRIBE', 'data' => ['url' => $sub_type['url']]];
  794. }
  795. //普通强关
  796. if (in_array(1, $sub_type['type'])) {
  797. $src = $this->getRcodeInfo(['appid' => $officialAccount->appid], $this->book_info->bid);
  798. if (empty($src)) return false;
  799. if ($officialAccount->head_img) {
  800. $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $officialAccount->nickname . '&head_img=' . urlencode($officialAccount->head_img) . '&uid=' . $this->uid;
  801. } else {
  802. $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $officialAccount->nickname . '&uid=' . $this->uid;
  803. }
  804. return ['error_type' => 'WAP_NOT_SUBSCRIBE', 'data' => ['src' => $url, 'head_img' => $officialAccount->head_img]];
  805. }
  806. return false;
  807. }
  808. private function getOfficialAccountForceReadNotice()
  809. {
  810. }
  811. //强关页面的统计
  812. private function subscribeStats()
  813. {
  814. if ($this->send_order_id) {
  815. //$this->sendOrderSubscribePageUv($this->book_info->bid);
  816. //强关页面的uv
  817. /*try {
  818. Redis::sadd('subscribe_page_uv' . $this->send_order_id, $this->uid);
  819. Redis::sadd('subscribe_page_uv_send_order_ids', $this->send_order_id);
  820. } catch (\Exception $e) {
  821. }*/
  822. }
  823. }
  824. /**
  825. * 短推长
  826. */
  827. private function shortPushLong()
  828. {
  829. if ($this->book_info->charge_type = 'CHAPTER') return;
  830. $is_has_book_order = BookOrderService::isHasBookOrder($this->uid);
  831. if ($this->chapter->is_vip && $is_has_book_order) {
  832. $this->chapter->show_push_title = 1;
  833. $this->chapter->push_title = DataAnalysisBookConfig::getUserReaderPagePushBook($this->uid, $this->distribution_channel_id);
  834. }
  835. if (!$this->chapter->next_cid && $is_has_book_order) {
  836. $link = DataAnalysisBookConfig::getUserReaderPagePushBook($this->uid, $this->distribution_channel_id, 1);
  837. if ($link && isset($link['link']) && !empty($link['link'])) {
  838. $this->chapter->next_jump = 1;
  839. $this->chapter->next_jump_url = $link['link'];
  840. }
  841. }
  842. }
  843. /**
  844. * 短推长、短推短对比需求
  845. * 目标用户:全站短篇进入新注册且订阅短篇的付费用户
  846. * 方式:根据uid奇偶取用,奇:测试用户1 偶:测试用户2
  847. * 测试用户1:底部链接+完本推荐 均使用短篇小说
  848. * 测试用户2:底部链接+完本推荐 均使用长篇小说
  849. * 目标用户:全站短篇进入新注册且订阅短篇的付费用户
  850. */
  851. private function shortPushshort()
  852. {
  853. //新用户 注册时间大于某个值
  854. if(!$this->user){
  855. return ;
  856. }
  857. if(!env('SHORT_PUSH_SHORT_START_TIME') || strtotime($this->user->created_at) < env('SHORT_PUSH_SHORT_START_TIME')){
  858. return ;
  859. }
  860. //没有派单
  861. if(!$this->user->send_order_id) return ;
  862. //只在vip章节底部显示
  863. if(!$this->chapter->is_vip){
  864. return ;
  865. }
  866. //强关
  867. if(!$this->is_had_subscribe){
  868. return ;
  869. }
  870. //短篇进入
  871. $send_order_info = SendOrderService::getById($this->user->send_order_id);
  872. if(!$send_order_info || $send_order_info->charge_type != 'BOOK'){
  873. return ;
  874. }
  875. //订阅短篇的付费用户
  876. $is_has_book_order = BookOrderService::isHasBookOrder($this->uid);
  877. if(!$is_has_book_order) return ;
  878. //是否付费用户
  879. if(!OrderService::isPaidUser($this->uid)) return ;
  880. $type = $this->uid %2 == 1? 'BOOK':'CHAPTER';
  881. $result = DataAnalysisSelectUserService::create($this->uid, $this->distribution_channel_id, $type, 500, $attach = 'short2s2l');
  882. if(!$result) return ;
  883. //底部链接
  884. $this->chapter->show_push_title = 1;
  885. $this->chapter->push_title = DataAnalysisBookConfig::getUserReaderPagePushBookV2($this->uid, $this->distribution_channel_id,$type);
  886. //完本推荐
  887. if (!$this->chapter->next_cid ) {
  888. $link = DataAnalysisBookConfig::getUserReaderPagePushBookV2($this->uid, $this->distribution_channel_id,$type, 1);
  889. if($link && $link['link']){
  890. $this->chapter->next_jump = 1;
  891. $this->chapter->next_jump_url = $link['link'];
  892. }
  893. }
  894. }
  895. private function share()
  896. {
  897. if ($this->is_had_subscribe && in_array($this->distribution_channel_id, [2, 14, 211,4025,4147,691,123]) && $this->user) {//,4147,691,123,4025
  898. $this->chapter->is_show_share_button = 1;
  899. }
  900. }
  901. /**
  902. * 123 渠道阅读底部强关图片
  903. */
  904. private function specialSubscribeFlag()
  905. {
  906. if ($this->distribution_channel_id == 123 && !$this->is_had_subscribe) {
  907. $this->chapter->is_had_subscribe = 1;
  908. }
  909. }
  910. //订阅统计
  911. private function chapterOrderStats($fee)
  912. {
  913. $day = date('Y--m-d');
  914. try {
  915. Redis::hincrby('wap:chapterandbookorder:bid:' . $this->book_info->bid, $day, $fee);
  916. } catch (\Exception $e) {
  917. }
  918. $this->smartPushTestBook($this->book_info->bid, $fee);
  919. $specialChannelIdStats = env('SPECIAL_CHANNEL_STATS', 211);
  920. if (in_array($this->distribution_channel_id, explode(',', $specialChannelIdStats))) {
  921. WapVisitStatService::specialChannelIdStatsSave($this->uid, $this->book_info->bid, $fee);
  922. }
  923. }
  924. /**
  925. * 签到
  926. * @param $uid
  927. * @return int
  928. */
  929. protected function userSign($uid)
  930. {
  931. if (UserSignService::isSign($uid)) {
  932. //签过到了
  933. return 0;
  934. }
  935. if ($res = UserSignService::signToday($uid)) {
  936. //$sign_key = 'leyuee:wap:usersigni';
  937. //Redis::hset($sign_key, $uid, $res);
  938. return $res;
  939. }
  940. return 0;
  941. }
  942. /**
  943. * 添加订购记录
  944. * @param $book_info
  945. * @param $chapter_id
  946. * @param $fee
  947. * @return bool
  948. */
  949. protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
  950. {
  951. if ($book_info['charge_type'] == 'BOOK') {
  952. $data = [
  953. 'uid' => $this->uid,
  954. 'fee' => $fee,
  955. 'u' => Cookie::get('send_order_id'),
  956. 'distribution_channel_id' => $this->distribution_channel_id,
  957. 'bid' => $book_info->bid,
  958. 'book_name' => $book_info->book_name,
  959. 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
  960. ];
  961. return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
  962. } else {
  963. $data = [
  964. 'uid' => $this->uid,
  965. 'fee' => $fee,
  966. 'cid' => $chapter_id,
  967. 'bid' => $book_info->bid,
  968. 'distribution_channel_id' => $this->distribution_channel_id,
  969. 'book_name' => $book_info->book_name,
  970. 'chapter_name' => $chapter_name,
  971. 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
  972. 'is_remind' => $is_remind
  973. ];
  974. //print_r($data);
  975. if ($is_remind) {
  976. $this->addOrderRemind($book_info->bid);
  977. }
  978. return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
  979. }
  980. }
  981. protected function addOrderRemind($bid)
  982. {
  983. if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
  984. return true;
  985. } else {
  986. ChapterReminderService::add($this->uid, $bid);
  987. return true;
  988. }
  989. }
  990. /**
  991. * 是否订购提醒
  992. * @param $chapter_id
  993. * @return bool
  994. */
  995. protected function isOrderRemind($bid)
  996. {
  997. $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
  998. return $is_no_reminder == 0;
  999. }
  1000. /**
  1001. * 用户是否关注
  1002. * @param $uid
  1003. * @return bool
  1004. */
  1005. protected function getSubscribe()
  1006. {
  1007. $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  1008. if ($res) {
  1009. $this->force_subscribe_time = isset($res->created_at)?$res->created_at:null;
  1010. return true;
  1011. }
  1012. return false;
  1013. }
  1014. /**
  1015. * 获取公众号信息
  1016. * @param $distribution_channel_id
  1017. */
  1018. protected function getOfficialAccount()
  1019. {
  1020. $distribution_channel_id = $this->distribution_channel_id;
  1021. $res = OfficialAccountService::canUseOfficialAccountByChannelId(compact('distribution_channel_id'));
  1022. if (isset($res->nickname) && !empty($res->nickname)) {
  1023. Cookie::queue('force_subscribe_name', $res->nickname, env('U_COOKIE_EXPIRE'));
  1024. }
  1025. return $res;
  1026. }
  1027. /**
  1028. * 获取二维码
  1029. * @param $param
  1030. * @return bool
  1031. */
  1032. private function getRcodeInfo($param, $bid)
  1033. {
  1034. //return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGI8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZEZ0T0ZoSHljM2kxOTUwQU5zY08AAgRF8-xbAwQAjScA";
  1035. $param_need = [
  1036. 'gzh_app_id' => $param['appid'],
  1037. 'scene_id' => $this->uid,
  1038. 'timestamp' => time(),
  1039. ];
  1040. $param_need['sign'] = $this->getSign($param_need);
  1041. $client = new Client(['timeout' => 3.0,]);
  1042. try {
  1043. Log::info('get qrcode url is:' . 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need));
  1044. $qrcode_url_res = $client->request('get', 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need))->getBody()->getContents();
  1045. if ($qrcode_url_res) {
  1046. $qrcode_url = json_decode($qrcode_url_res, true);
  1047. if ($qrcode_url['code'] == 1) {
  1048. //保存强关时的bid
  1049. if (isset($qrcode_url['data']) && !empty($qrcode_url['data'])) {
  1050. Redis::hset('force_subscribe_from_bid', $param['appid'] . '_' . $this->uid, $bid);
  1051. $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0;
  1052. Redis::hset('force_subscribe_from_send_order_id', $param['appid'] . '_' . $this->uid, $send_order_id);
  1053. Log::info('uid is' . $this->uid . '--qrcode is:' . $qrcode_url['data']);
  1054. return $qrcode_url['data'];
  1055. }
  1056. }
  1057. }
  1058. } catch (\Exception $e) {
  1059. //\Log::info($e);
  1060. //Redis::sadd('force_subscribe_qrcode:error', $param['appid'] . '_' . time());
  1061. }
  1062. return false;
  1063. }
  1064. /**
  1065. * 获取订购记录
  1066. * @param $book_info
  1067. * @param $chapter_id
  1068. * @return bool
  1069. */
  1070. private function getOrderRecord($bid, $chapter_id)
  1071. {
  1072. //包年记录
  1073. $uid = $this->uid;
  1074. $res = YearOrderService::getRecord($uid);
  1075. if ($res) return true;
  1076. $res = null;
  1077. //单本订购记录
  1078. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  1079. if ($res) return true;
  1080. $res = null;
  1081. //章节订购记录
  1082. $chapterOrder = new ChapterOrderService();
  1083. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  1084. return false;
  1085. }
  1086. /**
  1087. * 计算价格
  1088. * @param $book_info
  1089. * @param $chapter_size
  1090. * @return float
  1091. */
  1092. private function getPrice($book_info, $chapter)
  1093. {
  1094. if ($book_info->charge_type == 'BOOK') {
  1095. $fee = $book_info->price * 100;
  1096. } else {
  1097. //$fee = ceil($chapter->size/100);
  1098. //$channel_fee = BookService::getChapterPrice()
  1099. $channel_fee = BookService::getChapterPrice($this->distribution_channel_id);
  1100. if ($channel_fee) {
  1101. $price_rate = $channel_fee / 100;
  1102. } else {
  1103. //$price_rate = 0.012;
  1104. $price_rate = env('DEFAULT_CHAPTER_PRICE', 0.015);
  1105. }
  1106. //Log::info($price_rate);
  1107. $fee = ceil($chapter->size * $price_rate);
  1108. /*if($this->isRaisePrice()){
  1109. $fee = round($chapter->size * 0.018);
  1110. }*/
  1111. }
  1112. //首个计费章节书币价格以35书币为基准,低于35提升至35,原价高于35书币,维持原价
  1113. if (isset($chapter->sequence) && isset($book_info->vip_seq)) {
  1114. if ($chapter->sequence == $book_info->vip_seq) {
  1115. if ($fee < 35) {
  1116. $fee = 35;
  1117. }
  1118. }
  1119. }
  1120. return $fee;
  1121. }
  1122. //降低付费用户书币价值
  1123. private function isRaisePrice(){
  1124. if(!$this->uid)
  1125. return false;
  1126. if(!$this->user)
  1127. return false;
  1128. if($this->user->balance < 100){
  1129. return false;
  1130. }
  1131. if(!in_array($this->distribution_channel_id,[211,123])){
  1132. return false;
  1133. }
  1134. if(DataAnalysisSelectUserService::getByUidAndType($this->uid,'RAISE')){
  1135. return true;
  1136. }
  1137. return false;
  1138. }
  1139. /**
  1140. * 获取强关章节数
  1141. * @param $book
  1142. * @return int
  1143. */
  1144. private function getSubscribeChapterNum($book)
  1145. {
  1146. //派单强关
  1147. if ($this->send_order_id) {
  1148. $send_order_info = SendOrderService::getById($this->send_order_id);
  1149. if ($send_order_info && $send_order_info->book_id == $book->bid && $send_order_info->subscribe_chapter_seq) {
  1150. return $send_order_info->subscribe_chapter_seq;
  1151. }
  1152. }
  1153. $subscribe = BookSubscribleChapterService::getSubcribleChapter($book->bid, $this->distribution_channel_id);
  1154. if ($subscribe) {
  1155. return (isset($subscribe->subscribe_chapter_id) && $subscribe->subscribe_chapter_id > 0) ? $subscribe->subscribe_chapter_id : $book->force_subscribe_chapter_seq;
  1156. }
  1157. return $book->force_subscribe_chapter_seq;
  1158. }
  1159. /**
  1160. * 判断访问的域名和数据库指定的域名是否一致,一致返回false ,不一致 true
  1161. * @param $domain 当前访问的doain
  1162. * @return bool
  1163. */
  1164. private function isVisitDomainEqualBookDomain($domain)
  1165. {
  1166. if ($domain == 'zhuishuyun' && stripos($this->book_info->promotion_domain, 'leyuee') !== false) {
  1167. return false;
  1168. }
  1169. return stripos($this->book_info->promotion_domain, $domain) === false;
  1170. }
  1171. //获取对当前图书对应域名的链接
  1172. private function getCorrespondBookUrl()
  1173. {
  1174. $url = sprintf(
  1175. 'https://site%s.%s/reader?bid=%s&cid=%s&send_order_id=%s&fromtype=%s&stats=2',
  1176. $this->en_distribution_channel_id,
  1177. $this->book_info->promotion_domain,
  1178. $this->en_bid,
  1179. $this->cid,
  1180. $this->send_order_id,
  1181. $this->from_type
  1182. );
  1183. return $url;
  1184. }
  1185. /**
  1186. * 用户添加标签
  1187. * @param $book_info
  1188. */
  1189. private function addTag($book_info)
  1190. {
  1191. if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
  1192. try {
  1193. UserDeepReadTagService::addTag([
  1194. 'uid' => $this->uid,
  1195. 'bid' => $book_info->bid,
  1196. 'book_name' => $book_info->book_name,
  1197. 'category_id' => $book_info->category_id,
  1198. 'category_name' => $book_info->category_name,
  1199. 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
  1200. 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
  1201. 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
  1202. ]);
  1203. } catch (\Exception $e) {
  1204. }
  1205. }
  1206. }
  1207. private function newUserRewardRead()
  1208. {
  1209. $count = ChapterOrderService::getUserRecordCount($this->uid);
  1210. return $count > 2;
  1211. }
  1212. private function isBookOrdered($bid)
  1213. {
  1214. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
  1215. if ($chapter_order) return true;
  1216. $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
  1217. if ($res) return true;
  1218. return false;
  1219. }
  1220. private function beforeForceSubAndBeforeVipUvAndPv($book, $book_force_seq, $chapter)
  1221. {
  1222. $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 14;
  1223. $prev_sub_seq = 0;
  1224. if ($book_force_seq) {
  1225. $prev_sub_seq = $book_force_seq - 1;
  1226. }
  1227. $prev_vip_seq = 0;
  1228. $date = date('Y-m-d');
  1229. if (isset($book->vip_seq) && !empty($book->vip_seq)) {
  1230. $prev_vip_seq = $book->vip_seq - 1;
  1231. }
  1232. if ($chapter->sequence == $prev_vip_seq) {
  1233. $uv_key = 'book:' . $book->bid . ':beforevip:uv:date:' . $date . ':send_order_id:' . $send_order_id;
  1234. $pv_key = 'book:' . $book->bid . ':beforevip:pv:send_order_id:' . $send_order_id;
  1235. Redis::hincrby($pv_key, $date, 1);
  1236. Redis::hincrby($pv_key, 'total', 1);
  1237. Redis::sadd($uv_key, $this->uid);
  1238. Redis::sadd('beforevip' . $date, $book->bid . '-' . $send_order_id);
  1239. }
  1240. if ($chapter->sequence == $prev_sub_seq) {
  1241. $uv_key = 'book:' . $book->bid . ':beforeforcesub:uv:date:' . $date . ':send_order_id:' . $send_order_id;
  1242. $pv_key = 'book:' . $book->bid . ':beforeforcesub::pvsend_order_id:' . $send_order_id;
  1243. Redis::hincrby($pv_key, $date, 1);
  1244. Redis::hincrby($pv_key, 'total', 1);
  1245. Redis::sadd($uv_key, $this->uid);
  1246. Redis::sadd('beforeforcesub' . $date, $book->bid . '-' . $send_order_id);
  1247. }
  1248. }
  1249. private function readRecordOther()
  1250. {
  1251. $bid = $this->book_info->bid;
  1252. $cid = $this->cid;
  1253. $distribution_channel_id = $this->distribution_channel_id;
  1254. $send_order_id = $this->send_order_id;
  1255. $from = $this->from_type;
  1256. $sequence = $this->chapter->sequence;
  1257. ReadRecordStatsService::record($this->uid,$bid,$cid,$distribution_channel_id,$send_order_id,$from,$sequence);
  1258. /*$chapter = $this->chapter;
  1259. try {
  1260. $data = [];
  1261. $data['uid'] = $this->uid;
  1262. $data['bid'] = $chapter->bid;
  1263. $data['cid'] = $chapter->id;
  1264. $data['is_vip'] = $chapter->is_vip;
  1265. $data['seq'] = $chapter->sequence;
  1266. $data['created_at'] = date('Y-m-d H:i:s');
  1267. $data['updated_at'] = date('Y-m-d H:i:s');
  1268. DB::table('read_records')->insert($data);
  1269. } catch (\Exception $e) {
  1270. }*/
  1271. }
  1272. /**
  1273. * 下架图书 true:下架不能阅读了, false:可以正常阅读
  1274. * @return bool
  1275. */
  1276. private function isOffShelf()
  1277. {
  1278. $book_info = $this->book_info;
  1279. if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
  1280. return true;
  1281. }
  1282. //屏蔽一本书1042 2626
  1283. if (in_array($book_info->bid, [1042, 2626]) && $this->distribution_channel_id == 123) {
  1284. return true;
  1285. }
  1286. if ($book_info->is_on_shelf == 4) {
  1287. //版权到期,有阅读记录还可以继续阅读,订购
  1288. /*if (!ReadRecordService::getRecordByUidBid($this->uid, $book_info->bid)) {
  1289. return true;
  1290. }*/
  1291. //版权到期,有包年可以继续阅读
  1292. $year_order = YearOrderService::getRecord($this->uid);
  1293. if($year_order){
  1294. return false;
  1295. }
  1296. //版权到期,有订购记录还可以继续阅读,订购
  1297. $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $book_info->bid);
  1298. if (!$chapter_order) return true;
  1299. }
  1300. if($book_info->is_on_shelf == 10){
  1301. //Log::info('ddddddddddddddddddddddddddd');
  1302. $yq_book_user = BookUserService::selectUser($this->uid);
  1303. //Log::info($yq_book_user);
  1304. if($yq_book_user && $yq_book_user->type == 'ENABLE'){
  1305. return false;
  1306. }
  1307. return true;
  1308. }
  1309. return false;
  1310. }
  1311. //章节被删除的情况
  1312. private function chapterNotExists()
  1313. {
  1314. $chapter = $this->chapter;
  1315. $cid = $this->cid;
  1316. if ($chapter) return false;
  1317. //章节不存在的情况
  1318. $no_check = ChapterService::getChapterNameByIdNoCheck($cid);
  1319. $h5_scheme = 'https';
  1320. if (!$no_check) {
  1321. //章节真正不存在的情况
  1322. $url = $h5_scheme . '://' . _domain() . '/catalog?id=' . $this->en_bid;
  1323. return $url;
  1324. }
  1325. //章节被删除的情况
  1326. if ($no_check->next_cid) {
  1327. $url = $h5_scheme . '://' . _domain() . '/reader?bid=' . $this->en_bid . '&cid=' . $no_check->next_cid;
  1328. return $url;
  1329. }
  1330. //章节被删除的是最后一章的情况
  1331. $url = $h5_scheme . '://' . _domain() . '/catalog?id=' . $this->en_bid . '&sequence=' . $no_check->sequence;
  1332. return $url;
  1333. }
  1334. /**
  1335. * 深度阅读
  1336. * @param $chapter
  1337. */
  1338. private function deepReadRecord()
  1339. {
  1340. if (!env('ON_BOOK_UV_PV', false)) {
  1341. return;
  1342. }
  1343. $chapter = $this->chapter;
  1344. $key = 'book:' . $chapter->bid . ':deepread:uv';
  1345. $chapter_key = 'book:' . $chapter->bid . ':chapterseq:' . $chapter->sequence;
  1346. if (Redis::scard($key) > 50000) {
  1347. if (Redis::Sismember($key, $this->uid)) {
  1348. Redis::sadd($chapter_key, $this->uid);
  1349. }
  1350. } else {
  1351. Redis::sadd($key, $this->uid);
  1352. Redis::sadd($chapter_key, $this->uid);
  1353. }
  1354. }
  1355. /**
  1356. * 强关类型
  1357. * @param $appid
  1358. * @return array
  1359. */
  1360. private function getSubscribeType($appid, $bid)
  1361. {
  1362. $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0;
  1363. $sub_setting = ChannelSubscribeSettingService::getSubscribeTypeByAppId($appid);
  1364. if (!$sub_setting) return ['type' => [1], 'url' => ''];
  1365. $types = explode(',', $sub_setting->force_subscribe_type);
  1366. $url = '';
  1367. if (in_array(3, $types) && !empty($sub_setting->resource_url)) {
  1368. $h5_scheme = env('H5_SCHEME', 'https');
  1369. $url = $h5_scheme . '://' . _domain() . '/subscribeauth/?uid=' . $this->uid . '&distribution_channel_id=' . $this->distribution_channel_id . '&appid=' . $appid . '&bid=' . $bid . '&send_order_id=' . $send_order_id;
  1370. }
  1371. return ['type' => $types, 'url' => $url];
  1372. }
  1373. private function showChapterPrice($bid, $charge_type)
  1374. {
  1375. if ($charge_type == 'BOOK') {
  1376. return false;
  1377. }
  1378. $show_chapter_price_bid = env('SHOW_CHAPTER_PRICE_BID', 'all');
  1379. if ($show_chapter_price_bid != 'all') {
  1380. $show_chapter_price_bid_array = explode(',', $show_chapter_price_bid);
  1381. if (!in_array($bid, $show_chapter_price_bid_array)) {
  1382. return false;
  1383. }
  1384. }
  1385. $show_chapter_price_channel = env('SHOW_CHAPTER_PRICE_CHANNEL', '');
  1386. if (!$show_chapter_price_channel) {
  1387. return false;
  1388. }
  1389. if ($show_chapter_price_channel == 'all') {
  1390. return true;
  1391. }
  1392. $show_chapter_price_channel_array = explode(',', $show_chapter_price_channel);
  1393. if (in_array($this->distribution_channel_id, $show_chapter_price_channel_array)) {
  1394. return true;
  1395. }
  1396. return false;
  1397. }
  1398. /**
  1399. * 阅读统计
  1400. */
  1401. private function chapterStats()
  1402. {
  1403. $chapter = $this->chapter;
  1404. $bid = $this->book_info->bid;
  1405. //派单精确统计
  1406. if ($chapter->sequence <= 30) {
  1407. //$this->sendOrderChapterUv($bid, $chapter->sequence);
  1408. }
  1409. //智能推送 测书统计章节uv
  1410. if ($chapter->sequence <= 60) {
  1411. //测书数据 由30改到60 2018-11-26 18:00
  1412. $this->smartPushTestBookChapterUv($bid, $chapter->sequence);
  1413. }
  1414. //智能推送 测书统计第二章 uv
  1415. if ($chapter->sequence == 2) {
  1416. $this->smartPushTestBookSecondChapterUv($bid);
  1417. }
  1418. // 统计前5张uv 会放在book_five_chapter_uv表中,脚本在 \App\Console\Commands\BookTest::data1里面
  1419. // 作用早忘记了
  1420. $field = date('Y-m-d');
  1421. /*
  1422. if ($chapter->sequence <= 5 && $this->send_order_id) {
  1423. try {
  1424. Redis::sadd(sprintf('book_before_five_uv_%s_%s_%s', $field, $bid, $chapter->sequence), $this->uid);
  1425. Redis::sadd('book_before_five_uvs', sprintf('%s_%s_%s', $field, $bid, $chapter->sequence));
  1426. } catch (\Exception $e) {
  1427. }
  1428. }*/
  1429. //统计点击率
  1430. $key = 'book_click_num_bid_' . $bid;
  1431. try {
  1432. Redis::HINCRBY($key, $field, 1);
  1433. } catch (\Exception $e) {
  1434. }
  1435. //阅读页面pvuv
  1436. $this->recordReaderUvAndPv();
  1437. }
  1438. private function smartPushTestBook($bid, $balance)
  1439. {
  1440. $smart_bid = ReadRecordService::getSmartPush($this->uid);
  1441. if ($smart_bid && in_array($bid, $smart_bid)) {
  1442. $field = sprintf('%s_amount', $bid);
  1443. try {
  1444. Redis::HINCRBY('smart_push_test_book', $field, $balance);
  1445. Redis::sadd('smart_push_test_book_user_count' . $bid, $this->uid);
  1446. } catch (\Exception $e) {
  1447. }
  1448. }
  1449. }
  1450. private function smartPushTestBookSecondChapterUv($bid)
  1451. {
  1452. $smart_bid = ReadRecordService::getSmartPush($this->uid);
  1453. if ($smart_bid && in_array($bid, $smart_bid)) {
  1454. try {
  1455. Redis::sadd('smart_push_test_book_second_uv' . $bid, $this->uid);
  1456. } catch (\Exception $e) {
  1457. }
  1458. }
  1459. }
  1460. private function smartPushTestBookChapterUv($bid, $sequence)
  1461. {
  1462. $smart_bid = ReadRecordService::getSmartPush($this->uid);
  1463. if ($smart_bid && in_array($bid, $smart_bid)) {
  1464. try {
  1465. $key = 'smartPushTestBookChapterUv:bid:%s:seq:%s';
  1466. Redis::sadd(sprintf($key, $bid, $sequence), $this->uid);
  1467. } catch (\Exception $e) {
  1468. }
  1469. }
  1470. }
  1471. /**
  1472. * 测书 智能推送统计
  1473. * @param $bid
  1474. */
  1475. private function smartPushTestBookPayPageUv($bid)
  1476. {
  1477. $smart_bid = ReadRecordService::getSmartPush($this->uid);
  1478. if ($smart_bid && in_array($bid, $smart_bid)) {
  1479. try {
  1480. $key = 'smartPushTestBookPayPageUv:bid:%s';
  1481. Redis::sadd(sprintf($key, $bid), $this->uid);
  1482. } catch (\Exception $e) {
  1483. }
  1484. }
  1485. }
  1486. /**
  1487. * 派单精确统计--章节
  1488. * @param $bid
  1489. * @param $sequence
  1490. */
  1491. private function sendOrderChapterUv($bid, $sequence)
  1492. {
  1493. if ($this->send_order_id) {
  1494. $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
  1495. if (!$send_order_bid) {
  1496. $send_order_info = SendOrderService::getById($this->send_order_id);
  1497. if ($send_order_info) {
  1498. $send_order_bid = $send_order_info->book_id;
  1499. Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
  1500. }
  1501. } else {
  1502. $send_order_bid_arr = explode('-', $send_order_bid);
  1503. $send_order_bid = $send_order_bid_arr[0];
  1504. }
  1505. if ($send_order_bid && $send_order_bid == $bid) {
  1506. try {
  1507. $key = 'accurateSendOrderChapterUv:bid:%s:seq:%s:sendorderid:' . $this->send_order_id;
  1508. Redis::sadd(sprintf($key, $bid, $sequence), $this->uid);
  1509. } catch (\Exception $e) {
  1510. }
  1511. }
  1512. }
  1513. }
  1514. /**
  1515. * 派单精确统计--强关页面uv
  1516. * @param $bid
  1517. */
  1518. private function sendOrderSubscribePageUv($bid)
  1519. {
  1520. if ($this->send_order_id) {
  1521. $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
  1522. if (!$send_order_bid) {
  1523. $send_order_info = SendOrderService::getById($this->send_order_id);
  1524. if ($send_order_info) {
  1525. $send_order_bid = $send_order_info->book_id;
  1526. Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
  1527. }
  1528. } else {
  1529. $send_order_bid_arr = explode('-', $send_order_bid);
  1530. $send_order_bid = $send_order_bid_arr[0];
  1531. }
  1532. if ($send_order_bid && $send_order_bid == $bid) {
  1533. try {
  1534. $key = 'accurateSendOrderSubscribePageUv:bid:%s:sendorderid:' . $this->send_order_id;
  1535. Redis::sadd(sprintf($key, $bid), $this->uid);
  1536. } catch (\Exception $e) {
  1537. }
  1538. }
  1539. }
  1540. }
  1541. /**
  1542. * 派单精确统计--支付页面uv
  1543. * @param $bid
  1544. */
  1545. private function sendOrderPayPageUv($bid)
  1546. {
  1547. if ($this->send_order_id) {
  1548. $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
  1549. if (!$send_order_bid) {
  1550. $send_order_info = SendOrderService::getById($this->send_order_id);
  1551. if ($send_order_info) {
  1552. $send_order_bid = $send_order_info->book_id;
  1553. Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
  1554. }
  1555. } else {
  1556. $send_order_bid_arr = explode('-', $send_order_bid);
  1557. $send_order_bid = $send_order_bid_arr[0];
  1558. }
  1559. if ($send_order_bid && $send_order_bid == $bid) {
  1560. try {
  1561. $key = 'accurateSendOrderPayPageUv:bid:%s:send_order_id:' . $this->send_order_id;
  1562. Redis::sadd(sprintf($key, $bid), $this->uid);
  1563. } catch (\Exception $e) {
  1564. }
  1565. }
  1566. }
  1567. }
  1568. private function recordReaderUvAndPv()
  1569. {
  1570. WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
  1571. }
  1572. //用户是否在广告样本中
  1573. private function isUserInAdSample(){
  1574. $res = DataAnalysisSelectUserService::getByUidAndType($this->uid,'AD');
  1575. if($res){
  1576. return true;
  1577. }else{
  1578. return false;
  1579. }
  1580. }
  1581. //阅读页面底部是否显示广告
  1582. private function isShowAd(){
  1583. $ad_status = env('AD_STATUS',1);
  1584. if(!$ad_status){
  1585. return ;
  1586. }
  1587. if(!in_array($this->distribution_channel_id,[2,14,123,211])){
  1588. return ;
  1589. }
  1590. //按章付费才显示
  1591. if($this->book_info->charge_type != 'CHAPTER'){
  1592. return ;
  1593. }
  1594. //用户是否在广告样本中
  1595. if(!$this->isUserInAdSample()) return ;
  1596. $cid = 0;
  1597. if($this->chapter && $this->chapter->next_cid){
  1598. $cid = $this->chapter->next_cid;
  1599. }
  1600. if(!$cid){
  1601. return ;
  1602. }
  1603. //付费用户没有广告
  1604. if(OrderService::isPaidUser($this->uid)) return ;
  1605. //如果下一张已经付费,广告不显示
  1606. if($this->getOrderRecord($this->book_info->bid, $cid)){
  1607. return ;
  1608. }
  1609. $next_chapter = ChapterService::getChapterNameById($cid, $this->book_info->bid);
  1610. //下一章事vip的话 才显示广告
  1611. if(!$next_chapter || !$next_chapter->is_vip){
  1612. return ;
  1613. }
  1614. $price = $this->getPrice($this->book_info,$next_chapter);
  1615. $flag = $price > $this->user->balance;
  1616. if( $flag ){
  1617. $this->chapter->is_show_ad = 1;
  1618. AdVisitStatService::create($this->uid,$this->book_info->bid,$this->cid,'EXPOSURE');
  1619. }
  1620. }
  1621. public function getWechatJsConfig(Request $request)
  1622. {
  1623. //try {
  1624. // $chapter->is_show_share_button = 1;
  1625. $bid = $request->input('bid', '');
  1626. $cid = $request->input('cid', '');
  1627. $url = $request->input('url', '');
  1628. $url = urldecode($url);
  1629. \Log::info('url:' . ($this->uid) . $url);
  1630. if (empty($bid) || empty($cid) || empty($url)) {
  1631. return response()->error('PARAM_EMPTY');
  1632. }
  1633. $share_url = 'https://'._domain().'/detail?fromtype=readershare&id='.$bid.'&fromflag='.($this->uid).'&fromcid='.$cid;
  1634. //$js_config = ChapterShareWechatConfigService::getConfig($url);
  1635. $app_hash = array(
  1636. 4025=>['appid'=>'wx80b618c9dcc940f7','appsecret'=>'255a2de8db51e4084b5e9087d26d4ecb'],
  1637. 4147=>['appid'=>'wx2a99699cd9572812','appsecret'=>'0e0d57f94eeba50abb3af6883df05a5c'],
  1638. 691=>['appid'=>'wx5cefcd251dc40693','appsecret'=>'755f64c85173dad21f20870e38f59d8a'],
  1639. 123=>['appid'=>'wx983808610aa9dcc5','appsecret'=>'91002999590b79f3c7be35fd73c04049'],
  1640. 211=>['appid'=>'wx39338e374cc2055b','appsecret'=>'1a4c2039be271b3811182be5bb53eb34'],
  1641. );
  1642. $appId = $app_hash[$this->distribution_channel_id]['appid'];
  1643. $appSecret = $app_hash[$this->distribution_channel_id]['appsecret'];
  1644. $js_config = (new ChapterShareWechatConfigService($appId,$appSecret))->getSignPackage($url);
  1645. /*$appid = DB::table('official_accounts')->where('distribution_channel_id',$this->distribution_channel_id)->first();//(['distribution_channel_id'=>$this->distribution_channel_id]);
  1646. $appid = $appid->appid;
  1647. //\Log::info('get_appid:'.($appid));
  1648. $js_config = (new ChapterShareWechatConfigService($appid))->getSignPackage($url);
  1649. //$chapter->js_config = $js_config;
  1650. //$chapter->share_url = $share_url;
  1651. $book = BookService::getBookById(Hashids::decode($bid)[0]);
  1652. $first_cid = $book->first_cid;
  1653. $share_url = 'https://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('SHARE_DOMAIN') . '/reader?fromtype=readershare&bid=' . $bid . '&cid=' . ($first_cid) . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
  1654. /*if (in_array($this->uid, explode(',', env('TEST_SHARE_UIDS')))) {
  1655. $share_url = 'https://site5017zqeyzwgyx9n8.zhuishuyun.com/reader?fromtype=readershare&bid=' . $bid . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
  1656. }*/
  1657. $book = BookService::getBookById(Hashids::decode($bid)[0]);
  1658. $first_cid = $book->first_cid;
  1659. $share_url = 'https://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('SHARE_DOMAIN') . '/reader?fromtype=readershare&bid=' . $bid . '&cid=' . ($first_cid) . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
  1660. if (in_array($this->distribution_channel_id, [2, 14])) {
  1661. $js_config = ChapterShareWechatConfigService::getConfig($url);
  1662. $share_url = 'https://site' . ($this->distribution_channel_id) . '.' . env('SHARE_DOMAIN') . '/reader?fromtype=readershare&bid=' . $bid . '&cid=' . ($first_cid) . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
  1663. }
  1664. $js_config['share_url'] = $share_url;
  1665. /*} catch (\Exception $e) {
  1666. \Log::error($e->getMessage());
  1667. }*/
  1668. //\Log::info($js_config);
  1669. return response()->success($js_config);
  1670. }
  1671. }