WelcomeController.php 120 KB

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