WelcomeController.php 120 KB

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