WelcomeController.php 104 KB

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