ChapterController.php 83 KB

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