WelcomeController.php 107 KB

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