WelcomeController.php 121 KB

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