WelcomeController.php 118 KB

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