WelcomeController.php 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503
  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-07-25/reader-banner.png';
  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. $title = "追书云";
  513. $get_force_subscribe_name = false;
  514. $subscribe = $request->cookie('force_subscribe_name');
  515. $appid = $request->get('appid');
  516. //用户进来携带的公众号信息
  517. if ($appid) {
  518. $force_subscribe_official = DB::table('official_accounts')->where('appid', $appid)->select('nickname')->first();
  519. if ($force_subscribe_official) {
  520. $title = $force_subscribe_official->nickname;
  521. if ($title) return $title;
  522. }
  523. }
  524. if ($subscribe) return $subscribe;
  525. //强关公众号名称
  526. $force_subscribe = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  527. $this->force_subscribe_info = $force_subscribe;
  528. if ($force_subscribe) {
  529. $force_subscribe_official = DB::table('official_accounts')->where('appid', $force_subscribe->appid)->select('nickname')->first();
  530. if ($force_subscribe_official) {
  531. $title = $force_subscribe_official->nickname;
  532. $get_force_subscribe_name = true;
  533. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  534. }
  535. }
  536. //可用公众号名称
  537. if (!$get_force_subscribe_name) {
  538. $res = OfficialAccountService::canUseOfficialAccountByChannelId(['distribution_channel_id' => $this->distribution_channel_id]);
  539. if ($res && isset($res->nickname) && !empty($res->nickname)) {
  540. $title = $res->nickname;
  541. Cookie::queue('force_subscribe_name', $title, 12 * 3600);
  542. }
  543. }
  544. return $title;
  545. }
  546. private function appad()
  547. {
  548. if ($this->force_subscribe_info) {
  549. $force_subscribe_info = $this->force_subscribe_info;
  550. } else {
  551. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  552. //\Log::info(':'.($this->uid).'force_subs1:'.json_encode($force_subscribe_info));
  553. }
  554. if (!$force_subscribe_info) {
  555. return false;
  556. }
  557. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  558. if ($force_sub_user_by_openid) {
  559. $force_subscribe_info = $force_sub_user_by_openid;
  560. //\Log::info('force_subs:'.json_encode($force_subscribe_info));
  561. }
  562. //\Log::info('force_subscribe_:'.json_encode($force_subscribe_info));
  563. //\Log::info('distribution_channel_id:'.$this->distribution_channel_id);
  564. if ($force_subscribe_info->subscribe_time &&
  565. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  566. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  567. //!AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  568. in_array($this->distribution_channel_id, explode(',', env('SHARE_OPEN_SITE')))
  569. ) {
  570. return true;
  571. }
  572. return false;
  573. }
  574. //CPC广告的优化逻辑
  575. private function cpcAd($openid)
  576. {
  577. if (in_array($this->uid, explode(',', env('TEST_CPC_UID')))) {
  578. return true;
  579. }
  580. //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])){
  581. $cpc_status = Redis::hget('channel:setting:' . $this->distribution_channel_id, 'cpc_status');
  582. if (is_null($cpc_status) || $cpc_status == 1) {
  583. $cookie_ad_status = Cookie::get('cpc_ad_status');
  584. if ($cookie_ad_status) return $cookie_ad_status == 'show';
  585. //$property = UserDivisionCpcPropertyService::userLevel($openid);
  586. /*if(UserService::isCpcUser($this->uid)){
  587. Cookie::queue('cpc_ad_status', 'show');
  588. return true;
  589. }*/
  590. if ($this->property == 'none') {
  591. Cookie::queue('cpc_ad_status', 'show');
  592. return true;
  593. }
  594. }
  595. Cookie::queue('cpc_ad_status', 'unshow');
  596. return false;
  597. }
  598. private function pddAd()
  599. {
  600. if ($this->isPddAdSites()) {
  601. return [
  602. 'banner' => 'https://cdn-novel.iycdm.com/h5/20190531/banner.jpg',
  603. 'url' => 'https://m.ycsd.cn/reader/9F69C5F384552E71/663249E009CA5AC0?u=13002705&isLogin=1'
  604. ];
  605. }
  606. return '';
  607. }
  608. private function isPddAdSites()
  609. {
  610. 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]);
  611. }
  612. private function isMiWan()
  613. {
  614. $miwan_channel_ids = redisEnv('MIWAN_CHANNEL_ID');
  615. if (!$miwan_channel_ids) return false;
  616. return in_array($this->distribution_channel_id, explode(',', $miwan_channel_ids));
  617. }
  618. /**
  619. * 获取客服图片
  620. */
  621. private function getCustomerServiceImg()
  622. {
  623. $setting = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  624. if ($setting && $setting->customer_img_url) {
  625. $customer_service = $setting->customer_img_url;
  626. } else {
  627. $customer_service = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  628. //$customer_service = 'https://cdn-novel.iycdm.com/static/img/kefu20190330.jpg';
  629. }
  630. return $customer_service;
  631. }
  632. /**
  633. * 推广链接跳转到用户上一阅读的章节
  634. */
  635. private function formWechatMsgJump(Request $request)
  636. {
  637. $path = $request->path();
  638. if ($path != 'reader') {
  639. return null;
  640. }
  641. $source = $request->input('source');
  642. if (!$source || $source != 'wechatmsg') {
  643. return null;
  644. }
  645. $bid = 0;
  646. $bid_str = $request->input('bid');
  647. $cid = $request->input('cid');
  648. try {
  649. $bid_arr = Hashids::decode($bid_str);
  650. if (isset($bid_arr[0])) {
  651. $bid = $bid_arr[0];
  652. }
  653. } catch (\Exception $e) {
  654. }
  655. if (!$bid) return null;
  656. $record_info = '';
  657. try {
  658. $record_info = ReadRecordService::getRecordByUidBid($this->uid, $bid);
  659. } catch (\Exception $e) {
  660. }
  661. if (!$record_info) return null;
  662. $record_info_arr = explode('_', $record_info);
  663. $param = $request->except(['_url', 'source', 'cid']);
  664. $param['stats'] = 1;
  665. if (isset($record_info_arr[0])) {
  666. $param['cid'] = $record_info_arr[0];
  667. if ($cid && $cid != $record_info_arr[0]) {
  668. $h5_scheme = env('H5_SCHEME', 'https');
  669. $param_str = http_build_query($param);
  670. $url = $h5_scheme . '://' . _domain() . '/reader?' . $param_str;
  671. return $url;
  672. }
  673. }
  674. return null;
  675. }
  676. //用户是否在广告样本中
  677. private function isUserInAdSample()
  678. {
  679. $res = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'AD_V2');
  680. if ($res) {
  681. return true;
  682. } else {
  683. return false;
  684. }
  685. }
  686. /**
  687. * 三天回本活动
  688. * @param Request $request
  689. * @return
  690. */
  691. public function activity(Request $request)
  692. {
  693. $send_time = Redis::hget('add_news_recovery_push_activity' . $this->uid, 'time');
  694. $send_time = time() - 100;
  695. if ($send_time) {
  696. if (time() - $send_time < 86400) {
  697. $activity_id = 1;
  698. $activity_info = ActivityService::getById($activity_id);
  699. if ($activity_info && $activity_info->product_id) {
  700. $from = $request->input('fromtype', 'main');
  701. Redis::sadd('push:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from . ':date:' . date('Y-m-d'), $this->uid);
  702. Redis::hincrby('customer:push:click:activity:distribution_channel_id:' . $this->distribution_channel_id . 'from:' . $from, date('Y-m-d'), 1);
  703. $param = [
  704. 'uid' => $this->uid,
  705. 'distribution_channel_id' => $this->distribution_channel_id,
  706. 'product_id' => $activity_info->product_id,
  707. 'activity_id' => $activity_id,
  708. 'fromtype' => $from,
  709. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . encodeDistributionChannelId($this->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/person'
  710. ];
  711. Redis::hdel('add_news_recovery_push_activity' . $this->uid, 'time');
  712. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  713. return view('pay.order.activity', ['url' => $url, 'code' => 0]);
  714. }
  715. }
  716. }
  717. return redirect('/continue');
  718. //return view('pay.order.activity', ['code' => 1, 'url' => '']);
  719. }
  720. /**
  721. * 商户活动
  722. * @param Request $request
  723. * @return view
  724. */
  725. public function channelActivity(Request $request)
  726. {
  727. $token = $request->input('token');
  728. //return view('pay.order.saleactivity', ['url' => $token, 'code' => 0]);
  729. $activity_info = ActivityService::getByToken($token);
  730. if ($activity_info && $activity_info->product_id) {
  731. $from = $request->input('fromtype', 'main');
  732. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  733. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  734. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  735. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  736. Redis::sadd($uv_key, $this->uid);
  737. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  738. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  739. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  740. // $from = $request->input('from', 'main');
  741. // $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  742. // $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  743. // $uv_key = sprintf($uv_key_format,$activity_info->id,$this->distribution_channel_id,date('Y-m-d'));
  744. // $pv_key = sprintf($pv_key_format,$activity_info->id,$this->distribution_channel_id);
  745. // Redis::sadd($uv_key,$this->uid);
  746. // Redis::hincrby($pv_key,date('Y-m-d'),1);
  747. $param = [
  748. 'uid' => $this->uid,
  749. 'distribution_channel_id' => $this->distribution_channel_id,
  750. 'product_id' => $activity_info->product_id,
  751. 'activity_id' => $activity_info->id,
  752. 'fromtype' => $from,
  753. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  754. ];
  755. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  756. return view('pay.order.saleactivity', ['url' => $url, 'code' => 0]);
  757. }
  758. }
  759. return view('pay.order.saleactivity', ['url' => '###', 'code' => 0]);
  760. }
  761. public function springActivityV1(Request $request)
  762. {
  763. $token = $request->input('token');
  764. $activity_info = ActivityService::getByToken($token);
  765. if ($activity_info) {
  766. $from = $request->input('fromtype', 'main');
  767. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  768. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  769. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  770. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  771. Redis::sadd($uv_key, $this->uid);
  772. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  773. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  774. if ($request->input('redirect_url')) {
  775. $redirect_url = $request->input('redirect_url');
  776. $redirect_url = urldecode($redirect_url);
  777. }
  778. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  779. $param_fifty = [
  780. 'uid' => $this->uid,
  781. 'distribution_channel_id' => $this->distribution_channel_id,
  782. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_FIFTY', 2),
  783. 'activity_id' => $activity_info->id,
  784. 'fromtype' => $from,
  785. 'pay_redirect_url' => $redirect_url
  786. ];
  787. $param_hundred = [
  788. 'uid' => $this->uid,
  789. 'distribution_channel_id' => $this->distribution_channel_id,
  790. 'product_id' => env('SPRING_ACTIVITY_PRODUCT_HUNDRED', 3),
  791. 'activity_id' => $activity_info->id,
  792. 'fromtype' => $from,
  793. 'pay_redirect_url' => $redirect_url
  794. ];
  795. $url_fifty = env('CREATE_PAY_URL') . '?' . http_build_query($param_fifty);
  796. $url_hundred = env('CREATE_PAY_URL') . '?' . http_build_query($param_hundred);
  797. return view('pay.order.springactivity', ['url' => ['fifty' => $url_fifty, 'hundred' => $url_hundred], 'code' => 0]);
  798. } else if (time() <= strtotime($activity_info->start_time)) {
  799. return view('pay.order.springactivity', ['url' => [], 'code' => 1]);
  800. } else {
  801. return view('pay.order.springactivity', ['url' => [], 'code' => 2]);
  802. }
  803. }
  804. return view('pay.order.springactivity', ['url' => [], 'code' => 3]);
  805. }
  806. public function springActivity(Request $request)
  807. {
  808. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  809. $token = $request->input('token');
  810. $activity_info = ActivityService::getByToken($token);
  811. if (!$activity_info) {
  812. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  813. return redirect()->to($default_url);
  814. }
  815. $from = $request->input('fromtype', 'main');
  816. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  817. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  818. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  819. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  820. Redis::sadd($uv_key, $this->uid);
  821. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  822. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  823. if ($request->input('redirect_url')) {
  824. $redirect_url = $request->input('redirect_url');
  825. $redirect_url = urldecode($redirect_url);
  826. }
  827. //未开始
  828. if (time() < strtotime($activity_info->start_time)) {
  829. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1]);
  830. }
  831. //结束
  832. if (time() > strtotime($activity_info->end_time)) {
  833. return view('pay.order.springactivity2019', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2]);
  834. }
  835. $product_ids = [4063, 4064];
  836. $url = [];
  837. foreach ($product_ids as $product_id) {
  838. $param = [
  839. 'uid' => $this->uid,
  840. 'distribution_channel_id' => $this->distribution_channel_id,
  841. 'product_id' => $product_id,
  842. 'activity_id' => $activity_info->id,
  843. 'fromtype' => $from,
  844. 'pay_redirect_url' => $redirect_url,
  845. 'limit' => 100,
  846. ];
  847. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  848. }
  849. return view('pay.order.springactivity2019', ['url' => $url, 'code' => 0]);
  850. }
  851. /**
  852. *
  853. */
  854. public function womenActivity(Request $request)
  855. {
  856. $token = $request->input('token');
  857. $activity_info = ActivityService::getByToken($token);
  858. if ($activity_info) {
  859. $from = $request->input('fromtype', 'main');
  860. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  861. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  862. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  863. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  864. Redis::sadd($uv_key, $this->uid);
  865. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  866. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  867. if ($request->input('redirect_url')) {
  868. $redirect_url = $request->input('redirect_url');
  869. $redirect_url = urldecode($redirect_url);
  870. }
  871. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  872. $param = [
  873. 'uid' => $this->uid,
  874. 'distribution_channel_id' => $this->distribution_channel_id,
  875. 'product_id' => $activity_info->product_id,
  876. 'activity_id' => $activity_info->id,
  877. 'fromtype' => $from,
  878. 'pay_redirect_url' => $redirect_url
  879. ];
  880. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  881. return view('pay.order.womenactivity', ['url' => $url, 'code' => 0]);
  882. } else if (time() <= strtotime($activity_info->start_time)) {
  883. return view('pay.order.womenactivity', ['url' => [], 'code' => 1]);
  884. } else {
  885. return view('pay.order.womenactivity', ['url' => [], 'code' => 2]);
  886. }
  887. }
  888. return view('pay.order.womenactivity', ['url' => [], 'code' => 3]);
  889. }
  890. public function newUserActivity(Request $request)
  891. {
  892. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  893. $from = $request->input('fromtype', 'main');
  894. $send_time = $request->input('send_time');
  895. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  896. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  897. $activity_id = env('NEW_USER_ACTIVITY_ID', 5);
  898. $activity_info = ActivityService::getById($activity_id);
  899. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  900. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  901. Redis::sadd($uv_key, $this->uid);
  902. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  903. if (!$send_time) {
  904. 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)]);
  905. }
  906. $end_time_str = date('Y-m-d', $send_time + 86400);
  907. $end_time = strtotime(date('Y-m-d', $send_time + 86400) . ' 23:59:59');
  908. if ($send_time > $end_time) {
  909. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  910. }
  911. if (time() > $end_time) {
  912. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  913. }
  914. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  915. if ($order) {
  916. 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)]);
  917. //return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  918. }
  919. $param = [
  920. 'uid' => $this->uid,
  921. 'distribution_channel_id' => $this->distribution_channel_id,
  922. 'product_id' => $activity_info->product_id,
  923. 'activity_id' => $activity_info->id,
  924. 'fromtype' => $from,
  925. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  926. ];
  927. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  928. return view('pay.order.newUserActivity', ['url' => $url, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  929. }
  930. public function channelActivityNine(Request $request)
  931. {
  932. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  933. $token = $request->input('token');
  934. $activity_info = ActivityService::getByToken($token);
  935. if ($activity_info && $activity_info->product_id) {
  936. $from = $request->input('fromtype', 'main');
  937. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  938. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  939. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  940. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  941. Redis::sadd($uv_key, $this->uid);
  942. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  943. //渠道不符合
  944. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  945. 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)]);
  946. }
  947. //活动未开始
  948. if (time() < strtotime($activity_info->start_time)) {
  949. return view('pay.order.longactivitynine', ['url' => '###', 'code' => -3, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  950. }
  951. //活动结束
  952. if (time() > strtotime($activity_info->end_time)) {
  953. 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)]);
  954. }
  955. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_info->id)->count();
  956. //参加过了
  957. if ($order) {
  958. 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)]);
  959. }
  960. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
  961. $not_allow_paid_user_channel_id = env('NOT_ALLOW_PAID_USER_CHANNEL_ID', 0);
  962. //不允许支付过的用户参见9.9的活动
  963. if ($not_allow_paid_user_channel_id &&
  964. in_array($this->distribution_channel_id, explode(',', $not_allow_paid_user_channel_id)) &&
  965. Order::where('uid', $this->uid)->where('status', 'PAID')->first()
  966. ) {
  967. return view('pay.order.longactivitynine', ['url' => '', 'code' => -4, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
  968. }
  969. $param = [
  970. 'uid' => $this->uid,
  971. 'distribution_channel_id' => $this->distribution_channel_id,
  972. 'product_id' => $activity_info->product_id,
  973. 'activity_id' => $activity_info->id,
  974. 'fromtype' => $from,
  975. 'limit' => 1,
  976. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  977. ];
  978. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  979. 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)]);
  980. }
  981. }
  982. 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)]);
  983. }
  984. public function channelActivitySixtyEight(Request $request)
  985. {
  986. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  987. $token = $request->input('token');
  988. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn68.jpg';
  989. $activity_info = ActivityService::getByToken($token);
  990. if ($activity_info && $activity_info->product_id) {
  991. $from = $request->input('fromtype', 'main');
  992. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  993. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  994. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  995. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  996. Redis::sadd($uv_key, $this->uid);
  997. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  998. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  999. //渠道不符合
  1000. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  1001. 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)]);
  1002. }
  1003. //活动未开始
  1004. if (time() < strtotime($activity_info->start_time)) {
  1005. 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)]);
  1006. }
  1007. //活动结束
  1008. if (time() > strtotime($activity_info->end_time)) {
  1009. 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)]);
  1010. }
  1011. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1012. $param = [
  1013. 'uid' => $this->uid,
  1014. 'distribution_channel_id' => $this->distribution_channel_id,
  1015. 'product_id' => $activity_info->product_id,
  1016. 'activity_id' => $activity_info->id,
  1017. 'fromtype' => $from,
  1018. 'limit' => 100,
  1019. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1020. ];
  1021. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1022. return view('pay.order.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)]);
  1023. }
  1024. }
  1025. 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)]);
  1026. }
  1027. public function channelActivityFortyEight(Request $request)
  1028. {
  1029. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1030. $token = $request->input('token');
  1031. $activity_info = ActivityService::getByToken($token);
  1032. $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
  1033. if ($activity_info && $activity_info->product_id) {
  1034. $from = $request->input('fromtype', 'main');
  1035. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1036. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1037. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1038. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1039. Redis::sadd($uv_key, $this->uid);
  1040. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1041. //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
  1042. //渠道不符合
  1043. if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
  1044. 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)]);
  1045. }
  1046. //活动未开始
  1047. if (time() < strtotime($activity_info->start_time)) {
  1048. 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)]);
  1049. }
  1050. //活动结束
  1051. if (time() > strtotime($activity_info->end_time)) {
  1052. 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)]);
  1053. }
  1054. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1055. $param = [
  1056. 'uid' => $this->uid,
  1057. 'distribution_channel_id' => $this->distribution_channel_id,
  1058. 'product_id' => $activity_info->product_id,
  1059. 'activity_id' => $activity_info->id,
  1060. 'fromtype' => $from,
  1061. 'limit' => 100,
  1062. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1063. ];
  1064. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1065. 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)]);
  1066. }
  1067. }
  1068. 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)]);
  1069. }
  1070. public function channelNewUserActivity(Request $request)
  1071. {
  1072. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1073. $token = $request->get('token');
  1074. $activity_info = ActivityService::getByToken($token);
  1075. $from = $request->get('fromtype', 'main');
  1076. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1077. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1078. if ($activity_info && $activity_info->product_id) {
  1079. $activity_id = $activity_info->id;
  1080. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1081. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1082. Redis::sadd($uv_key, $this->uid);
  1083. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1084. //活动未开始
  1085. if (time() < strtotime($activity_info->start_time)) {
  1086. 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)]);
  1087. }
  1088. //活动结束
  1089. if (time() > strtotime($activity_info->end_time)) {
  1090. 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)]);
  1091. }
  1092. $charge_count = Order::where('uid', $this->uid)->where('status', 'PAID')->count();
  1093. if ($charge_count > 0) {
  1094. //不是新用户
  1095. 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)]);
  1096. }
  1097. $param = [
  1098. 'uid' => $this->uid,
  1099. 'distribution_channel_id' => $this->distribution_channel_id,
  1100. 'product_id' => $activity_info->product_id,
  1101. 'activity_id' => $activity_info->id,
  1102. 'fromtype' => $from,
  1103. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1104. ];
  1105. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1106. 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)]);
  1107. }
  1108. 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)]);
  1109. }
  1110. /**
  1111. * 清明活动
  1112. */
  1113. public function qingMingActivity(Request $request)
  1114. {
  1115. $token = $request->input('token');
  1116. $activity_info = ActivityService::getByToken($token);
  1117. if ($activity_info) {
  1118. $from = $request->input('fromtype', 'main');
  1119. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1120. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1121. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1122. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1123. Redis::sadd($uv_key, $this->uid);
  1124. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1125. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1126. if ($request->input('redirect_url')) {
  1127. $redirect_url = $request->input('redirect_url');
  1128. $redirect_url = urldecode($redirect_url);
  1129. }
  1130. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1131. $param = [
  1132. 'uid' => $this->uid,
  1133. 'distribution_channel_id' => $this->distribution_channel_id,
  1134. 'product_id' => $activity_info->product_id,
  1135. 'activity_id' => $activity_info->id,
  1136. 'fromtype' => $from,
  1137. 'pay_redirect_url' => $redirect_url
  1138. ];
  1139. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1140. return view('pay.order.qingmingactivity', ['url' => $url, 'code' => 0]);
  1141. } else if (time() <= strtotime($activity_info->start_time)) {
  1142. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 1]);
  1143. } else {
  1144. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 2]);
  1145. }
  1146. }
  1147. return view('pay.order.qingmingactivity', ['url' => [], 'code' => 3]);
  1148. }
  1149. public function readDayActivity(Request $request)
  1150. {
  1151. $token = $request->input('token');
  1152. $activity_info = ActivityService::getByToken($token);
  1153. if ($activity_info) {
  1154. $from = $request->input('fromtype', 'main');
  1155. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1156. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1157. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1158. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1159. Redis::sadd($uv_key, $this->uid);
  1160. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1161. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $this->distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1162. if ($request->input('redirect_url')) {
  1163. $redirect_url = $request->input('redirect_url');
  1164. $redirect_url = urldecode($redirect_url);
  1165. }
  1166. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1167. $param = [
  1168. 'uid' => $this->uid,
  1169. 'distribution_channel_id' => $this->distribution_channel_id,
  1170. 'product_id' => $activity_info->product_id,
  1171. 'activity_id' => $activity_info->id,
  1172. 'fromtype' => $from,
  1173. 'pay_redirect_url' => $redirect_url,
  1174. 'limit' => 100,
  1175. ];
  1176. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1177. return view('pay.order.laborDay', ['url' => $url, 'code' => 0]);
  1178. } else if (time() <= strtotime($activity_info->start_time)) {
  1179. return view('pay.order.laborDay', ['url' => [], 'code' => 1]);
  1180. } else {
  1181. return view('pay.order.laborDay', ['url' => [], 'code' => 2]);
  1182. }
  1183. }
  1184. return view('pay.order.laborDay', ['url' => [], 'code' => 3]);
  1185. }
  1186. public function commonActivity(Request $request)
  1187. {
  1188. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1189. $token = $request->input('token');
  1190. $activity_info = ActivityService::getByToken($token);
  1191. if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
  1192. $imgs = json_decode($activity_info->setting, 1);
  1193. $from = $request->input('fromtype', 'main');
  1194. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1195. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1196. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1197. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1198. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1199. if ($request->input('redirect_url')) {
  1200. $redirect_url = $request->input('redirect_url');
  1201. $redirect_url = urldecode($redirect_url);
  1202. }
  1203. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1204. Redis::sadd($uv_key, $this->uid);
  1205. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1206. $param = [
  1207. 'uid' => $this->uid,
  1208. 'distribution_channel_id' => $this->distribution_channel_id,
  1209. 'product_id' => $activity_info->product_id,
  1210. 'activity_id' => $activity_info->id,
  1211. 'fromtype' => $from,
  1212. 'pay_redirect_url' => $redirect_url,
  1213. 'limit' => 100,
  1214. ];
  1215. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1216. return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
  1217. } else if (time() <= strtotime($activity_info->start_time)) {
  1218. return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
  1219. } else {
  1220. return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
  1221. }
  1222. }
  1223. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1224. return redirect()->to($default_url);
  1225. }
  1226. public function yearActivity(Request $request)
  1227. {
  1228. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1229. $from = $request->input('fromtype', 'main');
  1230. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1231. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1232. if (empty($sites)) {
  1233. return redirect()->to($not_access_url);
  1234. }
  1235. $site_arr = explode(',', $sites);
  1236. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1237. return redirect()->to($not_access_url);
  1238. }
  1239. $year_activity_id = env('YEAR_ACTIVITY_ID');
  1240. if (!$year_activity_id) {
  1241. return redirect()->to($not_access_url);
  1242. }
  1243. $activity_info = Activity::find($year_activity_id);
  1244. if (!$activity_info) {
  1245. return redirect()->to($not_access_url);
  1246. }
  1247. $activity_id = $year_activity_id;
  1248. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1249. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1250. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1251. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1252. Redis::sadd($uv_key, $this->uid);
  1253. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1254. $start = $activity_info->start_time;
  1255. $end = $activity_info->end_time;
  1256. if (empty($start) || empty($end)) {
  1257. return redirect()->to($not_access_url);
  1258. }
  1259. $male_site = env('YEAR_MALE_SITE');
  1260. if ($male_site && in_array($this->distribution_channel_id, explode(',', $male_site))) {
  1261. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_MALE_BID'))));
  1262. } else {
  1263. $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('YEAR_FEMALE_BID'))));
  1264. }
  1265. $is_get = 0;
  1266. $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count();
  1267. //$old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $old_year_activity_id)->count();
  1268. $old_discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->whereIn('activity_id', [643, 827, 1104, 1294])->count();
  1269. if ($discount_coupon) {
  1270. $is_get = 1;
  1271. }
  1272. if ($old_discount_coupon) {
  1273. //51活动领取过 优惠80
  1274. $discount = 80;
  1275. $product_id = $activity_info->product_id;
  1276. } else {
  1277. //51活动领未取过 优惠50
  1278. $discount = 50;
  1279. $product_id = 1450;
  1280. }
  1281. if (time() < strtotime($start)) {
  1282. //未开始
  1283. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 1, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1284. }
  1285. if (time() > strtotime($end)) {
  1286. //结束
  1287. return view('pay.order.yearactivityV3', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 2, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1288. }
  1289. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1290. //参加过了
  1291. if ($order) {
  1292. //return view('pay.order.yearactivityV2', ['url' => '', 'is_get' => 1, 'coupons_url' => '', 'code' => 3, 'books' => $books, 'activity_id' => $activity_id, 'discount' => $discount]);
  1293. }
  1294. $param = [
  1295. 'uid' => $this->uid,
  1296. 'distribution_channel_id' => $this->distribution_channel_id,
  1297. 'product_id' => $product_id,
  1298. 'activity_id' => $activity_id,
  1299. 'fromtype' => $from,
  1300. 'limit' => 10,
  1301. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1302. ];
  1303. $this->getCoupons($activity_id);
  1304. $coupons_url = $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1305. $param['product_id'] = 5;
  1306. $primary_url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1307. 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]);
  1308. }
  1309. private function getCoupons($activity_id)
  1310. {
  1311. if (!DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count()) {
  1312. DB::table('discount_coupons')->insert([
  1313. 'uid' => $this->uid,
  1314. 'activity_id' => $activity_id,
  1315. 'created_at' => date('Y-m-d H:i:s'),
  1316. 'updated_at' => date('Y-m-d H:i:s')
  1317. ]);
  1318. }
  1319. }
  1320. public function summerActivity(Request $request)
  1321. {
  1322. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1323. $from = $request->input('fromtype', 'main');
  1324. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1325. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1326. if (empty($sites)) {
  1327. return redirect()->to($not_access_url);
  1328. }
  1329. if ($sites != 'all') {
  1330. $site_arr = explode(',', $sites);
  1331. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1332. return redirect()->to($not_access_url);
  1333. }
  1334. }
  1335. $activity_id = 350;
  1336. $activity_info = Activity::find($activity_id);
  1337. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1338. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1339. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1340. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1341. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1342. if ($request->input('redirect_url')) {
  1343. $redirect_url = $request->input('redirect_url');
  1344. $redirect_url = urldecode($redirect_url);
  1345. }
  1346. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1347. Redis::sadd($uv_key, $this->uid);
  1348. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1349. $url_array = [];
  1350. $product_id_array = [2158, 2159, 2160, 2161];
  1351. foreach ($product_id_array as $v) {
  1352. $param = [
  1353. 'uid' => $this->uid,
  1354. 'distribution_channel_id' => $this->distribution_channel_id,
  1355. 'product_id' => $v,
  1356. 'activity_id' => $activity_id,
  1357. 'fromtype' => $from,
  1358. 'pay_redirect_url' => $redirect_url,
  1359. 'limit' => 100,
  1360. ];
  1361. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1362. $url_array[] = $url;
  1363. }
  1364. return view('pay.order.summerActivity', ['url' => '', 'code' => 0, 'url_array' => $url_array]);
  1365. } else if (time() <= strtotime($activity_info->start_time)) {
  1366. return view('pay.order.summerActivity', ['url' => [], 'code' => 1]);
  1367. } else {
  1368. return view('pay.order.summerActivity', ['url' => [], 'code' => 2]);
  1369. }
  1370. }
  1371. public function newUserSale(Request $request)
  1372. {
  1373. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1374. $from = $request->input('fromtype', 'main');
  1375. $send_time = $request->input('send_time');
  1376. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1377. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1378. $activity_id = 402;
  1379. $activity_info = ActivityService::getById($activity_id);
  1380. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1381. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1382. Redis::sadd($uv_key, $this->uid);
  1383. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1384. // 2226,2227,2228,22229,2230
  1385. if (!$send_time) {
  1386. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1387. 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)]);
  1388. }
  1389. $end_time_str = date('Y-m-d', $send_time + 3 * 86400);
  1390. $end_time = strtotime(date('Y-m-d', $send_time + 3 * 86400) . ' 23:59:59');
  1391. if ($send_time > $end_time) {
  1392. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1393. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -1, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1394. }
  1395. if (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' => -2, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1398. }
  1399. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1400. if ($order) {
  1401. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id);
  1402. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1403. }
  1404. $url_info = $this->getUrls($activity_info->setting, $from, $this->distribution_channel_id, $encode_distribution_channel_id, $activity_id, true);
  1405. return view('pay.order.newUserOtherActivity', ['url' => $url_info, 'code' => 0, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1406. }
  1407. private function getUrls($activity_info_setting, $from, $channel_id, $encode_channel_id, $activity_id, $is_access = false)
  1408. {
  1409. $product = DB::table('products')
  1410. ->whereIn('id', explode(',', $activity_info_setting))
  1411. ->select('id', 'price', 'type', 'given')
  1412. ->get();
  1413. $url_info = [];
  1414. $url_info['year'] = ['url' => '###'];
  1415. $url_info['charge'] = [];
  1416. $param = [
  1417. 'uid' => $this->uid,
  1418. 'distribution_channel_id' => $this->distribution_channel_id,
  1419. 'product_id' => $channel_id,
  1420. 'limit' => 1,
  1421. 'fromtype' => $from,
  1422. 'activity_id' => $activity_id,
  1423. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1424. ];
  1425. if (!$product) {
  1426. return $url_info;
  1427. }
  1428. foreach ($product as $v) {
  1429. if (in_array($this->distribution_channel_id, [6917, 6918, 6939]) && $v->type == 'YEAR_ORDER') {
  1430. continue;
  1431. }
  1432. if ($is_access) {
  1433. $param['product_id'] = $v->id;
  1434. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1435. } else {
  1436. $url = '###';
  1437. }
  1438. if ($v->type == 'YEAR_ORDER') {
  1439. $url_info['year']['url'] = $url;
  1440. } else {
  1441. $temp = [];
  1442. $temp['url'] = $url;
  1443. $temp['price'] = (int)$v->price;
  1444. $temp['given'] = (int)($v->given / 100);
  1445. $temp['total'] = $v->price * 100 + $v->given;
  1446. if ($v->price == 30) {
  1447. $temp['old_given'] = '无折扣';
  1448. } elseif ($v->price == 50) {
  1449. $temp['old_given'] = '送40元';
  1450. } elseif ($v->price == 100) {
  1451. $temp['old_given'] = '送100元';
  1452. } elseif ($v->price == 200) {
  1453. $temp['old_given'] = '送200元';
  1454. } else {
  1455. $temp['old_given'] = '';
  1456. }
  1457. $url_info['charge'][] = $temp;
  1458. }
  1459. }
  1460. return $url_info;
  1461. }
  1462. public function nationalDayActivity(Request $request)
  1463. {
  1464. $token = $request->input('token', '');
  1465. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1466. $activity_info = ActivityService::getByToken($token);
  1467. if (!$activity_info) {
  1468. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1469. return redirect()->to($not_access_url);
  1470. }
  1471. $from = $request->input('fromtype', 'main');
  1472. $activity_id = $activity_info->id;
  1473. $activty_ids = env('NATIONAL_DAY_ACTIVITY_IDS', '1,2,3');
  1474. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1475. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1476. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1477. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1478. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1479. if ($request->input('redirect_url')) {
  1480. $redirect_url = $request->input('redirect_url');
  1481. $redirect_url = urldecode($redirect_url);
  1482. }
  1483. $activity_status = -1;
  1484. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1485. $activity_status = 1;
  1486. }
  1487. if (time() < strtotime($activity_info->start_time)) {
  1488. //未开始
  1489. $activity_status = -1;
  1490. }
  1491. if (time() > strtotime($activity_info->end_time)) {
  1492. //结束
  1493. $activity_status = -2;
  1494. }
  1495. Redis::sadd($uv_key, $this->uid);
  1496. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1497. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1498. if ($user_charge_count == 0) {
  1499. $is_first_charge = 1;
  1500. } else {
  1501. $is_first_charge = 0;
  1502. }
  1503. $url_array = [];
  1504. $product_id_array = explode(',', $activty_ids);
  1505. foreach ($product_id_array as $key => $v) {
  1506. if ($user_charge_count >= 1 && $key == 0) {
  1507. //continue;
  1508. }
  1509. $param = [
  1510. 'uid' => $this->uid,
  1511. 'distribution_channel_id' => $this->distribution_channel_id,
  1512. 'product_id' => $v,
  1513. 'activity_id' => $activity_id,
  1514. 'fromtype' => $from,
  1515. 'pay_redirect_url' => $redirect_url,
  1516. 'limit' => 100,
  1517. ];
  1518. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1519. $url_array[] = $url;
  1520. }
  1521. return view('pay.order.nationalDayActivity', ['url' => $url_array, 'is_first_charge' => $is_first_charge, 'code' => $activity_status]);
  1522. }
  1523. public function cYactivity(Request $request)
  1524. {
  1525. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1526. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1527. $site_arr = explode(',', env('YEAR_ACTIVITY_CHANNEL', '2'));
  1528. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1529. return redirect()->to($default_url);
  1530. }
  1531. $activity_info = ActivityService::getById(929);
  1532. if ($activity_info) {
  1533. $from = $request->input('fromtype', 'main');
  1534. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1535. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1536. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1537. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1538. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1539. if ($request->input('redirect_url')) {
  1540. $redirect_url = $request->input('redirect_url');
  1541. $redirect_url = urldecode($redirect_url);
  1542. }
  1543. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1544. Redis::sadd($uv_key, $this->uid);
  1545. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1546. $param = [
  1547. 'uid' => $this->uid,
  1548. 'distribution_channel_id' => $this->distribution_channel_id,
  1549. 'product_id' => $activity_info->product_id,
  1550. 'activity_id' => $activity_info->id,
  1551. 'fromtype' => $from,
  1552. 'pay_redirect_url' => $redirect_url,
  1553. 'limit' => 100,
  1554. ];
  1555. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1556. return view('pay.order.cyangActivity', ['url' => $url, 'code' => 0,]);
  1557. } else if (time() <= strtotime($activity_info->start_time)) {
  1558. return view('pay.order.cyangActivity', ['url' => [], 'code' => 1,]);
  1559. } else {
  1560. return view('pay.order.cyangActivity', ['url' => [], 'code' => 2,]);
  1561. }
  1562. }
  1563. return redirect()->to($default_url);
  1564. return view('pay.order.cyangActivity', []);
  1565. }
  1566. public function newUserForeverActivity(Request $request)
  1567. {
  1568. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1569. $from = $request->input('fromtype', 'main');
  1570. $send_time = $request->input('send_time');
  1571. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1572. if ($this->distribution_channel_id != 123) {
  1573. return redirect()->to($default_url);
  1574. }
  1575. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1576. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1577. $activity_id = env('FOREVER_ACTIVITY_ID', 5);
  1578. $activity_info = ActivityService::getById($activity_id);
  1579. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1580. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1581. Redis::sadd($uv_key, $this->uid);
  1582. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1583. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1584. if (!$send_time) {
  1585. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1586. }
  1587. $end_time = $send_time + 86400 * 3;
  1588. $time_diff = $end_time - time();
  1589. if ($time_diff <= 0) {
  1590. return view('pay.order.foreverActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'books' => $books]);
  1591. }
  1592. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1593. if ($order) {
  1594. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1595. }*/
  1596. $books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1597. $day = floor($time_diff / 86400);
  1598. $hour = floor(($time_diff - $day * 86400) / 3600);
  1599. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1600. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1601. $param = [
  1602. 'uid' => $this->uid,
  1603. 'distribution_channel_id' => $this->distribution_channel_id,
  1604. 'product_id' => $activity_info->product_id,
  1605. 'activity_id' => $activity_info->id,
  1606. 'fromtype' => $from,
  1607. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1608. ];
  1609. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1610. return view('pay.order.foreverActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'books' => $books]);
  1611. }
  1612. public function tempC()
  1613. {
  1614. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1615. $param = [
  1616. 'uid' => $this->uid,
  1617. 'distribution_channel_id' => $this->distribution_channel_id,
  1618. 'product_id' => 1450,
  1619. 'activity_id' => 0,
  1620. 'fromtype' => 'tempC',
  1621. 'limit' => 10,
  1622. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1623. ];
  1624. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1625. return redirect()->to($url);
  1626. }
  1627. /**
  1628. * 68元包年活动
  1629. * @param Request $request
  1630. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1631. */
  1632. public function otherYearActivity(Request $request)
  1633. {
  1634. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1635. $from = $request->input('fromtype', 'main');
  1636. $send_time = $request->input('send_time');
  1637. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1638. if ($this->distribution_channel_id != 123) {
  1639. return redirect()->to($default_url);
  1640. }
  1641. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1642. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1643. $activity_id = env('68_YEAR_ACTIVITY_ID', 5);
  1644. $activity_info = ActivityService::getById($activity_id);
  1645. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1646. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1647. Redis::sadd($uv_key, $this->uid);
  1648. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1649. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1650. $books = '';
  1651. $time_diff = 0;
  1652. if (!$send_time) {
  1653. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -3, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1654. }
  1655. $end_time = $send_time + 86400 * 3;
  1656. $time_diff = $end_time - time();
  1657. if ($time_diff <= 0) {
  1658. return view('pay.order.otherYearActivity', ['url' => '###', 'code' => -2, 'time' => ['day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0], 'time_diff' => $time_diff]);
  1659. }
  1660. /*$order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('activity_id', $activity_id)->count();
  1661. if ($order) {
  1662. return view('pay.order.newUserActivity', ['url' => '###', 'code' => -3, 'start_time' => date('Y-m-d', $send_time), 'end_time' => $end_time_str]);
  1663. }*/
  1664. //$books = $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', env('FOREVER_ACTIVITY_BID'))));
  1665. $day = floor($time_diff / 86400);
  1666. $hour = floor(($time_diff - $day * 86400) / 3600);
  1667. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1668. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1669. $param = [
  1670. 'uid' => $this->uid,
  1671. 'distribution_channel_id' => $this->distribution_channel_id,
  1672. 'product_id' => $activity_info->product_id,
  1673. 'activity_id' => $activity_info->id,
  1674. 'fromtype' => $from,
  1675. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1676. ];
  1677. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1678. return view('pay.order.otherYearActivity', ['url' => $url, 'code' => 0, 'time' => compact('day', 'hour', 'minute', 'second'), 'time_diff' => $time_diff]);
  1679. }
  1680. /**
  1681. * 双十一购物节统计
  1682. * @param Request $request
  1683. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Swoft\Http\Message\Server\Response
  1684. */
  1685. public function shoppingDayActivity(Request $request)
  1686. {
  1687. $token = $request->input('token', '');
  1688. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1689. $activity_info = ActivityService::getByToken($token);
  1690. if (!$activity_info) {
  1691. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1692. return redirect()->to($not_access_url);
  1693. }
  1694. $from = $request->input('fromtype', 'main');
  1695. $activity_id = $activity_info->id;
  1696. $activty_ids = env('SHOPPING_DAY_ACTIVITY_IDS', '1,2,3');
  1697. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1698. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1699. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1700. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1701. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1702. if ($request->input('redirect_url')) {
  1703. $redirect_url = $request->input('redirect_url');
  1704. $redirect_url = urldecode($redirect_url);
  1705. }
  1706. $activity_status = -1;
  1707. if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
  1708. $activity_status = 1;
  1709. }
  1710. if (time() < strtotime($activity_info->start_time)) {
  1711. //未开始
  1712. $activity_status = -1;
  1713. }
  1714. if (time() > strtotime($activity_info->end_time)) {
  1715. //结束
  1716. $activity_status = -2;
  1717. }
  1718. Redis::sadd($uv_key, $this->uid);
  1719. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1720. $user_charge_count = (int)(Order::where('uid', $this->uid)->where('status', 'PAID')->count());
  1721. if ($user_charge_count == 0) {
  1722. $is_first_charge = 1;
  1723. } else {
  1724. $is_first_charge = 0;
  1725. }
  1726. $url_array = [];
  1727. $time_diff = strtotime($activity_info->end_time) - time();
  1728. $day = 0;
  1729. $hour = 0;
  1730. $minute = 0;
  1731. $second = 0;
  1732. if ($time_diff > 0) {
  1733. $day = floor($time_diff / 86400);
  1734. $hour = floor(($time_diff - $day * 86400) / 3600);
  1735. $minute = floor(($time_diff - $day * 86400 - $hour * 3600) / 60);
  1736. $second = $time_diff - $day * 86400 - $hour * 3600 - $minute * 60;
  1737. }
  1738. $product_id_array = explode(',', $activty_ids);
  1739. $product_infos = DB::table('products')->whereIn('id', $product_id_array)->select('id', 'price', 'given')->get();
  1740. foreach ($product_infos as $key => $v) {
  1741. if ($user_charge_count >= 1 && $key == 0) {
  1742. continue;
  1743. }
  1744. $limit = 100;
  1745. if ($key == 0) {
  1746. $limit = 1;
  1747. }
  1748. $param = [
  1749. 'uid' => $this->uid,
  1750. 'distribution_channel_id' => $this->distribution_channel_id,
  1751. 'product_id' => $v->id,
  1752. 'activity_id' => $activity_id,
  1753. 'fromtype' => $from,
  1754. 'pay_redirect_url' => $redirect_url,
  1755. 'limit' => $limit,
  1756. ];
  1757. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1758. $url_array[] = ['url' => $url, 'price' => (int)$v->price, 'given' => $v->given / 100, 'get' => $v->price * 100 + $v->given];
  1759. }
  1760. return view('pay.order.shoppingDayActivity', [
  1761. 'url' => $url_array,
  1762. 'is_first_charge' => $is_first_charge,
  1763. 'code' => $activity_status,
  1764. 'time' => compact('day', 'hour', 'minute', 'second'),
  1765. 'user_charge_count' => $user_charge_count,
  1766. 'time_diff' => $time_diff
  1767. ]
  1768. );
  1769. }
  1770. public function thanksGivingDayActivity(Request $request)
  1771. {
  1772. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1773. $from = $request->input('fromtype', 'main');
  1774. $sites = env('YEAR_ACTIVITY_CHANNEL', '');
  1775. $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1776. if (empty($sites)) {
  1777. return redirect()->to($not_access_url);
  1778. }
  1779. $site_arr = explode(',', $sites);
  1780. if (!in_array($this->distribution_channel_id, $site_arr)) {
  1781. return redirect()->to($not_access_url);
  1782. }
  1783. $year_activity_id = 1367;
  1784. $activity_info = Activity::find($year_activity_id);
  1785. if (!$activity_info) {
  1786. return redirect()->to($not_access_url);
  1787. }
  1788. $activity_id = $year_activity_id;
  1789. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1790. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1791. $uv_key = sprintf($uv_key_format, $activity_id, $this->distribution_channel_id, date('Y-m-d'));
  1792. $pv_key = sprintf($pv_key_format, $activity_id, $this->distribution_channel_id);
  1793. Redis::sadd($uv_key, $this->uid);
  1794. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1795. $start = $activity_info->start_time;
  1796. $end = $activity_info->end_time;
  1797. if (empty($start) || empty($end)) {
  1798. return redirect()->to($not_access_url);
  1799. }
  1800. $url = ['slow' => 'javascript:void(0)', 'height' => 'javascript:void(0)'];
  1801. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->select('id')->first();
  1802. $charge_count = 0;
  1803. if ($order) {
  1804. $charge_count = 1;
  1805. }
  1806. if (time() < strtotime($start)) {
  1807. //未开始
  1808. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 1, 'charge_count' => $charge_count]);
  1809. }
  1810. if (time() > strtotime($end)) {
  1811. //结束
  1812. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 2, 'charge_count' => $charge_count]);
  1813. }
  1814. //3483 3484
  1815. $param = [
  1816. 'uid' => $this->uid,
  1817. 'distribution_channel_id' => $this->distribution_channel_id,
  1818. 'product_id' => 3483,
  1819. 'activity_id' => $activity_id,
  1820. 'fromtype' => $from,
  1821. 'limit' => 1,
  1822. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1823. ];
  1824. $this->getCoupons($activity_id);
  1825. $url['slow'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1826. $param['product_id'] = 3484;
  1827. $param['limit'] = 100;
  1828. $url['height'] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1829. return view('pay.order.thanksGivingDayActivity', ['url' => $url, 'code' => 0, 'charge_count' => $charge_count]);
  1830. }
  1831. public function greatColdActivity(Request $request)
  1832. {
  1833. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1834. $token = $request->input('token');
  1835. $activity_info = ActivityService::getByToken($token);
  1836. if (!$activity_info) {
  1837. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1838. return redirect()->to($default_url);
  1839. }
  1840. $from = $request->input('fromtype', 'main');
  1841. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1842. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1843. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1844. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1845. Redis::sadd($uv_key, $this->uid);
  1846. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1847. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1848. if ($request->input('redirect_url')) {
  1849. $redirect_url = $request->input('redirect_url');
  1850. $redirect_url = urldecode($redirect_url);
  1851. }
  1852. $least_charge_amount = Order::select('id', 'price')
  1853. ->where('uid', $this->uid)
  1854. ->where('status', 'PAID')
  1855. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1856. ->max('price');
  1857. $type = 'litter';
  1858. $product_ids = [3962, 3963];
  1859. $img = [
  1860. 'litter' => [
  1861. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8-active.png',
  1862. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/8.png',
  1863. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23-active.png',
  1864. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/23.png',
  1865. ],
  1866. 'big' => [
  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. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58-active.png',
  1870. 'https://cdn-novel.iycdm.com/h5/activity-2019-01-17/58.png',
  1871. ],
  1872. ];
  1873. if ($least_charge_amount && $least_charge_amount >= 30) {
  1874. $type = 'big';
  1875. $product_ids = [3960, 3961];
  1876. }
  1877. //未开始
  1878. if (time() < strtotime($activity_info->start_time)) {
  1879. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1880. }
  1881. //结束
  1882. if (time() > strtotime($activity_info->end_time)) {
  1883. return view('pay.order.greatColdActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1884. }
  1885. $url = [];
  1886. foreach ($product_ids as $product_id) {
  1887. $param = [
  1888. 'uid' => $this->uid,
  1889. 'distribution_channel_id' => $this->distribution_channel_id,
  1890. 'product_id' => $product_id,
  1891. 'activity_id' => $activity_info->id,
  1892. 'fromtype' => $from,
  1893. 'pay_redirect_url' => $redirect_url,
  1894. 'limit' => 100,
  1895. ];
  1896. $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1897. }
  1898. return view('pay.order.greatColdActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1899. }
  1900. public function channelYearActivity(Request $request)
  1901. {
  1902. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1903. $id = 2628;
  1904. $activity_info = ActivityService::getById($id);
  1905. if ($activity_info && $activity_info->product_id) {
  1906. $from = $request->input('fromtype', 'main');
  1907. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1908. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1909. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1910. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1911. Redis::sadd($uv_key, $this->uid);
  1912. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1913. $param = [
  1914. 'uid' => $this->uid,
  1915. 'distribution_channel_id' => $this->distribution_channel_id,
  1916. 'product_id' => $activity_info->product_id,
  1917. 'activity_id' => $activity_info->id,
  1918. 'fromtype' => $from,
  1919. 'limit' => 30,
  1920. 'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
  1921. ];
  1922. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1923. return view('pay.order.channelYearActivity', ['url' => $url]);
  1924. }
  1925. $url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1926. return redirect()->to($url);
  1927. }
  1928. //春分活动
  1929. public function vernalEquinoxActivity(Request $request)
  1930. {
  1931. $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
  1932. $token = $request->input('token');
  1933. $activity_info = ActivityService::getByToken($token);
  1934. if (!$activity_info) {
  1935. $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
  1936. return redirect()->to($default_url);
  1937. }
  1938. $from = $request->input('fromtype', 'main');
  1939. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  1940. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  1941. $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
  1942. $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
  1943. Redis::sadd($uv_key, $this->uid);
  1944. Redis::hincrby($pv_key, date('Y-m-d'), 1);
  1945. $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
  1946. if ($request->input('redirect_url')) {
  1947. $redirect_url = $request->input('redirect_url');
  1948. $redirect_url = urldecode($redirect_url);
  1949. }
  1950. $least_charge_amount = Order::select('id', 'price')
  1951. ->where('uid', $this->uid)
  1952. ->where('status', 'PAID')
  1953. ->where('created_at', '>=', strtotime($activity_info->start_time) - 60 * 86400)
  1954. ->max('price');
  1955. $type = 'litter';
  1956. if ($least_charge_amount && $least_charge_amount >= 30) {
  1957. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg50.jpg';
  1958. $product_ids = 4806;
  1959. } else {
  1960. $img = 'https://cdn-novel.iycdm.com/h5/activity-2019-03-20/bg23.jpg';
  1961. $product_ids = 4805;
  1962. }
  1963. //未开始
  1964. if (time() < strtotime($activity_info->start_time)) {
  1965. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -1, 'type' => $type, 'img' => $img]);
  1966. }
  1967. //结束
  1968. if (time() > strtotime($activity_info->end_time)) {
  1969. return view('pay.order.vernalEquinoxActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => -2, 'type' => $type, 'img' => $img]);
  1970. }
  1971. $param = [
  1972. 'uid' => $this->uid,
  1973. 'distribution_channel_id' => $this->distribution_channel_id,
  1974. 'product_id' => $product_ids,
  1975. 'activity_id' => $activity_info->id,
  1976. 'fromtype' => $from,
  1977. 'pay_redirect_url' => $redirect_url,
  1978. 'limit' => 100,
  1979. ];
  1980. $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
  1981. return view('pay.order.vernalEquinoxActivity', ['url' => $url, 'code' => 0, 'type' => $type, 'img' => $img]);
  1982. }
  1983. private function userPproperty()
  1984. {
  1985. if ($this->property == 'undefined') {
  1986. if ($this->user && time() - strtotime($this->user->created_at) >= 3 * 66400) {
  1987. $info = UserDivisionCpcPropertyService::calculateUserPropertyV2($this->uid);
  1988. if ($info && $info['property'] != 'undefined') {
  1989. UserDivisionCpcPropertyService::updateV2($info['openid'], $info['property']);
  1990. }
  1991. }
  1992. }
  1993. /*$old = UserDivisionCpcPropertyService::userLevel($openid);
  1994. if(!$old) return ;
  1995. $this->property = $old->property;
  1996. if($old->type != 'NEW') return ;
  1997. $send_data = array(
  1998. 'type' => 'visit',
  1999. 'data' => ['openid'=>$openid,'uid'=>$this->uid]
  2000. );
  2001. try {
  2002. $send = new SendStatisticsList($send_data);
  2003. $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list');
  2004. dispatch($job);
  2005. } catch (\Exception $e) {
  2006. \Log::info($e);
  2007. }*/
  2008. }
  2009. private function guidePersonalAccountV2(){
  2010. //内部站点导粉
  2011. list($inner_sites,$year_qrcode,$month_qrcode,$out_qrcode,$active_qrcode) = redisEnvMulti(
  2012. 'GUIDE_PERSONAL_ACCOUNT_SITES',
  2013. 'ACTIVE_YEAR_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2014. 'ACTIVE_MONTH_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2015. 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  2016. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE'
  2017. );
  2018. $banner = '';
  2019. if(!$this->activity_status){
  2020. $banner = 'https://cdn-novel.iycdm.com/crm/guide/reader-banner.jpg';
  2021. }
  2022. //if(in_array($thy))
  2023. if ($inner_sites && in_array($this->distribution_channel_id, explode(',', $inner_sites))) {
  2024. //1.包年包月用户
  2025. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2026. if ($get_info) return '';
  2027. $charge = false;
  2028. if (in_array($this->property, ['medium', 'high'])) {
  2029. $charge = true;
  2030. } else {
  2031. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2032. $charge = true;
  2033. }
  2034. }
  2035. if(!$charge) return '';
  2036. if($year_qrcode && OrderService::isYearOrderUser($this->uid) ){
  2037. //包年
  2038. return ['title' => '包年VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_YEAR&fee=500','banner'=>$banner];
  2039. }
  2040. if($month_qrcode && UserMonthService::isMonthOrderUser($this->uid) ){
  2041. //包月
  2042. return ['title' => '包月VIP专属爆款小说书单>>', 'link' => '/guidestremv2?group=ACTIVE_MONTH&fee=500','banner'=>$banner];
  2043. }
  2044. if($active_qrcode){
  2045. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500','banner'=>$banner];
  2046. }
  2047. return '';
  2048. }
  2049. //外站导粉
  2050. if($out_qrcode && Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)){
  2051. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2052. if ($get_info) return '';
  2053. $charge = false;
  2054. if (in_array($this->property, ['medium', 'high'])) {
  2055. $charge = true;
  2056. } else {
  2057. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2058. $charge = true;
  2059. }
  2060. }
  2061. if(!$charge) return '';
  2062. $filter_city = ['长沙', '深圳', '杭州'];
  2063. $ip2region = new Ip2Region();
  2064. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2065. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2066. } else {
  2067. $ip = get_client_ip();
  2068. }
  2069. $info = [];
  2070. try {
  2071. $info = $ip2region->btreeSearch($ip);
  2072. } catch (\Exception $e) {
  2073. }
  2074. if (!$info || !isset($info['region'])) return '';
  2075. $region = explode('|', $info['region']);
  2076. $city = isset($region[3]) ? $region[3] : '';
  2077. if (in_array($city, $filter_city)) {
  2078. return '';
  2079. }
  2080. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2081. if ($count < 50) {
  2082. return '';
  2083. }
  2084. Cookie::queue('is_force_out_guide', 1);
  2085. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500','banner'=>$banner];
  2086. }
  2087. //渠道自己导粉
  2088. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2089. if (empty($other_crm_config[0]) && empty($other_crm_config[1])) return '';
  2090. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2091. if ($get_info) return '';
  2092. if($this->is_paid || $this->distribution_channel_id == 6687)
  2093. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1],'banner'=>''];
  2094. return '';
  2095. }
  2096. private function guidePersonalAccount($openid)
  2097. {
  2098. //weidian
  2099. $other_crm_config = Redis::hmget('channel:setting:' . $this->distribution_channel_id, ['crm_status', 'crm_link']);
  2100. $crm_config = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
  2101. $out_status = Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id);
  2102. if (empty($other_crm_config[0]) && empty($other_crm_config[1]) && empty($crm_config[0]) && empty($crm_config[1]) && empty($out_status)) {
  2103. return '';
  2104. }
  2105. //Log::info('guidePersonalAccount1111111111111111111111');
  2106. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  2107. if ($get_info) return '';
  2108. //Log::info('guidePersonalAccount2222222222222222222222');
  2109. $charge = false;
  2110. if (in_array($this->property, ['medium', 'high'])) {
  2111. $charge = true;
  2112. } else {
  2113. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  2114. $charge = true;
  2115. }
  2116. }
  2117. if ($this->distribution_channel_id == 6687) {
  2118. $charge = true;
  2119. }
  2120. if (!$charge) return '';
  2121. //其他渠道自己导粉
  2122. if ($other_crm_config[0] && $other_crm_config[1]) {
  2123. if ($charge)
  2124. return ['title' => '点击领取200书币>>', 'link' => $other_crm_config[1]];
  2125. return '';
  2126. }
  2127. //站外导粉
  2128. if ($out_status) {
  2129. if (!$charge) return '';
  2130. if (empty($crm_config[2])) {
  2131. return '';
  2132. }
  2133. $filter_city = ['长沙', '深圳', '杭州'];
  2134. $ip2region = new Ip2Region();
  2135. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
  2136. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2137. } else {
  2138. $ip = get_client_ip();
  2139. }
  2140. $info = [];
  2141. try {
  2142. $info = $ip2region->btreeSearch($ip);
  2143. } catch (\Exception $e) {
  2144. }
  2145. if (!$info || !isset($info['region'])) return '';
  2146. $region = explode('|', $info['region']);
  2147. $city = isset($region[3]) ? $region[3] : '';
  2148. if (in_array($city, $filter_city)) {
  2149. return '';
  2150. }
  2151. $count = ChapterOrderService::getRecentChapterOrderCount($this->uid);
  2152. if ($count < 50) {
  2153. return '';
  2154. }
  2155. Cookie::queue('is_force_out_guide', 1);
  2156. //Redis::hset('crm:out_guide_exposure_user',$openid,$this->uid);
  2157. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2158. }
  2159. //Log::info('guidePersonalAccount33333333333333333');
  2160. if (empty($crm_config[0]) || empty($crm_config[1])) return '';
  2161. //Log::info('guidePersonalAccount4444444444444444');
  2162. if (!in_array($this->distribution_channel_id, explode(',', $crm_config[0]))) {
  2163. return '';
  2164. }
  2165. //Log::info('guidePersonalAccount555555555555555');
  2166. if ($charge) {
  2167. return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2168. //return ['title' => '您有500书币待领取>>', 'link' => '/guidestrem?uid=' . $this->uid . '&fee=500'];
  2169. }
  2170. return '';
  2171. }
  2172. private function setIsPaid()
  2173. {
  2174. $charge = Order::where('uid', $this->uid)
  2175. ->where('status', 'PAID')
  2176. ->select('id')
  2177. ->first();
  2178. if ($charge) {
  2179. Cookie::queue('is_paid', 1);
  2180. $this->is_paid = true;
  2181. } else {
  2182. Cookie::queue('is_paid', 0);
  2183. $this->is_paid = false;
  2184. }
  2185. }
  2186. private function setProperty($openid)
  2187. {
  2188. $property = UserDivisionCpcPropertyService::userLevelV2($openid);
  2189. $this->property = $property;
  2190. }
  2191. //统计ua
  2192. private function recordUA($ua)
  2193. {
  2194. $is_ua_open = RedisEnv('ua_open');
  2195. if ($is_ua_open && $ua)//开启
  2196. {
  2197. //判断是否已经统计
  2198. $has_got = Redis::hget('book_read:' . $this->uid, 'ua');
  2199. if (!$has_got) {
  2200. try {
  2201. Redis::hset('book_read:' . $this->uid, 'ua', 1);
  2202. UserService::recordUA($ua, $this->uid);
  2203. } catch (\Exception $e) {
  2204. }
  2205. }
  2206. }
  2207. }
  2208. private function monthOrderInfo($openid)
  2209. {
  2210. return '';
  2211. $property = $this->property;
  2212. if (!$property) return '';
  2213. $month_info = UserMonthService::getOrderAndSignStatusByUid($this->uid);
  2214. if($month_info){
  2215. return [
  2216. 'price' => '30元',
  2217. 'text' => '30元包月 全站万本精彩小说免费看',
  2218. 'link' => generateMonthOrderUrl($this->uid),
  2219. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2220. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2221. ];
  2222. /*if(in_array('MONTH',$month_info)){
  2223. return [
  2224. 'price' => '30元',
  2225. 'text' => '30元包月 全站万本精彩小说免费看',
  2226. 'link' => generateMonthOrderUrl($this->uid),
  2227. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2228. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2229. ];
  2230. }
  2231. if(in_array('WEEK',$month_info)){
  2232. return [
  2233. 'price' => '7元',
  2234. 'text' => '7元包周 全站万本精彩小说免费看',
  2235. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2236. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2237. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2238. ];
  2239. }*/
  2240. }
  2241. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))) {
  2242. $info = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'MONTH_V2');
  2243. if ($info) {
  2244. if ($info->attach == 'show' || $info->attach == 'week-show') {
  2245. return [
  2246. 'price' => '30元',
  2247. 'text' => '30元包月 全站万本精彩小说免费看',
  2248. 'link' => generateMonthOrderUrl($this->uid),
  2249. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2250. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2251. ];
  2252. }
  2253. /*if ($info->attach == 'week-show') {
  2254. return [
  2255. 'price' => '7元',
  2256. 'text' => '7元包周 全站万本精彩小说免费看',
  2257. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2258. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2259. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2260. ];
  2261. }*/
  2262. return '';
  2263. }
  2264. }
  2265. if (in_array($this->distribution_channel_id, explode(',', redisEnv('OPEN_ORDER_INNER_SITES')))
  2266. && in_array($property, ['none', 'low', 'medium'])
  2267. ) {
  2268. if (!UserMonthService::isSignMonth($openid)) {
  2269. $start_time = redisEnv('MONTH_TEMPLATE_COMPARE_START_TIME', 0);
  2270. if (!$start_time || (strtotime($this->user->created_at) < $start_time)) {
  2271. if ($property == 'nonenone') {
  2272. return [
  2273. 'price' => '7元',
  2274. 'text' => '7元包周 全站万本精彩小说免费看',
  2275. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2276. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2277. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2278. ];
  2279. } else {
  2280. return [
  2281. 'price' => '30元',
  2282. 'text' => '30元包月 全站万本精彩小说免费看',
  2283. 'link' => generateMonthOrderUrl($this->uid),
  2284. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2285. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2286. ];
  2287. }
  2288. }
  2289. $attach = $this->uid % 2 == 0 ? 'show' : 'hide';
  2290. if ($attach == 'hide') return '';
  2291. if ($property == 'nonenone') {
  2292. return [
  2293. 'price' => '7元',
  2294. 'text' => '7元包周 全站万本精彩小说免费看',
  2295. 'link' => generateMonthOrderUrlV2($this->uid, env('MONTH_WEEK_ORDER_PLAN_ID'), _getIp()),
  2296. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-2.png',
  2297. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/week-order-1.png'
  2298. ];
  2299. } else {
  2300. return [
  2301. 'price' => '30元',
  2302. 'text' => '30元包月 全站万本精彩小说免费看',
  2303. 'link' => generateMonthOrderUrl($this->uid),
  2304. 'focus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_check.png',
  2305. 'unfocus_img'=>'https://cdn-novel.iycdm.com/h5/monthpay/month_order_1.png'
  2306. ];
  2307. }
  2308. }
  2309. }
  2310. return '';
  2311. }
  2312. private function isXiyueUser()
  2313. {
  2314. //$result = DB::table('xiyue_zsy_users')->where('uid',$this->uid)->select('id')->first();
  2315. if ($this->distribution_channel_id == 6985) {
  2316. return [
  2317. 'is_xiyue_user' => 1,
  2318. 'debug' => (int)env('XI_YUE_SHARE_DEBUG', 0),
  2319. 'xiyue_index_page' => env('XIYUE_HOST') . '/',
  2320. 'xiyue_pay_page' => env('XIYUE_HOST') . '/',
  2321. 'xiyue_pay_unfocus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_unfocus_img.png',
  2322. 'xiyue_pay_focus_img' => 'https://cdn-novel.iycdm.com/h5/xiyue/xiyue_pay_focus_img.png',
  2323. 'openid' => $this->user->openid,
  2324. 'register_url' => 'https://sitel12x4nj487yevw0m.leyuee.com/xiyue/sharelink'
  2325. ];
  2326. }
  2327. return "";
  2328. }
  2329. }