WelcomeController.php 102 KB

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