ChapterController.php 84 KB

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