ChapterController.php 81 KB

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