WelcomeController.php 113 KB

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