WelcomeController.php 103 KB

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