Base.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use app\common\controller\All;
  5. use ip_limit\IpLocationQuery;
  6. class Base extends All
  7. {
  8. var $_group;
  9. var $_user;
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. $this->check_ip_limit();
  14. $this->check_site_status();
  15. $this->label_maccms();
  16. $this->check_browser_jump();
  17. $this->label_user();
  18. }
  19. protected function check_ip_limit()
  20. {
  21. // 获取IP限制配置
  22. $mainland_ip_limit = $GLOBALS['config']['site']['mainland_ip_limit'] ?? "0";
  23. // 如果为0,不限制,直接通过
  24. if ($mainland_ip_limit == "0") {
  25. return;
  26. }
  27. // 获取用户真实IP
  28. $user_ip = mac_get_client_ip();
  29. try {
  30. $ipQuery = new IpLocationQuery();
  31. $country_code = $ipQuery->queryProvince($user_ip);
  32. // 根据配置进行限制
  33. if ($mainland_ip_limit == "1") {
  34. // 只允许中国大陆IP
  35. if ($country_code === "") {
  36. echo $this->fetch('public/close');
  37. die;
  38. }
  39. } elseif ($mainland_ip_limit == "2") {
  40. // 不允许中国大陆IP
  41. if ($country_code !== "") {
  42. echo $this->fetch('public/close');
  43. die;
  44. }
  45. }
  46. } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
  47. // 局域网IP或无效IP,直接通过
  48. return;
  49. } catch (\Exception $e) {
  50. // 其他异常
  51. return;
  52. }
  53. }
  54. public function _empty()
  55. {
  56. header("HTTP/1.0 404 Not Found");
  57. echo '<script>setTimeout(function (){location.href="'.MAC_PATH.'";},'.(2000).');</script>';
  58. $msg = lang('page_not_found');
  59. abort(404,$msg);
  60. exit;
  61. }
  62. protected function check_show($aj=0)
  63. {
  64. if($GLOBALS['config']['app']['show'] ==0){
  65. echo $this->error(lang('show_close'));
  66. exit;
  67. }
  68. if($GLOBALS['config']['app']['show_verify'] ==1 && $aj==0){
  69. if(empty(session('show_verify'))){
  70. mac_no_cahche();
  71. $this->assign('type','show');
  72. echo $this->label_fetch('public/verify');
  73. exit;
  74. }
  75. }
  76. }
  77. protected function check_ajax()
  78. {
  79. if($GLOBALS['config']['app']['ajax_page'] ==0){
  80. echo $this->error(lang('ajax_close'));
  81. exit;
  82. }
  83. }
  84. protected function check_search($param,$aj=0)
  85. {
  86. if($GLOBALS['config']['app']['search'] ==0){
  87. echo $this->error(lang('search_close'));
  88. exit;
  89. }
  90. if($param['page']==1 && mac_get_time_span("last_searchtime") < $GLOBALS['config']['app']['search_timespan']){
  91. echo $this->error(lang('search_frequently')."".$GLOBALS['config']['app']['search_timespan']."".lang('seconds'));
  92. exit;
  93. }
  94. if($GLOBALS['config']['app']['search_verify'] ==1 && $aj ==0){
  95. if(empty(session('search_verify'))){
  96. mac_no_cahche();
  97. $this->assign('type','search');
  98. echo $this->label_fetch('public/verify');
  99. exit;
  100. }
  101. }
  102. }
  103. protected function check_site_status()
  104. {
  105. if ($GLOBALS['config']['site']['site_status'] == 0) {
  106. $this->assign('close_tip',$GLOBALS['config']['site']['site_close_tip']);
  107. echo $this->fetch('public/close');
  108. die;
  109. }
  110. }
  111. protected function check_browser_jump()
  112. {
  113. if (ENTRANCE=='index' && $GLOBALS['config']['app']['browser_junmp'] == 1) {
  114. $agent = $_SERVER['HTTP_USER_AGENT'];
  115. if(strpos($agent, 'QQ/')||strpos($agent, 'MicroMessenger')!==false){
  116. echo $this->fetch('public/browser');
  117. die;
  118. }
  119. }
  120. }
  121. protected function check_user_popedom($type_id,$popedom,$param=[],$flag='',$info=[],$trysee=0)
  122. {
  123. $user = $GLOBALS['user'];
  124. $group_ids = explode(',', $user['group_id']);
  125. $group_list = model('Group')->getCache();
  126. $res = false;
  127. foreach($group_ids as $group_id) {
  128. if(!isset($group_list[$group_id])) {
  129. continue;
  130. }
  131. $group = $group_list[$group_id];
  132. if(strpos(','.$group['group_type'],','.$type_id.',')!==false && !empty($group['group_popedom'][$type_id][$popedom])!==false){
  133. $res = true;
  134. break;
  135. }
  136. }
  137. $pre = $flag;
  138. $col = 'detail';
  139. if($flag=='play' || $flag=='down'){
  140. $pre = 'vod';
  141. $col = $flag;
  142. }
  143. if(in_array($pre,['art','vod','actor','website'])){
  144. $points = $info[$pre.'_points_'.$col];
  145. if($GLOBALS['config']['user'][$pre.'_points_type']=='1'){
  146. $points = $info[$pre.'_points'];
  147. }
  148. }
  149. if($GLOBALS['config']['user']['status']==0){
  150. }
  151. elseif($popedom==2 && in_array($pre,['art','actor','website'])){
  152. $has_permission = false;
  153. $has_trysee = false;
  154. foreach($group_ids as $group_id) {
  155. if(!isset($group_list[$group_id])) {
  156. continue;
  157. }
  158. $group = $group_list[$group_id];
  159. if(!empty($group['group_popedom'][$type_id][2])) {
  160. $has_permission = true;
  161. }
  162. if($trysee > 0) {
  163. $has_trysee = true;
  164. }
  165. }
  166. if($res===false){
  167. if($has_trysee){
  168. return ['code'=>1,'msg'=>lang('controller/in_try_see'),'trysee'=>$trysee];
  169. }
  170. return ['code'=>3001,'msg'=>lang('controller/no_popedom'),'trysee'=>0];
  171. }
  172. if(max($group_ids)<3 && $points>0){
  173. $mid = mac_get_mid($pre);
  174. $where=[];
  175. $where['ulog_mid'] = $mid;
  176. $where['ulog_type'] = 1;
  177. $where['ulog_rid'] = $param['id'];
  178. $where['ulog_sid'] = $param['page'];
  179. $where['ulog_nid'] = 0;
  180. $where['user_id'] = $user['user_id'];
  181. $where['ulog_points'] = $points;
  182. if($GLOBALS['config']['user'][$pre.'_points_type']=='1'){
  183. $where['ulog_sid'] = 0;
  184. }
  185. $res = model('Ulog')->infoData($where);
  186. if($res['code'] > 1) {
  187. return ['code'=>3003,'msg'=>lang('controller/pay_play_points',[$points]),'points'=>$points,'confirm'=>1,'trysee'=>0];
  188. }
  189. }
  190. }
  191. elseif($popedom==3){
  192. $has_permission = false;
  193. foreach($group_ids as $group_id) {
  194. if(!isset($group_list[$group_id])) {
  195. continue;
  196. }
  197. $group = $group_list[$group_id];
  198. if(!empty($group['group_popedom'][$type_id][5])) {
  199. $has_permission = true;
  200. break;
  201. }
  202. }
  203. if ($res === false) {
  204. if ($has_permission && max($group_ids) < 3) {
  205. return ['code'=>3002,'msg'=>lang('controller/in_try_see'),'trysee'=>$trysee];
  206. }
  207. else {
  208. return ['code'=>3001,'msg'=>lang('controller/no_popedom'),'trysee'=>0];
  209. }
  210. }
  211. if(max($group_ids)<3 && $points>0){
  212. $where=[];
  213. $where['ulog_mid'] = 1;
  214. $where['ulog_type'] = $flag=='play' ? 4 : 5;
  215. $where['ulog_rid'] = $param['id'];
  216. $where['ulog_sid'] = $param['sid'];
  217. $where['ulog_nid'] = $param['nid'];
  218. $where['user_id'] = $user['user_id'];
  219. $where['ulog_points'] = $points;
  220. if($GLOBALS['config']['user']['vod_points_type']=='1'){
  221. $where['ulog_sid'] = 0;
  222. $where['ulog_nid'] = 0;
  223. }
  224. $res_ulog = model('Ulog')->infoData($where);
  225. if($res_ulog['code'] > 1) {
  226. return ['code'=>3003,'msg'=>lang('controller/pay_play_points',[$points]),'points'=>$points,'confirm'=>1,'trysee'=>0];
  227. }
  228. }
  229. }
  230. else{
  231. if($res===false){
  232. return ['code'=>1001,'msg'=>lang('controller/no_popedom')];
  233. }
  234. if($popedom == 4){
  235. if(max($group_ids)==1 && $points>0){
  236. return ['code'=>4001,'msg'=>lang('controller/charge_data'),'trysee'=>0];
  237. }
  238. elseif(max($group_ids)==2 && $points>0){
  239. $where=[];
  240. $where['ulog_mid'] = 1;
  241. $where['ulog_type'] = $flag=='play' ? 4 : 5;
  242. $where['ulog_rid'] = $param['id'];
  243. $where['ulog_sid'] = $param['sid'];
  244. $where['ulog_nid'] = $param['nid'];
  245. $where['user_id'] = $user['user_id'];
  246. $where['ulog_points'] = $points;
  247. if($GLOBALS['config']['user']['vod_points_type']=='1'){
  248. $where['ulog_sid'] = 0;
  249. $where['ulog_nid'] = 0;
  250. }
  251. $res = model('Ulog')->infoData($where);
  252. if($res['code'] > 1) {
  253. return ['code'=>4003,'msg'=>lang('controller/pay_down_points',[$points]),'points'=>$points,'confirm'=>1,'trysee'=>0];
  254. }
  255. }
  256. }
  257. elseif($popedom==5){
  258. $has_permission = false;
  259. $has_trysee = false;
  260. foreach($group_ids as $group_id) {
  261. if(!isset($group_list[$group_id])) {
  262. continue;
  263. }
  264. $group = $group_list[$group_id];
  265. if(!empty($group['group_popedom'][$type_id][3])) {
  266. $has_permission = true;
  267. }
  268. if(!empty($group['group_popedom'][$type_id][5])) {
  269. $has_trysee = true;
  270. }
  271. }
  272. if(!$has_permission && $has_trysee && max($group_ids) < 3){
  273. $where=[];
  274. $where['ulog_mid'] = 1;
  275. $where['ulog_type'] = $flag=='play' ? 4 : 5;
  276. $where['ulog_rid'] = $param['id'];
  277. $where['ulog_sid'] = $param['sid'];
  278. $where['ulog_nid'] = $param['nid'];
  279. $where['user_id'] = $user['user_id'];
  280. $where['ulog_points'] = $points;
  281. if($GLOBALS['config']['user']['vod_points_type']=='1'){
  282. $where['ulog_sid'] = 0;
  283. $where['ulog_nid'] = 0;
  284. }
  285. $res = model('Ulog')->infoData($where);
  286. if($points>0 && $res['code'] == 1) {
  287. return ['code'=>5001,'msg'=>lang('controller/popedom_ok')];
  288. }
  289. if ($user['user_id'] > 0) {
  290. if ($points > intval($user['user_points'])) {
  291. return ['code'=>5002,'msg'=>lang('controller/not_enough_points',[$points,$user['user_points'] ]),'trysee'=>$trysee];
  292. }
  293. else {
  294. return ['code'=>5001,'msg'=>lang('controller/try_see_end',[$points, $user['user_points']]),'trysee'=>$trysee];
  295. }
  296. }
  297. else {
  298. if ($points > 0) {
  299. return ['code'=>5002,'msg'=>lang('controller/not_enough_points',[$points,$user['user_points'] ]),'trysee'=>$trysee];
  300. }
  301. else {
  302. return ['code'=>5001,'msg'=>lang('controller/try_see_end',[$points, $user['user_points']]),'trysee'=>$trysee];
  303. }
  304. }
  305. }
  306. }
  307. }
  308. return ['code'=>1,'msg'=>lang('controller/popedom_ok')];
  309. }
  310. }