123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142 |
- <?php
- namespace App\Http\Controllers\Wap\Book;
- use App\Modules\Book\Models\DataAnalysisBookConfig;
- use App\Modules\Book\Services\BookService;
- use App\Modules\Book\Services\ChapterCommentsService;
- use App\Modules\Book\Services\ChapterShareWechatConfigService;
- use App\Modules\Statistic\Models\DataAnalysisSelectUser;
- use App\Modules\Statistic\Services\AdVisitStatService;
- use App\Modules\Statistic\Services\DataAnalysisChapterService;
- use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
- use App\Modules\Statistic\Services\WapVisitStatService;
- use App\Modules\Subscribe\Services\CrmChapterOrderDetailService;
- use App\Modules\Subscribe\Services\CustomChapterOrderService;
- use App\Modules\Subscribe\Services\OrderService;
- use App\Modules\Subscribe\Models\Order;
- use App\Modules\User\Services\CrmUserService;
- use App\Modules\User\Services\ForceGuidePersonAccountService;
- use App\Modules\User\Services\ForceSubscribeUserIService;
- use App\Modules\User\Services\ReadRecordStatsService;
- use App\Modules\User\Services\UserBindHkWelfareService;
- use App\Modules\User\Services\UserService;
- use App\Modules\YunQi\Services\BookUserService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Wap\BaseController;
- use Cookie;
- use Redis;
- use App\Modules\Book\Services\ChapterService;
- use App\Modules\User\Services\ReadRecordService;
- use App\Http\Controllers\Wap\Book\Transformers\ChapterTransformer;
- use App\Modules\Book\Services\BookConfigService;
- use App\Http\Controllers\Wap\Book\Transformers\ChapterListTransformer;
- use App\Modules\Subscribe\Services\BookOrderService;
- use App\Modules\Subscribe\Services\ChapterOrderService;
- use App\Modules\Subscribe\Services\YearOrderService;
- use App\Modules\OfficialAccount\Services\ForceSubscribeService;
- use App\Modules\Subscribe\Services\ChapterReminderService;
- use App\Modules\OfficialAccount\Services\OfficialAccountService;
- use Hashids;
- use GuzzleHttp\Client;
- use Log;
- use DB;
- use App\Modules\User\Services\UserSignService;
- use App\Modules\SendOrder\Services\SendOrderService;
- use App\Modules\User\Services\UserDeepReadTagService;
- use App\Modules\Book\Services\BookSubscribleChapterService;
- use App\Modules\Channel\Services\ChannelSubscribeSettingService;
- class ChapterController extends BaseController
- {
- /**
- * @apiDefine Chapter 章节
- */
- //用户是否强关
- private $is_had_subscribe = false;
- //章节是否需要强关
- private $is_need_subscribe;
- //用户信息
- private $user;
- //图书信息
- private $book_info;
- //cid
- private $cid;
- //加密的bid
- private $en_bid;
- //章节信息
- private $chapter;
- //强关时间
- private $force_subscribe_time = null;
- //关注的appid
- private $need_subscribe_appid;
- private $need_subscribe_name;
- private $is_first_book_order = 0;
- private $domain;
- private $crm_order = '';
- /**
- * @apiVersion 1.0.0
- * @apiDescription 章节列表不分页
- * @api {get} books/{bid}/allcatalog 章节列表不分页
- * @apiGroup Chapter
- * @apiName getCatalog
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {Array} data.list 分页结果集
- * @apiSuccess {Int} data.list.bid bid
- * @apiSuccess {Int} data.list.chapter_id 章节id
- * @apiSuccess {String} data.list.chapter_name 章节名称
- * @apiSuccess {Int} data.list.chapter_sequence 序号
- * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
- * @apiSuccess {Int} data.list.chapter_size 章节大小
- * @apiSuccess {Int} data.list.prev_cid 上一章节id
- * @apiSuccess {Int} data.list.next_cid 下一章节
- * @apiSuccess {String} data.list.recent_update_at 更新时间
- * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
- * @apiSuccess {String} data.list.is_show_price 是否显示价格
- * @apiSuccess {String} data.list.price 价格
- * @apiSuccess {object} data.meta 分页信息
- * @apiSuccess {Int} data.meta.total 总条数
- * @apiSuccess {Int} data.meta.per_page 每页条数
- * @apiSuccess {Int} data.meta.current_page 当前页
- * @apiSuccess {Int} data.meta.last_page 最后页
- * @apiSuccess {String} data.meta.next_page_url 下一页
- * @apiSuccess {String} data.meta.prev_page_url 上一页
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data:
- * [
- * {
- * bid: 5,
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * is_need_subscirbe: 1,
- * },
- * {
- * bid: 5,
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * is_need_subscirbe: 1,
- * },
- * ]
- * }
- */
- public function getCatalog(Request $request, $t, $domain, $bid)
- {
- if (!$this->checkUid()) {
- return response()->error('WAP_NOT_LOGIN');
- }
- $this->en_bid = $bid;
- $bid = Hashids::decode($bid)[0];
- $lists = ChapterService::getChapterLists($bid);
- $book_info = BookConfigService::getBookById($bid);
- if (!$book_info) {
- return response()->error('PARAM_ERROR');
- }
- $this->book_info = $book_info;
- $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
- foreach ($lists as $v) {
- $v->is_show_price = $is_show_price;
- $v->price = '';
- if ($is_show_price) {
- $v->price = $this->getPrice($book_info, $v);
- }
- }
- return response()->collection(new ChapterListTransformer, $lists);
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 章节列表分页
- * @api {get} books/{bid}/catalog 章节列表分页
- * @apiGroup Chapter
- * @apiName getCatalogPerPage
- * @apiParam {Int} page_size 分页大小(默认15)
- * @apiParam {Int} page 页码(默认1)
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {Array} data.list 分页结果集
- * @apiSuccess {Int} data.list.bid bid
- * @apiSuccess {Int} data.list.chapter_id 章节id
- * @apiSuccess {String} data.list.chapter_name 章节名称
- * @apiSuccess {Int} data.list.chapter_sequence 序号
- * @apiSuccess {Int} data.list.chapter_is_vip 是否vip
- * @apiSuccess {Int} data.list.chapter_size 章节大小
- * @apiSuccess {Int} data.list.prev_cid 上一章节id
- * @apiSuccess {Int} data.list.next_cid 下一章节
- * @apiSuccess {String} data.list.recent_update_at 更新时间
- * @apiSuccess {String} data.list.is_need_subscirbe 是否强制关注
- * @apiSuccess {String} data.list.is_show_price 是否显示价格
- * @apiSuccess {String} data.list.price 价格
- * @apiSuccess {object} data.meta 分页信息
- * @apiSuccess {Int} data.meta.total 总条数
- * @apiSuccess {Int} data.meta.per_page 每页条数
- * @apiSuccess {Int} data.meta.current_page 当前页
- * @apiSuccess {Int} data.meta.last_page 最后页
- * @apiSuccess {String} data.meta.next_page_url 下一页
- * @apiSuccess {String} data.meta.prev_page_url 上一页
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data:
- * list:[
- * {
- * bid: 5,
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * is_need_subscirbe: 1,
- * },
- * {
- * bid: 5,
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * is_need_subscirbe: 1,
- * },
- * ]
- * meta:{
- * total: 1253,
- * per_page: 15,
- * current_page: 1,
- * last_page: 84,
- * next_page_url: "http://myapi.cn/api/books/1/chapter?page=2",
- * prev_page_url: ""
- * }
- * }
- */
- public function getCatalogPerPage(Request $request, $t, $domain, $bid)
- {
- if (!$this->checkUid()) {
- return response()->error('WAP_NOT_LOGIN');
- }
- $this->en_bid = $bid;
- $bid_array = Hashids::decode($bid);
- if (isset($bid_array[0])) {
- $bid = $bid_array[0];
- } else {
- return response()->error('PARAM_ERROR');
- }
- $book_info = BookConfigService::getBookById($bid);
- if (!$book_info) {
- return response()->error('PARAM_ERROR');
- }
- $this->book_info = $book_info;
- $page_size = $request->input('page_size', 15);
- if($page_size>=100) $page_size=100;
- $res = ChapterService::getChapterListsPage($bid, $page_size);
- $is_show_price = $this->showChapterPrice($bid, $book_info->charge_type);
- foreach ($res as $v) {
- $v->is_show_price = $is_show_price;
- $v->price = '';
- if ($is_show_price) {
- $v->price = $this->getPrice($book_info, $v);
- }
- }
- return response()->pagination(new ChapterListTransformer, $res);
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 章节内容
- * @api {get} books/{bid}/chapters/{chapter_id} 章节内容
- * @apiGroup Chapter
- * @apiName index
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {Int} data.chapter_id 章节id
- * @apiSuccess {String} data.chapter_name 章节名称
- * @apiSuccess {Int} data.chapter_sequence 序号
- * @apiSuccess {Int} data.chapter_is_vip 是否vip
- * @apiSuccess {Int} data.chapter_size 章节大小
- * @apiSuccess {Int} data.prev_cid 上一章节id
- * @apiSuccess {Int} data.next_cid 下一章节
- * @apiSuccess {String} data.recent_update_at 更新时间
- * @apiSuccess {String} data.chapter_content 章节内容
- * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
- * @apiSuccess {Int} data.is_show_subscribe_link 是否显示底部强关链接
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: {
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
- * }
- * }
- */
- public function index(Request $request, $t, $domain, $bid, $cid)
- {
- $this->domain = $domain;
- $special_user_log = env('SPECIAL_USER_LOG');
- //注意:内部约定用 有此参数不需要强关
- $inter_not_need_sub = $request->has('inter_not_need_sub') ? true : false;
- $ad_status = $request->get('ad_status');
- //$ad_status = 0;
- $has_force_show_qrcode_cookie = Cookie::get('force_show_qrcode');
- Cookie::queue('force_show_qrcode', 1, -1);
- if (!$this->checkUid()) {
- myLog('special')->info('chapter index controller---$this->checkUid() fail-------');
- return response()->error('WAP_NOT_LOGIN');
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('in chapters--------------------------');
- $my_log->info('param is');
- $my_log->info($request->all());
- $my_log->info('$t is: '.$t);
- $my_log->info('$domain is: '.$domain);
- $my_log->info('$bid is: '.$bid);
- $my_log->info('$cid is: '.$cid);
- $my_log->info('$uri is: '. $request->path());
- }
- $this->en_bid = $bid;
- $bid = explode(',',$bid)[0];
- $bid = Hashids::decode($bid)[0];
- if($special_user_log && $special_user_log == $this->uid){
- myLog('special')->info('decode bid is: '.$bid);
- }
- //获取图书信息
- $book_info = BookConfigService::getBookById($bid);
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('book_info is ');
- $my_log->info($book_info);
- }
- //是否开启全站按章模式
- $global_charge_by_chapter_channels = explode(',',env('GLOBAL_CHARGE_BY_CHAPTER_CHANNEL'));
- if(in_array($this->distribution_channel_id,$global_charge_by_chapter_channels))
- {
- $book_info->charge_type = 'CHAPTER';
- }
- if (empty($book_info)) return response()->error('WAP_SYS_ERROR');
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('book info ok--------------------------');
- }
- $this->book_info = $book_info;
- $this->cid = $cid;
- //下架图书不能看
- if ($this->isOffShelf()) {
- return response()->error('WAP_OFF_SHELF');
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('on shelf ok--------------------------');
- }
- //获取章节信息
- $chapter = ChapterService::getChapterNameById($cid, $bid);
- $this->chapter = $chapter;
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('chapters-info--is-----------------------');
- $my_log->info($chapter);
- }
- //章节被删除
- if (($is_delete = $this->chapterNotExists())) {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('chapters-----delete---------------------');
- }
- return response()->error('WAP_DOMAIN_NOT_MATCH', [
- 'url' => $is_delete
- ]);
- }
- if(($result = $this->forceGuidePerson())){
- return response()->error('WAP_DOMAIN_NOT_MATCH', [
- 'url' => $result
- ]);
- }
- /*//强制导粉
- //$force_guide_sites = redisEnv('FORCE_GUIDE_SITES');
- //$img = redisEnv('GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
- list($force_guide_sites,$img) = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES','FORCE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
- if($force_guide_sites &&
- $img &&
- in_array($this->distribution_channel_id,explode(',',$force_guide_sites)) &&
- $this->is_paid &&
- ($this->chapter->sequence == 2 || $this->chapter->sequence == 8)&&
- !UserBindHkWelfareService::isHasGet($this->uid) &&
- ForceGuidePersonAccountService::isShow($this->uid,$bid,$cid)
- ){
- return response()->error('WAP_DOMAIN_NOT_MATCH', [
- '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)
- ]);
- }*/
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('chapters-----ok---------------------');
- }
- //获取强关章节数
- $subscribe_seq = $this->getSubscribeChapterNum($book_info);
- //章节是否需要强关 TRUE:不需要,false:需要
- $force_subscribe = $subscribe_seq > $chapter->sequence;
- $this->is_need_subscribe = !$force_subscribe;
- //图书域名,book_configs表的promotion_domain 要跟当前的主机名匹配 在强关章节后3章
- $visit_domain_check_seq = $subscribe_seq + 3;
- $is_forced_check_domain = false;
- $force_domain_iycdm_bids = explode(',',env('FORCE_DOMAIN_IYCDM_BIDS'));
- $force_domain_leyuee_bids = explode(',',env('FORCE_DOMAIN_LEYUEE_BIDS'));
- $force_domain_bids = [
- 'iycdm.com'=>$force_domain_iycdm_bids,
- 'leyuee.com'=>$force_domain_leyuee_bids
- ];
- //强制走指定域名
- foreach ($force_domain_bids as $_force_domain=>$_force_domain_bid)
- {
- if(in_array($bid,$_force_domain_bid))
- {
- $is_forced_check_domain = true;
- $visit_domain_check_seq = 0;
- $this->book_info->promotion_domain = $_force_domain;break;
- }
- }
- if ($this->isVisitDomainNotEqualBookDomain($domain, $visit_domain_check_seq, $is_forced_check_domain) ) {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('book domain not match------------------------');
- }
- return response()->error('WAP_DOMAIN_NOT_MATCH', [
- 'url' => $this->getCorrespondBookUrl()
- ]);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('book domain jump--------------------------');
- }
- $user_info = $this->_user_info;
- $this->user = $user_info;
- //用户是否强关
- $this->is_had_subscribe = $is_had_subscribe = $inter_not_need_sub ? true : $this->getSubscribe();
- //判断当前是否有强制显示服务号信息的cookie、已经关注 跳转到服务号信息引导页
- if($has_force_show_qrcode_cookie && $is_had_subscribe)
- {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('do not have force show qrcode cookie-------------------------');
- }
- $force_read_url = '/subscribe/getFromUser';//服务号信息引导页
- $force_read_data = ['src' => $force_read_url];
- return response()->error('WAP_NOT_SUBSCRIBE', $force_read_data);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('has force show qrcode cookie-ok-------------------------');
- }
- if ($force_subscribe || $chapter->is_vip == 0) {
- //vip前一张和枪管前一张的访问统计
- $this->beforeForceSubAndBeforeVipUvAndPv($book_info, $subscribe_seq, $chapter);
- }
- //不用关注且不是vip章节
- if ($force_subscribe && $chapter->is_vip == 0) {
- //获取公共号
- $officialAccount = $this->getOfficialAccount();
- $this->chapter->is_show_subscribe_link = 0;
- //非强关,但是设置了弱关,阅读页底部显示强关链接
- if ($officialAccount && isset($officialAccount->appid) && !empty($officialAccount->appid)) {
- $sub_type = $this->getSubscribeType($officialAccount->appid, $bid);
- if (in_array(2, $sub_type['type']) && !$is_had_subscribe) {
- $this->chapter->is_show_subscribe_link = 1;
- }
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('do not force subscribe-and is not vip-------------------------');
- }
- $this->getChapter();
- return response()->item(new ChapterTransformer, $this->chapter);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('11111111111111111111111111111111111111111');
- }
- //需要强制关注 不是vip章节 已经关注了
- if (!$force_subscribe && $chapter->is_vip == 0 && $is_had_subscribe) {
- $this->getChapter();
- return response()->item(new ChapterTransformer, $this->chapter);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('222222222222222222222222222222222222222');
- }
- //需要强制关注 没关注
- if ((!$force_subscribe) && !$is_had_subscribe) {
- $force_data = $this->forceSubscribe();
- if ($force_data) {
- $this->subscribeStats();
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('need subscribe-------------------------');
- }
- //阅读记录
- ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
- 'cid' => $cid, 'chapter_name' => $chapter->name]);
- return response()->error($force_data['error_type'], $force_data['data']);
- }
- //取不到公众号则不用强关
- if ($chapter->is_vip == 0) {
- $this->getChapter();
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('official fail--------------------------');
- }
- return response()->item(new ChapterTransformer, $this->chapter);
- }
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('33333333333333333333333333333333333333333');
- }
- //已经付费
- if ($this->getOrderRecord($bid, $cid)) {
- $this->getChapter();
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('had order order record--------------------------');
- }
- return response()->item(new ChapterTransformer, $this->chapter);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('4444444444444444444444444444444444444444444');
- }
- //获取价格
- $fee = $this->getPrice($book_info, $chapter);
- //广告
- if($this->isUserInAdSample() && $ad_status && $ad_status == 1 && $user_info->balance < $fee){
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('ad-----in--------------------');
- }
- //广告解锁2张
- /*if($this->chapter->next_cid){
- $next_chapter = ChapterService::getChapterNameById($this->chapter->next_cid, $bid);
- if($next_chapter){
- $next_chapter_name = $next_chapter->name;
- $this->bookOrderOrChapterOrder($book_info, $this->chapter->next_cid, 0, $next_chapter_name, 1);
- AdVisitStatService::create($this->uid,$this->book_info->bid,$this->chapter->next_cid,'UNLOCK_2');
- }
- }*/
- //$this->chapter->is_show_ad = 0;
- $result = AdVisitStatService::getInfoV2($this->uid, $cid, ['UNLOCK', 'UNLOCK_2']);
- if ($result){
- $this->getChapter();
- $this->bookOrderOrChapterOrder($book_info, $cid, 0, $chapter->name, 1);
- return response()->item(new ChapterTransformer, $this->chapter);
- }
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('5555555555555555555555555555555555');
- }
- //以上都是不用付费的情况******************************************************
- //未付费
- //返回的价格信息
- $data = [
- 'book_id' => $this->en_bid,
- 'book_name' => $book_info->book_name,
- 'chapter_name' => $chapter->name,
- 'chapter_id' => $cid,
- 'pay_type' => $book_info->charge_type,
- 'fee' => $fee,
- 'user_balance' => $user_info->balance,
- 'product_id' => $book_info->product_id,
- 'uid' => $this->uid,
- 'distribution_channel_id' => $this->distribution_channel_id,
- 'is_discount' => 0,
- 'discount_fee' => '',
- 'discount' => '',
- 'is_first_book_order'=>$this->is_first_book_order
- ];
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('data is:');
- $my_log->info($data);
- }
- //余额不足 弹窗提醒
- if ($user_info['balance'] < $fee) {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance is lack');
- $my_log->info('user balance is: '.$user_info['balance']);
- $my_log->info('fee is: '.$fee);
- }
- //$this->smartPushTestBookPayPageUv($bid);
- //$this->sendOrderPayPageUv($bid);
- //除了单本订购 其他的都不提醒,直接跳转到充值页面
- if ($book_info->charge_type == 'CHAPTER') {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('chapter order balance lack');
- }
- return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
- }
- //需要提箱
- if ($this->isOrderRemind($bid)) {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance lack remind');
- }
- return response()->error('WAP_BOOK_BALANCE_PAY', $data);
- //return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
- } else {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance lack not remind');
- }
- return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
- }
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('6666666666666666666666666666666666666');
- }
- //余额充足 单本弹窗提醒,章节直接扣费
- if ($this->isOrderRemind($bid) && $book_info->charge_type == 'BOOK') {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance enough remind');
- }
- return response()->error('WAP_BOOK_BUY', $data);
- }
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('77777777777777777777777777777');
- }
- //付费 不提醒
- if ($this->balancePay($book_info, $chapter, 0)) {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance pay ok-----');
- }
- $this->getChapter();
- return response()->item(new ChapterTransformer, $this->chapter);
- } else {
- if($special_user_log && $special_user_log == $this->uid){
- $my_log = myLog('special');
- $my_log->info('balance pay fails!!!!!!!!!!!!!!!!');
- }
- //付费 异常
- return response()->error('WAP_SYS_ERROR');
- }
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 余额支付
- * @api {get} books/{bid}/balance/chapterOrders/{cid} 余额支付
- * @apiGroup Chapter
- * @apiName pay
- * @apiParam (Int) remind 提醒
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {Int} data.chapter_id 章节id
- * @apiSuccess {String} data.chapter_name 章节名称
- * @apiSuccess {Int} data.chapter_sequence 序号
- * @apiSuccess {Int} data.chapter_is_vip 是否vip
- * @apiSuccess {Int} data.chapter_size 章节大小
- * @apiSuccess {Int} data.prev_cid 上一章节id
- * @apiSuccess {Int} data.next_cid 下一章节
- * @apiSuccess {String} data.recent_update_at 更新时间
- * @apiSuccess {String} data.chapter_content 章节内容
- * @apiSuccess {Int} data.is_need_subscirbe 是否强制关注(删除)
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: {
- * chapter_id: 5,
- * chapter_name: "第1240章 不是我",
- * chapter_sequence: 1239,
- * chapter_is_vip: 1,
- * chapter_size: 2422,
- * prev_cid: 0,
- * next_cid: 0,
- * recent_update_at: 2017-11-20 15:01:56,
- * chapter_content: "叶妩被司行霈的阴阳怪气一吓,思路偏得太远了。 她张口结舌,忘记了自己要说什么。",
- * }
- * }
- */
- public function pay(Request $request, $t, $domain, $bid, $cid)
- {
- if (!$this->checkUid()) {
- return response()->error('NOT_LOGIN');
- }
- $remind = (int)$request->input('remind');
- $this->en_bid = $bid;
- $oldbid = $bid;
- $bid = Hashids::decode($bid)[0];
- $book_info = BookConfigService::getBookById($bid);;
- if (empty($book_info)) response()->error('WAP_SYS_ERROR');
- //获取章节
- $chapter = ChapterService::getChapterNameById($cid, $bid);
- if (!$chapter) {
- return response()->error('WAP_SYS_ERROR');
- }
- $this->chapter = $chapter;
- $this->book_info = $book_info;
- $this->cid = $cid;
- if ($this->balancePay($book_info, $chapter, $remind)) {
- ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
- 'cid' => $cid, 'chapter_name' => $chapter->name]);
- $this->getChapter();
- return response()->item(new ChapterTransformer, $this->chapter);
- } else {
- $fee = $this->getPrice($book_info, $chapter);
- $data = [
- 'book_id' => $oldbid,
- 'book_name' => $book_info->book_name,
- 'chapter_name' => $chapter->name,
- 'chapter_id' => $cid,
- 'pay_type' => $book_info->charge_type,
- 'fee' => $fee,
- 'user_balance' => $this->_user_info['balance'],
- 'product_id' => $book_info->product_id,
- 'uid' => $this->uid,
- 'distribution_channel_id' => $this->distribution_channel_id,
- 'is_discount' => 0,
- 'discount_fee' => '',
- 'discount' => '',
- 'is_first_book_order'=>$this->is_first_book_order
- ];
- //不需要提醒
- if ($book_info->charge_type == 'BOOK') {
- return response()->error('WAP_BOOK_SECOND_BALANCE_PAY', $data);
- } elseif ($book_info->charge_type == 'CHAPTER') {
- return response()->error('WAP_CHAPTER_SECOND_BALANCE_PAY', $data);
- } else {
- return response()->error('WAP_SYS_ERROR');
- }
- }
- }
- /**
- * 余额支付
- * @param $book_info
- * @param $chapter_id
- * @param $chapter_size
- * @return bool
- */
- protected function balancePay($book_info, $chapter, $is_remind)
- {
- $fee = $this->getPrice($book_info, $chapter);
- if ((int)$this->_user_info['balance'] >= $fee) {
- if ($this->bookOrderOrChapterOrder($book_info, $chapter->id, $fee, $chapter->name, $is_remind)) {
- $this->chapterOrderStats($fee);
- if($this->user){
- $this->user->balance -= $fee;
- }
- $this->customChapterOrderStats($fee);
- return true;
- }
- }
- return false;
- }
- /**
- * 获取章节内容
- * @param $bid
- * @param $cid
- * @return bool|mixed
- */
- private function getChapter()
- {
- //初始化 默认字段
- $this->initChapterDefaultField();
- //章节内容
- $chapter_content = ChapterService::getChapter($this->book_info->bid, $this->cid);
- //$this->chapter->content = str_replace($chapter_content->name, '', $chapter_content->content);
- $this->chapter->content = $chapter_content->content;
- //阅读记录
- if($this->chapter->sequence >= 2){
- ReadRecordService::addReadRecord(['uid' => $this->uid, 'bid' => $this->book_info->bid, 'book_name' => $this->book_info->book_name,
- 'cid' => $this->cid, 'chapter_name' => $this->chapter->name]);
- }
- //统计
- $this->chapterStats();
- //123特殊强关
- $this->specialSubscribeFlag();
- //签到奖励
- //$this->sign();
- //#短篇推送长篇需求#
- //$this->shortPushLong();
- //#短推长、短推短对比
- //$this->shortPushshort();
- //阅读器分享
- $this->share();
- //广告
- $this->isShowAd();
- //完整阅读纪录 阅读纪录
- $this->readRecordOther();
- //crm订阅
- $this->crmChapterStats();
- }
- /**
- * 章节阅读接口需要配置返回的字段
- */
- private function initChapterDefaultField()
- {
- if (!$this->chapter) {
- return;
- }
- //内容
- $this->chapter->content = '';
- //签到默认字段
- $this->chapter->sign_days = 1;
- $this->chapter->sign_status = 0;
- $this->chapter->sign_reard = 0;
- $this->chapter->sign_version = 'v1';
- $this->chapter->sign_items = [];//只有v2签到才会用到的字段
- //#短篇推送长篇需求#
- $this->chapter->next_jump = 0;
- $this->chapter->next_jump_url = '';
- $this->chapter->show_push_title = 0;
- $this->chapter->push_title_url = '';
- $this->chapter->push_title = [];
- //分享
- $this->chapter->is_show_share_button = 0;
- //6985的分享配置
- $this->chapter->share_config = '';
- //阅读底部强关图片 只有123有
- $this->chapter->is_had_subscribe = 0;
- //广告
- $this->chapter->is_show_ad = 0;//可不可点击
- $this->chapter->is_visiable_ad = 0;//可不可显示
- }
- private function sign()
- {
- //渠道123 未关注的签到放到强关前一章
- if ($this->distribution_channel_id == 123 && !$this->is_had_subscribe) {
- if ($this->book_info->force_subscribe_chapter_seq - 1 == $this->chapter->sequence) {
- $sign_status = $this->userSign($this->uid);
- //$sign_status = 0;
- $this->chapter->sign_status = $sign_status ? 1 : 0;
- $this->chapter->sign_reard = $sign_status;
- $this->chapter->sign_days = ReadRecordService::getSignCount($this->uid);
- if($this->chapter->sign_days && $this->chapter->sign_days>=8){
- $this->chapter->sign_items = $fee_pool = [50,50,120,50,50,50,150];
- }else{
- $this->chapter->sign_items = $fee_pool = [30,50,120,50,50,50,150];
- }
- }
- } else {
- $sign_status = $this->userSign($this->uid);
- //$sign_status =0;
- $this->chapter->sign_status = $sign_status ? 1 : 0;
- $this->chapter->sign_reard = $sign_status;
- $this->chapter->sign_days = ReadRecordService::getSignCount($this->uid);
- if($this->chapter->sign_days && $this->chapter->sign_days>=8){
- $this->chapter->sign_items = $fee_pool = [50,50,120,50,50,50,150];
- }else{
- $this->chapter->sign_items = $fee_pool = [30,50,120,50,50,50,150];
- }
- }
- }
- private function forceSubscribe()
- {
- if($this->need_subscribe_appid){
- $src = $this->getRcodeInfo(['appid' => $this->need_subscribe_appid], $this->book_info->bid);
- if (empty($src)) return false;
- $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $this->need_subscribe_name . '&uid=' . $this->uid;
- return ['error_type' => 'WAP_NOT_SUBSCRIBE', 'data' => ['src' => $url, 'head_img' => '']];
- }
- //获取公众号信息
- $officialAccount = $this->getOfficialAccount();
- if (!$officialAccount || empty($officialAccount->appid)) {
- return false;
- }
- //如果是链接强关,则跳转
- $sub_type = $this->getSubscribeType($officialAccount->appid, $this->book_info->bid);
- if (in_array(3, $sub_type['type']) && $sub_type['url']) {
- return ['error_type' => 'WAP_LINK_SUBSCRIBE', 'data' => ['url' => $sub_type['url']]];
- }
- //普通强关
- if (in_array(1, $sub_type['type'])) {
- $src = $this->getRcodeInfo(['appid' => $officialAccount->appid], $this->book_info->bid);
- if (empty($src)) return false;
- if ($officialAccount->head_img) {
- $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $officialAccount->nickname . '&head_img=' . urlencode($officialAccount->head_img) . '&uid=' . $this->uid;
- } else {
- $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $officialAccount->nickname . '&uid=' . $this->uid;
- }
- return ['error_type' => 'WAP_NOT_SUBSCRIBE', 'data' => ['src' => $url, 'head_img' => $officialAccount->head_img]];
- }
- return false;
- }
- //强关页面的统计
- private function subscribeStats()
- {
- if ($this->send_order_id) {
- //$this->sendOrderSubscribePageUv($this->book_info->bid);
- //强关页面的uv
- /*try {
- Redis::sadd('subscribe_page_uv' . $this->send_order_id, $this->uid);
- Redis::sadd('subscribe_page_uv_send_order_ids', $this->send_order_id);
- } catch (\Exception $e) {
- }*/
- }
- }
- /**
- * 短推长
- */
- private function shortPushLong()
- {
- if ($this->book_info->charge_type = 'CHAPTER') return;
- $is_has_book_order = BookOrderService::isHasBookOrder($this->uid);
- if ($this->chapter->is_vip && $is_has_book_order) {
- $this->chapter->show_push_title = 1;
- $this->chapter->push_title = DataAnalysisBookConfig::getUserReaderPagePushBook($this->uid, $this->distribution_channel_id);
- }
- if (!$this->chapter->next_cid && $is_has_book_order) {
- $link = DataAnalysisBookConfig::getUserReaderPagePushBook($this->uid, $this->distribution_channel_id, 1);
- if ($link && isset($link['link']) && !empty($link['link'])) {
- $this->chapter->next_jump = 1;
- $this->chapter->next_jump_url = $link['link'];
- }
- }
- }
- /**
- * 短推长、短推短对比需求
- * 目标用户:全站短篇进入新注册且订阅短篇的付费用户
- * 方式:根据uid奇偶取用,奇:测试用户1 偶:测试用户2
- * 测试用户1:底部链接+完本推荐 均使用短篇小说
- * 测试用户2:底部链接+完本推荐 均使用长篇小说
- * 目标用户:全站短篇进入新注册且订阅短篇的付费用户
- */
- private function shortPushshort()
- {
- //新用户 注册时间大于某个值
- if(!$this->user){
- return ;
- }
- if(!env('SHORT_PUSH_SHORT_START_TIME') || strtotime($this->user->created_at) < env('SHORT_PUSH_SHORT_START_TIME')){
- return ;
- }
- //没有派单
- if(!$this->user->send_order_id) return ;
- //只在vip章节底部显示
- if(!$this->chapter->is_vip){
- return ;
- }
- //强关
- if(!$this->is_had_subscribe){
- return ;
- }
- //短篇进入
- $send_order_info = SendOrderService::getById($this->user->send_order_id);
- if(!$send_order_info || $send_order_info->charge_type != 'BOOK'){
- return ;
- }
- //订阅短篇的付费用户
- $is_has_book_order = BookOrderService::isHasBookOrder($this->uid);
- if(!$is_has_book_order) return ;
- //是否付费用户
- if(!OrderService::isPaidUser($this->uid)) return ;
- $type = $this->uid %2 == 1? 'BOOK':'CHAPTER';
- $result = DataAnalysisSelectUserService::create($this->uid, $this->distribution_channel_id, $type, 500, $attach = 'short2s2l');
- if(!$result) return ;
- //底部链接
- $this->chapter->show_push_title = 1;
- $this->chapter->push_title = DataAnalysisBookConfig::getUserReaderPagePushBookV2($this->uid, $this->distribution_channel_id,$type);
- //完本推荐
- if (!$this->chapter->next_cid ) {
- $link = DataAnalysisBookConfig::getUserReaderPagePushBookV2($this->uid, $this->distribution_channel_id,$type, 1);
- if($link && $link['link']){
- $this->chapter->next_jump = 1;
- $this->chapter->next_jump_url = $link['link'];
- }
- }
- }
- private function share()
- {
- if ($this->is_had_subscribe && in_array($this->distribution_channel_id, [2, 14, 211,4025,4147,691,123]) && $this->user) {//,4147,691,123,4025
- $this->chapter->is_show_share_button = 1;
- }
- /*if($this->distribution_channel_id == 6985 && $this->domain == 'leyuee'){
- $appid = 'wx126331d1732978b0';
- $appSecret = '76231c41c24d4363243866f5f9dee55f';
- $config = new ChapterShareWechatConfigService($appid,$appSecret);
- //$config->setAccessToken('');
- $config->requestAccessToken();
- $config->requestJsApiTicket();
- $url = sprintf(
- 'https://site%s.leyuee.com/reader?bid=%s&cid=%s',
- $this->en_distribution_channel_id,
- $this->en_bid,
- $this->cid
- );
- //$url = url()->full();
- //$url = str_replace('http://','https://',$url);
- $this->chapter->share_config = $config->getJssdkConfig($url);
- }*/
- }
- /**
- * 123 渠道阅读底部强关图片
- */
- private function specialSubscribeFlag()
- {
- if ($this->distribution_channel_id == 123 && !$this->is_had_subscribe) {
- $this->chapter->is_had_subscribe = 1;
- }
- }
- //订阅统计
- private function chapterOrderStats($fee)
- {
- $day = date('Y--m-d');
- try {
- Redis::hincrby('wap:chapterandbookorder:bid:' . $this->book_info->bid, $day, $fee);
- } catch (\Exception $e) {
- }
- $this->smartPushTestBook($this->book_info->bid, $fee);
- $specialChannelIdStats = env('SPECIAL_CHANNEL_STATS', 211);
- if (in_array($this->distribution_channel_id, explode(',', $specialChannelIdStats))) {
- WapVisitStatService::specialChannelIdStatsSave($this->uid, $this->book_info->bid, $fee);
- }
- }
- /**
- * 签到
- * @param $uid
- * @return int
- */
- protected function userSign($uid)
- {
- if (UserSignService::isSign($uid)) {
- //签过到了
- return 0;
- }
- /*if(in_array($this->distribution_channel_id,explode(',',redisEnv('NEW_SIGN_CHANNELS','')))){
- $version = UserSignService::getUserSignVersion($this->uid);
- }else{
- $version = 'v1';
- }*/
- $version = UserSignService::getUserSignVersion($this->uid);
- $this->chapter->sign_version = $version;
- if ($res = UserSignService::signToday($uid,$this->chapter->sign_version)) {
- //$sign_key = 'leyuee:wap:usersigni';
- //Redis::hset($sign_key, $uid, $res);
- return $res;
- }
- return 0;
- }
- /**
- * 添加订购记录
- * @param $book_info
- * @param $chapter_id
- * @param $fee
- * @return bool
- */
- protected function bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)
- {
- if ($book_info['charge_type'] == 'BOOK') {
- $data = [
- 'uid' => $this->uid,
- 'fee' => $fee,
- 'u' => Cookie::get('send_order_id'),
- 'distribution_channel_id' => $this->distribution_channel_id,
- 'bid' => $book_info->bid,
- 'book_name' => $book_info->book_name,
- 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
- ];
- return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
- } else {
- $data = [
- 'uid' => $this->uid,
- 'fee' => $fee,
- 'cid' => $chapter_id,
- 'bid' => $book_info->bid,
- 'distribution_channel_id' => $this->distribution_channel_id,
- 'book_name' => $book_info->book_name,
- 'chapter_name' => $chapter_name,
- 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
- 'is_remind' => $is_remind
- ];
- //print_r($data);
- if ($is_remind) {
- $this->addOrderRemind($book_info->bid);
- }
- return ChapterOrderService::addOrderAndDecrUserBalance($data, $this->uid);
- }
- }
- protected function addOrderRemind($bid)
- {
- if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
- return true;
- } else {
- ChapterReminderService::add($this->uid, $bid);
- return true;
- }
- }
- /**
- * 是否订购提醒
- * @param $chapter_id
- * @return bool
- */
- protected function isOrderRemind($bid)
- {
- $is_no_reminder = ChapterReminderService::checkIsNoReminder($this->uid, $bid) ? 1 : 0;
- return $is_no_reminder == 0;
- }
- /**
- * 用户是否关注
- * @param $uid
- * @return bool
- */
- protected function getSubscribe()
- {
- $send_order_info = null;
- if(!$this->send_order_id && Redis::hget('channel:setting:'.$this->distribution_channel_id,'no_send_order_subscribe')){
- return true;
- }
- if($this->send_order_id){
- $send_order_info = SendOrderService::getById($this->send_order_id);
- }
- $send_order_subscribe_status = Redis::hget('channel:setting:'.$this->distribution_channel_id,'send_order_subscribe');
- /*if(is_null($send_order_subsribe_status)){
- $send_order_subsribe_status = 0;
- }*/
- //$send_order_subscribe_status = 0;
- if($send_order_subscribe_status &&
- $send_order_info &&
- $send_order_info->promotion_type == 'EXTERNAL' &&
- $send_order_info->send_time &&
- strtotime($send_order_info->send_time) >= 1557712800
- ){
- $subscribe_info = ForceSubscribeUserIService::subscribes($this->uid,$this->distribution_channel_id,$this->send_order_id);
- $this->need_subscribe_appid = $subscribe_info['appid'];
- $this->need_subscribe_name = $subscribe_info['name'];
- return $subscribe_info['is_subscribed'];
- }
- if($send_order_info &&
- $send_order_info->promotion_type == 'INTERNAL' &&
- strtotime($send_order_info->created_at) > 1555488000){
- return true;
- }
- $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
- if ($res) {
- $this->force_subscribe_time = isset($res->created_at)?$res->created_at:null;
- return true;
- }
- return false;
- }
- /**
- * 获取公众号信息
- * @param $distribution_channel_id
- */
- protected function getOfficialAccount()
- {
- $distribution_channel_id = $this->distribution_channel_id;
- $res = OfficialAccountService::canUseOfficialAccountByChannelId(compact('distribution_channel_id'));
- if (isset($res->nickname) && !empty($res->nickname)) {
- Cookie::queue('force_subscribe_name', $res->nickname, env('U_COOKIE_EXPIRE'));
- }
- return $res;
- }
- /**
- * 获取二维码
- * @param $param
- * @return bool
- */
- private function getRcodeInfo($param, $bid)
- {
- //return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGI8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZEZ0T0ZoSHljM2kxOTUwQU5zY08AAgRF8-xbAwQAjScA";
- $param_need = [
- 'gzh_app_id' => $param['appid'],
- 'scene_id' => $this->uid,
- 'timestamp' => time(),
- ];
- $param_need['sign'] = $this->getSign($param_need);
- $client = new Client(['timeout' => 3.0,]);
- try {
- Log::info('get qrcode url is:' . 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need));
- $qrcode_url_res = $client->request('get', 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need))->getBody()->getContents();
- if ($qrcode_url_res) {
- $qrcode_url = json_decode($qrcode_url_res, true);
- if ($qrcode_url['code'] == 1) {
- //保存强关时的bid
- if (isset($qrcode_url['data']) && !empty($qrcode_url['data'])) {
- Redis::hset('force_subscribe_from_bid', $param['appid'] . '_' . $this->uid, $bid);
- $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0;
- Redis::hset('force_subscribe_from_send_order_id', $param['appid'] . '_' . $this->uid, $send_order_id);
- Log::info('uid is' . $this->uid . '--qrcode is:' . $qrcode_url['data']);
- return $qrcode_url['data'];
- }
- }
- }
- } catch (\Exception $e) {
- //\Log::info($e);
- //Redis::sadd('force_subscribe_qrcode:error', $param['appid'] . '_' . time());
- }
- return false;
- }
- /**
- * 获取订购记录
- * @param $book_info
- * @param $chapter_id
- * @return bool
- */
- private function getOrderRecord($bid, $chapter_id)
- {
- //包年记录
- $uid = $this->uid;
- $res = YearOrderService::getRecord($uid);
- if ($res) {
- $this->crm_order = 'YEAR_ORDER';
- return true;
- }
- $res = null;
- //单本订购记录
- $res = BookOrderService::getRecordByuidBid($uid, $bid);
- if ($res) {
- $this->crm_order = 'BOOK_ORDER';
- return true;
- }
- $res = null;
- //章节订购记录
- $chapterOrder = new ChapterOrderService();
- if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) {
- return true;
- }
- $this->crm_order = 'CHAPTER_ORDER';
- return false;
- }
- /**
- * 计算价格
- * @param $book_info
- * @param $chapter_size
- * @return float
- */
- private function getPrice($book_info, $chapter)
- {
- if ($book_info->charge_type == 'BOOK') {
- if(BookOrderService::isHasBookOrder($this->uid)){
- $this->is_first_book_order = 0;
- return 1399;
- }else{
- $this->is_first_book_order = 1;
- return 899;
- }
- } else {
- $channel_fee = BookService::getChapterPrice($this->distribution_channel_id);
- if ($channel_fee) {
- $price_rate = $channel_fee / 100;
- } else {
- $price_rate = env('DEFAULT_CHAPTER_PRICE', 0.015);
- }
- //判断是否为测试
- $distribution_channel_id_price = Redis::hset('channel:price:setting:'.$this->distribution_channel_id,$book_info->bid);
- if($distribution_channel_id_price){
- $fee = ceil($chapter->size * $distribution_channel_id_price);
- if($fee >189) $fee = 189;
- return $fee;
- }
- if($this->distribution_channel_id == 4326 && $book_info->bid == 6450)
- {
- $price_rate = 0.05;
- $fee = ceil($chapter->size * $price_rate);
- if($fee >189) $fee = 189;
- }else{
- $fee = ceil($chapter->size * $price_rate);
- if($fee >60) $fee = 60;
- }
- if($fee <37) $fee = 37;
- return $fee;
- }
- }
- //降低付费用户书币价值
- private function isRaisePrice(){
- if(!$this->uid)
- return false;
- if(!$this->user)
- return false;
- if($this->user->balance < 100){
- return false;
- }
- if(!in_array($this->distribution_channel_id,[211,123])){
- return false;
- }
- if(DataAnalysisSelectUserService::getByUidAndType($this->uid,'RAISE')){
- return true;
- }
- return false;
- }
- /**
- * 获取强关章节数
- * @param $book
- * @return int
- */
- private function getSubscribeChapterNum($book)
- {
- $hour = date('G');
- $send_order_info = null;
- if(in_array($this->distribution_channel_id,[123,211]) && $this->send_order_id){
- //开启落地页强关的需求有变,需要在链接实际推广1小时后就开启功能
- $send_order_info = SendOrderService::getById($this->send_order_id);
- if($send_order_info && $send_order_info->send_time && time()-strtotime($send_order_info->send_time) > 3600){
- return 1;
- }
- }
- if($this->send_order_id && $hour <=5 && in_array($this->send_order_id,[392216,392218,415200,415212,415163])){
- return 1;
- }
- 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])){
- return 1;
- }
- //派单强关
- if ($this->send_order_id) {
- $send_order_info || $send_order_info = SendOrderService::getById($this->send_order_id);
- if ($send_order_info && $send_order_info->book_id == $book->bid && $send_order_info->subscribe_chapter_seq) {
- return $send_order_info->subscribe_chapter_seq;
- }
- }
- $subscribe = BookSubscribleChapterService::getSubcribleChapter($book->bid, $this->distribution_channel_id);
- if ($subscribe) {
- return (isset($subscribe->subscribe_chapter_id) && $subscribe->subscribe_chapter_id > 0) ? $subscribe->subscribe_chapter_id : $book->force_subscribe_chapter_seq;
- }
- return $book->force_subscribe_chapter_seq;
- }
- /**
- * 判断访问的域名和数据库指定的域名是否一致,一致返回false ,不一致 true
- * @param $domain 当前访问的doain
- * @return bool
- */
- private function isVisitDomainNotEqualBookDomain($domain, $check_seq, $is_forced=false)
- {
- if($this->chapter->sequence <= $check_seq) return false;//判断check章节序号
- $book_domain = $this->book_info->promotion_domain;
- if(!$is_forced)
- {
- if ($domain == 'zhuishuyun' && stripos($book_domain, 'leyuee') !== false) {
- return false;
- }
- }
- return stripos($book_domain, $domain) === false;
- }
- //获取对当前图书对应域名的链接
- private function getCorrespondBookUrl()
- {
- $url = sprintf(
- 'https://site%s.%s/reader?bid=%s&cid=%s&send_order_id=%s&fromtype=%s&stats=2&crm=%s',
- $this->en_distribution_channel_id,
- $this->book_info->promotion_domain,
- $this->en_bid,
- $this->cid,
- $this->send_order_id,
- $this->from_type,
- $this->crm
- );
- return $url;
- }
- /**
- * 用户添加标签
- * @param $book_info
- */
- private function addTag($book_info)
- {
- if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
- try {
- UserDeepReadTagService::addTag([
- 'uid' => $this->uid,
- 'bid' => $book_info->bid,
- 'book_name' => $book_info->book_name,
- 'category_id' => $book_info->category_id,
- 'category_name' => $book_info->category_name,
- 'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
- 'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
- 'send_order_id' => Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0,
- ]);
- } catch (\Exception $e) {
- }
- }
- }
- private function newUserRewardRead()
- {
- $count = ChapterOrderService::getUserRecordCount($this->uid);
- return $count > 2;
- }
- private function isBookOrdered($bid)
- {
- $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $bid);
- if ($chapter_order) return true;
- $res = BookOrderService::getRecordByuidBid($this->uid, $bid);
- if ($res) return true;
- return false;
- }
- private function beforeForceSubAndBeforeVipUvAndPv($book, $book_force_seq, $chapter)
- {
- $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 14;
- $prev_sub_seq = 0;
- if ($book_force_seq) {
- $prev_sub_seq = $book_force_seq - 1;
- }
- $prev_vip_seq = 0;
- $date = date('Y-m-d');
- if (isset($book->vip_seq) && !empty($book->vip_seq)) {
- $prev_vip_seq = $book->vip_seq - 1;
- }
- if ($chapter->sequence == $prev_vip_seq) {
- $uv_key = 'book:' . $book->bid . ':beforevip:uv:date:' . $date . ':send_order_id:' . $send_order_id;
- $pv_key = 'book:' . $book->bid . ':beforevip:pv:send_order_id:' . $send_order_id;
- Redis::hincrby($pv_key, $date, 1);
- Redis::hincrby($pv_key, 'total', 1);
- Redis::sadd($uv_key, $this->uid);
- Redis::sadd('beforevip' . $date, $book->bid . '-' . $send_order_id);
- }
- if ($chapter->sequence == $prev_sub_seq) {
- $uv_key = 'book:' . $book->bid . ':beforeforcesub:uv:date:' . $date . ':send_order_id:' . $send_order_id;
- $pv_key = 'book:' . $book->bid . ':beforeforcesub::pvsend_order_id:' . $send_order_id;
- Redis::hincrby($pv_key, $date, 1);
- Redis::hincrby($pv_key, 'total', 1);
- Redis::sadd($uv_key, $this->uid);
- Redis::sadd('beforeforcesub' . $date, $book->bid . '-' . $send_order_id);
- }
- }
- private function readRecordOther()
- {
- $bid = $this->book_info->bid;
- $cid = $this->cid;
- $distribution_channel_id = $this->distribution_channel_id;
- $send_order_id = $this->send_order_id;
- $from = $this->from_type;
- $sequence = $this->chapter->sequence;
- ReadRecordStatsService::record($this->uid,$bid,$cid,$distribution_channel_id,$send_order_id,$from,$sequence);
- /*$chapter = $this->chapter;
- try {
- $data = [];
- $data['uid'] = $this->uid;
- $data['bid'] = $chapter->bid;
- $data['cid'] = $chapter->id;
- $data['is_vip'] = $chapter->is_vip;
- $data['seq'] = $chapter->sequence;
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- DB::table('read_records')->insert($data);
- } catch (\Exception $e) {
- }*/
- }
- /**
- * 下架图书 true:下架不能阅读了, false:可以正常阅读
- * @return bool
- */
- private function isOffShelf()
- {
- $book_info = $this->book_info;
- //针对米玩站点部分图书放开
- $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];
- if(in_array($this->distribution_channel_id,$miwan_sites) && in_array($book_info->bid,[1154,1232,1276,1295,1535,1542,1629,2430,4437,4730]))
- {
- return false;
- }
- if ($book_info->is_on_shelf == 0 || $book_info->is_on_shelf == 3) {
- return true;
- }
- //屏蔽一本书1042 2626
- if (in_array($book_info->bid, [1042, 2626]) && $this->distribution_channel_id == 123) {
- return true;
- }
- if ($book_info->is_on_shelf == 4) {
- //版权到期,有阅读记录还可以继续阅读,订购
- /*if (!ReadRecordService::getRecordByUidBid($this->uid, $book_info->bid)) {
- return true;
- }*/
- //版权到期,有包年可以继续阅读
- $year_order = YearOrderService::getRecord($this->uid);
- if($year_order){
- return false;
- }
- //1155
- //版权到期,有订购记录还可以继续阅读,订购
- $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $book_info->bid);
- if (!$chapter_order) return true;
- if($book_info->bid == 1155){
- $charge_info = Order::where('uid',$this->uid)
- ->where('price','>=',redisEnv('OFF_SHELF_BOOK_LIMIT_CHARGE',0))
- ->where('from_bid',$book_info->bid)
- ->where('status','PAID')
- ->first();
- if(!$charge_info){
- return true;
- }
- }
- }
- if($book_info->is_on_shelf == 10){
- //Log::info('ddddddddddddddddddddddddddd');
- $yq_book_user = BookUserService::selectUser($this->uid);
- //Log::info($yq_book_user);
- if($yq_book_user && $yq_book_user->type == 'ENABLE'){
- return false;
- }
- return true;
- }
- //crm上架
- if($book_info->is_on_shelf == 5){
- if(!CrmUserService::isCrmUser($this->uid,$this->is_paid)){
- return true;
- }
- }
- return false;
- }
- //章节被删除的情况
- private function chapterNotExists()
- {
- $chapter = $this->chapter;
- $cid = $this->cid;
- if ($chapter) return false;
- //章节不存在的情况
- $no_check = ChapterService::getChapterNameByIdNoCheck($cid);
- $h5_scheme = 'https';
- if (!$no_check) {
- //章节真正不存在的情况
- $url = $h5_scheme . '://' . _domain() . '/catalog?id=' . $this->en_bid;
- return $url;
- }
- //章节被删除的情况
- // if ($no_check->next_cid) {
- // $url = $h5_scheme . '://' . _domain() . '/reader?bid=' . $this->en_bid . '&cid=' . $no_check->next_cid;
- // return $url;
- // }
- //章节被删除的是最后一章的情况
- $url = $h5_scheme . '://' . _domain() . '/catalog?id=' . $this->en_bid;// . '&sequence=' . $no_check->sequence;
- return $url;
- }
- /**
- * 深度阅读
- * @param $chapter
- */
- private function deepReadRecord()
- {
- if (!env('ON_BOOK_UV_PV', false)) {
- return;
- }
- $chapter = $this->chapter;
- $key = 'book:' . $chapter->bid . ':deepread:uv';
- $chapter_key = 'book:' . $chapter->bid . ':chapterseq:' . $chapter->sequence;
- if (Redis::scard($key) > 50000) {
- if (Redis::Sismember($key, $this->uid)) {
- Redis::sadd($chapter_key, $this->uid);
- }
- } else {
- Redis::sadd($key, $this->uid);
- Redis::sadd($chapter_key, $this->uid);
- }
- }
- /**
- * 强关类型
- * @param $appid
- * @return array
- */
- private function getSubscribeType($appid, $bid)
- {
- $send_order_id = Cookie::get('send_order_id') ? Cookie::get('send_order_id') : 0;
- $sub_setting = ChannelSubscribeSettingService::getSubscribeTypeByAppId($appid);
- if (!$sub_setting) return ['type' => [1], 'url' => ''];
- $types = explode(',', $sub_setting->force_subscribe_type);
- $url = '';
- if (in_array(3, $types) && !empty($sub_setting->resource_url)) {
- $h5_scheme = env('H5_SCHEME', 'https');
- $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;
- }
- return ['type' => $types, 'url' => $url];
- }
- private function showChapterPrice($bid, $charge_type)
- {
- if ($charge_type == 'BOOK') {
- return false;
- }
- $show_chapter_price_bid = env('SHOW_CHAPTER_PRICE_BID', 'all');
- if ($show_chapter_price_bid != 'all') {
- $show_chapter_price_bid_array = explode(',', $show_chapter_price_bid);
- if (!in_array($bid, $show_chapter_price_bid_array)) {
- return false;
- }
- }
- $show_chapter_price_channel = env('SHOW_CHAPTER_PRICE_CHANNEL', '');
- if (!$show_chapter_price_channel) {
- return false;
- }
- if ($show_chapter_price_channel == 'all') {
- return true;
- }
- $show_chapter_price_channel_array = explode(',', $show_chapter_price_channel);
- if (in_array($this->distribution_channel_id, $show_chapter_price_channel_array)) {
- return true;
- }
- return false;
- }
- /**
- * 阅读统计
- */
- private function chapterStats()
- {
- $chapter = $this->chapter;
- $bid = $this->book_info->bid;
- //派单精确统计
- if ($chapter->sequence <= 30) {
- //$this->sendOrderChapterUv($bid, $chapter->sequence);
- }
- //智能推送 测书统计章节uv
- if ($chapter->sequence <= 60) {
- //测书数据 由30改到60 2018-11-26 18:00
- if($this->book_info->test_status == 1){
- $this->smartPushTestBookChapterUv($bid, $chapter->sequence); //2019-07-09 10:30 cancel
- }
- }
- //智能推送 测书统计第二章 uv
- if ($chapter->sequence == 2) {
- $this->smartPushTestBookSecondChapterUv($bid);
- }
- // 统计前5张uv 会放在book_five_chapter_uv表中,脚本在 \App\Console\Commands\BookTest::data1里面
- // 作用早忘记了
- $field = date('Y-m-d');
- /*
- if ($chapter->sequence <= 5 && $this->send_order_id) {
- try {
- Redis::sadd(sprintf('book_before_five_uv_%s_%s_%s', $field, $bid, $chapter->sequence), $this->uid);
- Redis::sadd('book_before_five_uvs', sprintf('%s_%s_%s', $field, $bid, $chapter->sequence));
- } catch (\Exception $e) {
- }
- }*/
- //统计点击率
- $key = 'book_click_num_bid_' . $bid;
- try {
- Redis::HINCRBY($key, $field, 1);
- } catch (\Exception $e) {
- }
- //阅读页面pvuv
- $this->recordReaderUvAndPv();
- }
- private function smartPushTestBook($bid, $balance)
- {
- $smart_bid = ReadRecordService::getSmartPush($this->uid);
- if ($smart_bid && in_array($bid, $smart_bid)) {
- $field = sprintf('%s_amount', $bid);
- try {
- Redis::HINCRBY('smart_push_test_book', $field, $balance);
- Redis::sadd('smart_push_test_book_user_count' . $bid, $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- private function smartPushTestBookSecondChapterUv($bid)
- {
- $smart_bid = ReadRecordService::getSmartPush($this->uid);
- if ($smart_bid && in_array($bid, $smart_bid)) {
- try {
- Redis::sadd('smart_push_test_book_second_uv' . $bid, $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- private function smartPushTestBookChapterUv($bid, $sequence)
- {
- $smart_bid = ReadRecordService::getSmartPush($this->uid);
- if ($smart_bid && in_array($bid, $smart_bid)) {
- try {
- $key = 'smartPushTestBookChapterUv:bid:%s:seq:%s';
- Redis::sadd(sprintf($key, $bid, $sequence), $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- /**
- * 测书 智能推送统计
- * @param $bid
- */
- private function smartPushTestBookPayPageUv($bid)
- {
- $smart_bid = ReadRecordService::getSmartPush($this->uid);
- if ($smart_bid && in_array($bid, $smart_bid)) {
- try {
- $key = 'smartPushTestBookPayPageUv:bid:%s';
- Redis::sadd(sprintf($key, $bid), $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- /**
- * 派单精确统计--章节
- * @param $bid
- * @param $sequence
- */
- private function sendOrderChapterUv($bid, $sequence)
- {
- if ($this->send_order_id) {
- $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
- if (!$send_order_bid) {
- $send_order_info = SendOrderService::getById($this->send_order_id);
- if ($send_order_info) {
- $send_order_bid = $send_order_info->book_id;
- Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
- }
- } else {
- $send_order_bid_arr = explode('-', $send_order_bid);
- $send_order_bid = $send_order_bid_arr[0];
- }
- if ($send_order_bid && $send_order_bid == $bid) {
- try {
- $key = 'accurateSendOrderChapterUv:bid:%s:seq:%s:sendorderid:' . $this->send_order_id;
- Redis::sadd(sprintf($key, $bid, $sequence), $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- }
- /**
- * 派单精确统计--强关页面uv
- * @param $bid
- */
- private function sendOrderSubscribePageUv($bid)
- {
- if ($this->send_order_id) {
- $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
- if (!$send_order_bid) {
- $send_order_info = SendOrderService::getById($this->send_order_id);
- if ($send_order_info) {
- $send_order_bid = $send_order_info->book_id;
- Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
- }
- } else {
- $send_order_bid_arr = explode('-', $send_order_bid);
- $send_order_bid = $send_order_bid_arr[0];
- }
- if ($send_order_bid && $send_order_bid == $bid) {
- try {
- $key = 'accurateSendOrderSubscribePageUv:bid:%s:sendorderid:' . $this->send_order_id;
- Redis::sadd(sprintf($key, $bid), $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- }
- /**
- * 派单精确统计--支付页面uv
- * @param $bid
- */
- private function sendOrderPayPageUv($bid)
- {
- if ($this->send_order_id) {
- $send_order_bid = Redis::hget('sendOrderIdToBid', $this->send_order_id);
- if (!$send_order_bid) {
- $send_order_info = SendOrderService::getById($this->send_order_id);
- if ($send_order_info) {
- $send_order_bid = $send_order_info->book_id;
- Redis::hset('sendOrderIdToBid', $this->send_order_id, $send_order_bid . '-' . time());
- }
- } else {
- $send_order_bid_arr = explode('-', $send_order_bid);
- $send_order_bid = $send_order_bid_arr[0];
- }
- if ($send_order_bid && $send_order_bid == $bid) {
- try {
- $key = 'accurateSendOrderPayPageUv:bid:%s:send_order_id:' . $this->send_order_id;
- Redis::sadd(sprintf($key, $bid), $this->uid);
- } catch (\Exception $e) {
- }
- }
- }
- }
- private function recordReaderUvAndPv()
- {
- WapVisitStatService::recordReaderUvAndPv($this->uid, $this->distribution_channel_id);
- }
- //用户是否在广告样本中
- private function isUserInAdSample(){
- /*$res = DataAnalysisSelectUserService::getByUidAndType($this->uid,'AD_V2');
- if($res){
- return true;
- }else{
- return false;
- }*/
- $is_ad_user = Cookie::get('cpc_ad_status');
- if($is_ad_user && $is_ad_user == 'show') return true;
- return false;
- }
- //阅读页面底部是否显示广告
- private function isShowAd(){
- if (in_array($this->uid, explode(',', env('TEST_CPC_UID')))) {
- $this->chapter->is_visiable_ad = 1;
- if($this->chapter->is_vip){
- $this->chapter->is_show_ad = 1;
- }
- return ;
- }
- $ad_status = env('AD_STATUS',1);
- if(!$ad_status){
- return ;
- }
- if(!$this->is_had_subscribe){
- return ;
- }
- //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])){
- $cpc_status = Redis::hget('channel:setting:'.$this->distribution_channel_id,'cpc_status');
- if($cpc_status === '0'){
- return ;
- }
- //按章付费才显示
- if($this->book_info->charge_type != 'CHAPTER'){
- return ;
- }
- //用户是否在广告样本中
- //if(!$this->isUserInAdSample()) return ;
- $is_ad_user = Cookie::get('cpc_ad_status');
- if(!$is_ad_user || $is_ad_user != 'show') return ;
- $cid = 0;
- if($this->chapter && $this->chapter->next_cid){
- $cid = $this->chapter->next_cid;
- }
- if(!$cid){
- return ;
- }
- //付费用户没有广告
- if(OrderService::isPaidUser($this->uid)) return ;
- //如果下一张已经付费,广告不显示
- /*$exists = AdVisitStatService::getByUid($this->uid);
- if(!$exists){
- if($this->uid %2 == 0){
- DataAnalysisSelectUserService::create($this->uid,$this->distribution_channel_id,'AD_TEST_3',-1,'unshow');
- return ;
- }else{
- DataAnalysisSelectUserService::create($this->uid,$this->distribution_channel_id,'AD_TEST_3',-1,'show');
- }
- }*/
- //广告都显示
- $this->chapter->is_visiable_ad = 1;
- AdVisitStatService::create($this->uid,$this->book_info->bid,$this->cid,'EXPOSURE');
- if($this->getOrderRecord($this->book_info->bid, $cid)){
- return ;
- }
- $next_chapter = ChapterService::getChapterNameById($cid, $this->book_info->bid);
- //下一章事vip的话 才显示广告
- if(!$next_chapter || !$next_chapter->is_vip){
- return ;
- }
- $price = $this->getPrice($this->book_info,$next_chapter);
- $flag = $price > $this->user->balance;
- if( $flag ){
- $this->chapter->is_show_ad = 1;
- AdVisitStatService::create($this->uid,$this->book_info->bid,$this->cid,'CAN_CLICK');
- }
- }
- private function crmChapterStats(){
- $crm = Cookie::get('crm');
- if(!$crm)return ;
- if(!$this->crm_order) return ;
- $price_rate = env('DEFAULT_CHAPTER_PRICE', 0.015);
- $fee = ceil($this->chapter->size * $price_rate);
- if($fee <37) $fee = 37;
- if($fee >60) $fee = 60;
- try{
- CrmChapterOrderDetailService::create($this->uid,$fee,$this->book_info->bid,$crm,$this->cid,$this->crm_order);
- }catch (\Exception $e){}
- }
- private function customChapterOrderStats($fee)
- {
- //custom_290824
- Log::info('customChapterOrderStats start');
- Log::info($this->from_type);
- if(strpos($this->from_type,'custom') === false){
- return ;
- }
- $customer_id= str_ireplace('custom_','',$this->from_type);
- Log::info($customer_id);
- if(!$customer_id || !is_numeric($customer_id)) return ;
- $info = Redis::hget('latestcustomerinfo',$customer_id);
- if(!$info) return ;
- Log::info($info);
- $info_array = json_decode($info,1);
- Log::info($info_array);
- $customer_bid = isset($info_array['bid'])?$info_array['bid']:0;
- $customer_send_time = isset($info_array['send_time'])?$info_array['send_time']:0;
- if(!$customer_bid || !$customer_send_time) return ;
- CustomChapterOrderService::create([
- 'distribution_channel_id'=>$this->distribution_channel_id,
- 'bid'=>$this->book_info->bid,
- 'cid'=>$this->cid,
- 'book_name'=>$this->book_info->book_name,
- 'chapter_name'=>$this->chapter->name,
- 'uid'=>$this->uid,
- 'send_order_id'=>$this->send_order_id,
- 'fee'=>$fee,
- 'charge_balance'=>0,
- 'reward_balance'=>0,
- 'custom_id'=>$customer_id,
- 'flag'=>$customer_bid == $this->book_info->bid?1:0,
- 'send_time'=>$customer_send_time
- ]);
- }
- private function forceGuidePerson(){
- //强制导粉
- //$force_guide_sites = redisEnv('FORCE_GUIDE_SITES');
- //$img = redisEnv('GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
- $flag = 1;
- if(Redis::SISMEMBER('crm:out_channel_sites',$this->distribution_channel_id)){
- $img = redisEnv('OUT_FORCE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
- $force_guide_sites = $this->distribution_channel_id;
- $group = 'OUT_FORCE';
- $flag = Cookie::get('is_force_out_guide');
- $flag = $flag?$flag:0;
- }else{
- list($force_guide_sites,$img) = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES','FORCE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
- $group = 'FORCE';
- }
- if($flag && $force_guide_sites &&
- $img &&
- in_array($this->distribution_channel_id,explode(',',$force_guide_sites)) &&
- $this->is_paid &&
- ($this->chapter->sequence == 2 || $this->chapter->sequence == 8)&&
- !UserBindHkWelfareService::isHasGet($this->uid) &&
- ForceGuidePersonAccountService::isShow($this->uid,$this->book_info->bid,$this->cid)
- ){
- 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);
- }
- return '';
- }
- public function getWechatJsConfig(Request $request)
- {
- //try {
- // $chapter->is_show_share_button = 1;
- $bid = $request->input('bid', '');
- $cid = $request->input('cid', '');
- $url = $request->input('url', '');
- $url = urldecode($url);
- \Log::info('url:' . ($this->uid) . $url);
- if (empty($bid) || empty($cid) || empty($url)) {
- return response()->error('PARAM_EMPTY');
- }
- $share_url = 'https://'._domain().'/detail?fromtype=readershare&id='.$bid.'&fromflag='.($this->uid).'&fromcid='.$cid;
- //$js_config = ChapterShareWechatConfigService::getConfig($url);
- $app_hash = array(
- 4025=>['appid'=>'wx80b618c9dcc940f7','appsecret'=>'255a2de8db51e4084b5e9087d26d4ecb'],
- 4147=>['appid'=>'wx2a99699cd9572812','appsecret'=>'0e0d57f94eeba50abb3af6883df05a5c'],
- 691=>['appid'=>'wx5cefcd251dc40693','appsecret'=>'755f64c85173dad21f20870e38f59d8a'],
- 123=>['appid'=>'wx983808610aa9dcc5','appsecret'=>'91002999590b79f3c7be35fd73c04049'],
- 211=>['appid'=>'wx39338e374cc2055b','appsecret'=>'1a4c2039be271b3811182be5bb53eb34'],
- );
- $appId = $app_hash[$this->distribution_channel_id]['appid'];
- $appSecret = $app_hash[$this->distribution_channel_id]['appsecret'];
- $js_config = (new ChapterShareWechatConfigService($appId,$appSecret))->getSignPackage($url);
- /*$appid = DB::table('official_accounts')->where('distribution_channel_id',$this->distribution_channel_id)->first();//(['distribution_channel_id'=>$this->distribution_channel_id]);
- $appid = $appid->appid;
- //\Log::info('get_appid:'.($appid));
- $js_config = (new ChapterShareWechatConfigService($appid))->getSignPackage($url);
- //$chapter->js_config = $js_config;
- //$chapter->share_url = $share_url;
- $book = BookService::getBookById(Hashids::decode($bid)[0]);
- $first_cid = $book->first_cid;
- $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;
- /*if (in_array($this->uid, explode(',', env('TEST_SHARE_UIDS')))) {
- $share_url = 'https://site5017zqeyzwgyx9n8.zhuishuyun.com/reader?fromtype=readershare&bid=' . $bid . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
- }*/
- $book = BookService::getBookById(Hashids::decode($bid)[0]);
- $first_cid = $book->first_cid;
- $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;
- if (in_array($this->distribution_channel_id, [2, 14])) {
- $js_config = ChapterShareWechatConfigService::getConfig($url);
- $share_url = 'https://site' . ($this->distribution_channel_id) . '.' . env('SHARE_DOMAIN') . '/reader?fromtype=readershare&bid=' . $bid . '&cid=' . ($first_cid) . '&fromflag=' . ($this->uid) . '&fromcid=' . $cid;
- }
- $js_config['share_url'] = $share_url;
- /*} catch (\Exception $e) {
- \Log::error($e->getMessage());
- }*/
- //\Log::info($js_config);
- return response()->success($js_config);
- }
- }
|