WelcomeController.php 102 KB

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