Recharge.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. <?php
  2. /**
  3. * 前台控制器
  4. * 用户
  5. */
  6. namespace app\index\controller;
  7. use app\api\controller\Campaign;
  8. use app\common\controller\Frontend;
  9. use app\common\library\Ip;
  10. use app\common\library\Redis;
  11. use app\common\library\Ua;
  12. use app\common\service\VipCpService;
  13. use app\main\constants\ActivityConstants;
  14. use app\common\model\Orders;
  15. use app\common\service\CampaignService;
  16. use app\common\service\GussNovelService;
  17. use app\main\constants\CacheConstants;
  18. use app\main\constants\CampaignConstants;
  19. use app\main\constants\GoodsConstants;
  20. use app\main\constants\KafkaDotConstants;
  21. use app\main\constants\MqConstants;
  22. use app\main\constants\OrderContents;
  23. use app\main\constants\PayConstants;
  24. use app\main\constants\SiteConstants;
  25. use app\main\constants\UrlConstants;
  26. use app\main\constants\UserConstants;
  27. use app\main\helper\ArrayHelper;
  28. use app\main\model\object\AnalysisObject;
  29. use app\main\service\ActivityService;
  30. use app\main\service\AdminService;
  31. use app\main\service\AppGuideService;
  32. use app\main\service\BookService;
  33. use app\main\service\BuyMoreService;
  34. use app\main\service\ExportFansService;
  35. use app\main\service\FinancialService;
  36. use app\main\service\GoodsService;
  37. use app\main\service\FufenService;
  38. use app\main\service\KafkaDotService;
  39. use app\main\service\LogService;
  40. use app\main\service\MyScene;
  41. use app\main\service\SinglePushService;
  42. use app\main\service\UrlService;
  43. use app\main\service\OrderService;
  44. use app\main\service\UserdotService;
  45. use app\main\service\UserService;
  46. use app\main\service\MqUserPaySuccessService;
  47. use think\Config;
  48. use think\Cookie;
  49. use think\Request;
  50. use app\main\service\SubscripService;
  51. use think\Db;
  52. class Recharge extends Frontend
  53. {
  54. protected $layout = '';
  55. //充值
  56. public function pay()
  57. {
  58. $channel_id = UserService::instance()->getUserInfo()->channel_id;
  59. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
  60. $appGuideInfo = AppGuideService::instance()->getAppGuideInfo($channel_id);
  61. $hasGuide = count($appGuideInfo) ?? 0 ;
  62. $this->assign('hasGuide', $hasGuide);
  63. $this->assign('appGuideInfo', $appGuideInfo);
  64. $this->assignconfig('float_id', $this->request->get('float_id', ''));
  65. //跳转到支付域名
  66. $this->redirectPayHost($adminConfig);
  67. $showBookShelf = BookService::instance()->showBookShelfFun();
  68. $this->assign('showBookShelf', $showBookShelf);
  69. $is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $channel_id);
  70. $this->assign('is_show_tabbar', $is_show_tabbar);
  71. $this->assign('tab_choice', 'recharge');
  72. $this->assign('channel_id',$channel_id);
  73. $recentUrl = getCurrentDomain($channel_id, '/index/user/recent');
  74. //判断是不是消耗活动的跳转
  75. $activeId = 0;
  76. if($this->request->has('type')){
  77. $type = $this->request->get('type');
  78. $activeId = $this->request->get('active_id');
  79. switch ($type){
  80. case 1://消耗活动跳转
  81. $recentUrl = $activeId ? '/index/recharge/campaignIndex?active_id='.$activeId : $recentUrl;
  82. break;
  83. case 2://翻牌活动
  84. $recentUrl = $activeId ? '/index/activity/cardFlip?actId='.$activeId : $recentUrl;
  85. break;
  86. }
  87. }
  88. $this->assign('active_id', $activeId);
  89. $this->assign('recent_url', $recentUrl);
  90. $payment_method = empty($adminConfig['payment_method']) ? '0' : '1';
  91. $this->assign('payment_method',$payment_method);
  92. $is_pay = 0; //0未充值 1已充值
  93. UserService::instance()->setUserCache(Request::instance()->get('user_id'));
  94. if ($this->request->has('visitor')) {
  95. Cookie::set('visitor', $this->request->get('visitor'));
  96. }
  97. $kandian = 0;
  98. if (UserService::instance()->isLogin()) {
  99. $user = UserService::instance()->getUserInfo(true);
  100. // 引导位访问展示打点
  101. AppGuideService::instance()->appGuideViewDot($channel_id, $user->id, MqConstants::APP_GUIDE_POSITION_IDX_4);
  102. $kandian = FinancialService::instance()->getTotalKandianAndFreeKandian($user->id)->data;
  103. $is_pay = $user->is_pay;
  104. $this->assign('user_id', $user->id);
  105. $this->assign('user', $user->toArray());
  106. } else {
  107. $this->redirect($recentUrl);
  108. }
  109. $this->assign('kandian',$kandian);
  110. $is_test = AdminService::instance()->checkIsTestChannel(
  111. UserService::instance()->getUserInfo()->agent_id,
  112. UserService::instance()->getUserInfo()->channel_id
  113. );
  114. if (Config::get('site.goods_type_new_user') == GoodsConstants::GOODS_TYPE_NEW_DAY) {
  115. $is_new = date('Ymd', UserService::instance()->getUserInfo()->createtime) == date('Ymd');
  116. } else {
  117. $is_new = time() - UserService::instance()->getUserInfo()->createtime < 86400;
  118. }
  119. if (Ua::isWeiXin()) {
  120. $this->assign('business_line',PayConstants::BUSINESS_WECHAT);
  121. // $list = model('Goods')->getGoodsList(
  122. // PayConstants::BUSINESS_WECHAT,
  123. // PayConstants::GOODS_CATEGORY_RECHARGE,
  124. // PayConstants::GOODS_TYPE_KD,
  125. // $is_test,
  126. // $is_pay);
  127. $list = GoodsService::instance()->getCustomGoodsForFront($channel_id, $is_pay, $is_new, PayConstants::BUSINESS_WECHAT);
  128. $activityList = ActivityService::instance()->getRechargePageChannelActivity($user);
  129. if (!empty($activityList)) {
  130. $list = array_merge($list, $activityList);
  131. }
  132. } else {
  133. $this->assign('business_line',PayConstants::BUSINESS_APP);
  134. $list = model('Goods')->getGoodsList(PayConstants::BUSINESS_APP,PayConstants::GOODS_CATEGORY_RECHARGE,PayConstants::GOODS_TYPE_KD,$is_test,$is_pay);
  135. }
  136. $cpBook = false;
  137. if ($book_id = $this->request->param('book_id')) {
  138. $cpBook = VipCpService::instance()->isVipCpBook($book_id);
  139. }
  140. //VIP充值开关开启时,充值页,VIP商品,看点充值都显示
  141. $show_vip_at_home = ArrayHelper::array_get($this->adminconfig, 'show_vip_at_home');
  142. if (!$cpBook && $show_vip_at_home && ($adminConfig['vip_state'] ?? false) && ($adminConfig['vip_goods_id'] ?? null)) {
  143. if ($goods_info = model('goods')->getGoodsInfoById($adminConfig['vip_goods_id'])) {
  144. if (GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], $user)->data) {
  145. array_push($list, $goods_info);
  146. }
  147. }
  148. }
  149. $selectGoodsId = intval($this->request->param('goods_id'));
  150. $this->assign('select_goods_id', $selectGoodsId);
  151. $defaultGoods = $list[0];
  152. if ($selectGoodsId) {
  153. foreach ($list as $item) {
  154. if ($item['id'] == $selectGoodsId) {
  155. $defaultGoods = $item;
  156. break;
  157. }
  158. }
  159. } else {
  160. foreach ($list as $item) {
  161. if($item['default']??0){
  162. $defaultGoods = $item;
  163. break;
  164. }
  165. }
  166. }
  167. $defaultGoods['activity_id'] = $defaultGoods['activity_id'] ?? 0;
  168. $this->assign('list', $list);
  169. $this->assign('default_goods', $defaultGoods);
  170. $track = '{}';
  171. $user_id = UserService::instance()->getUserInfo()->id;
  172. if ($this->request->has('book_id')) {
  173. $book_id = $this->request->get('book_id');
  174. $bookInfo = model('Book')->BookInfo($book_id);
  175. if ($bookInfo) {
  176. if ($bookInfo['price'] > 0) {
  177. if ($bookInfo['billing_type'] == 1) {
  178. $price = FinancialService::instance()->getChapterPrice($book_id);
  179. $this->assign('bookBillingTip', '本章是VIP章节(' . $price . '书币/章)');
  180. } elseif ($bookInfo['billing_type'] == 2 && $bookInfo['price'] > 0) {
  181. $this->assign('bookBillingTip', '本书是VIP书籍(' . $bookInfo['price'] . '书币/本)');
  182. } else {
  183. $this->assign('bookBillingTip', '本章是VIP章节(' . Config::get('site.book_chapter_price') . '书币/章)');
  184. }
  185. }
  186. }
  187. $cache = UserdotService::instance()->getTrackCache($user_id, $book_id);
  188. if ($cache) {
  189. $track = $cache;
  190. }
  191. } else {
  192. $zone = $this->request->get('zone');
  193. $adid = $this->request->get('adid');
  194. $book_id = 0;
  195. $url = $this->request->get('from_url');
  196. if (!empty($zone) && !empty($adid)) {
  197. UserdotService::instance()->saveTrackInfo($url, $zone, $adid, $book_id);
  198. $cache = UserdotService::instance()->getTrackCache($user_id, $book_id);
  199. if ($cache) {
  200. $track = $cache;
  201. }
  202. }
  203. }
  204. $this->assign('track', $track);
  205. $buyMore = PayConstants::getBuyMore(UserService::instance()->getUserInfo()->id);
  206. $this->assign('buyMore', $buyMore);
  207. $buyMoreView = false;
  208. if (Config::get('site.theme') == 'yg' && $viewConfig = Config::get('site.buymoreview')) {
  209. if ($viewConfig == 2) {
  210. $buyMoreView = true;
  211. } else if($user_id % 2 == 0){
  212. $buyMoreView = true;
  213. }
  214. }
  215. $isOpenMishuTips = 0;
  216. $imgTimes = 1;
  217. if (Config::get('site.is_open_mishu_tip') == 1) {
  218. $isOpenMishuTips = 1;
  219. //判断IP 北京区域不弹
  220. $city = Ip::city();
  221. if (strrpos('北京市', $city) !== false) {
  222. $isOpenMishuTips = 0;
  223. }
  224. }
  225. $export_fans = ExportFansService::instance()->checkFansPayToExport($channel_id, $user_id)->data;
  226. $this->view->assign('fans', $export_fans);
  227. $this->view->assign('is_mishu', $isOpenMishuTips);
  228. $this->view->assign('img_times', $imgTimes);
  229. //未充值的redis
  230. $unRechargeKey = CacheConstants::getFansUnrecharge($user_id);
  231. Redis::instance()->set($unRechargeKey, '1', 180);
  232. if ($buyMoreView) {
  233. return $this->view->fetch('paymore');
  234. }else{
  235. return $this->view->fetch();
  236. }
  237. }
  238. //VIP充值页面
  239. public function vip()
  240. {
  241. //跳转支付域名
  242. $this->redirectPayHost($this->adminconfig,true);
  243. $this->assignconfig('float_id', $this->request->get('float_id', ''));
  244. $recentUrl = getCurrentDomain(UserService::instance()->getUserInfo()->channel_id, '/index/user/recent');
  245. //visitor设置
  246. UserService::instance()->setUserCache(Request::instance()->get('user_id'));
  247. if ($this->request->has('visitor')) {
  248. Cookie::set('visitor', $this->request->get('visitor'));
  249. }
  250. $this->view->assign('business_line',PayConstants::BUSINESS_WECHAT);
  251. if ($this->request->get('vip_custom_money') && !empty($this->adminconfig['vip_goods_id_custom'])) {
  252. $goodsId = $this->adminconfig['vip_goods_id_custom'];
  253. } else {
  254. $goodsId = $this->adminconfig['vip_goods_id'];
  255. }
  256. $goods_info = false;
  257. $isend = !!!$this->adminconfig['vip_state'];
  258. if ($goodsId) {
  259. $goods_info = GoodsService::instance()->getGoodsModel()->getGoodsInfoById($goodsId);
  260. if (!GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], UserService::instance()->getUserInfo())->data) {
  261. $goods_info = false;
  262. $isend = true;
  263. }
  264. }
  265. $this->assign('goods_info',$goods_info);
  266. $this->assign('recent_url', $recentUrl);
  267. $this->assign('isend', $isend);
  268. return $this->view->fetch('index@recharge/vip/'.$this->adminconfig['vip_pay_tpl']);
  269. }
  270. //小额充值
  271. public function smallpay()
  272. {
  273. $this->assignconfig('float_id', $this->request->get('float_id', ''));
  274. $channelId = UserService::instance()->getUserInfo()->channel_id;
  275. $userId = UserService::instance()->getUserInfo()->id;
  276. $recentUrl = getCurrentDomain($channelId, '/index/user/recent');
  277. $configChannelIds = Config::get('site.smallpay_channel_id') ?? '';
  278. if ($configChannelIds == '*') {
  279. $open = true;
  280. } else {
  281. $list = explode(',', $configChannelIds);
  282. $open = in_array($channelId, $list);
  283. }
  284. $id = Config::get('site.smallpay_goods_id');
  285. if (!$id || !$open) {
  286. $this->error('未开启小额充值', $recentUrl);
  287. }
  288. $goods_info = model('Goods')->getGoodsInfoById($id);
  289. if (!$goods_info) {
  290. $this->error('商品不存在', $recentUrl);
  291. }
  292. $cacheKey = CacheConstants::getSmallPayCache($userId);
  293. if (Redis::instance()->exists($cacheKey)) {
  294. $this->error('用户已支付过此商品', $recentUrl);
  295. }
  296. $this->redirectPayWithUri($this->adminconfig,'/index/recharge/smallpay?');
  297. $this->view->assign('business_line',PayConstants::BUSINESS_WECHAT);
  298. $this->assign('goods_info',$goods_info);
  299. $this->assign('recent_url', $recentUrl);
  300. return $this->view->fetch('index@recharge/smallpay/default');
  301. }
  302. public function redirectPayWithUri($adminConfig, $uri)
  303. {
  304. if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD){ //推广域名
  305. //Log::write('是推广域名进来的','cctest4');
  306. $params = $this->request->get();
  307. if (UserService::instance()->isLogin()) {
  308. $params['user_id'] = UserService::instance()->getUserInfo()->id;
  309. } elseif (Cookie::has('visitor')) {
  310. $params['visitor'] = Cookie::get('visitor');
  311. }
  312. if ($this->request->has('book_id')) {
  313. $params['book_id'] = $this->request->get('book_id');
  314. }
  315. if ($this->request->has('chapter_id')) {
  316. $params['chapter_id'] = $this->request->get('chapter_id');
  317. }
  318. if($this->request->has('redirect')){
  319. $params['redirect'] = $this->request->get('redirect');
  320. }
  321. if(isset($params['code'])){
  322. unset($params['code']);
  323. }
  324. //有菜单支付域名时,跳转菜单支付域名
  325. $menuophost = $adminConfig['menuophost'] ?? null;
  326. $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  327. if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){
  328. $payHost = Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'];
  329. }else{
  330. $payHost = Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'];
  331. }
  332. $payHost .= $uri;
  333. $payHost .= http_build_query($params);
  334. $this->redirect($payHost);
  335. }
  336. }
  337. /**
  338. * 跳转到支付域名
  339. * @param $adminConfig
  340. * @param $is_vip
  341. */
  342. public function redirectPayHost($adminConfig,$is_vip = false){
  343. if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD){ //推广域名
  344. //Log::write('是推广域名进来的','cctest4');
  345. $params = $this->request->get();
  346. $params['user_id'] = UserService::instance()->getUserInfo()->id;
  347. if ($this->request->has('book_id')) {
  348. $params['book_id'] = $this->request->get('book_id');
  349. }
  350. if ($this->request->has('chapter_id')) {
  351. $params['chapter_id'] = $this->request->get('chapter_id');
  352. }
  353. if($this->request->has('redirect')){
  354. $params['redirect'] = $this->request->get('redirect');
  355. }
  356. if(isset($params['code'])){
  357. unset($params['code']);
  358. }
  359. //有菜单支付域名时,跳转菜单支付域名
  360. $user_id = UserService::instance()->getUserInfo()->id;
  361. $channel_id = UserService::instance()->getUserChannelId()->data;
  362. $payHost = FufenService::instance()->getPayUrl($user_id, $channel_id)->data;
  363. // $menuophost = $adminConfig['menuophost'] ?? null;
  364. // $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  365. // if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){
  366. // $payHost = Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'];
  367. // }else{
  368. // $payHost = Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'];
  369. // }
  370. //VIP充值检查
  371. if(!$is_vip){
  372. $payHost .= '/index/recharge/pay?';
  373. }else{
  374. $payHost .= '/index/recharge/vip?';
  375. }
  376. $payHost .= http_build_query($params);
  377. $this->redirect($payHost);
  378. }
  379. }
  380. //充值记录
  381. public function record()
  382. {
  383. $userId = Cookie::get('user_id');
  384. if($this->request->isAjax()){ //如果是ajax请求
  385. $pageNo = $this->request->post('pageNo');
  386. $pageSize = intval($this->request->post('pagesize'));
  387. $startNo = ($pageNo-1)*$pageSize;
  388. $recharge = model('Recharge')->setConnect($userId)->where('user_id',$userId)->order('createtime','desc')->limit($startNo,$pageSize)->select();
  389. if(!$recharge){
  390. $recharge = [];
  391. }
  392. $data = [];
  393. foreach($recharge as $key=>$val){
  394. $data[$key] = is_array($val)?$val:$val->toArray();
  395. if($val['type']=='1' || $val['type']=='3' || $val['type']=='5' || $val['type']=='6'){ //书币
  396. $data[$key]['showItem'] = '';
  397. if(intval($val['kandian']) == 0){ //免费书币
  398. if(intval($val['free_kandian'])>0){
  399. $data[$key]['showItem'] = '+'.$val['free_kandian'].'书币'; //int转string
  400. $data[$key]['endDate'] = Date('Y-m-d',$val['free_endtime']); //书币失效日期
  401. }else{
  402. $data[$key]['showItem'] = $val['free_kandian'].'书币'; //int转string
  403. $data[$key]['endDate'] = '永久'; //书币失效日期
  404. }
  405. if($val['type']==1){
  406. $data[$key]['type_text'] = '充值赠送书币';
  407. } elseif(intval($val['type'])==6) {
  408. $data[$key]['type_text'] = '活动赠送书币';
  409. }
  410. }else{ //永久书币
  411. if(intval($val['kandian'])>0){
  412. $data[$key]['showItem'] = '+'.$val['kandian'].'书币'; //int转string
  413. }else{
  414. $data[$key]['showItem'] = $val['kandian'].'书币'; //int转string
  415. }
  416. $data[$key]['endDate'] = '永久'; //书币失效日期
  417. }
  418. }else{ //vip
  419. $data[$key]['showItem'] = '';
  420. if(intval($val['day']) > 0 || intval($val['hour'])>0){ //加vip时长
  421. if(intval($val['day'])>0){
  422. $data[$key]['showItem'] = '+'.$val['day'].'天';
  423. if(intval($val['hour']) > 0){
  424. $data[$key]['showItem'] = $data[$key]['showItem'].$val['hour'].'小时';
  425. }
  426. }else{
  427. $data[$key]['showItem'] ='+'.$val['hour'].'小时';
  428. }
  429. }else{ //减少vip时长
  430. if(intval($val['day']) <0){
  431. $data[$key]['showItem'] = $val['day'].'天';
  432. if(intval($val['hour'])<0){
  433. $data[$key]['showItem']= $data[$key]['showItem'].abs($val['hour']).'小时';
  434. }
  435. }else{
  436. if(intval($val['hour']) < 0){
  437. $data[$key]['showItem'] = $val['hour'].'小时';
  438. }
  439. }
  440. }
  441. //$data[$key]['endDate'] = '永久';
  442. $days = $val['day'] ?? 0;
  443. $hour = $val['hour'] ?? 0;
  444. //$data[$key]['endDate'] = '永久';
  445. if($val['vip_starttime']){
  446. $data[$key]['endDate'] = date('Y-m-d H:i:s', strtotime("+{$days} days {$hour} hours", $val['vip_starttime']));
  447. }else{
  448. $data[$key]['endDate'] = '-';
  449. }
  450. }
  451. }
  452. return json($data);
  453. }else{ //渲染第一页
  454. $recharge = model('Recharge')->setConnect($userId)->where('user_id',$userId)->order('createtime','desc')->limit(0,20)->select();
  455. if(!$recharge){
  456. $recharge = [];
  457. }
  458. $data = [];
  459. foreach($recharge as $key=>$val){
  460. $data[$key] = is_array($val)?$val:$val->toArray();
  461. $data[$key]['showItem'] = '';
  462. if($val['type']=='1' || $val['type']=='3' || $val['type']=='5' || $val['type']=='6'){ //书币
  463. if(intval($val['kandian']) == 0){ //免费书币
  464. if(intval($val['free_kandian'])>0){
  465. $data[$key]['showItem'] = '+'.$val['free_kandian'].'书币'; //int转string
  466. $data[$key]['endDate'] = Date('Y-m-d',$val['free_endtime']); //书币失效日期
  467. }else{
  468. $data[$key]['showItem'] = $val['free_kandian'].'书币'; //int转string
  469. $data[$key]['endDate'] = '永久'; //书币失效日期
  470. }
  471. if($val['type']==1){
  472. $data[$key]['type_text'] = '充值赠送书币';
  473. } elseif(intval($val['type'])==6) {
  474. $data[$key]['type_text'] = '活动赠送书币';
  475. }
  476. }else{ //永久书币
  477. if(intval($val['kandian'])>0){
  478. $data[$key]['showItem'] = '+'.$val['kandian'].'书币'; //int转string
  479. }else{
  480. $data[$key]['showItem'] = $val['kandian'].'书币'; //int转string
  481. }
  482. $data[$key]['endDate'] = '永久'; //书币失效日期
  483. }
  484. }else{ //vip
  485. if(intval($val['day']) > 0 || intval($val['hour'])>0){ //加vip时长
  486. if(intval($val['day'])>0){
  487. $data[$key]['showItem'] = '+'.$val['day'].'天';
  488. if(intval($val['hour']) > 0){
  489. $data[$key]['showItem'] = $data[$key]['showItem'].$val['hour'].'小时';
  490. }
  491. }else{
  492. $data[$key]['showItem'] ='+'.$val['hour'].'小时';
  493. }
  494. }else{ //减少vip时长
  495. if(intval($val['day']) <0){
  496. $data[$key]['showItem'] = $val['day'].'天';
  497. if(intval($val['hour'])<0){
  498. $data[$key]['showItem']= $data[$key]['showItem'].abs($val['hour']).'小时';
  499. }
  500. }else{
  501. if(intval($val['hour']) < 0){
  502. $data[$key]['showItem'] = $val['hour'].'小时';
  503. }
  504. }
  505. }
  506. $days = $val['day'] ?? 0;
  507. $hour = $val['hour'] ?? 0;
  508. if($val['vip_starttime']){
  509. $data[$key]['endDate'] = date('Y-m-d H:i:s', strtotime("+{$days} days {$hour} hours ", $val['vip_starttime']));
  510. }else{
  511. $data[$key]['endDate'] = '-';
  512. }
  513. }
  514. if ( in_array($val['extend_type'], [1,2]) ){
  515. $data[$key]['type_text'] = $val['extend_type'] == 1 ? '活动报名' : ($val['extend_type'] == 2 ? '活动赠送书币' : $data[$key]['type_text']);
  516. }
  517. }
  518. $adminconfig = $this->adminconfig;
  519. $this->view->assign('adminconfig',$adminconfig);
  520. $this->assign('res',$data);
  521. return $this->view->fetch();
  522. }
  523. }
  524. /**
  525. * @return mixed
  526. * @throws \think\Exception
  527. */
  528. public function activity()
  529. {
  530. $this->assignconfig('float_id', $this->request->get('float_id', ''));
  531. $id = intval($_GET['id']);
  532. $aid = intval($_GET['aid'] ?? 0);
  533. $is_range = 0;
  534. $user_id = UserService::instance()->getUserInfo()->id;
  535. $admin_id = UserService::instance()->getAdminId()->data;
  536. $channel_id = UserService::instance()->getUserInfo()->channel_id;
  537. if ($this->request->has('isrange') || $this->request->has('isRange')) {
  538. $is_range = 1;
  539. }
  540. /**
  541. * 获取渠道商/代理商资料
  542. */
  543. $adminExtend = AdminService::instance()->getAdminExtendModel()->getInfo($admin_id);
  544. $recent_url = getCurrentDomain($channel_id, '/index/user/recent');
  545. if (!$adminExtend) {
  546. $this->error('管理员信息获取失败', $recent_url);
  547. }
  548. $activityInfo = model('Activity')->getInfo($aid);
  549. $isGiveAct = false;
  550. if ($activityInfo && in_array($activityInfo['type'],
  551. [ActivityConstants::ACTIVITY_TYPE_CUSTOM, ActivityConstants::ACTIVITY_TYPE_GIVE])) {
  552. $isGiveAct = $activityInfo['type'] == ActivityConstants::ACTIVITY_TYPE_GIVE;
  553. $resource_info = model("Resource")->getInfo($id);
  554. if (empty($resource_info)) {
  555. $this->error('活动不存在', $recent_url);
  556. }
  557. $res['starttime'] = $activityInfo['starttime'];
  558. $res['endtime'] = $activityInfo['endtime'];
  559. $res['astatus'] = $activityInfo['status'];
  560. $res['aname'] = $activityInfo['name'];
  561. $res = array_merge($res, $resource_info);
  562. $res['activity_id'] = $aid;
  563. if (intval($activityInfo['limited'])) {
  564. $redis = Redis::instance();
  565. //用户在渠道自定义的活动充值次数统计
  566. if ($activityInfo['type'] == ActivityConstants::ACTIVITY_TYPE_CUSTOM) {
  567. $pay_count = intval($redis->hGet("ATPU:{$aid}", $user_id));
  568. if (intval($activityInfo['limited']) <= $pay_count) {
  569. $this->error("该活动限购 {$activityInfo['limited']} 次");
  570. }
  571. }
  572. //用户在赠币的活动充值次数统计
  573. if ($isGiveAct) {
  574. $this->assign('the_max_time', $activityInfo['limited']);
  575. $pay_count = intval($redis->hGet("ATGP:{$aid}", $user_id));
  576. if (intval($activityInfo['limited']) <= $pay_count) {
  577. $this->assign('is_max_end',1);
  578. }
  579. }
  580. }
  581. } else {
  582. //平台活动 缓存
  583. $key = 'P-A:'.$id;
  584. if (Redis::instance()->exists($key)) {
  585. $res = json_decode(Redis::instance()->get($key), true);
  586. } else {
  587. $res = model('resource')->join('activity a', 'a.id=resource.activity_id')->where('resource.id', $id)
  588. ->field('a.starttime,a.endtime,a.status as astatus,a.name as aname,resource.*')->find();
  589. if ($res) {
  590. Redis::instance()->set($key, json_encode($res, JSON_UNESCAPED_UNICODE), 60);
  591. }
  592. }
  593. }
  594. if(!$res){
  595. $this->error('活动不存在', $recent_url);
  596. }
  597. if ($res['goods_id'] > 0) {
  598. $goodsInfo = model("Goods")->getGoodsInfoById($res['goods_id']);
  599. if ($goodsInfo) {
  600. $res['money'] = $goodsInfo['money'];
  601. }
  602. }
  603. $this->assign('recent_url', $recent_url);
  604. if ($res['activity_id'] == 100) {
  605. if (UserService::instance()->getUserInfo()->is_pay == UserConstants::USER_IS_PAY_YES) {
  606. $is_range = 1;
  607. }
  608. }
  609. if($res['endtime'] < $this->time||empty($res['astatus'])){
  610. $this->assign('isend',1);
  611. }
  612. if($res['starttime'] > $this->time && !empty($res['astatus'])){
  613. $this->assign('needWait',1);
  614. $lastTime = $this->lastTime($res['starttime']);
  615. $this->assign('lastTime',$lastTime);
  616. }
  617. $arr = [];
  618. array_push($arr,"\r\n");
  619. array_push($arr,"\r");
  620. array_push($arr,"\n");
  621. $pay_url = '';
  622. $res['warning'] = str_replace($arr,"<br/>",$res['warning']);
  623. $to_url = getCurrentDomain($channel_id,'/index/user/recent');
  624. if ($admin_id) {
  625. $admin_info = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($admin_id);
  626. if (!empty($admin_info) && $admin_info['appid']) {
  627. $to_url = getCurrentDomain($admin_id, '/index/user/recent');
  628. }
  629. if ($admin_info) {
  630. $menuophost = $info['menuophost'] ?? null;
  631. $menuwxpay_host = $info['menuwxpay_host'] ?? null;
  632. if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) {
  633. $pay_url = Config::get('site.scheme') . '://' . $admin_info['menuwxpay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id;
  634. } else {
  635. $pay_url = Config::get('site.scheme') . '://' . $admin_info['wxpay_pay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id;
  636. }
  637. }
  638. }
  639. $payment_method = empty($admin_info['payment_method']) ? '0' : '1';
  640. $this->assign('res', $res);
  641. $this->assign('isGiveAct', $isGiveAct);
  642. $this->assign('payment_method', $payment_method);
  643. $this->assign('aid', $res['activity_id']);
  644. $this->assign('payUrl', $pay_url);
  645. $this->assign('toUrl', $to_url);
  646. $this->assign('isRange', $is_range);
  647. $track = '{}';
  648. $cache = UserdotService::instance()->getTrackCache($user_id, $res['activity_id']);
  649. if ($cache) {
  650. $track = $cache;
  651. }
  652. $this->assign('track', $track);
  653. if ($res['activity_id'] == 100 && Config::get("site.theme") == 'yg') {
  654. //首冲9块9 阳光主题加载另外模板
  655. return $this->fetch('activity_first_pay');
  656. }
  657. $oAna = new AnalysisObject();
  658. $oAna->type = KafkaDotConstants::TYPE_VISIT;
  659. $oAna->user_from = [
  660. 'activity_id' => $res['activity_id'],
  661. ];
  662. KafkaDotService::instance()->sendMsg($user_id, $oAna);
  663. return $this->fetch();
  664. }
  665. /**
  666. * 剩余时间
  667. * @param int $unixEndTime
  668. * @return string
  669. */
  670. function lastTime($unixEndTime=0)
  671. {
  672. if ($unixEndTime <= $this->time) { // 如果过了活动终止日期
  673. return '0天0时0分';
  674. }
  675. // 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分
  676. $time = $unixEndTime - $this->time;
  677. $days = 0;
  678. if ($time >= 86400) { // 如果大于1天
  679. $days = (int)($time / 86400);
  680. $time = $time % 86400; // 计算天后剩余的毫秒数
  681. }
  682. $xiaoshi = 0;
  683. if ($time >= 3600) { // 如果大于1小时
  684. $xiaoshi = (int)($time / 3600);
  685. $time = $time % 3600; // 计算小时后剩余的毫秒数
  686. }
  687. $fen = (int)($time / 60); // 剩下的毫秒数都算作分
  688. if(empty($fen)){
  689. $fen = 1;
  690. }
  691. return $days.'天'.$xiaoshi.'时'.$fen.'分';
  692. }
  693. /**
  694. * 自定义链接充值
  695. */
  696. public function special()
  697. {
  698. $this->assignconfig('float_id', $this->request->get('float_id', ''));
  699. $id = intval($_GET['id']);
  700. UserService::instance()->setUserCache(Request::instance()->get('user_id'));
  701. $user_id = UserService::instance()->getUserInfo()->id;
  702. $admin_id = UserService::instance()->getAdminId()->data;
  703. $channel_id = UserService::instance()->getUserInfo()->channel_id;
  704. if ($this->request->has('visitor')) {
  705. Cookie::set('visitor', $this->request->get('visitor'));
  706. }
  707. /**
  708. * 获取渠道商/代理商资料
  709. */
  710. $adminExtend = AdminService::instance()->getAdminExtendModel()->getInfo($admin_id);
  711. if (!$adminExtend) {
  712. $this->error('管理员信息获取失败');
  713. }
  714. //检测链接
  715. $urlInfo = model("SpecialRechargeUrl")->checkUrl($id);
  716. if ($urlInfo['code'] == 201 || $urlInfo['code'] == 202) {
  717. $this->error('链接不存在');
  718. die;
  719. }
  720. $is_range = $urlInfo['code'] == 203 ? 1 : 0;
  721. //获取商品信息
  722. $tplInfo = model("SpecialRechargeTpl")->getOne($urlInfo['data']['tpl_id']);
  723. if (empty($tplInfo)) {
  724. $this->error('链接信息不存在');
  725. die;
  726. }
  727. $res['title'] = $tplInfo['title'];
  728. $goodsInfo = model('Goods')->getGoodsInfoById($tplInfo['goods_id']);
  729. if (empty($goodsInfo)) {
  730. $this->error('商品信息不存在');
  731. }
  732. $res['money'] = $goodsInfo['money'];
  733. $res['kandian'] = $goodsInfo['kandian'];
  734. $res['free_kandian'] = $goodsInfo['free_kandian'];
  735. $res['day'] = $goodsInfo['day'];
  736. $res['free_day'] = $goodsInfo['free_day'];
  737. $res['type'] = $goodsInfo['type'];
  738. $res['category_id'] = $goodsInfo['category_id'];
  739. $res['goods_id'] = $tplInfo['goods_id'];
  740. $res['url_id'] = $id;
  741. $res['cost'] = $tplInfo['cost'];
  742. $to_url = getCurrentDomain($channel_id,'/index/user/recent');
  743. $pay_url = '';
  744. if ($admin_id) {
  745. $admin_info = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($admin_id);
  746. if (!empty($admin_info) && $admin_info['appid']) {
  747. $to_url = getCurrentDomain($admin_id, '/index/user/recent');
  748. }
  749. if ($admin_info) {
  750. $menuophost = $info['menuophost'] ?? null;
  751. $menuwxpay_host = $info['menuwxpay_host'] ?? null;
  752. if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) {
  753. $pay_url = Config::get('site.scheme') . '://' . $admin_info['menuwxpay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id;
  754. } else {
  755. $pay_url = Config::get('site.scheme') . '://' . $admin_info['wxpay_pay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id . '';
  756. }
  757. }
  758. }
  759. $payment_method = empty($admin_info['payment_method']) ? '0' : '1';
  760. $this->assign('res', $res);
  761. $this->assign('payment_method', $payment_method);
  762. $this->assign('url_id', $id);
  763. $this->assign('payUrl', $pay_url);
  764. $this->assign('toUrl', $to_url);
  765. $this->assign('isRange', $is_range);
  766. $this->assign('business_line', PayConstants::BUSINESS_WECHAT);
  767. if ($res['type'] == '2') {
  768. return $this->fetch('special_vip');
  769. }
  770. return $this->fetch();
  771. }
  772. /**
  773. * 读书挑战赛 活动入口
  774. * wud
  775. */
  776. public $campaginArr;
  777. public function campaignIndex(){
  778. //跳转到支付域名
  779. if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名
  780. $this->campaginArr['activeId'] = $this->request->get('active_id') ?? 1;
  781. $this->campaginArr['userInfo'] = UserService::instance()->getUserInfo();
  782. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($this->campaginArr['userInfo']->channel_id);
  783. $menuophost = $adminConfig['menuophost'] ?? null;
  784. $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  785. if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) {
  786. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'];
  787. } else {
  788. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'];
  789. }
  790. $payHost .= '/index/recharge/campaignIndex?';
  791. $params['from'] = 'wechat';
  792. $params['admin_id'] = $adminConfig['admin_id'];
  793. $params['channel_id'] = $this->campaginArr['userInfo']->channel_id;
  794. $params['user_id'] = $this -> campaginArr['userInfo']->id;
  795. $params['active_id'] = $this -> campaginArr['activeId'];
  796. $payHost .= http_build_query($params);
  797. $this -> redirect($payHost);
  798. }
  799. $this->campaignInit();
  800. $this->assign('percent', rand(80,99));
  801. $this->assign('channelUrl', $this->campaginArr['channelUrl']);
  802. $this->assign('active', $this->campaginArr['active']);
  803. $this->assign('log_host', Config::get('site.loghost')); //设置打点域名
  804. $matchLevel = [
  805. $this->campaginArr['active']['elementary_need'],
  806. $this->campaginArr['active']['intermediate_need'],
  807. $this->campaginArr['active']['advanced_need']
  808. ];
  809. switch ($this->campaginArr['status']) {
  810. case -1://活动未开始页面
  811. return $this->view->fetch('index@recharge/campaign/nullactive');
  812. break;
  813. case 0://报名页面
  814. $time = time();
  815. $curDate = date('Ymd', $time);
  816. // $predate = date('Ymd', $time-3600*24*8 );
  817. //随机返回弹幕
  818. $barrage = CampaignService::instance()->getBarrage10($matchLevel);
  819. // dump($barrage);exit;
  820. //获取最近一场得信息
  821. $preMatch = CampaignService::instance()->lastTimeMatch();
  822. //获取 前一天和今天的场次信息
  823. $Campaign = CampaignService::instance()->getMatchBatch( $matchLevel ,[$curDate] );
  824. //组装数据
  825. $assignData = [
  826. 'curDate'=>[],
  827. 'preDate'=>[]
  828. ];
  829. $goodsInfo = [];
  830. if ( !empty($Campaign) ){
  831. foreach ($Campaign as $k =>$v){
  832. if ( $curDate == $v['match_date'] ) {
  833. //获得当天场次的商品信息
  834. $goodsInfo = model('Goods')->getGoodsInfoById($v['goods_id']);
  835. $v['money'] = $goodsInfo['money'];
  836. $assignData['curDate'][$v['kandian']] = $v;
  837. }
  838. }
  839. }
  840. //计算上期瓜分书币
  841. foreach ($assignData['curDate'] as $kk=>&$vv){
  842. $vv['preAward'] = $preMatch[$vv['kandian']]??0;
  843. }
  844. //获得当前的总奖池 报名人数 预期奖励
  845. $dateNum = CampaignService::instance()->getAward($assignData['curDate'],$this->campaginArr['active']);
  846. $userKandian = FinancialService::instance()->getTotalKandian($this->campaginArr['userInfo']->id)->data;
  847. $this->assign('dateNum', $dateNum);
  848. $this->assign('barrage', $barrage );
  849. $this->assign('userKanDian', $userKandian);
  850. $this->assign('curData', $assignData['curDate'] );
  851. $this->assign('match', $matchLevel );
  852. $this->assign('goodsInfo', $goodsInfo );
  853. $this->assign('assignData', $assignData );
  854. $this->assign('webStatus', $this->campaginArr['status']);
  855. return $this->view->fetch('index@recharge/campaign/index');
  856. break;
  857. default://打卡页面
  858. //获取当前场次信息
  859. // $curMatch = CampaignService::instance()->getMatchByTime( $this->campaginArr['userMatch']['match_date'], $this->campaginArr['userMatch']['kandian']);
  860. $dateMatch = CampaignService::instance()->getMatchBatch($matchLevel,[$this->campaginArr['userMatch']['match_date']]);
  861. foreach ( $dateMatch as $key=>$val ){
  862. if ( $val['kandian'] == $this->campaginArr['userMatch']['kandian']){
  863. $curMatch = $val;
  864. }
  865. }
  866. //获得当前的总奖池 报名人数 预期奖励
  867. $dateNum = CampaignService::instance()->getAward($dateMatch,$this->campaginArr['active']);
  868. $curMatch['preKandian'] = intval($curMatch['kandian']*$dateNum['awardPercent']);
  869. //获取当天阅读章节
  870. $redisKey = CampaignConstants::getUserMatchReadKey($this->campaginArr['userInfo']->id);
  871. $curMatch['cur_read_num'] = Redis::instance()->get($redisKey);
  872. $curMatch['cur_read_num'] = !empty($curMatch['cur_read_num']) ? $curMatch['cur_read_num'] : 0 ;
  873. //自动打卡
  874. if ( $this->campaginArr['status'] == 5 && $curMatch['cur_read_num'] >= $this->campaginArr['active']['read_number'] ){//更新书库状态
  875. $sign = MyScene::getInstance($this->campaginArr['userInfo']->id, $this->campaginArr['userMatch']['match_id'])->sign();
  876. if ( $sign['code'] == 200 ){ //打卡成功
  877. $this->campaginArr['status'] = 11;
  878. }
  879. }
  880. //累计报名人数
  881. $levelArr = [
  882. $this->campaginArr['active']['elementary_need']=>'elementary_num',
  883. $this->campaginArr['active']['intermediate_need']=>'intermediate_num',
  884. $this->campaginArr['active']['advanced_need']=>'advanced_num'
  885. ];
  886. //本场次得基础人数
  887. $baseNum = $this->campaginArr['active'][$levelArr[$this->campaginArr['userMatch']['kandian']]];
  888. $dateNum['lSignNum'] = $baseNum + $curMatch['participator_num'];
  889. //更新上期活动的数据库状态
  890. if ( in_array( $this->campaginArr['status'], [9,12] ) ){
  891. CampaignService::instance()->updateUserMatch($this->campaginArr['userInfo']->id,$this->campaginArr['userMatch']['id'],5);
  892. }
  893. if( $this->campaginArr['status'] == 14 ){//未领奖
  894. CampaignService::instance()->updateUserMatch($this->campaginArr['userInfo']->id,$this->campaginArr['userMatch']['id'],6);
  895. }
  896. //更新当天的打卡次数
  897. // dump($curMatch);exit;
  898. $todaySignNUM = redis::instance()->get(CampaignConstants::getMatchSignNumToday($curMatch['id']));
  899. $dateNum['signNum'] = empty($todaySignNUM) ? $baseNum : $todaySignNUM+$baseNum;
  900. $dateNum['canquer'] = $dateNum['lSignNum']-$curMatch['success_num'];
  901. //打卡页面底部推荐书
  902. $this->campaginArr['userInfo']->sex = (int)$this->campaginArr['userInfo']->sex == 2 ? 2 : 1;
  903. $like = GussNovelService::instance()->getLikedNovels($this->campaginArr['userInfo']->sex,6);
  904. $this->assign('popType', $this->campaginArr['popType']);
  905. $this->assign('like', $like);
  906. $this->assign('dateNum', $dateNum);
  907. $this->assign('webStatus', $this->campaginArr['status']);
  908. $this->assign('userMatch', $this->campaginArr['userMatch'] );
  909. $this->assign('curMatch', $curMatch);
  910. $this->assign('userId', $this->campaginArr['userInfo']->id);
  911. return $this->view->fetch('index@recharge/campaign/clockIn');
  912. break;
  913. }
  914. }
  915. /**
  916. * 初始化 状态
  917. */
  918. private function campaignInit(){
  919. $this->campaginArr['activeId'] = $this->request->get('active_id') ?? 1;
  920. $this->campaginArr['userInfo'] = UserService::instance()->getUserInfo();
  921. // if( $realKandian = FinancialService::instance()->getTotalKandian($this->campaginArr['userInfo']->id)->data ){
  922. // $this->campaginArr['userInfo']->kandian = $realKandian;
  923. // };
  924. $this->campaginArr['popType'] = 0;//弹窗状态
  925. $this->campaginArr['channelUrl'] = getCurrentDomain($this->campaginArr['userInfo']->channel_id);
  926. $this->campaginArr['active'] = CampaignService::instance()->getActivityById( $this->campaginArr['activeId']);
  927. $this->campaginArr['userMatch'] = CampaignService ::instance()->getUserMatch( $this->campaginArr['userInfo']->id );
  928. //失败时判断活动是否结束
  929. $this->campaginArr['active']['next'] = 0;//给前端提供状态 是否有下一场
  930. $curDate = time();
  931. $status = -1;
  932. //没有活动
  933. if ( empty( $this->campaginArr['active'] ) ){
  934. $status = -1; //活动未开
  935. $this->campaginArr['status'] = $status;
  936. return ;
  937. }
  938. //活动设置为无效
  939. if ( $this->campaginArr['active']['status'] == 'hidden' && empty($this->campaginArr['userMatch']) ){
  940. $status = -1; //活动暂停
  941. $this->campaginArr['status'] = $status;
  942. return ;
  943. }
  944. // dump($this->campaginArr['active']);exit;
  945. //活动不在时间范围内
  946. if ( ($this->campaginArr['active']['start_time'] > $curDate || $this->campaginArr['active']['end_time'] < $curDate) ){
  947. if ( empty($this->campaginArr['userMatch']) || in_array( $this->campaginArr['userMatch']['status'], [4,5,6])){//已领奖 或 失败状态 未领奖 显示报名下一场
  948. $status = -1; //活动未开
  949. $this->campaginArr['status'] = $status;
  950. return ;
  951. }
  952. }else{ //活动进行中
  953. if ( empty($this->campaginArr['userMatch']) || in_array( $this->campaginArr['userMatch']['status'], [4,5,6]) ){
  954. $status = 0; //活动开始 ,没有报名
  955. $this->campaginArr['status'] = $status;
  956. return ;
  957. }
  958. }
  959. //判断用户最后一次参加的活动是不是 当前推广的活动
  960. try{
  961. if ( $this->campaginArr['activeId'] != $this->campaginArr['userMatch']['active_id'] ){
  962. $this->campaginArr['activeId'] = $this->campaginArr['userMatch']['active_id'];
  963. $this->campaginArr['active'] = CampaignService::instance()->getActivityById( $this->campaginArr['userMatch']['active_id'] );
  964. }
  965. }catch ( \Throwable $th ){
  966. LogService::error('活动首页 error001'.$th->getMessage());
  967. }
  968. $days = intval(($curDate-strtotime($this->campaginArr['userMatch']['match_date']))/86400);
  969. $day = $days - $this->campaginArr['userMatch']['num']; //应该打卡天数-实际打卡天数
  970. switch ( $day ){
  971. case 0:
  972. switch ( $this->campaginArr['userMatch']['status'] ){
  973. case 1:
  974. $status = 2; //报名成功, 明日打卡
  975. break;
  976. case 2:
  977. $status = 3; //打卡成功
  978. break;
  979. case 3:
  980. $status = 4; //挑战成功 明天领奖
  981. break;
  982. default:
  983. $status = 8; //成功推荐下一场
  984. break;
  985. }
  986. break;
  987. case 1:
  988. switch ($this->campaginArr['userMatch']['status'] ){
  989. case 3:
  990. $status = 6; //领奖页面
  991. break;
  992. default:
  993. $status = 5; //打卡
  994. break;
  995. }
  996. break;
  997. case 2:
  998. switch ( $this->campaginArr['userMatch']['status'] ){
  999. case 3:
  1000. $status = 6; //领奖页面
  1001. break;
  1002. default:
  1003. if ($this->campaginArr['userMatch']['is_again'] >=1){
  1004. $status = 9; //失败
  1005. }else{
  1006. $status = 7; //补卡
  1007. }
  1008. break;
  1009. }
  1010. break;
  1011. case 3:
  1012. if ($this->campaginArr['userMatch']['status'] == 3){
  1013. $status = 6;//领奖
  1014. }else{
  1015. $status = 9;
  1016. }
  1017. break;
  1018. default:
  1019. if ($this->campaginArr['userMatch']['status'] == 3){
  1020. $status = 14;//未领奖
  1021. }else{
  1022. $status = 9;
  1023. }
  1024. break;
  1025. }
  1026. if ( $this->campaginArr['active']['end_time'] > time() ){
  1027. $this->campaginArr['active']['next'] = 1;
  1028. $status = $status == 9 ? 12 : $status;
  1029. }else{
  1030. $this->campaginArr['active']['next'] = 0;//给前端提供状态 是否有下一场
  1031. }
  1032. //自动补卡
  1033. if ($status == 7){
  1034. $cSign = MyScene::getInstance($this->campaginArr['userInfo']->id, $this->campaginArr['userMatch']['match_id'])->cSign();
  1035. if ( $cSign['code'] == 200 ){ //补卡成功
  1036. $status = 10; //重新加载页面
  1037. }else{
  1038. $obj = CampaignService::instance()->setUserMatchFirstLogin($this->campaginArr['userInfo']->id);
  1039. $status = $obj ? $status : 13; //状态13 不进行页面弹窗
  1040. }
  1041. }
  1042. if ( $status == 2 ){//是否需要弹窗
  1043. $this->campaginArr['popType'] = Redis::instance()->del(CampaignConstants::getUserMatchFirstLogin($this->campaginArr['userInfo']->id));
  1044. }
  1045. $this->campaginArr['status'] = $status;
  1046. return ;
  1047. }
  1048. /**
  1049. * 我的挑战页面
  1050. * wud
  1051. */
  1052. public function myRecharge(){
  1053. $statusArr = [
  1054. 3=>'挑战中',
  1055. 4=>'挑战成功',
  1056. 5=>'挑战失败',
  1057. ];
  1058. $statusClass = [
  1059. 6=>'recharge_success ',
  1060. 4=>'recharge_success ',
  1061. 5=>'recharge_fail ',
  1062. ];
  1063. $sum = [
  1064. 'kandian_sum'=>0,
  1065. 'success_num'=>0,
  1066. 'reward_sum'=>0
  1067. ];
  1068. $userId = UserService::instance()->getUserInfo()->id;
  1069. $data = CampaignService::instance()->getUserRecharge( $userId );
  1070. $res=[
  1071. 'success'=>[],
  1072. 'ing'=>[],
  1073. 'fail'=>[],
  1074. ];
  1075. if ( !empty($data) ){
  1076. foreach( $data as $kk => $vv){
  1077. $sum['kandian_sum'] += $vv['kandian'];
  1078. if ($vv['status'] == 4 || $vv['status'] == 6){
  1079. $res['success'][] = $vv;
  1080. $sum['success_num'] ++;
  1081. $sum['reward_sum'] += $vv['reward'];
  1082. }
  1083. if ($vv['status'] <=3 ){
  1084. $res['ing'][] = $vv;
  1085. }
  1086. if ( $vv['status'] == 5 ){
  1087. $res['fail'][] = $vv;
  1088. }
  1089. }
  1090. unset($data);
  1091. }
  1092. $this->assign('sum', $sum );
  1093. $this->assign('match', $res );
  1094. return $this->fetch('index@recharge/campaign/myRecharge');
  1095. }
  1096. /**
  1097. * 测试
  1098. */
  1099. public function getRedisKeyTest()
  1100. {
  1101. // $userInfo['id'] = 135180;
  1102. // $userInfo['openid'] = "oxoco5zkESE0wf-IzxzUzZ0pytvQ";
  1103. // $orders = [
  1104. // 'order_id'=>62,
  1105. // 'money'=>1,
  1106. // 'kandian'=>20,
  1107. // 'channel_id'=>183,
  1108. // ];
  1109. // echo 'begin';
  1110. // MqUserPayCancelService::instance()->sendActiveToUser( $orders,$userInfo );
  1111. // $key = $this->request->get('key');
  1112. // $func = $this->request->get('func');
  1113. // $res = Redis::instance()->$func($key);
  1114. // dump($res);
  1115. }
  1116. public function subscription()
  1117. {
  1118. //跳转到支付域名
  1119. if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名
  1120. $userInfo = UserService::instance()->getUserInfo();
  1121. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($userInfo->channel_id);
  1122. $menuophost = $adminConfig['menuophost'] ?? null;
  1123. $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  1124. if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) {
  1125. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'];
  1126. } else {
  1127. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'];
  1128. }
  1129. $payHost .= '/index/recharge/subscription?';
  1130. $params['from'] = 'wechat';
  1131. $params['admin_id'] = $adminConfig['admin_id'];
  1132. $params['channel_id'] = $userInfo->channel_id;
  1133. $params['user_id'] = $userInfo->id;
  1134. $params['sub_code'] = $this->request->param('sub_code');
  1135. $params['type'] = $this->request->param('type');
  1136. $payHost .= http_build_query($params);
  1137. $this -> redirect($payHost);
  1138. }
  1139. //获取分享码
  1140. $subCode = $this->request->request('sub_code',0);
  1141. $userInfo = UserService::instance()->getUserInfo();
  1142. if (empty($userInfo)){
  1143. return $this->error('用户信息错误');
  1144. }
  1145. //获取业务域名
  1146. $channelUrl = getCurrentDomain($userInfo->channel_id);
  1147. //是否关注
  1148. $isFan = $userInfo->is_subscribe;
  1149. //是否已经报名活动
  1150. $subSer = SubscripService::instance();
  1151. $actUserInfo = $subSer->getActivityUser($userInfo);
  1152. $today = date('Ymd',time());
  1153. //acting 0 没有报名 1 报名当天 2 活动中
  1154. $actIng = empty($actUserInfo) ? 0 : ($actUserInfo['act_date'] == $today ? 1 : 2);
  1155. if (!empty($actUserInfo) && $actUserInfo['act_end_date'] < $today){//如果用户参加的活动已经结束
  1156. $actIng = 0;
  1157. }
  1158. //如果报名 获取报名场次的活动信息
  1159. $date = $actIng ? $actUserInfo['act_date'] : $today;
  1160. $activity = $subSer->getActivity($date);
  1161. //活动结束
  1162. if (empty($activity)){
  1163. return $this->error('活动未开始');
  1164. }
  1165. //获取最近的阅读记录
  1166. $recent = model('UserRecentlyRead')->getRecentlyRead(0, 1, null, true);
  1167. $channelUrl .= $recent['totalNum'] ? "index/user/recent" : "index/index/index";
  1168. $this->assign('ishaveRecent',$recent['totalNum']);
  1169. $this->assign('channelUrl',$channelUrl);
  1170. $this->assign('subCode',$subCode);
  1171. $this->assign('acting',$actIng);
  1172. $this->assign('isfan',$isFan);
  1173. return $this->fetch('index@recharge/subscrip/index',['activity'=>$activity]);
  1174. }
  1175. //充值单页
  1176. public function singlepage()
  1177. {
  1178. //跳转到支付域名
  1179. if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名
  1180. $userInfo = UserService::instance()->getUserInfo();
  1181. $adminConfig = $this->adminconfig;
  1182. $menuophost = $adminConfig['menuophost'] ?? null;
  1183. $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  1184. if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) {
  1185. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'];
  1186. } else {
  1187. $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'];
  1188. }
  1189. $params['from'] = 'wechat';
  1190. $params['user_id'] = $userInfo->id;
  1191. $payHost .= '/index/recharge/singlepage?';
  1192. $payHost .= http_build_query($params);
  1193. $this -> redirect($payHost);
  1194. }
  1195. if (!isset($userInfo)){
  1196. $userInfo = UserService::instance()->getUserInfo();
  1197. }
  1198. $pageId = $this->request->param('page_id',1);
  1199. $data = model("PrivateBookPage")->getResourceList($pageId);
  1200. if (empty($data) || !isset($data['resource'])){
  1201. $this->success('活动结束');
  1202. }
  1203. $data['end_time'] = ($data['end_time'] - time())*1000;
  1204. // dump($data);
  1205. $bookIds = array_column($data['resource'],'book_id');
  1206. $payBookIds = SinglePushService::instance()->isPayBook($bookIds,$userInfo);
  1207. foreach ($data['resource'] as $k =>&$v){
  1208. $v['is_pay'] = in_array($v['book_id'],$payBookIds) ? 1 : 0;
  1209. }
  1210. $tpl = 'page_single_push';
  1211. $channelUrl = getCurrentDomain($userInfo->channel_id);
  1212. $this->view->assign('channelUrl', $channelUrl);
  1213. $this->view->assign('data', $data);
  1214. return $this->fetch('index@recharge/singlepage/'.$tpl);
  1215. }
  1216. }