WelcomeController.php 110 KB

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