WelcomeController.php 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  1. <?php
  2. namespace App\Http\Controllers\Wap\Web;
  3. use App\Jobs\SendStatisticsList;
  4. use App\Jobs\SendTexts;
  5. use App\Libs\Ip2Region;
  6. use App\Modules\Activity\Services\ActivitySwitchService;
  7. use App\Modules\Channel\Services\ChannelActivitiesService;
  8. use App\Modules\Channel\Services\ChannelService;
  9. use App\Modules\Cpa\Services\AdvertiseUserQueueService;
  10. use App\Modules\Cpa\Services\AdvertiseUsersService;
  11. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  12. use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
  13. use App\Modules\Subscribe\Services\ChapterOrderService;
  14. use App\Modules\Subscribe\Services\OrderService;
  15. use App\Modules\User\Services\ForceSubscribeUserIService;
  16. use App\Modules\User\Services\UserBindHkWelfareService;
  17. use App\Modules\User\Services\UserDivisionCpcPropertyService;
  18. use App\Modules\User\Services\UserDivisionPropertyService;
  19. use App\Modules\User\Services\UserMonthService;
  20. use App\Modules\User\Services\UserService;
  21. use Illuminate\Http\Request;
  22. use App\Http\Controllers\Wap\BaseController;
  23. use Cookie;
  24. use App\Modules\OfficialAccount\Services\CustomMsgService;
  25. use App\Modules\Activity\Services\ActivityService;
  26. use Redis;
  27. use App\Modules\Subscribe\Models\Order;
  28. use App\Modules\Activity\Models\Activity;
  29. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  30. use Hashids;
  31. use App\Modules\User\Services\ReadRecordService;
  32. use App\Modules\Book\Services\BookConfigService;
  33. use DB;
  34. use App\Http\Controllers\Wap\Book\Transformers\BookTransformer;
  35. use Log;
  36. class WelcomeController extends BaseController
  37. {
  38. private $force_subscribe_info = null;
  39. private $property = '';
  40. private $user = null;
  41. /**
  42. * 首页
  43. */
  44. public function index(Request $request)
  45. {
  46. $url = $this->formWechatMsgJump($request);
  47. if ($url) {
  48. return redirect()->to($url);
  49. }
  50. $banners = [];//合并banner
  51. //site标题
  52. $title = $this->getSiteTitle($request);
  53. //客服图片
  54. $customer_service = $this->getCustomerServiceImg();
  55. //活动配置
  56. $activity_options = $this->activityOptions();
  57. $url = $activity_options['url'];
  58. $is_show_activity = $activity_options['is_show_activity'];
  59. $activity_title = $activity_options['activity_title'];
  60. $bottom_show_type = $activity_options['bottom_show_type'];
  61. $activity_img = $activity_options['activity_img'];
  62. $user = $activity_options['user'];
  63. $this->user = $user;
  64. $hidden_reader_menus = false;
  65. $send_order_id = $this->send_order_id;
  66. //隐藏阅读页面菜单
  67. if ($send_order_id && in_array($send_order_id, explode(',', env('HIDDEN_READER_MENUS')))) {
  68. $hidden_reader_menus = true;
  69. }
  70. $hidden_reader_bootstrap = false;
  71. //隐藏阅读引导页
  72. if (env('HIDDEN_READ_BOOTSTRAP') &&
  73. in_array($this->distribution_channel_id, explode(',', env('HIDDEN_READ_BOOTSTRAP')))
  74. ) {
  75. $hidden_reader_bootstrap = true;
  76. }
  77. //隐藏活动底部banner
  78. if (env('HIDDEN_ACTIVITY_BANNER') &&
  79. in_array($this->distribution_channel_id, explode(',', env('HIDDEN_ACTIVITY_BANNER')))
  80. ) {
  81. $is_show_activity = 0;
  82. }
  83. //代付
  84. $showDaiChong = \App\Modules\OfficialAccount\Services\PaySubstituteSwitchService::getChannelSwitch($this->distribution_channel_id);
  85. //老年站点
  86. $isOld = 0;
  87. $channel = ChannelService::getDistributionChannel($this->distribution_channel_id);
  88. if ($channel) {
  89. $isOld = $channel->is_old_user_site;
  90. }
  91. //fromtype
  92. $from = $request->get('fromtype');
  93. if (!$from) {
  94. $from = Cookie::get('from') ? Cookie::get('from') : 'main';
  95. }
  96. //crm
  97. $crm = $request->get('crm');
  98. if (!$crm) {
  99. $crm = Cookie::get('crm') ? Cookie::get('crm') : '';
  100. }
  101. //设置用户是否充值
  102. $this->setIsPaid();
  103. $this->setProperty($user->openid);
  104. $channel_activities_flag = $this->judgeChannelActivity($user);
  105. //最近阅读页面 推荐
  106. if (isset($user->sex)) {
  107. $latest_read_rec_books = $this->latest_read_rec_books($channel, $user->sex);
  108. } else {
  109. $latest_read_rec_books = [];
  110. }
  111. //广告样本
  112. $ad_status = env('AD_STATUS', 1);
  113. $adTargetId = false;
  114. if ($ad_status) {
  115. $adTargetId = $this->cpcAd($user->openid);
  116. }
  117. $cpc_channel = '';
  118. if ($adTargetId) {
  119. $cpc_channel = Redis::hget('channel:setting:' . $this->distribution_channel_id, 'cpc_channel');
  120. if (!$cpc_channel) $cpc_channel = 'zw005';
  121. $disable_channel = redisEnv('CPC_DISABLED_CHANNEL', '');
  122. if ($disable_channel && in_array($cpc_channel, explode(',', $disable_channel))) {
  123. $adTargetId = false;
  124. $cpc_channel = '';
  125. }
  126. }
  127. //目前推喜阅 自有广告曝光中低净值
  128. $self_pa_ad_switch = 0;
  129. if (in_array($this->property, ['none', 'low', 'medium']) && $this->isPddAdSites()) $self_pa_ad_switch = 1;
  130. //广告frame
  131. $is_show_ad_frame_setting = env('IS_SHOW_AD_FRAME_SETTING', '123');
  132. $is_show_ad_frame = false;
  133. if ($is_show_ad_frame_setting && in_array($this->distribution_channel_id, explode(',', $is_show_ad_frame_setting))) {
  134. $is_show_ad_frame = true;
  135. }
  136. //标题不显示书名
  137. $show_title_in_reader = false;
  138. $show_title_in_reader_setting = env('SHOW_TITLE_IN_READER_SETTING');
  139. if ($show_title_in_reader_setting && in_array($this->distribution_channel_id, explode(',', $show_title_in_reader_setting))) {
  140. $show_title_in_reader = true;
  141. }
  142. $hide_chapter_channels = explode(',', env('HIDE_CHAPTER_CONSUME_CHANNEL'));
  143. $is_hide_chapter_consume = in_array($this->distribution_channel_id, $hide_chapter_channels) ? 1 : 0;
  144. //广告
  145. // 屏蔽书名
  146. $self_config = ChannelService::check_channel_account_priv($this->distribution_channel_id, 'hide_book_name');
  147. $hide_book_name = 0;
  148. if (!empty($self_config)) {
  149. $hide_book_name = 1;
  150. }
  151. //原创pv uv
  152. $yctj = false;
  153. $yctj_url = '';
  154. if (in_array($this->distribution_channel_id, [2, 146, 155, 255, 691, 722, 4053, 4174, 4364, 4426])) {
  155. $yctj = true;
  156. $yctj_url = 'https://m.ycsd.cn/continueRead';
  157. }
  158. //app广告
  159. $add_ad_status = [
  160. 'appad' => false,
  161. 'appad_banner' => '',
  162. 'appad_url' => ''
  163. ];
  164. //突出包年的充值页面
  165. $outstanding_year_order = $this->outstandingYearOrder();
  166. $pdd_ad = $this->pddAd();
  167. //banner 合并
  168. if ($is_show_activity) {
  169. $banners[] = [
  170. 'img' => $activity_img,
  171. 'jump_url' => $url
  172. ];
  173. }
  174. //pdd 广告用户--增加banner
  175. if ($pdd_ad) {
  176. $pdd_ads = Redis::get('pdd_ads');//pdd广告
  177. if ($pdd_ads) {
  178. foreach (json_decode($pdd_ads, true) as $_ad) {
  179. $banners[] = [
  180. 'img' => $_ad['img'],
  181. 'jump_url' => $_ad['jump_url']
  182. ];
  183. }
  184. }
  185. }
  186. $xiyue_info = $this->isXiyueUser();
  187. //用户分割
  188. $this->userPproperty();
  189. $month_order_info = $this->monthOrderInfo($user->openid);
  190. $options = json_encode([
  191. 'distribution_channel_id' => (int)$this->distribution_channel_id,
  192. 'send_order_id' => $send_order_id,
  193. 'uid' => $this->uid,
  194. 'pay_url' => env('CREATE_PAY_URL'),
  195. 'title' => $title,
  196. 'kefu' => $customer_service,
  197. 'background' => env('WEB_READER_BACKGROUND'),
  198. 'font_size' => env('WEB_READER_FONT_SIZE'),
  199. 'page_style' => env('WEB_READER_PAGE_STYLE'),
  200. 'from' => $from,
  201. 'is_show_activity' => $is_show_activity,
  202. 'activity_url' => $url,
  203. 'activity_title' => $activity_title,
  204. 'bottom_show_type' => $bottom_show_type,
  205. 'activity_img' => $activity_img,
  206. 'special_bottom_sub_banner' => $this->getSpecialBottomSubBanner(),
  207. 'hidden_reader_menus' => $hidden_reader_menus,
  208. 'hidden_reader_bootstrap' => $hidden_reader_bootstrap,
  209. 'showDaiChong' => (int)$showDaiChong,
  210. 'isOld' => $isOld,
  211. 'sex' => $user ? $user->sex : 0,
  212. 'latest_read_rec_books' => $latest_read_rec_books,
  213. 'fission' => $this->fission(),//裂变
  214. 'channel_activities' => $channel_activities_flag,
  215. 'adTargetId' => $adTargetId,
  216. 'ad_type' => '1',
  217. 'is_show_ad_frame' => $is_show_ad_frame,
  218. 'show_title_in_reader' => $show_title_in_reader,
  219. 'is_hide_chapter_consume' => $is_hide_chapter_consume,
  220. 'hide_book_name' => $hide_book_name,
  221. 'yctj' => $yctj,
  222. 'yctj_url' => $yctj_url,
  223. 'appad' => $add_ad_status['appad'],
  224. 'appad_banner' => $add_ad_status['appad_banner'],
  225. 'appad_url' => $add_ad_status['appad_url'],
  226. 'outstanding_year_order' => $outstanding_year_order,
  227. 'share_domain' => env('share_domain_url'),
  228. 'share_switch' => 0,//无充值用户分享关闭
  229. 'pdd_ad' => $pdd_ad,
  230. 'special_pay_template' => $this->isMiWan(), //米玩站点特殊充值页面
  231. 'crm' => $crm,
  232. 'self_pa_ad_switch' => $self_pa_ad_switch,//自有平台广告开关
  233. 'banners' => $banners,
  234. 'guidepersonalaccount' => $this->guidePersonalAccountV2(),
  235. 'cpc_channel' => $cpc_channel,
  236. 'month_order_info' => $month_order_info,
  237. 'xiyue_info' => $xiyue_info
  238. ]);
  239. if ($this->uid == env('SPECIAL_USER_LOG', 2)) {
  240. myLog('special')->info('welcome --------------------------');
  241. myLog('special')->info(json_decode($options, 1));
  242. }
  243. //统计用户ua
  244. $ua = $request->server('HTTP_USER_AGENT');
  245. $this->recordUA($ua);
  246. return view('wap.index', compact('options', 'title'));
  247. }
  248. private function judgeChannelActivity($user_info)
  249. {
  250. //新渠道送书币活动
  251. $channel_activities_hash = [
  252. 500 => 'https://cdn-novel.iycdm.com/h5/five_hundred_coin.png',
  253. 1000 => 'https://cdn-novel.iycdm.com/h5/thoudends_coin.png'
  254. ];
  255. $channel_activities_flag = [
  256. 'shall_reward' => 0,
  257. 'amount' => '',
  258. 'image' => ''
  259. ];
  260. try {
  261. $channel_activities = ChannelActivitiesService::getValidActivity((int)$this->distribution_channel_id);
  262. if ($channel_activities) {
  263. if (time() - strtotime($user_info->created_at->format('Y-m-d H:i:s')) <= 5 * 60) { //对在5分钟之内新注册的用户进行打赏
  264. $reward_info = DB::table('fission')->where([
  265. ['type', '=', 2], ['uid', '=', $this->uid]
  266. ])->first();
  267. if (!$reward_info) { //未被打赏的新用户
  268. //$user_info = UserService::getById($this->uid);
  269. DB::beginTransaction();
  270. $user_info->balance = $user_info->balance + $channel_activities->amount;
  271. $user_info->reward_balance = $user_info->reward_balance + $channel_activities->amount;
  272. if ($user_info->save()) {
  273. $fission_data = [
  274. 'uid' => $this->uid,
  275. 'prize' => $channel_activities->amount,
  276. 'created_at' => date('Y-m-d H:i:s'),
  277. 'updated_at' => date('Y-m-d H:i:s'),
  278. 'type' => 2
  279. ];
  280. DB::table('fission')->insert($fission_data);
  281. DB::commit();
  282. $channel_activities_flag['shall_reward'] = 1;
  283. $channel_activities_flag['amount'] = $channel_activities->amount;
  284. $channel_activities_flag['image'] = $channel_activities_hash[$channel_activities->amount];
  285. $force_sub_info = DB::table('force_subscribe_users')->where([['uid', '=', $this->uid], ['is_subscribed', '=', 1]])->first();
  286. if ($force_sub_info) {
  287. $bookUrl = env('PROTOCOL') . '://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/';
  288. $res['openid'] = $force_sub_info->openid;
  289. $res['appid'] = $force_sub_info->appid;
  290. $res['content'] = "亲爱的会员您好:\n恭喜您获得" . ($channel_activities->amount) . "书币奖励\n<a href='" . $bookUrl . "'>去书城看书</a>";
  291. $res['type'] = 'one_task';
  292. $res['send_time'] = date("Y-m-d H:i:s");
  293. $res['task_id'] = md5('channel_activity_push');
  294. $send_data = array(
  295. 'send_time' => date("Y-m-d H:i:s"),
  296. 'data' => $res
  297. );
  298. dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay(0)->onQueue('send_texts_list'));
  299. }
  300. } else {
  301. DB::rollBack();
  302. }
  303. }
  304. }
  305. }
  306. } catch (\Exception $e) {
  307. \Log::error('channel activities error:channel_id:' . ($this->distribution_channel_id) . 'uid:' . ($this->uid) . ':' . ($e->getMessage()));
  308. }
  309. return $channel_activities_flag;
  310. }
  311. private function outstandingYearOrder()
  312. {
  313. $outstanding_year_order = false;
  314. if (in_array($this->distribution_channel_id, explode(',', env('CAN_NOT_OUTSTANDING_YEAR_ORDER_SITE')))) {
  315. return $outstanding_year_order;
  316. }
  317. //if( in_array($this->distribution_channel_id,explode(',',env('OUTSTANDING_YEAR_ORDER_SITE'))) ){
  318. //if($this->uid%2 == 0){
  319. //$userDivisionProperty = UserDivisionPropertyService::getUserProperty($this->uid);
  320. //$userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($this->uid);
  321. $this->property == 'high' && $outstanding_year_order = true;
  322. //}
  323. //}
  324. return $outstanding_year_order;
  325. }
  326. private function luckyUserForeverFree()
  327. {
  328. $lucky_user = 0;
  329. $lucky_user_img = '';
  330. if (!in_array($this->distribution_channel_id, [2, 14, 211])) return compact('lucky_user', 'lucky_user_img');
  331. try {
  332. $lucky_user = Redis::SISMEMBER('luckyYearOrderUser', $this->uid);
  333. } catch (\Exception $e) {
  334. }
  335. $lucky_user && $luckuser_img = 'https://cdn-novel.iycdm.com//h5/lucky.jpg';
  336. return compact('lucky_user', 'lucky_user_img');
  337. }
  338. private function latest_read_rec_books($channel, $sex)
  339. {
  340. $latest_read_rec_books = [];
  341. if ($channel->is_yq_move)//云栖迁移过来的站点
  342. {
  343. //用户性别
  344. if ($sex == 1)//男
  345. {
  346. $bids = [1896, 1969, 2115, 2526, 2610];
  347. } else {
  348. $bids = [1148, 1460, 1572, 1634, 2434, 2436];
  349. if (in_array($this->distribution_channel_id, [4042, 4043, 4044])) {
  350. $bids = [2323, 1347, 2168, 1550, 1295, 1574];
  351. }
  352. }
  353. $latest_read_rec_books = collectionTransform(new BookTransformer(), BookConfigService::getBooksByIds($bids));
  354. }
  355. return $latest_read_rec_books;
  356. }
  357. /**
  358. * 获取123底部强管banner
  359. */
  360. private function getSpecialBottomSubBanner()
  361. {
  362. $week = date('N');
  363. return 'https://cdn-novel.iycdm.com/h5/bottom_sub_banner/' . $week . '.jpg';
  364. }
  365. /**
  366. * 裂变
  367. * @return int
  368. */
  369. private function fission()
  370. {
  371. $fission_send_order_id = env('FISSION_SEND_ORDER_ID');
  372. if ($fission_send_order_id && $this->send_order_id && in_array($this->send_order_id, explode(',', $fission_send_order_id))) {
  373. $is_exist = DB::table('fission')->where('uid', $this->uid)->select('uid')->first();
  374. if (!$is_exist) {
  375. DB::table('fission')->insert([
  376. 'uid' => $this->uid,
  377. 'prize' => 200,
  378. 'created_at' => date('Y-m-d H:i:s'),
  379. 'updated_at' => date('Y-m-d H:i:s')
  380. ]);
  381. UserService::addBalance($this->uid, 200, 0, 200);
  382. return 1;
  383. }
  384. }
  385. return 0;
  386. }
  387. /**
  388. * 获取活动配置信息
  389. */
  390. private function activityOptions()
  391. {
  392. $h5_scheme = env('H5_SCHEME', 'https');
  393. $url = '';
  394. $is_show_activity = 0;
  395. $activity_title = '';
  396. $bottom_show_type = 1;
  397. $activity_img = '';
  398. $user = $this->userInfo($this->uid);
  399. /*$no_participate_activity = env('no_participate_activity', '');
  400. if ($no_participate_activity && in_array($this->distribution_channel_id, explode(',', $no_participate_activity))) {
  401. return compact('url', 'is_show_activity', 'activity_title', 'bottom_show_type', 'activity_img', 'user');
  402. }*/
  403. //自定义活动
  404. $show_custom_activity_channel = env('SHOW_CUSTOM_ACTIVITY_CHANNEL', '');
  405. if ($show_custom_activity_channel) {
  406. $custom_activity_page = ActivityService::getActiveCustomActivity($this->distribution_channel_id);
  407. if ($custom_activity_page) {
  408. if ($show_custom_activity_channel == 'all'
  409. || in_array($this->distribution_channel_id, explode(',', $show_custom_activity_channel))
  410. ) {
  411. $url = $h5_scheme . '://' . _domain() . $custom_activity_page->activity_page . '&fromtype=reader';;
  412. $is_show_activity = 1;
  413. $activity_title = '优惠活动';
  414. $bottom_show_type = 1;
  415. $activity_img = 'https://cdn-novel.iycdm.com/h5/2018-08-24-banner.png';
  416. }
  417. }
  418. }
  419. //自定义新用户活动
  420. $show_custom_new_user_activity_channel = env('SHOW_CUSTOM_NEW_USER_ACTIVITY_CHANNEL', '');
  421. if ($show_custom_new_user_activity_channel && in_array($this->distribution_channel_id, explode(',', $show_custom_new_user_activity_channel))) {
  422. $custom_activity_page = ActivityService::getActiveCustomActivityByType($this->distribution_channel_id, 'CUSTOM_NEW_USER');
  423. if ($custom_activity_page) {
  424. $charge_count = Order::where('uid', $this->uid)->where('status', 'PAID')->count();
  425. if ($charge_count == 0) {
  426. $url = $h5_scheme . '://' . _domain() . $custom_activity_page->activity_page;
  427. $is_show_activity = 1;
  428. $activity_title = '优惠活动';
  429. $bottom_show_type = 1;
  430. $activity_img = 'https://cdn-novel.iycdm.com/h5/2019-04-04-banner.jpg';
  431. }
  432. }
  433. }
  434. $activity_setting = ActivityService::getActivitySetting();
  435. if ($activity_setting) {
  436. $activity_id = isset($activity_setting['activity_id']) ? $activity_setting['activity_id'] : 0;
  437. $activity_info = Activity::find($activity_id);
  438. if ($activity_info &&
  439. time() > strtotime($activity_info->start_time) &&
  440. time() < strtotime($activity_info->end_time) &&
  441. $user &&
  442. isset($user->created_at) &&
  443. (time() - strtotime($user->created_at)) >= 86400 * 2
  444. ) {
  445. $activity_img = isset($activity_setting['wap_bottom_img']) ? $activity_setting['wap_bottom_img'] : '';
  446. //if (in_array($this->distribution_channel_id, [123, 211, 146, 155, 255, 256, 691, 722, 4364, 4427, 695, 4174, 4025, 4593, 4426, 4889, 4891, 4742, 4053, 4334, 4487, 5611, 6122, 6123, 6124, 8, 5, 160, 4236, 4237, 4241, 273, 148, 266, 202, 271])){
  447. $activity_pool = [
  448. 'https://cdn-novel.iycdm.com/h5/activity-2019-09-25/reader-banner-1.jpg',
  449. 'https://cdn-novel.iycdm.com/h5/activity-2019-09-25/reader-banner-2.jpg',
  450. 'https://cdn-novel.iycdm.com/h5/activity-2019-09-25/reader-banner-3.jpg'
  451. ];
  452. $activity_img = collect($activity_pool)->random();
  453. //}
  454. $url = $h5_scheme . '://' . _domain() . $activity_info->activity_page . '&fromtype=reader';
  455. $activity_title = isset($activity_setting['activity_title']) ? $activity_setting['activity_title'] : '';
  456. $status = ActivitySwitchService::isShowInPage($activity_id, $this->distribution_channel_id);
  457. if ($status) {
  458. $is_show_activity = 1;
  459. $bottom_show_type = 2;
  460. if ($activity_setting['activity_id'] == env('OTHER_ACTIVITY_ID', 0)) {
  461. if (!in_array($this->distribution_channel_id, explode(',', env('OTHER_ACTIVITY_CHANNEL', '1')))) {
  462. $is_show_activity = 0;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. $year_activity_id = env('YEAR_ACTIVITY_ID');
  469. if ($year_activity_id) {
  470. $activity_info = Activity::find($year_activity_id);
  471. if ($activity_info &&
  472. time() > strtotime($activity_info->start_time) &&
  473. time() < strtotime($activity_info->end_time) &&
  474. $user &&
  475. isset($user->created_at) &&
  476. (time() - strtotime($user->created_at)) >= 86400 * 2
  477. ) {
  478. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  479. if ($sites && in_array($this->distribution_channel_id, explode(',', $sites))) {
  480. $is_show_activity = 1;
  481. $bottom_show_type = 2;
  482. /*$old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->whereIn('activity_id', [643, 827,1104])->count();
  483. if ($old_discount_coupon) {
  484. $activity_img = 'https://cdn-novel.iycdm.com/h5/activity-2019-05-10/reader-80.jpg';
  485. } else {
  486. $activity_img = 'https://cdn-novel.iycdm.com/h5/activity-2019-05-10/reader-50.jpg';
  487. }*/
  488. //$activity_img = sprintf('https://cdn-novel.iycdm.com/h5/activity-2019-07-10/reader-banner%s.jpg',random_int(1,3));
  489. $activity_img = 'https://cdn-novel.iycdm.com/h5/activity-2019-07-25/reader-banner.png';
  490. $url = $h5_scheme . '://' . _domain() . $activity_info->activity_page . '&fromtype=reader';
  491. }
  492. }
  493. }
  494. return compact('url', 'is_show_activity', 'activity_title', 'bottom_show_type', 'activity_img', 'user');
  495. }
  496. /**
  497. * 获取site标题
  498. */
  499. private function getSiteTitle(Request $request)
  500. {
  501. if ($this->distribution_channel_id == 6398) return '花溪亭苑';
  502. if ($this->distribution_channel_id == 5216) return '花开文阁';
  503. if ($this->distribution_channel_id == 6985) return '喜阅微书店';
  504. if ($this->distribution_channel_id == 6375) return '荷香淑苑';
  505. if ($this->distribution_channel_id == 5237) return '悦月文摘';
  506. if ($this->distribution_channel_id == 6130) return '微友书坊';
  507. if ($this->distribution_channel_id == 6667) return '青青书舍';
  508. if ($this->distribution_channel_id == 7264) return '悠悠书汇';
  509. if ($this->distribution_channel_id == 7070) return '小飞文苑';
  510. $title = "追书云";
  511. $get_force_subscribe_name = false;
  512. $subscribe = $request->cookie('force_subscribe_name');
  513. $appid = $request->get('appid');
  514. //用户进来携带的公众号信息
  515. if ($appid) {
  516. $force_subscribe_official = DB::table('official_accounts')->where('appid', $appid)->select('nickname')->first();
  517. if ($force_subscribe_official) {
  518. $title = $force_subscribe_official->nickname;
  519. if ($title) return $title;
  520. }
  521. }
  522. if ($subscribe) return $subscribe;
  523. //强关公众号名称
  524. $force_subscribe = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  525. $this->force_subscribe_info = $force_subscribe;
  526. if ($force_subscribe) {
  527. $force_subscribe_official = DB::table('official_accounts')->where('appid', $force_subscribe->appid)->select('nickname')->first();
  528. if ($force_subscribe_official) {
  529. $title = $force_subscribe_official->nickname;
  530. $get_force_subscribe_name = true;
  531. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  532. }
  533. }
  534. //可用公众号名称
  535. if (!$get_force_subscribe_name) {
  536. $res = OfficialAccountService::canUseOfficialAccountByChannelId(['distribution_channel_id' => $this->distribution_channel_id]);
  537. if ($res && isset($res->nickname) && !empty($res->nickname)) {
  538. $title = $res->nickname;
  539. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  540. }
  541. }
  542. return $title;
  543. }
  544. private function appad()
  545. {
  546. if ($this->force_subscribe_info) {
  547. $force_subscribe_info = $this->force_subscribe_info;
  548. } else {
  549. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  550. //\Log::info(':'.($this->uid).'force_subs1:'.json_encode($force_subscribe_info));
  551. }
  552. if (!$force_subscribe_info) {
  553. return false;
  554. }
  555. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  556. if ($force_sub_user_by_openid) {
  557. $force_subscribe_info = $force_sub_user_by_openid;
  558. //\Log::info('force_subs:'.json_encode($force_subscribe_info));
  559. }
  560. //\Log::info('force_subscribe_:'.json_encode($force_subscribe_info));
  561. //\Log::info('distribution_channel_id:'.$this->distribution_channel_id);
  562. if ($force_subscribe_info->subscribe_time &&
  563. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  564. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  565. //!AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  566. in_array($this->distribution_channel_id, explode(',', env('SHARE_OPEN_SITE')))
  567. ) {
  568. return true;
  569. }
  570. return false;
  571. }
  572. //CPC广告的优化逻辑
  573. private function cpcAd($openid)
  574. {
  575. if (in_array($this->uid, explode(',', env('TEST_CPC_UID')))) {
  576. return true;
  577. }
  578. //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])){
  579. $cpc_status = Redis::hget('channel:setting:' . $this->distribution_channel_id, 'cpc_status');
  580. if (is_null($cpc_status) || $cpc_status == 1) {
  581. $cookie_ad_status = Cookie::get('cpc_ad_status');
  582. if ($cookie_ad_status) return $cookie_ad_status == 'show';
  583. //$property = UserDivisionCpcPropertyService::userLevel($openid);
  584. /*if(UserService::isCpcUser($this->uid)){
  585. Cookie::queue('cpc_ad_status', 'show');
  586. return true;
  587. }*/
  588. if ($this->property == 'none') {
  589. Cookie::queue('cpc_ad_status', 'show');
  590. return true;
  591. }
  592. }
  593. Cookie::queue('cpc_ad_status', 'unshow');
  594. return false;
  595. }
  596. private function pddAd()
  597. {
  598. if ($this->isPddAdSites()) {
  599. return [
  600. 'banner' => 'https://cdn-novel.iycdm.com/h5/20190531/banner.jpg',
  601. 'url' => 'https://m.ycsd.cn/reader/9F69C5F384552E71/663249E009CA5AC0?u=13002705&isLogin=1'
  602. ];
  603. }
  604. return '';
  605. }
  606. private function isPddAdSites()
  607. {
  608. return in_array($this->distribution_channel_id, [2, 123, 146, 155, 211, 256, 691, 695, 722, 4025, 4053, 4174, 4237, 4241, 4334, 4364, 4426, 4427, 4487, 4593, 4889, 4891, 5611]);
  609. }
  610. private function isMiWan()
  611. {
  612. $miwan_channel_ids = redisEnv('MIWAN_CHANNEL_ID');
  613. if (!$miwan_channel_ids) return false;
  614. return in_array($this->distribution_channel_id, explode(',', $miwan_channel_ids));
  615. }
  616. /**
  617. * 获取客服图片
  618. */
  619. private function getCustomerServiceImg()
  620. {
  621. $setting = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  622. if ($setting && $setting->customer_img_url) {
  623. $customer_service = $setting->customer_img_url;
  624. } else {
  625. $customer_service = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  626. //$customer_service = 'https://cdn-novel.iycdm.com/static/img/kefu20190330.jpg';
  627. }
  628. return $customer_service;
  629. }
  630. /**
  631. * 推广链接跳转到用户上一阅读的章节
  632. */
  633. private function formWechatMsgJump(Request $request)
  634. {
  635. $path = $request->path();
  636. if ($path != 'reader') {
  637. return null;
  638. }
  639. $source = $request->input('source');
  640. if (!$source || $source != 'wechatmsg') {
  641. return null;
  642. }
  643. $bid = 0;
  644. $bid_str = $request->input('bid');
  645. $cid = $request->input('cid');
  646. try {
  647. $bid_arr = Hashids::decode($bid_str);
  648. if (isset($bid_arr[0])) {
  649. $bid = $bid_arr[0];
  650. }
  651. } catch (\Exception $e) {
  652. }
  653. if (!$bid) return null;
  654. $record_info = '';
  655. try {
  656. $record_info = ReadRecordService::getRecordByUidBid($this->uid, $bid);
  657. } catch (\Exception $e) {
  658. }
  659. if (!$record_info) return null;
  660. $record_info_arr = explode('_', $record_info);
  661. $param = $request->except(['_url', 'source', 'cid']);
  662. $param['stats'] = 1;
  663. if (isset($record_info_arr[0])) {
  664. $param['cid'] = $record_info_arr[0];
  665. if ($cid && $cid != $record_info_arr[0]) {
  666. $h5_scheme = env('H5_SCHEME', 'https');
  667. $param_str = http_build_query($param);
  668. $url = $h5_scheme . '://' . _domain() . '/reader?' . $param_str;
  669. return $url;
  670. }
  671. }
  672. return null;
  673. }
  674. //用户是否在广告样本中
  675. private function isUserInAdSample()
  676. {
  677. $res = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'AD_V2');
  678. if ($res) {
  679. return true;
  680. } else {
  681. return false;
  682. }
  683. }
  684. /**
  685. * 三天回本活动
  686. * @param Request $request
  687. * @return
  688. */
  689. public function activity(Request $request)
  690. {
  691. $send_time = Redis::hget('add_news_recovery_push_activity' . $this->uid, 'time');
  692. $send_time = time() - 100;
  693. if ($send_time) {
  694. if (time() - $send_time < 86400) {
  695. $activity_id = 1;
  696. $activity_info = ActivityService::getById($activity_id);
  697. if ($activity_info && $activity_info->product_id) {
  698. $from = $request->input('fromtype', 'main');
  699. Redis::sadd('push:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from . ':date:' . date('Y-m-d'), $this->uid);
  700. Redis::hincrby('customer:push:click:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from, date('Y-m-d'), 1);
  701. $param = [
  702. 'uid' => $this->uid,
  703. 'distribution_channel_id' => $this->distribution_channel_id,
  704. 'product_id' => $activity_info->product_id,
  705. 'activity_id' => $activity_id,
  706. 'fromtype' => $from,
  707. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/person'
  708. ];
  709. Redis::hdel('add_news_recovery_push_activity' . $this->uid, 'time');
  710. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  711. return view('pay.order.activity', ['url' => $url, 'code' => 0]);
  712. }
  713. }
  714. }
  715. return redirect('/continue');
  716. //return view('pay.order.activity', ['code' => 1, 'url' => '']);
  717. }
  718. /**
  719. * 商户活动
  720. * @param Request $request
  721. * @return view
  722. */
  723. public function channelActivity(Request $request)
  724. {
  725. $token = $request->input('token');
  726. //return view('pay.order.saleactivity', ['url' => $token, 'code' => 0]);
  727. $activity_info = ActivityService::getByToken($token);
  728. if ($activity_info && $activity_info->product_id) {
  729. $from = $request->input('fromtype', 'main');
  730. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  731. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  732. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  733. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  734. Redis::sadd($uv_key, $this->uid);
  735. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  736. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  737. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  738. // $from = $request->input('from', 'main');
  739. // $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  740. // $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  741. // $uv_key = sprintf($uv_key_format,$activity_info->id,$this->distribution_channel_id,date('Y-m-d'));
  742. // $pv_key = sprintf($pv_key_format,$activity_info->id,$this->distribution_channel_id);
  743. // Redis::sadd($uv_key,$this->uid);
  744. // Redis::hincrby($pv_key,date('Y-m-d'),1);
  745. $param = [
  746. 'uid' => $this->uid,
  747. 'distribution_channel_id' => $this->distribution_channel_id,
  748. 'product_id' => $activity_info->product_id,
  749. 'activity_id' => $activity_info->id,
  750. 'fromtype' => $from,
  751. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  752. ];
  753. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  754. return view('pay.order.saleactivity', ['url' => $url, 'code' => 0]);
  755. }
  756. }
  757. return view('pay.order.saleactivity', ['url' => '###', 'code' => 0]);
  758. }
  759. public function springActivityV1(Request $request)
  760. {
  761. $token = $request->input('token');
  762. $activity_info = ActivityService::getByToken($token);
  763. if ($activity_info) {
  764. $from = $request->input('fromtype', 'main');
  765. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  766. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  767. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  768. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  769. Redis::sadd($uv_key, $this->uid);
  770. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  771. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  772. if ($request->input('redirect_url')) {
  773. $redirect_url = $request->input('redirect_url');
  774. $redirect_url = urldecode($redirect_url);
  775. }
  776. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  777. $param_fifty = [
  778. 'uid' => $this->uid,
  779. 'distribution_channel_id' => $this->distribution_channel_id,
  780. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_FIFTY', 2),
  781. 'activity_id' => $activity_info->id,
  782. 'fromtype' => $from,
  783. 'pay_redirect_url' => $redirect_url
  784. ];
  785. $param_hundred = [
  786. 'uid' => $this->uid,
  787. 'distribution_channel_id' => $this->distribution_channel_id,
  788. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_HUNDRED', 3),
  789. 'activity_id' => $activity_info->id,
  790. 'fromtype' => $from,
  791. 'pay_redirect_url' => $redirect_url
  792. ];
  793. $url_fifty = env('CREATE_PAY_URL') . '?' . http_build_query($param_fifty);
  794. $url_hundred = env('CREATE_PAY_URL') . '?' . http_build_query($param_hundred);
  795. return view('pay.order.springactivity', ['url' => ['fifty' => $url_fifty, 'hundred' => $url_hundred], 'code' => 0]);
  796. } else if (time() <= strtotime($activity_info->start_time)) {
  797. return view('pay.order.springactivity', ['url' => [], 'code' => 1]);
  798. } else {
  799. return view('pay.order.springactivity', ['url' => [], 'code' => 2]);
  800. }
  801. }
  802. return view('pay.order.springactivity', ['url' => [], 'code' => 3]);
  803. }
  804. public function springActivity(Request $request)
  805. {
  806. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  807. $token = $request->input('token');
  808. $activity_info = ActivityService::getByToken($token);
  809. if (!$activity_info) {
  810. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  811. return redirect()->to($default_url);
  812. }
  813. $from = $request->input('fromtype', 'main');
  814. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  815. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  816. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  817. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  818. Redis::sadd($uv_key, $this->uid);
  819. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  820. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  821. if ($request->input('redirect_url')) {
  822. $redirect_url = $request->input('redirect_url');
  823. $redirect_url = urldecode($redirect_url);
  824. }
  825. //未开始
  826. if (time() < strtotime($activity_info->start_time)) {
  827. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1]);
  828. }
  829. //结束
  830. if (time() > strtotime($activity_info->end_time)) {
  831. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2]);
  832. }
  833. $product_ids = [4063, 4064];
  834. $url = [];
  835. foreach ($product_ids as $product_id) {
  836. $param = [
  837. 'uid' => $this->uid,
  838. 'distribution_channel_id' => $this->distribution_channel_id,
  839. 'product_id' => $product_id,
  840. 'activity_id' => $activity_info->id,
  841. 'fromtype' => $from,
  842. 'pay_redirect_url' => $redirect_url,
  843. 'limit' => 100,
  844. ];
  845. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  846. }
  847. return view('pay.order.springactivity2019', ['url' => $url, 'code' => 0]);
  848. }
  849. /**
  850. *
  851. */
  852. public function womenActivity(Request $request)
  853. {
  854. $token = $request->input('token');
  855. $activity_info = ActivityService::getByToken($token);
  856. if ($activity_info) {
  857. $from = $request->input('fromtype', 'main');
  858. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  859. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  860. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  861. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  862. Redis::sadd($uv_key, $this->uid);
  863. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  864. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  865. if ($request->input('redirect_url')) {
  866. $redirect_url = $request->input('redirect_url');
  867. $redirect_url = urldecode($redirect_url);
  868. }
  869. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  870. $param = [
  871. 'uid' => $this->uid,
  872. 'distribution_channel_id' => $this->distribution_channel_id,
  873. 'product_id' => $activity_info->product_id,
  874. 'activity_id' => $activity_info->id,
  875. 'fromtype' => $from,
  876. 'pay_redirect_url' => $redirect_url
  877. ];
  878. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  879. return view('pay.order.womenactivity', ['url' => $url, 'code' => 0]);
  880. } else if (time() <= strtotime($activity_info->start_time)) {
  881. return view('pay.order.womenactivity', ['url' => [], 'code' => 1]);
  882. } else {
  883. return view('pay.order.womenactivity', ['url' => [], 'code' => 2]);
  884. }
  885. }
  886. return view('pay.order.womenactivity', ['url' => [], 'code' => 3]);
  887. }
  888. public function newUserActivity(Request $request)
  889. {
  890. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  891. $from = $request->input('fromtype', 'main');
  892. $send_time = $request->input('send_time');
  893. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  894. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  895. $activity_id = env('NEW_USER_ACTIVITY_ID', 5);
  896. $activity_info = ActivityService::getById($activity_id);
  897. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  898. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  899. Redis::sadd($uv_key, $this->uid);
  900. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  901. if (!$send_time) {
  902. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  903. }
  904. $end_time_str = date('Y-m-d', $send_time + 86400);
  905. $end_time = strtotime(date('Y-m-d', $send_time + 86400) . ' 23:59:59');
  906. if ($send_time > $end_time) {
  907. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  908. }
  909. if (time() > $end_time) {
  910. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  911. }
  912. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  913. if ($order) {
  914. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  915. //return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  916. }
  917. $param = [
  918. 'uid' => $this->uid,
  919. 'distribution_channel_id' => $this->distribution_channel_id,
  920. 'product_id' => $activity_info->product_id,
  921. 'activity_id' => $activity_info->id,
  922. 'fromtype' => $from,
  923. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  924. ];
  925. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  926. return view('pay.order.newUserActivity', ['url' => $url, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  927. }
  928. public function channelActivityNine(Request $request)
  929. {
  930. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  931. $token = $request->input('token');
  932. $activity_info = ActivityService::getByToken($token);
  933. if ($activity_info && $activity_info->product_id) {
  934. $from = $request->input('fromtype', 'main');
  935. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  936. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  937. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  938. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  939. Redis::sadd($uv_key, $this->uid);
  940. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  941. //渠道不符合
  942. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  943. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  944. }
  945. //活动未开始
  946. if (time() < strtotime($activity_info->start_time)) {
  947. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -3, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  948. }
  949. //活动结束
  950. if (time() > strtotime($activity_info->end_time)) {
  951. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  952. }
  953. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  954. //参加过了
  955. if ($order) {
  956. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  957. }
  958. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  959. $not_allow_paid_user_channel_id = env('NOT_ALLOW_PAID_USER_CHANNEL_ID', 0);
  960. //不允许支付过的用户参见9.9的活动
  961. if ($not_allow_paid_user_channel_id &&
  962. in_array($this->distribution_channel_id, explode(',', $not_allow_paid_user_channel_id)) &&
  963. Order::where('uid', $this->uid)->where('status', 'PAID')->first()
  964. ) {
  965. return view('pay.order.longactivitynine', ['url' => '', 'code' => -4, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  966. }
  967. $param = [
  968. 'uid' => $this->uid,
  969. 'distribution_channel_id' => $this->distribution_channel_id,
  970. 'product_id' => $activity_info->product_id,
  971. 'activity_id' => $activity_info->id,
  972. 'fromtype' => $from,
  973. 'limit' => 1,
  974. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  975. ];
  976. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  977. return view('pay.order.longactivitynine', ['url' => $url, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  978. }
  979. }
  980. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  981. }
  982. public function channelActivitySixtyEight(Request $request)
  983. {
  984. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  985. $token = $request->input('token');
  986. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn68.jpg';
  987. $activity_info = ActivityService::getByToken($token);
  988. if ($activity_info && $activity_info->product_id) {
  989. $from = $request->input('fromtype', 'main');
  990. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  991. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  992. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  993. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  994. Redis::sadd($uv_key, $this->uid);
  995. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  996. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  997. //渠道不符合
  998. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  999. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1000. }
  1001. //活动未开始
  1002. if (time() < strtotime($activity_info->start_time)) {
  1003. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -3, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1004. }
  1005. //活动结束
  1006. if (time() > strtotime($activity_info->end_time)) {
  1007. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1008. }
  1009. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1010. $param = [
  1011. 'uid' => $this->uid,
  1012. 'distribution_channel_id' => $this->distribution_channel_id,
  1013. 'product_id' => $activity_info->product_id,
  1014. 'activity_id' => $activity_info->id,
  1015. 'fromtype' => $from,
  1016. 'limit' => 100,
  1017. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1018. ];
  1019. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1020. return view('pay.order.longactivitysixtyeight', ['url' => $url, 'img' => $img, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1021. }
  1022. }
  1023. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1024. }
  1025. public function channelActivityFortyEight(Request $request)
  1026. {
  1027. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1028. $token = $request->input('token');
  1029. $activity_info = ActivityService::getByToken($token);
  1030. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
  1031. if ($activity_info && $activity_info->product_id) {
  1032. $from = $request->input('fromtype', 'main');
  1033. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1034. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1035. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1036. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1037. Redis::sadd($uv_key, $this->uid);
  1038. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1039. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  1040. //渠道不符合
  1041. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  1042. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1043. }
  1044. //活动未开始
  1045. if (time() < strtotime($activity_info->start_time)) {
  1046. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -3, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1047. }
  1048. //活动结束
  1049. if (time() > strtotime($activity_info->end_time)) {
  1050. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1051. }
  1052. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1053. $param = [
  1054. 'uid' => $this->uid,
  1055. 'distribution_channel_id' => $this->distribution_channel_id,
  1056. 'product_id' => $activity_info->product_id,
  1057. 'activity_id' => $activity_info->id,
  1058. 'fromtype' => $from,
  1059. 'limit' => 100,
  1060. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1061. ];
  1062. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1063. return view('pay.order.longactivitysixtyeight', ['url' => $url, 'img' => $img, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  1064. }
  1065. }
  1066. return view('pay.order.longactivitysixtyeight', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1067. }
  1068. public function channelNewUserActivity(Request $request)
  1069. {
  1070. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1071. $token = $request->get('token');
  1072. $activity_info = ActivityService::getByToken($token);
  1073. $from = $request->get('fromtype', 'main');
  1074. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1075. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1076. if ($activity_info && $activity_info->product_id) {
  1077. $activity_id = $activity_info->id;
  1078. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1079. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1080. Redis::sadd($uv_key, $this->uid);
  1081. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1082. //活动未开始
  1083. if (time() < strtotime($activity_info->start_time)) {
  1084. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => substr($activity_info->start_time, 0, 10), 'end_time' => substr($activity_info->end_time, 0, 10)]);
  1085. }
  1086. //活动结束
  1087. if (time() > strtotime($activity_info->end_time)) {
  1088. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => substr($activity_info->start_time, 0, 10), 'end_time' => substr($activity_info->end_time, 0, 10)]);
  1089. }
  1090. $charge_count = Order::where('uid', $this->uid)->where('status', 'PAID')->count();
  1091. if ($charge_count > 0) {
  1092. //不是新用户
  1093. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -1, 'start_time' => substr($activity_info->start_time, 0, 10), 'end_time' => substr($activity_info->end_time, 0, 10)]);
  1094. }
  1095. $param = [
  1096. 'uid' => $this->uid,
  1097. 'distribution_channel_id' => $this->distribution_channel_id,
  1098. 'product_id' => $activity_info->product_id,
  1099. 'activity_id' => $activity_info->id,
  1100. 'fromtype' => $from,
  1101. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1102. ];
  1103. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1104. return view('pay.order.newUserActivity', ['url' => $url, 'code' => 0, 'start_time' => substr($activity_info->start_time, 0, 10), 'end_time' => substr($activity_info->end_time, 0, 10)]);
  1105. }
  1106. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1107. }
  1108. /**
  1109. * 清明活动
  1110. */
  1111. public function qingMingActivity(Request $request)
  1112. {
  1113. $token = $request->input('token');
  1114. $activity_info = ActivityService::getByToken($token);
  1115. if ($activity_info) {
  1116. $from = $request->input('fromtype', 'main');
  1117. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1118. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1119. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1120. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1121. Redis::sadd($uv_key, $this->uid);
  1122. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1123. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1124. if ($request->input('redirect_url')) {
  1125. $redirect_url = $request->input('redirect_url');
  1126. $redirect_url = urldecode($redirect_url);
  1127. }
  1128. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1129. $param = [
  1130. 'uid' => $this->uid,
  1131. 'distribution_channel_id' => $this->distribution_channel_id,
  1132. 'product_id' => $activity_info->product_id,
  1133. 'activity_id' => $activity_info->id,
  1134. 'fromtype' => $from,
  1135. 'pay_redirect_url' => $redirect_url
  1136. ];
  1137. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1138. return view('pay.order.qingmingactivity', ['url' => $url, 'code' => 0]);
  1139. } else if (time() <= strtotime($activity_info->start_time)) {
  1140. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 1]);
  1141. } else {
  1142. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 2]);
  1143. }
  1144. }
  1145. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 3]);
  1146. }
  1147. public function readDayActivity(Request $request)
  1148. {
  1149. $token = $request->input('token');
  1150. $activity_info = ActivityService::getByToken($token);
  1151. if ($activity_info) {
  1152. $from = $request->input('fromtype', 'main');
  1153. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1154. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1155. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1156. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1157. Redis::sadd($uv_key, $this->uid);
  1158. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1159. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1160. if ($request->input('redirect_url')) {
  1161. $redirect_url = $request->input('redirect_url');
  1162. $redirect_url = urldecode($redirect_url);
  1163. }
  1164. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1165. $param = [
  1166. 'uid' => $this->uid,
  1167. 'distribution_channel_id' => $this->distribution_channel_id,
  1168. 'product_id' => $activity_info->product_id,
  1169. 'activity_id' => $activity_info->id,
  1170. 'fromtype' => $from,
  1171. 'pay_redirect_url' => $redirect_url,
  1172. 'limit' => 100,
  1173. ];
  1174. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1175. return view('pay.order.laborDay', ['url' => $url, 'code' => 0]);
  1176. } else if (time() <= strtotime($activity_info->start_time)) {
  1177. return view('pay.order.laborDay', ['url' => [], 'code' => 1]);
  1178. } else {
  1179. return view('pay.order.laborDay', ['url' => [], 'code' => 2]);
  1180. }
  1181. }
  1182. return view('pay.order.laborDay', ['url' => [], 'code' => 3]);
  1183. }
  1184. public function commonActivity(Request $request)
  1185. {
  1186. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1187. $token = $request->input('token');
  1188. $activity_info = ActivityService::getByToken($token);
  1189. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
  1190. $imgs = json_decode($activity_info->setting, 1);
  1191. $from = $request->input('fromtype', 'main');
  1192. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1193. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1194. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1195. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1196. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1197. if ($request->input('redirect_url')) {
  1198. $redirect_url = $request->input('redirect_url');
  1199. $redirect_url = urldecode($redirect_url);
  1200. }
  1201. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1202. Redis::sadd($uv_key, $this->uid);
  1203. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1204. $param = [
  1205. 'uid' => $this->uid,
  1206. 'distribution_channel_id' => $this->distribution_channel_id,
  1207. 'product_id' => $activity_info->product_id,
  1208. 'activity_id' => $activity_info->id,
  1209. 'fromtype' => $from,
  1210. 'pay_redirect_url' => $redirect_url,
  1211. 'limit' => 100,
  1212. ];
  1213. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1214. return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
  1215. } else if (time() <= strtotime($activity_info->start_time)) {
  1216. return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
  1217. } else {
  1218. return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
  1219. }
  1220. }
  1221. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1222. return redirect()->to($default_url);
  1223. }
  1224. public function yearActivity(Request $request)
  1225. {
  1226. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1227. $from = $request->input('fromtype', 'main');
  1228. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1229. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1230. if (empty($sites)) {
  1231. return redirect()->to($not_access_url);
  1232. }
  1233. $site_arr = explode(',', $sites);
  1234. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1235. return redirect()->to($not_access_url);
  1236. }
  1237. $year_activity_id = env('YEAR_ACTIVITY_ID');
  1238. if (!$year_activity_id) {
  1239. return redirect()->to($not_access_url);
  1240. }
  1241. $activity_info = Activity::find($year_activity_id);
  1242. if (!$activity_info) {
  1243. return redirect()->to($not_access_url);
  1244. }
  1245. $activity_id = $year_activity_id;
  1246. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1247. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1248. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1249. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1250. Redis::sadd($uv_key, $this->uid);
  1251. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1252. $start = $activity_info->start_time;
  1253. $end = $activity_info->end_time;
  1254. if (empty($start) || empty($end)) {
  1255. return redirect()->to($not_access_url);
  1256. }
  1257. $male_site = env('YEAR_MALE_SITE');
  1258. if ($male_site && in_array($this->distribution_channel_id, explode(',', $male_site))) {
  1259. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_MALE_BID'))));
  1260. } else {
  1261. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_FEMALE_BID'))));
  1262. }
  1263. $is_get = 0;
  1264. $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count();
  1265. //$old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $old_year_activity_id)->count();
  1266. $old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->whereIn('activity_id', [643, 827, 1104, 1294])->count();
  1267. if ($discount_coupon) {
  1268. $is_get = 1;
  1269. }
  1270. if ($old_discount_coupon) {
  1271. //51活动领取过 优惠80
  1272. $discount = 80;
  1273. $product_id = $activity_info->product_id;
  1274. } else {
  1275. //51活动领未取过 优惠50
  1276. $discount = 50;
  1277. $product_id = 1450;
  1278. }
  1279. if (time() < strtotime($start)) {
  1280. //未开始
  1281. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 1, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1282. }
  1283. if (time() > strtotime($end)) {
  1284. //结束
  1285. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 2, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1286. }
  1287. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1288. //参加过了
  1289. if ($order) {
  1290. //return view('pay.order.yearactivityV2', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 3, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1291. }
  1292. $param = [
  1293. 'uid' => $this->uid,
  1294. 'distribution_channel_id' => $this->distribution_channel_id,
  1295. 'product_id' => $product_id,
  1296. 'activity_id' => $activity_id,
  1297. 'fromtype' => $from,
  1298. 'limit' => 10,
  1299. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1300. ];
  1301. $this->getCoupons($activity_id);
  1302. $coupons_url = $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1303. $param['product_id'] = 5;
  1304. $primary_url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1305. return view('pay.order.yearactivityV3', ['url' => $primary_url, 'is_get' => $is_get, 'coupons_url' => $coupons_url, 'code' => 0, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1306. }
  1307. private function getCoupons($activity_id)
  1308. {
  1309. if (!DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count()) {
  1310. DB::table('discount_coupons')->insert([
  1311. 'uid' => $this->uid,
  1312. 'activity_id' => $activity_id,
  1313. 'created_at' => date('Y-m-d H:i:s'),
  1314. 'updated_at' => date('Y-m-d H:i:s')
  1315. ]);
  1316. }
  1317. }
  1318. public function summerActivity(Request $request)
  1319. {
  1320. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1321. $from = $request->input('fromtype', 'main');
  1322. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1323. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1324. if (empty($sites)) {
  1325. return redirect()->to($not_access_url);
  1326. }
  1327. if ($sites != 'all') {
  1328. $site_arr = explode(',', $sites);
  1329. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1330. return redirect()->to($not_access_url);
  1331. }
  1332. }
  1333. $activity_id = 350;
  1334. $activity_info = Activity::find($activity_id);
  1335. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1336. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1337. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1338. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1339. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1340. if ($request->input('redirect_url')) {
  1341. $redirect_url = $request->input('redirect_url');
  1342. $redirect_url = urldecode($redirect_url);
  1343. }
  1344. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1345. Redis::sadd($uv_key, $this->uid);
  1346. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1347. $url_array = [];
  1348. $product_id_array = [2158, 2159, 2160, 2161];
  1349. foreach ($product_id_array as $v) {
  1350. $param = [
  1351. 'uid' => $this->uid,
  1352. 'distribution_channel_id' => $this->distribution_channel_id,
  1353. 'product_id' => $v,
  1354. 'activity_id' => $activity_id,
  1355. 'fromtype' => $from,
  1356. 'pay_redirect_url' => $redirect_url,
  1357. 'limit' => 100,
  1358. ];
  1359. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1360. $url_array[] = $url;
  1361. }
  1362. return view('pay.order.summerActivity', ['url' => '', 'code' => 0, 'url_array' => $url_array]);
  1363. } else if (time() <= strtotime($activity_info->start_time)) {
  1364. return view('pay.order.summerActivity', ['url' => [], 'code' => 1]);
  1365. } else {
  1366. return view('pay.order.summerActivity', ['url' => [], 'code' => 2]);
  1367. }
  1368. }
  1369. public function newUserSale(Request $request)
  1370. {
  1371. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1372. $from = $request->input('fromtype', 'main');
  1373. $send_time = $request->input('send_time');
  1374. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1375. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1376. $activity_id = 402;
  1377. $activity_info = ActivityService::getById($activity_id);
  1378. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1379. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1380. Redis::sadd($uv_key, $this->uid);
  1381. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1382. // 2226,2227,2228,22229,2230
  1383. if (!$send_time) {
  1384. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1385. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
  1386. }
  1387. $end_time_str = date('Y-m-d', $send_time + 3 * 86400);
  1388. $end_time = strtotime(date('Y-m-d', $send_time + 3 * 86400) . ' 23:59:59');
  1389. if ($send_time > $end_time) {
  1390. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1391. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -1, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1392. }
  1393. if (time() > $end_time) {
  1394. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1395. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1396. }
  1397. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1398. if ($order) {
  1399. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1400. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1401. }
  1402. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id, true);
  1403. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1404. }
  1405. private function getUrls($activity_info_setting, $from, $channel_id, $encode_channel_id, $activity_id, $is_access = false)
  1406. {
  1407. $product = DB::table('products')
  1408. ->whereIn('id', explode(',', $activity_info_setting))
  1409. ->select('id', 'price', 'type', 'given')
  1410. ->get();
  1411. $url_info = [];
  1412. $url_info['year'] = ['url' => '###'];
  1413. $url_info['charge'] = [];
  1414. $param = [
  1415. 'uid' => $this->uid,
  1416. 'distribution_channel_id' => $this->distribution_channel_id,
  1417. 'product_id' => $channel_id,
  1418. 'limit' => 1,
  1419. 'fromtype' => $from,
  1420. 'activity_id' => $activity_id,
  1421. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1422. ];
  1423. if (!$product) {
  1424. return $url_info;
  1425. }
  1426. foreach ($product as $v) {
  1427. if (in_array($this->distribution_channel_id, [6917, 6918, 6939]) && $v->type == 'YEAR_ORDER') {
  1428. continue;
  1429. }
  1430. if ($is_access) {
  1431. $param['product_id'] = $v->id;
  1432. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1433. } else {
  1434. $url = '###';
  1435. }
  1436. if ($v->type == 'YEAR_ORDER') {
  1437. $url_info['year']['url'] = $url;
  1438. } else {
  1439. $temp = [];
  1440. $temp['url'] = $url;
  1441. $temp['price'] = (int)$v->price;
  1442. $temp['given'] = (int)($v->given / 100);
  1443. $temp['total'] = $v->price * 100 + $v->given;
  1444. if ($v->price == 30) {
  1445. $temp['old_given'] = '无折扣';
  1446. } elseif ($v->price == 50) {
  1447. $temp['old_given'] = '送40元';
  1448. } elseif ($v->price == 100) {
  1449. $temp['old_given'] = '送100元';
  1450. } elseif ($v->price == 200) {
  1451. $temp['old_given'] = '送200元';
  1452. } else {
  1453. $temp['old_given'] = '';
  1454. }
  1455. $url_info['charge'][] = $temp;
  1456. }
  1457. }
  1458. return $url_info;
  1459. }
  1460. public function nationalDayActivity(Request $request)
  1461. {
  1462. $token = $request->input('token', '');
  1463. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1464. $activity_info = ActivityService::getByToken($token);
  1465. if (!$activity_info) {
  1466. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1467. return redirect()->to($not_access_url);
  1468. }
  1469. $from = $request->input('fromtype', 'main');
  1470. $activity_id = $activity_info->id;
  1471. $activty_ids = env('NATIONAL_DAY_ACTIVITY_IDS', '1,2,3');
  1472. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1473. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1474. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1475. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1476. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1477. if ($request->input('redirect_url')) {
  1478. $redirect_url = $request->input('redirect_url');
  1479. $redirect_url = urldecode($redirect_url);
  1480. }
  1481. $activity_status = -1;
  1482. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1483. $activity_status = 1;
  1484. }
  1485. if (time() < strtotime($activity_info->start_time)) {
  1486. //未开始
  1487. $activity_status = -1;
  1488. }
  1489. if (time() > strtotime($activity_info->end_time)) {
  1490. //结束
  1491. $activity_status = -2;
  1492. }
  1493. Redis::sadd($uv_key, $this->uid);
  1494. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1495. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1496. if ($user_charge_count == 0) {
  1497. $is_first_charge = 1;
  1498. } else {
  1499. $is_first_charge = 0;
  1500. }
  1501. $url_array = [];
  1502. $product_id_array = explode(',', $activty_ids);
  1503. foreach ($product_id_array as $key => $v) {
  1504. if ($user_charge_count >= 1 && $key == 0) {
  1505. //continue;
  1506. }
  1507. $param = [
  1508. 'uid' => $this->uid,
  1509. 'distribution_channel_id' => $this->distribution_channel_id,
  1510. 'product_id' => $v,
  1511. 'activity_id' => $activity_id,
  1512. 'fromtype' => $from,
  1513. 'pay_redirect_url' => $redirect_url,
  1514. 'limit' => 100,
  1515. ];
  1516. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1517. $url_array[] = $url;
  1518. }
  1519. return view('pay.order.nationalDayActivity', ['url' => $url_array, 'is_first_charge' => $is_first_charge, 'code' => $activity_status]);
  1520. }
  1521. public function cYactivity(Request $request)
  1522. {
  1523. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1524. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1525. $site_arr = explode(',', env('YEAR_ACTIVITY_CHANNEL', '2'));
  1526. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1527. return redirect()->to($default_url);
  1528. }
  1529. $activity_info = ActivityService::getById(929);
  1530. if ($activity_info) {
  1531. $from = $request->input('fromtype', 'main');
  1532. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1533. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1534. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1535. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1536. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1537. if ($request->input('redirect_url')) {
  1538. $redirect_url = $request->input('redirect_url');
  1539. $redirect_url = urldecode($redirect_url);
  1540. }
  1541. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1542. Redis::sadd($uv_key, $this->uid);
  1543. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1544. $param = [
  1545. 'uid' => $this->uid,
  1546. 'distribution_channel_id' => $this->distribution_channel_id,
  1547. 'product_id' => $activity_info->product_id,
  1548. 'activity_id' => $activity_info->id,
  1549. 'fromtype' => $from,
  1550. 'pay_redirect_url' => $redirect_url,
  1551. 'limit' => 100,
  1552. ];
  1553. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1554. return view('pay.order.cyangActivity', ['url' => $url, 'code' => 0,]);
  1555. } else if (time() <= strtotime($activity_info->start_time)) {
  1556. return view('pay.order.cyangActivity', ['url' => [], 'code' => 1,]);
  1557. } else {
  1558. return view('pay.order.cyangActivity', ['url' => [], 'code' => 2,]);
  1559. }
  1560. }
  1561. return redirect()->to($default_url);
  1562. return view('pay.order.cyangActivity', []);
  1563. }
  1564. public function newUserForeverActivity(Request $request)
  1565. {
  1566. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1567. $from = $request->input('fromtype', 'main');
  1568. $send_time = $request->input('send_time');
  1569. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1570. if ($this->distribution_channel_id != 123) {
  1571. return redirect()->to($default_url);
  1572. }
  1573. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1574. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1575. $activity_id = env('FOREVER_ACTIVITY_ID', 5);
  1576. $activity_info = ActivityService::getById($activity_id);
  1577. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1578. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1579. Redis::sadd($uv_key, $this->uid);
  1580. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1581. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1582. if (!$send_time) {
  1583. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1584. }
  1585. $end_time = $send_time + 86400 * 3;
  1586. $time_diff = $end_time - time();
  1587. if ($time_diff <= 0) {
  1588. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1589. }
  1590. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1591. if ($order) {
  1592. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1593. }*/
  1594. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1595. $day = floor($time_diff / 86400);
  1596. $hour = floor(($time_diff - $day * 86400) / 3600);
  1597. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1598. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1599. $param = [
  1600. 'uid' => $this->uid,
  1601. 'distribution_channel_id' => $this->distribution_channel_id,
  1602. 'product_id' => $activity_info->product_id,
  1603. 'activity_id' => $activity_info->id,
  1604. 'fromtype' => $from,
  1605. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1606. ];
  1607. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1608. return view('pay.order.foreverActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'books' => $books]);
  1609. }
  1610. public function tempC()
  1611. {
  1612. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1613. $param = [
  1614. 'uid' => $this->uid,
  1615. 'distribution_channel_id' => $this->distribution_channel_id,
  1616. 'product_id' => 1450,
  1617. 'activity_id' => 0,
  1618. 'fromtype' => 'tempC',
  1619. 'limit' => 10,
  1620. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1621. ];
  1622. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1623. return redirect()->to($url);
  1624. }
  1625. /**
  1626. * 68元包年活动
  1627. * @param Request $request
  1628. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1629. */
  1630. public function otherYearActivity(Request $request)
  1631. {
  1632. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1633. $from = $request->input('fromtype', 'main');
  1634. $send_time = $request->input('send_time');
  1635. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1636. if ($this->distribution_channel_id != 123) {
  1637. return redirect()->to($default_url);
  1638. }
  1639. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1640. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1641. $activity_id = env('68_YEAR_ACTIVITY_ID', 5);
  1642. $activity_info = ActivityService::getById($activity_id);
  1643. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1644. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1645. Redis::sadd($uv_key, $this->uid);
  1646. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1647. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1648. $books = '';
  1649. $time_diff = 0;
  1650. if (!$send_time) {
  1651. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1652. }
  1653. $end_time = $send_time + 86400 * 3;
  1654. $time_diff = $end_time - time();
  1655. if ($time_diff <= 0) {
  1656. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1657. }
  1658. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1659. if ($order) {
  1660. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1661. }*/
  1662. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1663. $day = floor($time_diff / 86400);
  1664. $hour = floor(($time_diff - $day * 86400) / 3600);
  1665. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1666. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1667. $param = [
  1668. 'uid' => $this->uid,
  1669. 'distribution_channel_id' => $this->distribution_channel_id,
  1670. 'product_id' => $activity_info->product_id,
  1671. 'activity_id' => $activity_info->id,
  1672. 'fromtype' => $from,
  1673. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1674. ];
  1675. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1676. return view('pay.order.otherYearActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'time_diff' => $time_diff]);
  1677. }
  1678. /**
  1679. * 双十一购物节统计
  1680. * @param Request $request
  1681. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1682. */
  1683. public function shoppingDayActivity(Request $request)
  1684. {
  1685. $token = $request->input('token', '');
  1686. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1687. $activity_info = ActivityService::getByToken($token);
  1688. if (!$activity_info) {
  1689. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1690. return redirect()->to($not_access_url);
  1691. }
  1692. $from = $request->input('fromtype', 'main');
  1693. $activity_id = $activity_info->id;
  1694. $activty_ids = env('SHOPPING_DAY_ACTIVITY_IDS', '1,2,3');
  1695. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1696. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1697. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1698. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1699. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1700. if ($request->input('redirect_url')) {
  1701. $redirect_url = $request->input('redirect_url');
  1702. $redirect_url = urldecode($redirect_url);
  1703. }
  1704. $activity_status = -1;
  1705. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1706. $activity_status = 1;
  1707. }
  1708. if (time() < strtotime($activity_info->start_time)) {
  1709. //未开始
  1710. $activity_status = -1;
  1711. }
  1712. if (time() > strtotime($activity_info->end_time)) {
  1713. //结束
  1714. $activity_status = -2;
  1715. }
  1716. Redis::sadd($uv_key, $this->uid);
  1717. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1718. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1719. if ($user_charge_count == 0) {
  1720. $is_first_charge = 1;
  1721. } else {
  1722. $is_first_charge = 0;
  1723. }
  1724. $url_array = [];
  1725. $time_diff = strtotime($activity_info->end_time) - time();
  1726. $day = 0;
  1727. $hour = 0;
  1728. $minute = 0;
  1729. $second = 0;
  1730. if ($time_diff > 0) {
  1731. $day = floor($time_diff / 86400);
  1732. $hour = floor(($time_diff - $day * 86400) / 3600);
  1733. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1734. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1735. }
  1736. $product_id_array = explode(',', $activty_ids);
  1737. $product_infos = DB::table('products')->whereIn('id', $product_id_array)->select('id', 'price', 'given')->get();
  1738. foreach ($product_infos as $key => $v) {
  1739. if ($user_charge_count >= 1 && $key == 0) {
  1740. continue;
  1741. }
  1742. $limit = 100;
  1743. if ($key == 0) {
  1744. $limit = 1;
  1745. }
  1746. $param = [
  1747. 'uid' => $this->uid,
  1748. 'distribution_channel_id' => $this->distribution_channel_id,
  1749. 'product_id' => $v->id,
  1750. 'activity_id' => $activity_id,
  1751. 'fromtype' => $from,
  1752. 'pay_redirect_url' => $redirect_url,
  1753. 'limit' => $limit,
  1754. ];
  1755. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1756. $url_array[] = ['url' => $url, 'price' => (int)$v->price, 'given' => $v->given / 100, 'get' => $v->price * 100 + $v->given];
  1757. }
  1758. return view('pay.order.shoppingDayActivity', [
  1759. 'url' => $url_array,
  1760. 'is_first_charge' => $is_first_charge,
  1761. 'code' => $activity_status,
  1762. 'time' => compact('day', 'hour', 'minute', 'second'),
  1763. 'user_charge_count' => $user_charge_count,
  1764. 'time_diff' => $time_diff
  1765. ]
  1766. );
  1767. }
  1768. public function thanksGivingDayActivity(Request $request)
  1769. {
  1770. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1771. $from = $request->input('fromtype', 'main');
  1772. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1773. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1774. if (empty($sites)) {
  1775. return redirect()->to($not_access_url);
  1776. }
  1777. $site_arr = explode(',', $sites);
  1778. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1779. return redirect()->to($not_access_url);
  1780. }
  1781. $year_activity_id = 1367;
  1782. $activity_info = Activity::find($year_activity_id);
  1783. if (!$activity_info) {
  1784. return redirect()->to($not_access_url);
  1785. }
  1786. $activity_id = $year_activity_id;
  1787. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1788. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1789. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1790. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1791. Redis::sadd($uv_key, $this->uid);
  1792. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1793. $start = $activity_info->start_time;
  1794. $end = $activity_info->end_time;
  1795. if (empty($start) || empty($end)) {
  1796. return redirect()->to($not_access_url);
  1797. }
  1798. $url = ['slow' => 'javascript:void(0)', 'height' => 'javascript:void(0)'];
  1799. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->select('id')->first();
  1800. $charge_count = 0;
  1801. if ($order) {
  1802. $charge_count = 1;
  1803. }
  1804. if (time() < strtotime($start)) {
  1805. //未开始
  1806. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 1, 'charge_count' => $charge_count]);
  1807. }
  1808. if (time() > strtotime($end)) {
  1809. //结束
  1810. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 2, 'charge_count' => $charge_count]);
  1811. }
  1812. //3483 3484
  1813. $param = [
  1814. 'uid' => $this->uid,
  1815. 'distribution_channel_id' => $this->distribution_channel_id,
  1816. 'product_id' => 3483,
  1817. 'activity_id' => $activity_id,
  1818. 'fromtype' => $from,
  1819. 'limit' => 1,
  1820. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1821. ];
  1822. $this->getCoupons($activity_id);
  1823. $url['slow'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1824. $param['product_id'] = 3484;
  1825. $param['limit'] = 100;
  1826. $url['height'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1827. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 0, 'charge_count' => $charge_count]);
  1828. }
  1829. public function greatColdActivity(Request $request)
  1830. {
  1831. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1832. $token = $request->input('token');
  1833. $activity_info = ActivityService::getByToken($token);
  1834. if (!$activity_info) {
  1835. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1836. return redirect()->to($default_url);
  1837. }
  1838. $from = $request->input('fromtype', 'main');
  1839. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1840. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1841. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1842. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1843. Redis::sadd($uv_key, $this->uid);
  1844. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1845. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1846. if ($request->input('redirect_url')) {
  1847. $redirect_url = $request->input('redirect_url');
  1848. $redirect_url = urldecode($redirect_url);
  1849. }
  1850. $least_charge_amount = Order::select('id', 'price')
  1851. ->where('uid', $this->uid)
  1852. ->where('status', 'PAID')
  1853. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1854. ->max('price');
  1855. $type = 'litter';
  1856. $product_ids = [3962, 3963];
  1857. $img = [
  1858. 'litter' => [
  1859. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8-active.png',
  1860. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8.png',
  1861. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23-active.png',
  1862. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23.png',
  1863. ],
  1864. 'big' => [
  1865. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23-active.png',
  1866. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23.png',
  1867. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58-active.png',
  1868. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58.png',
  1869. ],
  1870. ];
  1871. if ($least_charge_amount && $least_charge_amount >= 30) {
  1872. $type = 'big';
  1873. $product_ids = [3960, 3961];
  1874. }
  1875. //未开始
  1876. if (time() < strtotime($activity_info->start_time)) {
  1877. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1878. }
  1879. //结束
  1880. if (time() > strtotime($activity_info->end_time)) {
  1881. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1882. }
  1883. $url = [];
  1884. foreach ($product_ids as $product_id) {
  1885. $param = [
  1886. 'uid' => $this->uid,
  1887. 'distribution_channel_id' => $this->distribution_channel_id,
  1888. 'product_id' => $product_id,
  1889. 'activity_id' => $activity_info->id,
  1890. 'fromtype' => $from,
  1891. 'pay_redirect_url' => $redirect_url,
  1892. 'limit' => 100,
  1893. ];
  1894. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1895. }
  1896. return view('pay.order.greatColdActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1897. }
  1898. public function channelYearActivity(Request $request)
  1899. {
  1900. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1901. $id = 2628;
  1902. $activity_info = ActivityService::getById($id);
  1903. if ($activity_info && $activity_info->product_id) {
  1904. $from = $request->input('fromtype', 'main');
  1905. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1906. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1907. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1908. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1909. Redis::sadd($uv_key, $this->uid);
  1910. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1911. $param = [
  1912. 'uid' => $this->uid,
  1913. 'distribution_channel_id' => $this->distribution_channel_id,
  1914. 'product_id' => $activity_info->product_id,
  1915. 'activity_id' => $activity_info->id,
  1916. 'fromtype' => $from,
  1917. 'limit' => 30,
  1918. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1919. ];
  1920. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1921. return view('pay.order.channelYearActivity', ['url' => $url]);
  1922. }
  1923. $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1924. return redirect()->to($url);
  1925. }
  1926. //春分活动
  1927. public function vernalEquinoxActivity(Request $request)
  1928. {
  1929. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1930. $token = $request->input('token');
  1931. $activity_info = ActivityService::getByToken($token);
  1932. if (!$activity_info) {
  1933. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1934. return redirect()->to($default_url);
  1935. }
  1936. $from = $request->input('fromtype', 'main');
  1937. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1938. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1939. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1940. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1941. Redis::sadd($uv_key, $this->uid);
  1942. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1943. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1944. if ($request->input('redirect_url')) {
  1945. $redirect_url = $request->input('redirect_url');
  1946. $redirect_url = urldecode($redirect_url);
  1947. }
  1948. $least_charge_amount = Order::select('id', 'price')
  1949. ->where('uid', $this->uid)
  1950. ->where('status', 'PAID')
  1951. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1952. ->max('price');
  1953. $type = 'litter';
  1954. if ($least_charge_amount && $least_charge_amount >= 30) {
  1955. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg50.jpg';
  1956. $product_ids = 4806;
  1957. } else {
  1958. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg23.jpg';
  1959. $product_ids = 4805;
  1960. }
  1961. //未开始
  1962. if (time() < strtotime($activity_info->start_time)) {
  1963. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1964. }
  1965. //结束
  1966. if (time() > strtotime($activity_info->end_time)) {
  1967. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1968. }
  1969. $param = [
  1970. 'uid' => $this->uid,
  1971. 'distribution_channel_id' => $this->distribution_channel_id,
  1972. 'product_id' => $product_ids,
  1973. 'activity_id' => $activity_info->id,
  1974. 'fromtype' => $from,
  1975. 'pay_redirect_url' => $redirect_url,
  1976. 'limit' => 100,
  1977. ];
  1978. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1979. return view('pay.order.vernalEquinoxActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1980. }
  1981. private function userPproperty()
  1982. {
  1983. if ($this->property == 'undefined') {
  1984. if ($this->user && time() - strtotime($this->user->created_at) >= 3 * 66400) {
  1985. $info = UserDivisionCpcPropertyService::calculateUserPropertyV2($this->uid);
  1986. if ($info && $info['property'] != 'undefined') {
  1987. UserDivisionCpcPropertyService::updateV2($info['openid'], $info['property']);
  1988. }
  1989. }
  1990. }
  1991. /*$old = UserDivisionCpcPropertyService::userLevel($openid);
  1992. if(!$old) return ;
  1993. $this->property = $old->property;
  1994. if($old->type != 'NEW') return ;
  1995. $send_data = array(
  1996. 'type' => 'visit',
  1997. 'data' => ['openid'=>$openid,'uid'=>$this->uid]
  1998. );
  1999. try {
  2000. $send = new SendStatisticsList($send_data);
  2001. $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list');
  2002. dispatch($job);
  2003. } catch (\Exception $e) {
  2004. \Log::info($e);
  2005. }*/
  2006. }
  2007. private function guidePersonalAccountV2(){
  2008. //内部站点导粉
  2009. list($inner_sites,$year_qrcode,$month_qrcode,$out_qrcode,$active_qrcode) = redisEnvMulti(
  2010. 'GUIDE_PERSONAL_ACCOUNT_SITES',
  2011. 'ACTIVE_YEAR_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2012. 'ACTIVE_MONTH_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2013. 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2014. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE'
  2015. );
  2016. //if(in_array($thy))
  2017. if ($inner_sites && in_array($this->distribution_channel_id, explode(',', $inner_sites))) {
  2018. //1.包年包月用户
  2019. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2020. if ($get_info) return '';
  2021. $charge = false;
  2022. if (in_array($this->property, ['medium', 'high'])) {
  2023. $charge = true;
  2024. } else {
  2025. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2026. $charge = true;
  2027. }
  2028. }
  2029. if(!$charge) return '';
  2030. if($year_qrcode && OrderService::isYearOrderUser($this->uid) ){
  2031. //包年
  2032. return ['title' => '包年VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_YEAR&fee=500','banner'=>'https://cdn-novel.iycdm.com/crm/guide/reader-banner.jpg'];
  2033. }
  2034. if($month_qrcode && UserMonthService::isMonthOrderUser($this->uid) ){
  2035. //包月
  2036. return ['title' => '包月VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_MONTH&fee=500','banner'=>'https://cdn-novel.iycdm.com/crm/guide/reader-banner.jpg'];
  2037. }
  2038. if($active_qrcode){
  2039. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500','banner'=>'https://cdn-novel.iycdm.com/crm/guide/reader-banner.jpg'];
  2040. }
  2041. return '';
  2042. }
  2043. //外站导粉
  2044. if($out_qrcode && Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)){
  2045. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2046. if ($get_info) return '';
  2047. $charge = false;
  2048. if (in_array($this->property, ['medium', 'high'])) {
  2049. $charge = true;
  2050. } else {
  2051. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2052. $charge = true;
  2053. }
  2054. }
  2055. if(!$charge) return '';
  2056. $filter_city = ['长沙', '深圳', '杭州'];
  2057. $ip2region = new Ip2Region();
  2058. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2059. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2060. } else {
  2061. $ip = get_client_ip();
  2062. }
  2063. $info = [];
  2064. try {
  2065. $info = $ip2region->btreeSearch($ip);
  2066. } catch (\Exception $e) {
  2067. }
  2068. if (!$info || !isset($info['region'])) return '';
  2069. $region = explode('|', $info['region']);
  2070. $city = isset($region[3]) ? $region[3] : '';
  2071. if (in_array($city, $filter_city)) {
  2072. return '';
  2073. }
  2074. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2075. if ($count < 50) {
  2076. return '';
  2077. }
  2078. Cookie::queue('is_force_out_guide', 1);
  2079. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500','banner'=>'https://cdn-novel.iycdm.com/crm/guide/reader-banner.jpg'];
  2080. }
  2081. //渠道自己导粉
  2082. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2083. if (empty($other_crm_config[0]) && empty($other_crm_config[1])) return '';
  2084. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2085. if ($get_info) return '';
  2086. if($this->is_paid || $this->distribution_channel_id == 6687)
  2087. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1],'banner'=>''];
  2088. return '';
  2089. }
  2090. private function guidePersonalAccount($openid)
  2091. {
  2092. //weidian
  2093. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2094. $crm_config = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
  2095. $out_status = Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id);
  2096. if (empty($other_crm_config[0]) && empty($other_crm_config[1]) && empty($crm_config[0]) && empty($crm_config[1]) && empty($out_status)) {
  2097. return '';
  2098. }
  2099. //Log::info('guidePersonalAccount1111111111111111111111');
  2100. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2101. if ($get_info) return '';
  2102. //Log::info('guidePersonalAccount2222222222222222222222');
  2103. $charge = false;
  2104. if (in_array($this->property, ['medium', 'high'])) {
  2105. $charge = true;
  2106. } else {
  2107. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2108. $charge = true;
  2109. }
  2110. }
  2111. if ($this->distribution_channel_id == 6687) {
  2112. $charge = true;
  2113. }
  2114. if (!$charge) return '';
  2115. //其他渠道自己导粉
  2116. if ($other_crm_config[0] && $other_crm_config[1]) {
  2117. if ($charge)
  2118. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1]];
  2119. return '';
  2120. }
  2121. //站外导粉
  2122. if ($out_status) {
  2123. if (!$charge) return '';
  2124. if (empty($crm_config[2])) {
  2125. return '';
  2126. }
  2127. $filter_city = ['长沙', '深圳', '杭州'];
  2128. $ip2region = new Ip2Region();
  2129. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2130. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2131. } else {
  2132. $ip = get_client_ip();
  2133. }
  2134. $info = [];
  2135. try {
  2136. $info = $ip2region->btreeSearch($ip);
  2137. } catch (\Exception $e) {
  2138. }
  2139. if (!$info || !isset($info['region'])) return '';
  2140. $region = explode('|', $info['region']);
  2141. $city = isset($region[3]) ? $region[3] : '';
  2142. if (in_array($city, $filter_city)) {
  2143. return '';
  2144. }
  2145. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2146. if ($count < 50) {
  2147. return '';
  2148. }
  2149. Cookie::queue('is_force_out_guide', 1);
  2150. //Redis::hset('crm:out_guide_exposure_user',$openid,$this->uid);
  2151. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2152. }
  2153. //Log::info('guidePersonalAccount33333333333333333');
  2154. if (empty($crm_config[0]) || empty($crm_config[1])) return '';
  2155. //Log::info('guidePersonalAccount4444444444444444');
  2156. if (!in_array($this->distribution_channel_id, explode(',', $crm_config[0]))) {
  2157. return '';
  2158. }
  2159. //Log::info('guidePersonalAccount555555555555555');
  2160. if ($charge) {
  2161. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2162. //return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2163. }
  2164. return '';
  2165. }
  2166. private function setIsPaid()
  2167. {
  2168. $charge = Order::where('uid', $this->uid)
  2169. ->where('status', 'PAID')
  2170. ->select('id')
  2171. ->first();
  2172. if ($charge) {
  2173. Cookie::queue('is_paid', 1);
  2174. $this->is_paid = true;
  2175. } else {
  2176. Cookie::queue('is_paid', 0);
  2177. $this->is_paid = false;
  2178. }
  2179. }
  2180. private function setProperty($openid)
  2181. {
  2182. $property = UserDivisionCpcPropertyService::userLevelV2($openid);
  2183. $this->property = $property;
  2184. }
  2185. //统计ua
  2186. private function recordUA($ua)
  2187. {
  2188. $is_ua_open = RedisEnv('ua_open');
  2189. if ($is_ua_open && $ua)//开启
  2190. {
  2191. //判断是否已经统计
  2192. $has_got = Redis::hget('book_read:' . $this->uid, 'ua');
  2193. if (!$has_got) {
  2194. try {
  2195. Redis::hset('book_read:' . $this->uid, 'ua', 1);
  2196. UserService::recordUA($ua, $this->uid);
  2197. } catch (\Exception $e) {
  2198. }
  2199. }
  2200. }
  2201. }
  2202. private function monthOrderInfo($openid)
  2203. {
  2204. return '';
  2205. $property = $this->property;
  2206. if (!$property) return '';
  2207. $month_info = UserMonthService::getOrderAndSignStatusByUid($this->uid);
  2208. if($month_info){
  2209. return [
  2210. 'price' => '30元',
  2211. 'text' => '30元包月 全站万本精彩小说免费看',
  2212. 'link' => generateMonthOrderUrl($this->uid),
  2213. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2214. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2215. ];
  2216. /*if(in_array('MONTH',$month_info)){
  2217. return [
  2218. 'price' => '30元',
  2219. 'text' => '30元包月 全站万本精彩小说免费看',
  2220. 'link' => generateMonthOrderUrl($this->uid),
  2221. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2222. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2223. ];
  2224. }
  2225. if(in_array('WEEK',$month_info)){
  2226. return [
  2227. 'price' => '7元',
  2228. 'text' => '7元包周 全站万本精彩小说免费看',
  2229. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2230. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2231. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2232. ];
  2233. }*/
  2234. }
  2235. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))) {
  2236. $info = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'MONTH_V2');
  2237. if ($info) {
  2238. if ($info->attach == 'show' || $info->attach == 'week-show') {
  2239. return [
  2240. 'price' => '30元',
  2241. 'text' => '30元包月 全站万本精彩小说免费看',
  2242. 'link' => generateMonthOrderUrl($this->uid),
  2243. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2244. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2245. ];
  2246. }
  2247. /*if ($info->attach == 'week-show') {
  2248. return [
  2249. 'price' => '7元',
  2250. 'text' => '7元包周 全站万本精彩小说免费看',
  2251. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2252. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2253. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2254. ];
  2255. }*/
  2256. return '';
  2257. }
  2258. }
  2259. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))
  2260. && in_array($property, ['none', 'low', 'medium'])
  2261. ) {
  2262. if (!UserMonthService::isSignMonth($openid)) {
  2263. $start_time = redisEnv('MONTH_TEMPLATE_COMPARE_START_TIME', 0);
  2264. if (!$start_time || (strtotime($this->user->created_at) < $start_time)) {
  2265. if ($property == 'nonenone') {
  2266. return [
  2267. 'price' => '7元',
  2268. 'text' => '7元包周 全站万本精彩小说免费看',
  2269. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2270. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2271. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2272. ];
  2273. } else {
  2274. return [
  2275. 'price' => '30元',
  2276. 'text' => '30元包月 全站万本精彩小说免费看',
  2277. 'link' => generateMonthOrderUrl($this->uid),
  2278. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2279. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2280. ];
  2281. }
  2282. }
  2283. $attach = $this->uid % 2 == 0 ? 'show' : 'hide';
  2284. if ($attach == 'hide') return '';
  2285. if ($property == 'nonenone') {
  2286. return [
  2287. 'price' => '7元',
  2288. 'text' => '7元包周 全站万本精彩小说免费看',
  2289. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2290. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2291. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2292. ];
  2293. } else {
  2294. return [
  2295. 'price' => '30元',
  2296. 'text' => '30元包月 全站万本精彩小说免费看',
  2297. 'link' => generateMonthOrderUrl($this->uid),
  2298. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2299. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2300. ];
  2301. }
  2302. }
  2303. }
  2304. return '';
  2305. }
  2306. private function isXiyueUser()
  2307. {
  2308. //$result = DB::table('xiyue_zsy_users')->where('uid',$this->uid)->select('id')->first();
  2309. if ($this->distribution_channel_id == 6985) {
  2310. return [
  2311. 'is_xiyue_user' => 1,
  2312. 'debug' => (int)env('XI_YUE_SHARE_DEBUG', 0),
  2313. 'xiyue_index_page' => env('XIYUE_HOST') . '/',
  2314. 'xiyue_pay_page' => env('XIYUE_HOST') . '/',
  2315. 'xiyue_pay_unfocus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_unfocus_img.png',
  2316. 'xiyue_pay_focus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_focus_img.png',
  2317. 'openid' => $this->user->openid,
  2318. 'register_url' => 'https://sitel12x4nj487yevw0m.leyuee.com/xiyue/sharelink'
  2319. ];
  2320. }
  2321. return "";
  2322. }
  2323. }