ChapterController.php 83 KB

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