WelcomeController.php 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  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-06-05/reader-banner.jpg',
  449. 'https://cdn-novel.iycdm.com/h5/activity-2019-06-05/reader-banner2.jpg',
  450. 'https://cdn-novel.iycdm.com/h5/activity-2019-06-05/reader-banner3.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. $title = "追书云";
  507. $get_force_subscribe_name = false;
  508. $subscribe = $request->cookie('force_subscribe_name');
  509. $appid = $request->get('appid');
  510. //用户进来携带的公众号信息
  511. if ($appid) {
  512. $force_subscribe_official = DB::table('official_accounts')->where('appid', $appid)->select('nickname')->first();
  513. if ($force_subscribe_official) {
  514. $title = $force_subscribe_official->nickname;
  515. if ($title) return $title;
  516. }
  517. }
  518. if ($subscribe) return $subscribe;
  519. //强关公众号名称
  520. $force_subscribe = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  521. $this->force_subscribe_info = $force_subscribe;
  522. if ($force_subscribe) {
  523. $force_subscribe_official = DB::table('official_accounts')->where('appid', $force_subscribe->appid)->select('nickname')->first();
  524. if ($force_subscribe_official) {
  525. $title = $force_subscribe_official->nickname;
  526. $get_force_subscribe_name = true;
  527. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  528. }
  529. }
  530. //可用公众号名称
  531. if (!$get_force_subscribe_name) {
  532. $res = OfficialAccountService::canUseOfficialAccountByChannelId(['distribution_channel_id' => $this->distribution_channel_id]);
  533. if ($res && isset($res->nickname) && !empty($res->nickname)) {
  534. $title = $res->nickname;
  535. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  536. }
  537. }
  538. return $title;
  539. }
  540. private function appad()
  541. {
  542. if ($this->force_subscribe_info) {
  543. $force_subscribe_info = $this->force_subscribe_info;
  544. } else {
  545. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  546. //\Log::info(':'.($this->uid).'force_subs1:'.json_encode($force_subscribe_info));
  547. }
  548. if (!$force_subscribe_info) {
  549. return false;
  550. }
  551. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  552. if ($force_sub_user_by_openid) {
  553. $force_subscribe_info = $force_sub_user_by_openid;
  554. //\Log::info('force_subs:'.json_encode($force_subscribe_info));
  555. }
  556. //\Log::info('force_subscribe_:'.json_encode($force_subscribe_info));
  557. //\Log::info('distribution_channel_id:'.$this->distribution_channel_id);
  558. if ($force_subscribe_info->subscribe_time &&
  559. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  560. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  561. //!AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  562. in_array($this->distribution_channel_id, explode(',', env('SHARE_OPEN_SITE')))
  563. ) {
  564. return true;
  565. }
  566. return false;
  567. }
  568. //CPC广告的优化逻辑
  569. private function cpcAd($openid)
  570. {
  571. if (in_array($this->uid, explode(',', env('TEST_CPC_UID')))) {
  572. return true;
  573. }
  574. //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])){
  575. $cpc_status = Redis::hget('channel:setting:' . $this->distribution_channel_id, 'cpc_status');
  576. if (is_null($cpc_status) || $cpc_status == 1) {
  577. $cookie_ad_status = Cookie::get('cpc_ad_status');
  578. if ($cookie_ad_status) return $cookie_ad_status == 'show';
  579. //$property = UserDivisionCpcPropertyService::userLevel($openid);
  580. /*if(UserService::isCpcUser($this->uid)){
  581. Cookie::queue('cpc_ad_status', 'show');
  582. return true;
  583. }*/
  584. if ($this->property == 'none') {
  585. Cookie::queue('cpc_ad_status', 'show');
  586. return true;
  587. }
  588. }
  589. Cookie::queue('cpc_ad_status', 'unshow');
  590. return false;
  591. }
  592. private function pddAd()
  593. {
  594. if ($this->isPddAdSites()) {
  595. return [
  596. 'banner' => 'https://cdn-novel.iycdm.com/h5/20190531/banner.jpg',
  597. 'url' => 'https://m.ycsd.cn/reader/9F69C5F384552E71/663249E009CA5AC0?u=13002705&isLogin=1'
  598. ];
  599. }
  600. return '';
  601. }
  602. private function isPddAdSites()
  603. {
  604. 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]);
  605. }
  606. private function isMiWan()
  607. {
  608. $miwan_channel_ids = redisEnv('MIWAN_CHANNEL_ID');
  609. if (!$miwan_channel_ids) return false;
  610. return in_array($this->distribution_channel_id, explode(',', $miwan_channel_ids));
  611. }
  612. /**
  613. * 获取客服图片
  614. */
  615. private function getCustomerServiceImg()
  616. {
  617. $setting = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  618. if ($setting && $setting->customer_img_url) {
  619. $customer_service = $setting->customer_img_url;
  620. } else {
  621. $customer_service = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  622. //$customer_service = 'https://cdn-novel.iycdm.com/static/img/kefu20190330.jpg';
  623. }
  624. return $customer_service;
  625. }
  626. /**
  627. * 推广链接跳转到用户上一阅读的章节
  628. */
  629. private function formWechatMsgJump(Request $request)
  630. {
  631. $path = $request->path();
  632. if ($path != 'reader') {
  633. return null;
  634. }
  635. $source = $request->input('source');
  636. if (!$source || $source != 'wechatmsg') {
  637. return null;
  638. }
  639. $bid = 0;
  640. $bid_str = $request->input('bid');
  641. $cid = $request->input('cid');
  642. try {
  643. $bid_arr = Hashids::decode($bid_str);
  644. if (isset($bid_arr[0])) {
  645. $bid = $bid_arr[0];
  646. }
  647. } catch (\Exception $e) {
  648. }
  649. if (!$bid) return null;
  650. $record_info = '';
  651. try {
  652. $record_info = ReadRecordService::getRecordByUidBid($this->uid, $bid);
  653. } catch (\Exception $e) {
  654. }
  655. if (!$record_info) return null;
  656. $record_info_arr = explode('_', $record_info);
  657. $param = $request->except(['_url', 'source', 'cid']);
  658. $param['stats'] = 1;
  659. if (isset($record_info_arr[0])) {
  660. $param['cid'] = $record_info_arr[0];
  661. if ($cid && $cid != $record_info_arr[0]) {
  662. $h5_scheme = env('H5_SCHEME', 'https');
  663. $param_str = http_build_query($param);
  664. $url = $h5_scheme . '://' . _domain() . '/reader?' . $param_str;
  665. return $url;
  666. }
  667. }
  668. return null;
  669. }
  670. //用户是否在广告样本中
  671. private function isUserInAdSample()
  672. {
  673. $res = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'AD_V2');
  674. if ($res) {
  675. return true;
  676. } else {
  677. return false;
  678. }
  679. }
  680. /**
  681. * 三天回本活动
  682. * @param Request $request
  683. * @return
  684. */
  685. public function activity(Request $request)
  686. {
  687. $send_time = Redis::hget('add_news_recovery_push_activity' . $this->uid, 'time');
  688. $send_time = time() - 100;
  689. if ($send_time) {
  690. if (time() - $send_time < 86400) {
  691. $activity_id = 1;
  692. $activity_info = ActivityService::getById($activity_id);
  693. if ($activity_info && $activity_info->product_id) {
  694. $from = $request->input('fromtype', 'main');
  695. Redis::sadd('push:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from . ':date:' . date('Y-m-d'), $this->uid);
  696. Redis::hincrby('customer:push:click:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from, date('Y-m-d'), 1);
  697. $param = [
  698. 'uid' => $this->uid,
  699. 'distribution_channel_id' => $this->distribution_channel_id,
  700. 'product_id' => $activity_info->product_id,
  701. 'activity_id' => $activity_id,
  702. 'fromtype' => $from,
  703. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/person'
  704. ];
  705. Redis::hdel('add_news_recovery_push_activity' . $this->uid, 'time');
  706. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  707. return view('pay.order.activity', ['url' => $url, 'code' => 0]);
  708. }
  709. }
  710. }
  711. return redirect('/continue');
  712. //return view('pay.order.activity', ['code' => 1, 'url' => '']);
  713. }
  714. /**
  715. * 商户活动
  716. * @param Request $request
  717. * @return view
  718. */
  719. public function channelActivity(Request $request)
  720. {
  721. $token = $request->input('token');
  722. //return view('pay.order.saleactivity', ['url' => $token, 'code' => 0]);
  723. $activity_info = ActivityService::getByToken($token);
  724. if ($activity_info && $activity_info->product_id) {
  725. $from = $request->input('fromtype', 'main');
  726. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  727. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  728. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  729. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  730. Redis::sadd($uv_key, $this->uid);
  731. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  732. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  733. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  734. // $from = $request->input('from', 'main');
  735. // $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  736. // $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  737. // $uv_key = sprintf($uv_key_format,$activity_info->id,$this->distribution_channel_id,date('Y-m-d'));
  738. // $pv_key = sprintf($pv_key_format,$activity_info->id,$this->distribution_channel_id);
  739. // Redis::sadd($uv_key,$this->uid);
  740. // Redis::hincrby($pv_key,date('Y-m-d'),1);
  741. $param = [
  742. 'uid' => $this->uid,
  743. 'distribution_channel_id' => $this->distribution_channel_id,
  744. 'product_id' => $activity_info->product_id,
  745. 'activity_id' => $activity_info->id,
  746. 'fromtype' => $from,
  747. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  748. ];
  749. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  750. return view('pay.order.saleactivity', ['url' => $url, 'code' => 0]);
  751. }
  752. }
  753. return view('pay.order.saleactivity', ['url' => '###', 'code' => 0]);
  754. }
  755. public function springActivityV1(Request $request)
  756. {
  757. $token = $request->input('token');
  758. $activity_info = ActivityService::getByToken($token);
  759. if ($activity_info) {
  760. $from = $request->input('fromtype', 'main');
  761. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  762. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  763. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  764. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  765. Redis::sadd($uv_key, $this->uid);
  766. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  767. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  768. if ($request->input('redirect_url')) {
  769. $redirect_url = $request->input('redirect_url');
  770. $redirect_url = urldecode($redirect_url);
  771. }
  772. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  773. $param_fifty = [
  774. 'uid' => $this->uid,
  775. 'distribution_channel_id' => $this->distribution_channel_id,
  776. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_FIFTY', 2),
  777. 'activity_id' => $activity_info->id,
  778. 'fromtype' => $from,
  779. 'pay_redirect_url' => $redirect_url
  780. ];
  781. $param_hundred = [
  782. 'uid' => $this->uid,
  783. 'distribution_channel_id' => $this->distribution_channel_id,
  784. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_HUNDRED', 3),
  785. 'activity_id' => $activity_info->id,
  786. 'fromtype' => $from,
  787. 'pay_redirect_url' => $redirect_url
  788. ];
  789. $url_fifty = env('CREATE_PAY_URL') . '?' . http_build_query($param_fifty);
  790. $url_hundred = env('CREATE_PAY_URL') . '?' . http_build_query($param_hundred);
  791. return view('pay.order.springactivity', ['url' => ['fifty' => $url_fifty, 'hundred' => $url_hundred], 'code' => 0]);
  792. } else if (time() <= strtotime($activity_info->start_time)) {
  793. return view('pay.order.springactivity', ['url' => [], 'code' => 1]);
  794. } else {
  795. return view('pay.order.springactivity', ['url' => [], 'code' => 2]);
  796. }
  797. }
  798. return view('pay.order.springactivity', ['url' => [], 'code' => 3]);
  799. }
  800. public function springActivity(Request $request)
  801. {
  802. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  803. $token = $request->input('token');
  804. $activity_info = ActivityService::getByToken($token);
  805. if (!$activity_info) {
  806. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  807. return redirect()->to($default_url);
  808. }
  809. $from = $request->input('fromtype', 'main');
  810. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  811. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  812. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  813. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  814. Redis::sadd($uv_key, $this->uid);
  815. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  816. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  817. if ($request->input('redirect_url')) {
  818. $redirect_url = $request->input('redirect_url');
  819. $redirect_url = urldecode($redirect_url);
  820. }
  821. //未开始
  822. if (time() < strtotime($activity_info->start_time)) {
  823. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1]);
  824. }
  825. //结束
  826. if (time() > strtotime($activity_info->end_time)) {
  827. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2]);
  828. }
  829. $product_ids = [4063, 4064];
  830. $url = [];
  831. foreach ($product_ids as $product_id) {
  832. $param = [
  833. 'uid' => $this->uid,
  834. 'distribution_channel_id' => $this->distribution_channel_id,
  835. 'product_id' => $product_id,
  836. 'activity_id' => $activity_info->id,
  837. 'fromtype' => $from,
  838. 'pay_redirect_url' => $redirect_url,
  839. 'limit' => 100,
  840. ];
  841. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  842. }
  843. return view('pay.order.springactivity2019', ['url' => $url, 'code' => 0]);
  844. }
  845. /**
  846. *
  847. */
  848. public function womenActivity(Request $request)
  849. {
  850. $token = $request->input('token');
  851. $activity_info = ActivityService::getByToken($token);
  852. if ($activity_info) {
  853. $from = $request->input('fromtype', 'main');
  854. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  855. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  856. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  857. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  858. Redis::sadd($uv_key, $this->uid);
  859. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  860. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  861. if ($request->input('redirect_url')) {
  862. $redirect_url = $request->input('redirect_url');
  863. $redirect_url = urldecode($redirect_url);
  864. }
  865. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  866. $param = [
  867. 'uid' => $this->uid,
  868. 'distribution_channel_id' => $this->distribution_channel_id,
  869. 'product_id' => $activity_info->product_id,
  870. 'activity_id' => $activity_info->id,
  871. 'fromtype' => $from,
  872. 'pay_redirect_url' => $redirect_url
  873. ];
  874. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  875. return view('pay.order.womenactivity', ['url' => $url, 'code' => 0]);
  876. } else if (time() <= strtotime($activity_info->start_time)) {
  877. return view('pay.order.womenactivity', ['url' => [], 'code' => 1]);
  878. } else {
  879. return view('pay.order.womenactivity', ['url' => [], 'code' => 2]);
  880. }
  881. }
  882. return view('pay.order.womenactivity', ['url' => [], 'code' => 3]);
  883. }
  884. public function newUserActivity(Request $request)
  885. {
  886. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  887. $from = $request->input('fromtype', 'main');
  888. $send_time = $request->input('send_time');
  889. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  890. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  891. $activity_id = env('NEW_USER_ACTIVITY_ID', 5);
  892. $activity_info = ActivityService::getById($activity_id);
  893. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  894. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  895. Redis::sadd($uv_key, $this->uid);
  896. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  897. if (!$send_time) {
  898. 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)]);
  899. }
  900. $end_time_str = date('Y-m-d', $send_time + 86400);
  901. $end_time = strtotime(date('Y-m-d', $send_time + 86400) . ' 23:59:59');
  902. if ($send_time > $end_time) {
  903. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  904. }
  905. if (time() > $end_time) {
  906. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  907. }
  908. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  909. if ($order) {
  910. 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)]);
  911. //return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  912. }
  913. $param = [
  914. 'uid' => $this->uid,
  915. 'distribution_channel_id' => $this->distribution_channel_id,
  916. 'product_id' => $activity_info->product_id,
  917. 'activity_id' => $activity_info->id,
  918. 'fromtype' => $from,
  919. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  920. ];
  921. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  922. return view('pay.order.newUserActivity', ['url' => $url, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  923. }
  924. public function channelActivityNine(Request $request)
  925. {
  926. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  927. $token = $request->input('token');
  928. $activity_info = ActivityService::getByToken($token);
  929. if ($activity_info && $activity_info->product_id) {
  930. $from = $request->input('fromtype', 'main');
  931. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  932. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  933. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  934. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  935. Redis::sadd($uv_key, $this->uid);
  936. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  937. //渠道不符合
  938. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  939. 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)]);
  940. }
  941. //活动未开始
  942. if (time() < strtotime($activity_info->start_time)) {
  943. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -3, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  944. }
  945. //活动结束
  946. if (time() > strtotime($activity_info->end_time)) {
  947. 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)]);
  948. }
  949. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  950. //参加过了
  951. if ($order) {
  952. 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)]);
  953. }
  954. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  955. $not_allow_paid_user_channel_id = env('NOT_ALLOW_PAID_USER_CHANNEL_ID', 0);
  956. //不允许支付过的用户参见9.9的活动
  957. if ($not_allow_paid_user_channel_id &&
  958. in_array($this->distribution_channel_id, explode(',', $not_allow_paid_user_channel_id)) &&
  959. Order::where('uid', $this->uid)->where('status', 'PAID')->first()
  960. ) {
  961. return view('pay.order.longactivitynine', ['url' => '', 'code' => -4, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  962. }
  963. $param = [
  964. 'uid' => $this->uid,
  965. 'distribution_channel_id' => $this->distribution_channel_id,
  966. 'product_id' => $activity_info->product_id,
  967. 'activity_id' => $activity_info->id,
  968. 'fromtype' => $from,
  969. 'limit' => 1,
  970. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  971. ];
  972. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  973. 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)]);
  974. }
  975. }
  976. 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)]);
  977. }
  978. public function channelActivitySixtyEight(Request $request)
  979. {
  980. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  981. $token = $request->input('token');
  982. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn68.jpg';
  983. $activity_info = ActivityService::getByToken($token);
  984. if ($activity_info && $activity_info->product_id) {
  985. $from = $request->input('fromtype', 'main');
  986. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  987. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  988. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  989. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  990. Redis::sadd($uv_key, $this->uid);
  991. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  992. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  993. //渠道不符合
  994. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  995. 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)]);
  996. }
  997. //活动未开始
  998. if (time() < strtotime($activity_info->start_time)) {
  999. 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)]);
  1000. }
  1001. //活动结束
  1002. if (time() > strtotime($activity_info->end_time)) {
  1003. 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)]);
  1004. }
  1005. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1006. $param = [
  1007. 'uid' => $this->uid,
  1008. 'distribution_channel_id' => $this->distribution_channel_id,
  1009. 'product_id' => $activity_info->product_id,
  1010. 'activity_id' => $activity_info->id,
  1011. 'fromtype' => $from,
  1012. 'limit' => 100,
  1013. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1014. ];
  1015. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1016. 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)]);
  1017. }
  1018. }
  1019. 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)]);
  1020. }
  1021. public function channelActivityFortyEight(Request $request)
  1022. {
  1023. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1024. $token = $request->input('token');
  1025. $activity_info = ActivityService::getByToken($token);
  1026. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
  1027. if ($activity_info && $activity_info->product_id) {
  1028. $from = $request->input('fromtype', 'main');
  1029. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1030. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1031. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1032. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1033. Redis::sadd($uv_key, $this->uid);
  1034. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1035. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  1036. //渠道不符合
  1037. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  1038. 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)]);
  1039. }
  1040. //活动未开始
  1041. if (time() < strtotime($activity_info->start_time)) {
  1042. 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)]);
  1043. }
  1044. //活动结束
  1045. if (time() > strtotime($activity_info->end_time)) {
  1046. 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)]);
  1047. }
  1048. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1049. $param = [
  1050. 'uid' => $this->uid,
  1051. 'distribution_channel_id' => $this->distribution_channel_id,
  1052. 'product_id' => $activity_info->product_id,
  1053. 'activity_id' => $activity_info->id,
  1054. 'fromtype' => $from,
  1055. 'limit' => 100,
  1056. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1057. ];
  1058. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1059. 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)]);
  1060. }
  1061. }
  1062. 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)]);
  1063. }
  1064. public function channelNewUserActivity(Request $request)
  1065. {
  1066. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1067. $token = $request->get('token');
  1068. $activity_info = ActivityService::getByToken($token);
  1069. $from = $request->get('fromtype', 'main');
  1070. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1071. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1072. if ($activity_info && $activity_info->product_id) {
  1073. $activity_id = $activity_info->id;
  1074. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1075. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1076. Redis::sadd($uv_key, $this->uid);
  1077. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1078. //活动未开始
  1079. if (time() < strtotime($activity_info->start_time)) {
  1080. 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)]);
  1081. }
  1082. //活动结束
  1083. if (time() > strtotime($activity_info->end_time)) {
  1084. 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)]);
  1085. }
  1086. $charge_count = Order::where('uid', $this->uid)->where('status', 'PAID')->count();
  1087. if ($charge_count > 0) {
  1088. //不是新用户
  1089. 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)]);
  1090. }
  1091. $param = [
  1092. 'uid' => $this->uid,
  1093. 'distribution_channel_id' => $this->distribution_channel_id,
  1094. 'product_id' => $activity_info->product_id,
  1095. 'activity_id' => $activity_info->id,
  1096. 'fromtype' => $from,
  1097. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1098. ];
  1099. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1100. 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)]);
  1101. }
  1102. 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)]);
  1103. }
  1104. /**
  1105. * 清明活动
  1106. */
  1107. public function qingMingActivity(Request $request)
  1108. {
  1109. $token = $request->input('token');
  1110. $activity_info = ActivityService::getByToken($token);
  1111. if ($activity_info) {
  1112. $from = $request->input('fromtype', 'main');
  1113. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1114. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1115. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1116. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1117. Redis::sadd($uv_key, $this->uid);
  1118. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1119. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1120. if ($request->input('redirect_url')) {
  1121. $redirect_url = $request->input('redirect_url');
  1122. $redirect_url = urldecode($redirect_url);
  1123. }
  1124. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1125. $param = [
  1126. 'uid' => $this->uid,
  1127. 'distribution_channel_id' => $this->distribution_channel_id,
  1128. 'product_id' => $activity_info->product_id,
  1129. 'activity_id' => $activity_info->id,
  1130. 'fromtype' => $from,
  1131. 'pay_redirect_url' => $redirect_url
  1132. ];
  1133. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1134. return view('pay.order.qingmingactivity', ['url' => $url, 'code' => 0]);
  1135. } else if (time() <= strtotime($activity_info->start_time)) {
  1136. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 1]);
  1137. } else {
  1138. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 2]);
  1139. }
  1140. }
  1141. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 3]);
  1142. }
  1143. public function readDayActivity(Request $request)
  1144. {
  1145. $token = $request->input('token');
  1146. $activity_info = ActivityService::getByToken($token);
  1147. if ($activity_info) {
  1148. $from = $request->input('fromtype', 'main');
  1149. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1150. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1151. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1152. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1153. Redis::sadd($uv_key, $this->uid);
  1154. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1155. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1156. if ($request->input('redirect_url')) {
  1157. $redirect_url = $request->input('redirect_url');
  1158. $redirect_url = urldecode($redirect_url);
  1159. }
  1160. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1161. $param = [
  1162. 'uid' => $this->uid,
  1163. 'distribution_channel_id' => $this->distribution_channel_id,
  1164. 'product_id' => $activity_info->product_id,
  1165. 'activity_id' => $activity_info->id,
  1166. 'fromtype' => $from,
  1167. 'pay_redirect_url' => $redirect_url,
  1168. 'limit' => 100,
  1169. ];
  1170. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1171. return view('pay.order.laborDay', ['url' => $url, 'code' => 0]);
  1172. } else if (time() <= strtotime($activity_info->start_time)) {
  1173. return view('pay.order.laborDay', ['url' => [], 'code' => 1]);
  1174. } else {
  1175. return view('pay.order.laborDay', ['url' => [], 'code' => 2]);
  1176. }
  1177. }
  1178. return view('pay.order.laborDay', ['url' => [], 'code' => 3]);
  1179. }
  1180. public function commonActivity(Request $request)
  1181. {
  1182. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1183. $token = $request->input('token');
  1184. $activity_info = ActivityService::getByToken($token);
  1185. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
  1186. $imgs = json_decode($activity_info->setting, 1);
  1187. $from = $request->input('fromtype', 'main');
  1188. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1189. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1190. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1191. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1192. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1193. if ($request->input('redirect_url')) {
  1194. $redirect_url = $request->input('redirect_url');
  1195. $redirect_url = urldecode($redirect_url);
  1196. }
  1197. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1198. Redis::sadd($uv_key, $this->uid);
  1199. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1200. $param = [
  1201. 'uid' => $this->uid,
  1202. 'distribution_channel_id' => $this->distribution_channel_id,
  1203. 'product_id' => $activity_info->product_id,
  1204. 'activity_id' => $activity_info->id,
  1205. 'fromtype' => $from,
  1206. 'pay_redirect_url' => $redirect_url,
  1207. 'limit' => 100,
  1208. ];
  1209. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1210. return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
  1211. } else if (time() <= strtotime($activity_info->start_time)) {
  1212. return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
  1213. } else {
  1214. return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
  1215. }
  1216. }
  1217. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1218. return redirect()->to($default_url);
  1219. }
  1220. public function yearActivity(Request $request)
  1221. {
  1222. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1223. $from = $request->input('fromtype', 'main');
  1224. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1225. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1226. if (empty($sites)) {
  1227. return redirect()->to($not_access_url);
  1228. }
  1229. $site_arr = explode(',', $sites);
  1230. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1231. return redirect()->to($not_access_url);
  1232. }
  1233. $year_activity_id = env('YEAR_ACTIVITY_ID');
  1234. if (!$year_activity_id) {
  1235. return redirect()->to($not_access_url);
  1236. }
  1237. $activity_info = Activity::find($year_activity_id);
  1238. if (!$activity_info) {
  1239. return redirect()->to($not_access_url);
  1240. }
  1241. $activity_id = $year_activity_id;
  1242. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1243. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1244. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1245. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1246. Redis::sadd($uv_key, $this->uid);
  1247. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1248. $start = $activity_info->start_time;
  1249. $end = $activity_info->end_time;
  1250. if (empty($start) || empty($end)) {
  1251. return redirect()->to($not_access_url);
  1252. }
  1253. $male_site = env('YEAR_MALE_SITE');
  1254. if ($male_site && in_array($this->distribution_channel_id, explode(',', $male_site))) {
  1255. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_MALE_BID'))));
  1256. } else {
  1257. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_FEMALE_BID'))));
  1258. }
  1259. $is_get = 0;
  1260. $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count();
  1261. //$old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $old_year_activity_id)->count();
  1262. $old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->whereIn('activity_id', [643, 827, 1104, 1294])->count();
  1263. if ($discount_coupon) {
  1264. $is_get = 1;
  1265. }
  1266. if ($old_discount_coupon) {
  1267. //51活动领取过 优惠80
  1268. $discount = 80;
  1269. $product_id = $activity_info->product_id;
  1270. } else {
  1271. //51活动领未取过 优惠50
  1272. $discount = 50;
  1273. $product_id = 1450;
  1274. }
  1275. if (time() < strtotime($start)) {
  1276. //未开始
  1277. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 1, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1278. }
  1279. if (time() > strtotime($end)) {
  1280. //结束
  1281. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 2, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1282. }
  1283. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1284. //参加过了
  1285. if ($order) {
  1286. //return view('pay.order.yearactivityV2', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 3, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1287. }
  1288. $param = [
  1289. 'uid' => $this->uid,
  1290. 'distribution_channel_id' => $this->distribution_channel_id,
  1291. 'product_id' => $product_id,
  1292. 'activity_id' => $activity_id,
  1293. 'fromtype' => $from,
  1294. 'limit' => 10,
  1295. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1296. ];
  1297. $this->getCoupons($activity_id);
  1298. $coupons_url = $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1299. $param['product_id'] = 5;
  1300. $primary_url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1301. 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]);
  1302. }
  1303. private function getCoupons($activity_id)
  1304. {
  1305. if (!DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count()) {
  1306. DB::table('discount_coupons')->insert([
  1307. 'uid' => $this->uid,
  1308. 'activity_id' => $activity_id,
  1309. 'created_at' => date('Y-m-d H:i:s'),
  1310. 'updated_at' => date('Y-m-d H:i:s')
  1311. ]);
  1312. }
  1313. }
  1314. public function summerActivity(Request $request)
  1315. {
  1316. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1317. $from = $request->input('fromtype', 'main');
  1318. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1319. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1320. if (empty($sites)) {
  1321. return redirect()->to($not_access_url);
  1322. }
  1323. if ($sites != 'all') {
  1324. $site_arr = explode(',', $sites);
  1325. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1326. return redirect()->to($not_access_url);
  1327. }
  1328. }
  1329. $activity_id = 350;
  1330. $activity_info = Activity::find($activity_id);
  1331. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1332. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1333. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1334. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1335. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1336. if ($request->input('redirect_url')) {
  1337. $redirect_url = $request->input('redirect_url');
  1338. $redirect_url = urldecode($redirect_url);
  1339. }
  1340. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1341. Redis::sadd($uv_key, $this->uid);
  1342. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1343. $url_array = [];
  1344. $product_id_array = [2158, 2159, 2160, 2161];
  1345. foreach ($product_id_array as $v) {
  1346. $param = [
  1347. 'uid' => $this->uid,
  1348. 'distribution_channel_id' => $this->distribution_channel_id,
  1349. 'product_id' => $v,
  1350. 'activity_id' => $activity_id,
  1351. 'fromtype' => $from,
  1352. 'pay_redirect_url' => $redirect_url,
  1353. 'limit' => 100,
  1354. ];
  1355. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1356. $url_array[] = $url;
  1357. }
  1358. return view('pay.order.summerActivity', ['url' => '', 'code' => 0, 'url_array' => $url_array]);
  1359. } else if (time() <= strtotime($activity_info->start_time)) {
  1360. return view('pay.order.summerActivity', ['url' => [], 'code' => 1]);
  1361. } else {
  1362. return view('pay.order.summerActivity', ['url' => [], 'code' => 2]);
  1363. }
  1364. }
  1365. public function newUserSale(Request $request)
  1366. {
  1367. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1368. $from = $request->input('fromtype', 'main');
  1369. $send_time = $request->input('send_time');
  1370. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1371. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1372. $activity_id = 402;
  1373. $activity_info = ActivityService::getById($activity_id);
  1374. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1375. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1376. Redis::sadd($uv_key, $this->uid);
  1377. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1378. // 2226,2227,2228,22229,2230
  1379. if (!$send_time) {
  1380. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1381. 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)]);
  1382. }
  1383. $end_time_str = date('Y-m-d', $send_time + 3 * 86400);
  1384. $end_time = strtotime(date('Y-m-d', $send_time + 3 * 86400) . ' 23:59:59');
  1385. if ($send_time > $end_time) {
  1386. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1387. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -1, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1388. }
  1389. if (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' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1392. }
  1393. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1394. if ($order) {
  1395. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1396. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1397. }
  1398. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id, true);
  1399. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1400. }
  1401. private function getUrls($activity_info_setting, $from, $channel_id, $encode_channel_id, $activity_id, $is_access = false)
  1402. {
  1403. $product = DB::table('products')
  1404. ->whereIn('id', explode(',', $activity_info_setting))
  1405. ->select('id', 'price', 'type', 'given')
  1406. ->get();
  1407. $url_info = [];
  1408. $url_info['year'] = ['url' => '###'];
  1409. $url_info['charge'] = [];
  1410. $param = [
  1411. 'uid' => $this->uid,
  1412. 'distribution_channel_id' => $this->distribution_channel_id,
  1413. 'product_id' => $channel_id,
  1414. 'limit' => 1,
  1415. 'fromtype' => $from,
  1416. 'activity_id' => $activity_id,
  1417. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1418. ];
  1419. if (!$product) {
  1420. return $url_info;
  1421. }
  1422. foreach ($product as $v) {
  1423. if (in_array($this->distribution_channel_id, [6917, 6918, 6939]) && $v->type == 'YEAR_ORDER') {
  1424. continue;
  1425. }
  1426. if ($is_access) {
  1427. $param['product_id'] = $v->id;
  1428. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1429. } else {
  1430. $url = '###';
  1431. }
  1432. if ($v->type == 'YEAR_ORDER') {
  1433. $url_info['year']['url'] = $url;
  1434. } else {
  1435. $temp = [];
  1436. $temp['url'] = $url;
  1437. $temp['price'] = (int)$v->price;
  1438. $temp['given'] = (int)($v->given / 100);
  1439. $temp['total'] = $v->price * 100 + $v->given;
  1440. if ($v->price == 30) {
  1441. $temp['old_given'] = '无折扣';
  1442. } elseif ($v->price == 50) {
  1443. $temp['old_given'] = '送40元';
  1444. } elseif ($v->price == 100) {
  1445. $temp['old_given'] = '送100元';
  1446. } elseif ($v->price == 200) {
  1447. $temp['old_given'] = '送200元';
  1448. } else {
  1449. $temp['old_given'] = '';
  1450. }
  1451. $url_info['charge'][] = $temp;
  1452. }
  1453. }
  1454. return $url_info;
  1455. }
  1456. public function nationalDayActivity(Request $request)
  1457. {
  1458. $token = $request->input('token', '');
  1459. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1460. $activity_info = ActivityService::getByToken($token);
  1461. if (!$activity_info) {
  1462. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1463. return redirect()->to($not_access_url);
  1464. }
  1465. $from = $request->input('fromtype', 'main');
  1466. $activity_id = $activity_info->id;
  1467. $activty_ids = env('NATIONAL_DAY_ACTIVITY_IDS', '1,2,3');
  1468. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1469. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1470. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1471. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1472. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1473. if ($request->input('redirect_url')) {
  1474. $redirect_url = $request->input('redirect_url');
  1475. $redirect_url = urldecode($redirect_url);
  1476. }
  1477. $activity_status = -1;
  1478. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1479. $activity_status = 1;
  1480. }
  1481. if (time() < strtotime($activity_info->start_time)) {
  1482. //未开始
  1483. $activity_status = -1;
  1484. }
  1485. if (time() > strtotime($activity_info->end_time)) {
  1486. //结束
  1487. $activity_status = -2;
  1488. }
  1489. Redis::sadd($uv_key, $this->uid);
  1490. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1491. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1492. if ($user_charge_count == 0) {
  1493. $is_first_charge = 1;
  1494. } else {
  1495. $is_first_charge = 0;
  1496. }
  1497. $url_array = [];
  1498. $product_id_array = explode(',', $activty_ids);
  1499. foreach ($product_id_array as $key => $v) {
  1500. if ($user_charge_count >= 1 && $key == 0) {
  1501. //continue;
  1502. }
  1503. $param = [
  1504. 'uid' => $this->uid,
  1505. 'distribution_channel_id' => $this->distribution_channel_id,
  1506. 'product_id' => $v,
  1507. 'activity_id' => $activity_id,
  1508. 'fromtype' => $from,
  1509. 'pay_redirect_url' => $redirect_url,
  1510. 'limit' => 100,
  1511. ];
  1512. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1513. $url_array[] = $url;
  1514. }
  1515. return view('pay.order.nationalDayActivity', ['url' => $url_array, 'is_first_charge' => $is_first_charge, 'code' => $activity_status]);
  1516. }
  1517. public function cYactivity(Request $request)
  1518. {
  1519. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1520. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1521. $site_arr = explode(',', env('YEAR_ACTIVITY_CHANNEL', '2'));
  1522. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1523. return redirect()->to($default_url);
  1524. }
  1525. $activity_info = ActivityService::getById(929);
  1526. if ($activity_info) {
  1527. $from = $request->input('fromtype', 'main');
  1528. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1529. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1530. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1531. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1532. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1533. if ($request->input('redirect_url')) {
  1534. $redirect_url = $request->input('redirect_url');
  1535. $redirect_url = urldecode($redirect_url);
  1536. }
  1537. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1538. Redis::sadd($uv_key, $this->uid);
  1539. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1540. $param = [
  1541. 'uid' => $this->uid,
  1542. 'distribution_channel_id' => $this->distribution_channel_id,
  1543. 'product_id' => $activity_info->product_id,
  1544. 'activity_id' => $activity_info->id,
  1545. 'fromtype' => $from,
  1546. 'pay_redirect_url' => $redirect_url,
  1547. 'limit' => 100,
  1548. ];
  1549. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1550. return view('pay.order.cyangActivity', ['url' => $url, 'code' => 0,]);
  1551. } else if (time() <= strtotime($activity_info->start_time)) {
  1552. return view('pay.order.cyangActivity', ['url' => [], 'code' => 1,]);
  1553. } else {
  1554. return view('pay.order.cyangActivity', ['url' => [], 'code' => 2,]);
  1555. }
  1556. }
  1557. return redirect()->to($default_url);
  1558. return view('pay.order.cyangActivity', []);
  1559. }
  1560. public function newUserForeverActivity(Request $request)
  1561. {
  1562. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1563. $from = $request->input('fromtype', 'main');
  1564. $send_time = $request->input('send_time');
  1565. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1566. if ($this->distribution_channel_id != 123) {
  1567. return redirect()->to($default_url);
  1568. }
  1569. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1570. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1571. $activity_id = env('FOREVER_ACTIVITY_ID', 5);
  1572. $activity_info = ActivityService::getById($activity_id);
  1573. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1574. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1575. Redis::sadd($uv_key, $this->uid);
  1576. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1577. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1578. if (!$send_time) {
  1579. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1580. }
  1581. $end_time = $send_time + 86400 * 3;
  1582. $time_diff = $end_time - time();
  1583. if ($time_diff <= 0) {
  1584. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1585. }
  1586. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1587. if ($order) {
  1588. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1589. }*/
  1590. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1591. $day = floor($time_diff / 86400);
  1592. $hour = floor(($time_diff - $day * 86400) / 3600);
  1593. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1594. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1595. $param = [
  1596. 'uid' => $this->uid,
  1597. 'distribution_channel_id' => $this->distribution_channel_id,
  1598. 'product_id' => $activity_info->product_id,
  1599. 'activity_id' => $activity_info->id,
  1600. 'fromtype' => $from,
  1601. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1602. ];
  1603. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1604. return view('pay.order.foreverActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'books' => $books]);
  1605. }
  1606. public function tempC()
  1607. {
  1608. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1609. $param = [
  1610. 'uid' => $this->uid,
  1611. 'distribution_channel_id' => $this->distribution_channel_id,
  1612. 'product_id' => 1450,
  1613. 'activity_id' => 0,
  1614. 'fromtype' => 'tempC',
  1615. 'limit' => 10,
  1616. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1617. ];
  1618. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1619. return redirect()->to($url);
  1620. }
  1621. /**
  1622. * 68元包年活动
  1623. * @param Request $request
  1624. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1625. */
  1626. public function otherYearActivity(Request $request)
  1627. {
  1628. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1629. $from = $request->input('fromtype', 'main');
  1630. $send_time = $request->input('send_time');
  1631. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1632. if ($this->distribution_channel_id != 123) {
  1633. return redirect()->to($default_url);
  1634. }
  1635. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1636. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1637. $activity_id = env('68_YEAR_ACTIVITY_ID', 5);
  1638. $activity_info = ActivityService::getById($activity_id);
  1639. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1640. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1641. Redis::sadd($uv_key, $this->uid);
  1642. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1643. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1644. $books = '';
  1645. $time_diff = 0;
  1646. if (!$send_time) {
  1647. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1648. }
  1649. $end_time = $send_time + 86400 * 3;
  1650. $time_diff = $end_time - time();
  1651. if ($time_diff <= 0) {
  1652. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1653. }
  1654. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1655. if ($order) {
  1656. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1657. }*/
  1658. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1659. $day = floor($time_diff / 86400);
  1660. $hour = floor(($time_diff - $day * 86400) / 3600);
  1661. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1662. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1663. $param = [
  1664. 'uid' => $this->uid,
  1665. 'distribution_channel_id' => $this->distribution_channel_id,
  1666. 'product_id' => $activity_info->product_id,
  1667. 'activity_id' => $activity_info->id,
  1668. 'fromtype' => $from,
  1669. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1670. ];
  1671. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1672. return view('pay.order.otherYearActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'time_diff' => $time_diff]);
  1673. }
  1674. /**
  1675. * 双十一购物节统计
  1676. * @param Request $request
  1677. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1678. */
  1679. public function shoppingDayActivity(Request $request)
  1680. {
  1681. $token = $request->input('token', '');
  1682. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1683. $activity_info = ActivityService::getByToken($token);
  1684. if (!$activity_info) {
  1685. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1686. return redirect()->to($not_access_url);
  1687. }
  1688. $from = $request->input('fromtype', 'main');
  1689. $activity_id = $activity_info->id;
  1690. $activty_ids = env('SHOPPING_DAY_ACTIVITY_IDS', '1,2,3');
  1691. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1692. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1693. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1694. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1695. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1696. if ($request->input('redirect_url')) {
  1697. $redirect_url = $request->input('redirect_url');
  1698. $redirect_url = urldecode($redirect_url);
  1699. }
  1700. $activity_status = -1;
  1701. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1702. $activity_status = 1;
  1703. }
  1704. if (time() < strtotime($activity_info->start_time)) {
  1705. //未开始
  1706. $activity_status = -1;
  1707. }
  1708. if (time() > strtotime($activity_info->end_time)) {
  1709. //结束
  1710. $activity_status = -2;
  1711. }
  1712. Redis::sadd($uv_key, $this->uid);
  1713. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1714. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1715. if ($user_charge_count == 0) {
  1716. $is_first_charge = 1;
  1717. } else {
  1718. $is_first_charge = 0;
  1719. }
  1720. $url_array = [];
  1721. $time_diff = strtotime($activity_info->end_time) - time();
  1722. $day = 0;
  1723. $hour = 0;
  1724. $minute = 0;
  1725. $second = 0;
  1726. if ($time_diff > 0) {
  1727. $day = floor($time_diff / 86400);
  1728. $hour = floor(($time_diff - $day * 86400) / 3600);
  1729. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1730. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1731. }
  1732. $product_id_array = explode(',', $activty_ids);
  1733. $product_infos = DB::table('products')->whereIn('id', $product_id_array)->select('id', 'price', 'given')->get();
  1734. foreach ($product_infos as $key => $v) {
  1735. if ($user_charge_count >= 1 && $key == 0) {
  1736. continue;
  1737. }
  1738. $limit = 100;
  1739. if ($key == 0) {
  1740. $limit = 1;
  1741. }
  1742. $param = [
  1743. 'uid' => $this->uid,
  1744. 'distribution_channel_id' => $this->distribution_channel_id,
  1745. 'product_id' => $v->id,
  1746. 'activity_id' => $activity_id,
  1747. 'fromtype' => $from,
  1748. 'pay_redirect_url' => $redirect_url,
  1749. 'limit' => $limit,
  1750. ];
  1751. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1752. $url_array[] = ['url' => $url, 'price' => (int)$v->price, 'given' => $v->given / 100, 'get' => $v->price * 100 + $v->given];
  1753. }
  1754. return view('pay.order.shoppingDayActivity', [
  1755. 'url' => $url_array,
  1756. 'is_first_charge' => $is_first_charge,
  1757. 'code' => $activity_status,
  1758. 'time' => compact('day', 'hour', 'minute', 'second'),
  1759. 'user_charge_count' => $user_charge_count,
  1760. 'time_diff' => $time_diff
  1761. ]
  1762. );
  1763. }
  1764. public function thanksGivingDayActivity(Request $request)
  1765. {
  1766. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1767. $from = $request->input('fromtype', 'main');
  1768. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1769. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1770. if (empty($sites)) {
  1771. return redirect()->to($not_access_url);
  1772. }
  1773. $site_arr = explode(',', $sites);
  1774. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1775. return redirect()->to($not_access_url);
  1776. }
  1777. $year_activity_id = 1367;
  1778. $activity_info = Activity::find($year_activity_id);
  1779. if (!$activity_info) {
  1780. return redirect()->to($not_access_url);
  1781. }
  1782. $activity_id = $year_activity_id;
  1783. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1784. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1785. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1786. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1787. Redis::sadd($uv_key, $this->uid);
  1788. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1789. $start = $activity_info->start_time;
  1790. $end = $activity_info->end_time;
  1791. if (empty($start) || empty($end)) {
  1792. return redirect()->to($not_access_url);
  1793. }
  1794. $url = ['slow' => 'javascript:void(0)', 'height' => 'javascript:void(0)'];
  1795. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->select('id')->first();
  1796. $charge_count = 0;
  1797. if ($order) {
  1798. $charge_count = 1;
  1799. }
  1800. if (time() < strtotime($start)) {
  1801. //未开始
  1802. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 1, 'charge_count' => $charge_count]);
  1803. }
  1804. if (time() > strtotime($end)) {
  1805. //结束
  1806. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 2, 'charge_count' => $charge_count]);
  1807. }
  1808. //3483 3484
  1809. $param = [
  1810. 'uid' => $this->uid,
  1811. 'distribution_channel_id' => $this->distribution_channel_id,
  1812. 'product_id' => 3483,
  1813. 'activity_id' => $activity_id,
  1814. 'fromtype' => $from,
  1815. 'limit' => 1,
  1816. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1817. ];
  1818. $this->getCoupons($activity_id);
  1819. $url['slow'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1820. $param['product_id'] = 3484;
  1821. $param['limit'] = 100;
  1822. $url['height'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1823. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 0, 'charge_count' => $charge_count]);
  1824. }
  1825. public function greatColdActivity(Request $request)
  1826. {
  1827. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1828. $token = $request->input('token');
  1829. $activity_info = ActivityService::getByToken($token);
  1830. if (!$activity_info) {
  1831. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1832. return redirect()->to($default_url);
  1833. }
  1834. $from = $request->input('fromtype', 'main');
  1835. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1836. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1837. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1838. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1839. Redis::sadd($uv_key, $this->uid);
  1840. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1841. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1842. if ($request->input('redirect_url')) {
  1843. $redirect_url = $request->input('redirect_url');
  1844. $redirect_url = urldecode($redirect_url);
  1845. }
  1846. $least_charge_amount = Order::select('id', 'price')
  1847. ->where('uid', $this->uid)
  1848. ->where('status', 'PAID')
  1849. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1850. ->max('price');
  1851. $type = 'litter';
  1852. $product_ids = [3962, 3963];
  1853. $img = [
  1854. 'litter' => [
  1855. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8-active.png',
  1856. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8.png',
  1857. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23-active.png',
  1858. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23.png',
  1859. ],
  1860. 'big' => [
  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. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58-active.png',
  1864. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58.png',
  1865. ],
  1866. ];
  1867. if ($least_charge_amount && $least_charge_amount >= 30) {
  1868. $type = 'big';
  1869. $product_ids = [3960, 3961];
  1870. }
  1871. //未开始
  1872. if (time() < strtotime($activity_info->start_time)) {
  1873. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1874. }
  1875. //结束
  1876. if (time() > strtotime($activity_info->end_time)) {
  1877. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1878. }
  1879. $url = [];
  1880. foreach ($product_ids as $product_id) {
  1881. $param = [
  1882. 'uid' => $this->uid,
  1883. 'distribution_channel_id' => $this->distribution_channel_id,
  1884. 'product_id' => $product_id,
  1885. 'activity_id' => $activity_info->id,
  1886. 'fromtype' => $from,
  1887. 'pay_redirect_url' => $redirect_url,
  1888. 'limit' => 100,
  1889. ];
  1890. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1891. }
  1892. return view('pay.order.greatColdActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1893. }
  1894. public function channelYearActivity(Request $request)
  1895. {
  1896. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1897. $id = 2628;
  1898. $activity_info = ActivityService::getById($id);
  1899. if ($activity_info && $activity_info->product_id) {
  1900. $from = $request->input('fromtype', 'main');
  1901. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1902. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1903. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1904. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1905. Redis::sadd($uv_key, $this->uid);
  1906. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1907. $param = [
  1908. 'uid' => $this->uid,
  1909. 'distribution_channel_id' => $this->distribution_channel_id,
  1910. 'product_id' => $activity_info->product_id,
  1911. 'activity_id' => $activity_info->id,
  1912. 'fromtype' => $from,
  1913. 'limit' => 30,
  1914. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1915. ];
  1916. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1917. return view('pay.order.channelYearActivity', ['url' => $url]);
  1918. }
  1919. $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1920. return redirect()->to($url);
  1921. }
  1922. //春分活动
  1923. public function vernalEquinoxActivity(Request $request)
  1924. {
  1925. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1926. $token = $request->input('token');
  1927. $activity_info = ActivityService::getByToken($token);
  1928. if (!$activity_info) {
  1929. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1930. return redirect()->to($default_url);
  1931. }
  1932. $from = $request->input('fromtype', 'main');
  1933. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1934. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1935. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1936. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1937. Redis::sadd($uv_key, $this->uid);
  1938. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1939. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1940. if ($request->input('redirect_url')) {
  1941. $redirect_url = $request->input('redirect_url');
  1942. $redirect_url = urldecode($redirect_url);
  1943. }
  1944. $least_charge_amount = Order::select('id', 'price')
  1945. ->where('uid', $this->uid)
  1946. ->where('status', 'PAID')
  1947. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1948. ->max('price');
  1949. $type = 'litter';
  1950. if ($least_charge_amount && $least_charge_amount >= 30) {
  1951. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg50.jpg';
  1952. $product_ids = 4806;
  1953. } else {
  1954. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg23.jpg';
  1955. $product_ids = 4805;
  1956. }
  1957. //未开始
  1958. if (time() < strtotime($activity_info->start_time)) {
  1959. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1960. }
  1961. //结束
  1962. if (time() > strtotime($activity_info->end_time)) {
  1963. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1964. }
  1965. $param = [
  1966. 'uid' => $this->uid,
  1967. 'distribution_channel_id' => $this->distribution_channel_id,
  1968. 'product_id' => $product_ids,
  1969. 'activity_id' => $activity_info->id,
  1970. 'fromtype' => $from,
  1971. 'pay_redirect_url' => $redirect_url,
  1972. 'limit' => 100,
  1973. ];
  1974. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1975. return view('pay.order.vernalEquinoxActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1976. }
  1977. private function userPproperty()
  1978. {
  1979. if ($this->property == 'undefined') {
  1980. if ($this->user && time() - strtotime($this->user->created_at) >= 3 * 66400) {
  1981. $info = UserDivisionCpcPropertyService::calculateUserPropertyV2($this->uid);
  1982. if ($info && $info['property'] != 'undefined') {
  1983. UserDivisionCpcPropertyService::updateV2($info['openid'], $info['property']);
  1984. }
  1985. }
  1986. }
  1987. /*$old = UserDivisionCpcPropertyService::userLevel($openid);
  1988. if(!$old) return ;
  1989. $this->property = $old->property;
  1990. if($old->type != 'NEW') return ;
  1991. $send_data = array(
  1992. 'type' => 'visit',
  1993. 'data' => ['openid'=>$openid,'uid'=>$this->uid]
  1994. );
  1995. try {
  1996. $send = new SendStatisticsList($send_data);
  1997. $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list');
  1998. dispatch($job);
  1999. } catch (\Exception $e) {
  2000. \Log::info($e);
  2001. }*/
  2002. }
  2003. private function guidePersonalAccountV2(){
  2004. //内部站点导粉
  2005. list($inner_sites,$year_qrcode,$month_qrcode,$out_qrcode) = redisEnvMulti(
  2006. 'GUIDE_PERSONAL_ACCOUNT_SITES',
  2007. 'ACTIVE_YEAR_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2008. 'ACTIVE_MONTH_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2009. 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE'
  2010. );
  2011. //if(in_array($thy))
  2012. if ($inner_sites && in_array($this->distribution_channel_id, explode(',', $inner_sites))) {
  2013. //1.包年包月用户
  2014. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2015. if ($get_info) return '';
  2016. $charge = false;
  2017. if (in_array($this->property, ['medium', 'high'])) {
  2018. $charge = true;
  2019. } else {
  2020. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2021. $charge = true;
  2022. }
  2023. }
  2024. if(!$charge) return '';
  2025. if($year_qrcode && OrderService::isYearOrderUser($this->uid) ){
  2026. //包年
  2027. return ['title' => '包年VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_YEAR&fee=500'];
  2028. }
  2029. if($month_qrcode && UserMonthService::isMonthOrderUser($this->uid) ){
  2030. //包月
  2031. return ['title' => '包月VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_MONTH&fee=500'];
  2032. }
  2033. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2034. }
  2035. //外站导粉
  2036. if($out_qrcode && Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)){
  2037. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2038. if ($get_info) return '';
  2039. $charge = false;
  2040. if (in_array($this->property, ['medium', 'high'])) {
  2041. $charge = true;
  2042. } else {
  2043. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2044. $charge = true;
  2045. }
  2046. }
  2047. if(!$charge) return '';
  2048. $filter_city = ['长沙', '深圳', '杭州'];
  2049. $ip2region = new Ip2Region();
  2050. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2051. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2052. } else {
  2053. $ip = get_client_ip();
  2054. }
  2055. $info = [];
  2056. try {
  2057. $info = $ip2region->btreeSearch($ip);
  2058. } catch (\Exception $e) {
  2059. }
  2060. if (!$info || !isset($info['region'])) return '';
  2061. $region = explode('|', $info['region']);
  2062. $city = isset($region[3]) ? $region[3] : '';
  2063. if (in_array($city, $filter_city)) {
  2064. return '';
  2065. }
  2066. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2067. if ($count < 50) {
  2068. return '';
  2069. }
  2070. Cookie::queue('is_force_out_guide', 1);
  2071. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2072. }
  2073. //渠道自己导粉
  2074. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2075. if (empty($other_crm_config[0]) && empty($other_crm_config[1])) return '';
  2076. if($this->is_paid || $this->distribution_channel_id == 6687)
  2077. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1]];
  2078. return '';
  2079. }
  2080. private function guidePersonalAccount($openid)
  2081. {
  2082. //weidian
  2083. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2084. $crm_config = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
  2085. $out_status = Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id);
  2086. if (empty($other_crm_config[0]) && empty($other_crm_config[1]) && empty($crm_config[0]) && empty($crm_config[1]) && empty($out_status)) {
  2087. return '';
  2088. }
  2089. //Log::info('guidePersonalAccount1111111111111111111111');
  2090. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2091. if ($get_info) return '';
  2092. //Log::info('guidePersonalAccount2222222222222222222222');
  2093. $charge = false;
  2094. if (in_array($this->property, ['medium', 'high'])) {
  2095. $charge = true;
  2096. } else {
  2097. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2098. $charge = true;
  2099. }
  2100. }
  2101. if ($this->distribution_channel_id == 6687) {
  2102. $charge = true;
  2103. }
  2104. if (!$charge) return '';
  2105. //其他渠道自己导粉
  2106. if ($other_crm_config[0] && $other_crm_config[1]) {
  2107. if ($charge)
  2108. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1]];
  2109. return '';
  2110. }
  2111. //站外导粉
  2112. if ($out_status) {
  2113. if (!$charge) return '';
  2114. if (empty($crm_config[2])) {
  2115. return '';
  2116. }
  2117. $filter_city = ['长沙', '深圳', '杭州'];
  2118. $ip2region = new Ip2Region();
  2119. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2120. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2121. } else {
  2122. $ip = get_client_ip();
  2123. }
  2124. $info = [];
  2125. try {
  2126. $info = $ip2region->btreeSearch($ip);
  2127. } catch (\Exception $e) {
  2128. }
  2129. if (!$info || !isset($info['region'])) return '';
  2130. $region = explode('|', $info['region']);
  2131. $city = isset($region[3]) ? $region[3] : '';
  2132. if (in_array($city, $filter_city)) {
  2133. return '';
  2134. }
  2135. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2136. if ($count < 50) {
  2137. return '';
  2138. }
  2139. Cookie::queue('is_force_out_guide', 1);
  2140. //Redis::hset('crm:out_guide_exposure_user',$openid,$this->uid);
  2141. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2142. }
  2143. //Log::info('guidePersonalAccount33333333333333333');
  2144. if (empty($crm_config[0]) || empty($crm_config[1])) return '';
  2145. //Log::info('guidePersonalAccount4444444444444444');
  2146. if (!in_array($this->distribution_channel_id, explode(',', $crm_config[0]))) {
  2147. return '';
  2148. }
  2149. //Log::info('guidePersonalAccount555555555555555');
  2150. if ($charge) {
  2151. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2152. //return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2153. }
  2154. return '';
  2155. }
  2156. private function setIsPaid()
  2157. {
  2158. $charge = Order::where('uid', $this->uid)
  2159. ->where('status', 'PAID')
  2160. ->select('id')
  2161. ->first();
  2162. if ($charge) {
  2163. Cookie::queue('is_paid', 1);
  2164. $this->is_paid = true;
  2165. } else {
  2166. Cookie::queue('is_paid', 0);
  2167. $this->is_paid = false;
  2168. }
  2169. }
  2170. private function setProperty($openid)
  2171. {
  2172. $property = UserDivisionCpcPropertyService::userLevelV2($openid);
  2173. $this->property = $property;
  2174. }
  2175. //统计ua
  2176. private function recordUA($ua)
  2177. {
  2178. $is_ua_open = RedisEnv('ua_open');
  2179. if ($is_ua_open && $ua)//开启
  2180. {
  2181. //判断是否已经统计
  2182. $has_got = Redis::hget('book_read:' . $this->uid, 'ua');
  2183. if (!$has_got) {
  2184. try {
  2185. Redis::hset('book_read:' . $this->uid, 'ua', 1);
  2186. UserService::recordUA($ua, $this->uid);
  2187. } catch (\Exception $e) {
  2188. }
  2189. }
  2190. }
  2191. }
  2192. private function monthOrderInfo($openid)
  2193. {
  2194. $property = $this->property;
  2195. if (!$property) return '';
  2196. $month_info = UserMonthService::getOrderAndSignStatusByUid($this->uid);
  2197. if($month_info){
  2198. if(in_array('MONTH',$month_info)){
  2199. return [
  2200. 'price' => '30元',
  2201. 'text' => '30元包月 全站万本精彩小说免费看',
  2202. 'link' => generateMonthOrderUrl($this->uid),
  2203. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2204. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2205. ];
  2206. }
  2207. if(in_array('WEEK',$month_info)){
  2208. return [
  2209. 'price' => '7元',
  2210. 'text' => '7元包周 全站万本精彩小说免费看',
  2211. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2212. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2213. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2214. ];
  2215. }
  2216. }
  2217. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))) {
  2218. $info = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'MONTH_V2');
  2219. if ($info) {
  2220. if ($info->attach == 'show') {
  2221. return [
  2222. 'price' => '30元',
  2223. 'text' => '30元包月 全站万本精彩小说免费看',
  2224. 'link' => generateMonthOrderUrl($this->uid),
  2225. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2226. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2227. ];
  2228. }
  2229. if ($info->attach == 'week-show') {
  2230. return [
  2231. 'price' => '7元',
  2232. 'text' => '7元包周 全站万本精彩小说免费看',
  2233. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2234. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2235. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2236. ];
  2237. }
  2238. return '';
  2239. }
  2240. }
  2241. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))
  2242. && in_array($property, ['none', 'low', 'medium'])
  2243. ) {
  2244. if (!UserMonthService::isSignMonth($openid)) {
  2245. $start_time = redisEnv('MONTH_TEMPLATE_COMPARE_START_TIME', 0);
  2246. if (!$start_time || (strtotime($this->user->created_at) < $start_time)) {
  2247. if ($property == 'none') {
  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. } else {
  2256. return [
  2257. 'price' => '30元',
  2258. 'text' => '30元包月 全站万本精彩小说免费看',
  2259. 'link' => generateMonthOrderUrl($this->uid),
  2260. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2261. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2262. ];
  2263. }
  2264. }
  2265. $attach = $this->uid % 2 == 0 ? 'show' : 'hide';
  2266. if ($attach == 'hide') return '';
  2267. if ($property == 'none') {
  2268. return [
  2269. 'price' => '7元',
  2270. 'text' => '7元包周 全站万本精彩小说免费看',
  2271. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2272. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2273. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2274. ];
  2275. } else {
  2276. return [
  2277. 'price' => '30元',
  2278. 'text' => '30元包月 全站万本精彩小说免费看',
  2279. 'link' => generateMonthOrderUrl($this->uid),
  2280. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2281. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2282. ];
  2283. }
  2284. }
  2285. }
  2286. return '';
  2287. }
  2288. private function isXiyueUser()
  2289. {
  2290. //$result = DB::table('xiyue_zsy_users')->where('uid',$this->uid)->select('id')->first();
  2291. if ($this->distribution_channel_id == 6985) {
  2292. return [
  2293. 'is_xiyue_user' => 1,
  2294. 'debug' => (int)env('XI_YUE_SHARE_DEBUG', 0),
  2295. 'xiyue_index_page' => env('XIYUE_HOST') . '/',
  2296. 'xiyue_pay_page' => env('XIYUE_HOST') . '/',
  2297. 'xiyue_pay_unfocus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_unfocus_img.png',
  2298. 'xiyue_pay_focus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_focus_img.png',
  2299. 'openid' => $this->user->openid,
  2300. 'register_url' => 'https://sitel12x4nj487yevw0m.leyuee.com/xiyue/sharelink'
  2301. ];
  2302. }
  2303. return "";
  2304. }
  2305. }