ChapterController.php 79 KB

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