CommonBaseController.class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?php
  2. namespace bibidd\Controller;
  3. use Think\Controller;
  4. /**
  5. * 公共控制器,用于封装公函数。 v2.0 by:bingtan11
  6. */
  7. class CommonBaseController extends Controller
  8. {
  9. /**
  10. * 添加相应头
  11. * @return void
  12. */
  13. protected function addHeaders()
  14. {
  15. header('Content-Type:text/json;charset=utf-8');
  16. header('Access-Control-Allow-Origin:*');
  17. header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
  18. header('Access-Control-Allow-Methods:POST');
  19. header('Access-Control-Expose-Headers:*');
  20. }
  21. /**
  22. * 检查登录用户ID
  23. * @param $uid
  24. * @return void
  25. */
  26. protected function checkUserIsExist($uid)
  27. {
  28. if (empty($uid)) {
  29. $this->returnDataAndSendMsg("用户不存在");
  30. die();
  31. }
  32. $userInfo = M("user_info")->where("id='$uid'")->find();
  33. if (empty($userInfo)) {
  34. $this->returnDataAndSendMsg("用户不存在");
  35. die();
  36. }
  37. return $userInfo;
  38. }
  39. protected function returnData()
  40. {
  41. $this->addHeaders();
  42. $data['status'] = '0';
  43. $data['code'] = '202';//未携带参数,请求失败
  44. $data['message'] = 'error';
  45. echo json_encode($data);
  46. }
  47. protected function returnDataAndSendMsg($errMsg)
  48. {
  49. $this->addHeaders();
  50. $data['status'] = '0';
  51. $data['code'] = '202';//未携带参数,请求失败
  52. $data['message'] = $errMsg;
  53. echo json_encode($data);
  54. }
  55. /**
  56. * 为list数组添加广告
  57. * @param $adv_type 需要添加的广告类型
  58. * @param $adv_number 需要添加广告数
  59. * @param $start_point 追加的开始位置
  60. * @param $dataList 原始数组
  61. * @return void
  62. */
  63. protected function addAdvForDataList($adv_type, $adv_number, $start_point, $dataList)
  64. {
  65. $return_data = $dataList;
  66. //获取广告
  67. $adv_list = M("slgj_advert_list")->where("type='$adv_type'")->Field("img,jump_link,number")->order("rand()")->LIMIT($adv_number)->select();
  68. $jia_num = $start_point;
  69. $qishi_num = 0;
  70. $data_list_number = count($dataList);
  71. $quzheng_num = floor($data_list_number / $start_point);
  72. foreach ($adv_list as $key => $value) {
  73. $charu_array = array();
  74. $charu_array = array($adv_list[$key]);
  75. array_splice($return_data, $jia_num, 0, $charu_array);
  76. $jia_num += ($start_point + 1);
  77. $qishi_num += 1;
  78. if ($qishi_num >= $quzheng_num) {
  79. break;
  80. }
  81. }
  82. return $return_data;
  83. }
  84. protected function addAdvForDataList_increase($adv_type, $adv_number, $start_point, $dataList, $increase_num)
  85. {
  86. $return_data = $dataList;
  87. //获取广告
  88. $adv_list = M("slgj_advert_list")->where("type='$adv_type'")->Field("img,jump_link,number")->order("rand()")->LIMIT($adv_number)->select();
  89. $jia_num = $start_point;
  90. $qishi_num = 0;
  91. $data_list_number = count($dataList);
  92. $quzheng_num = floor($data_list_number / $start_point);
  93. foreach ($adv_list as $key => $value) {
  94. $charu_array = array();
  95. $charu_array = array($adv_list[$key]);
  96. array_splice($return_data, $jia_num, 0, $charu_array);
  97. $jia_num += ($increase_num + 1);
  98. $qishi_num += 1;
  99. if ($qishi_num >= $quzheng_num) {
  100. break;
  101. }
  102. }
  103. return $return_data;
  104. }
  105. /**
  106. *
  107. * 穿插数据
  108. * @param $src_data_list 被需要追加的列表
  109. * @param $insert_data_list 需要追加的列表
  110. * @param $start_point 追加启始位置,下标为0
  111. * @param $increase_num 增长数,间隔多少条数据插入
  112. * @return void
  113. */
  114. protected function insert_data_list($src_data_list, $insert_data_list, $start_point, $increase_num)
  115. {
  116. $return_data = $src_data_list;
  117. //获取广告
  118. $adv_list = $insert_data_list;
  119. $jia_num = $start_point;
  120. $qishi_num = 0;
  121. $data_list_number = count($src_data_list);
  122. $quzheng_num = floor($data_list_number / $increase_num);
  123. foreach ($adv_list as $key => $value) {
  124. $charu_array = array();
  125. $charu_array = array($adv_list[$key]);
  126. array_splice($return_data, $jia_num, 0, $charu_array);
  127. $jia_num += ($increase_num + 1);
  128. $qishi_num += 1;
  129. if ($qishi_num >= $quzheng_num) {
  130. break;
  131. }
  132. }
  133. return $return_data;
  134. }
  135. /**
  136. * 发送手机验证码
  137. * @param $mobile
  138. * @param $code
  139. * @return mixed
  140. */
  141. protected function sendMessage($mobile, $code)
  142. {
  143. // $mobile = ""; // 多个号码可用逗号分隔,最多200个
  144. $content = "您的验证码:" . $code . ",如非本人操作,请忽略本短信!"; // string 不建议太长
  145. $encode = "utf-8"; // 可选参数
  146. //可传 notify 或 ad , adcard,adfangchan,dxztd 五参数, notify: 表示通知类, ad: 表示106通道广告类,
  147. // adcard: 表示卡发通道广告类, adfangchan:表示106房产专用通道,dxztd:表示低限制通道,
  148. // 严禁用通知类发广告,否则将关掉api接口同时封帐号不退余额,严重的提交相关部门处理。
  149. $smstype = 'notify';
  150. $url = "http://www.huiyuandx.com/api/sms_send?";
  151. $url .= "user=liujinzaixian&";
  152. $url .= "hash=ab7d44b9599db2e2b4d2bf5ab35666cb&";
  153. $url .= "encode=$encode&";
  154. $url .= "smstype=$smstype&";
  155. $url .= "mobile=" . urlencode($mobile) . "&content=" . urlencode($content) . "";
  156. $ctx = stream_context_create(array(
  157. 'http' => array(
  158. 'timeout' => 30,
  159. 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;YNSMS API v1.0;)"
  160. )
  161. )
  162. );
  163. $r = file_get_contents($url, 0, $ctx);
  164. $rs = json_decode($r, true);
  165. return $rs;
  166. }
  167. /*
  168. * 生成随机字符串
  169. *
  170. * $length 字符串长度
  171. */
  172. protected function random_str($length)
  173. {
  174. // 密码字符集,可任意添加你需要的字符
  175. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  176. $str = '';
  177. for ($i = 0; $i < $length; $i++) {
  178. $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  179. }
  180. return $str;
  181. }
  182. protected function random_num($length)
  183. {
  184. // 密码字符集,可任意添加你需要的字符
  185. $chars = '1234567890';
  186. $str = '';
  187. for ($i = 0; $i < $length; $i++) {
  188. $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  189. }
  190. return $str;
  191. }
  192. protected function getIp()
  193. {
  194. if (isset($_SERVER['http_cf_connecting_ip'])) { // 支持Cloudflare
  195. $ip = $_SERVER['http_cf_connecting_ip'];
  196. } elseif (isset($_SERVER['REMOTE_ADDR']) === true) {
  197. $ip = $_SERVER['REMOTE_ADDR'];
  198. if (preg_match('/^(?:127|10)\.0\.0\.[12]?\d{1,2}$/', $ip)) {
  199. if (isset($_SERVER['HTTP_X_REAL_IP'])) {
  200. $ip = $_SERVER['HTTP_X_REAL_IP'];
  201. } elseif (isset($_SERVER['http_x_forewarded_for'])) {
  202. $ip = $_SERVER['http_x_forewarded_for'];
  203. }
  204. }
  205. } else {
  206. $ip = '127.0.0.1';
  207. }
  208. if (in_array($ip, ['::1', '0.0.0.0', '本地主机'], true)) {
  209. $ip = '127.0.0.1';
  210. }
  211. $filter = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
  212. if ($filter === false) {
  213. $ip = '127.0.0.1';
  214. }
  215. return $ip;
  216. }
  217. /**
  218. * 发送消息
  219. * @return void
  220. */
  221. protected function send_msg_to_telegram($botToken, $chatId, $text)
  222. {
  223. //$botToken = $_POST['token'];
  224. $website = "https://api.telegram.org/bot" . $botToken;
  225. //$chatId = $_POST['chatId']; // 你想要发送消息的聊天ID
  226. //$text = $_POST['text'];
  227. $params = [
  228. 'chat_id' => $chatId,
  229. 'text' => $text
  230. ];
  231. $ch = curl_init($website . '/sendMessage');
  232. curl_setopt($ch, CURLOPT_HEADER, false);
  233. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  234. curl_setopt($ch, CURLOPT_POST, 1);
  235. curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
  236. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  237. $result = curl_exec($ch);
  238. if ($result === false) {
  239. // 如果请求失败,获取错误信息
  240. $error = curl_error($ch);
  241. $error_code = curl_errno($ch);
  242. // 输出错误信息
  243. curl_close($ch);
  244. return $error;
  245. }
  246. curl_close($ch);
  247. if ($result !== false) {
  248. // 如果请求成功,你可以对结果进行处理
  249. $response = json_decode($result, true);
  250. return $response;
  251. }
  252. }
  253. /**
  254. *
  255. * 根据用户ip返回用户的省和市的信息
  256. * @param $ip
  257. * @return mixed
  258. */
  259. protected function get_user_ip_info($ip)
  260. {
  261. $appId = "clLLhaWabJJnrWjE";
  262. $appSecret = "9e82fed66e40e3e438f3fe416a95925a";
  263. $url = "https://api.jumdata.com/ip/query";
  264. $method = "POST";
  265. $headers = array();
  266. //根据API的要求,定义相对应的Content-Type
  267. array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
  268. $timestamp = $this->getUnixTimestamp();
  269. $sign = hash('sha256', $appId . $appSecret . $timestamp); // 生成sign
  270. $bodys = "appId=" . $appId . "&sign=" . $sign . "&timestamp=" . $timestamp . "&productCode=ip_query" . "&ip=" . $ip;
  271. $curl = curl_init();
  272. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  273. curl_setopt($curl, CURLOPT_URL, $url);
  274. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  275. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  276. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  277. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  278. if (1 == strpos("$" . $url, "https://")) {
  279. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  280. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  281. }
  282. $return = curl_exec($curl);
  283. $return_end = json_decode($return, true);
  284. return $return_end;
  285. }
  286. protected function getUnixTimestamp()
  287. {
  288. list($s1, $s2) = explode(' ', microtime());
  289. return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
  290. }
  291. /**
  292. * 处理文件上传
  293. * @param $files
  294. * @return array
  295. */
  296. protected function dealFiles($files)
  297. {
  298. $fileArray = array();
  299. $n = 0;
  300. if (is_array($files['name'])) {
  301. $keys = array_keys($files);
  302. foreach ($files['name'] as $key => $value) {
  303. foreach ($keys as $_key) {
  304. $fileArray[$n][$_key] = $files[$_key][$key];
  305. }
  306. $n++;
  307. }
  308. } else {
  309. $fileArray = $files; // 单个文件上传
  310. }
  311. return $fileArray;
  312. }
  313. /**
  314. * 通过id查找元素
  315. * @param $batch_list
  316. * @param $id
  317. * @return mixed
  318. */
  319. protected function get_info_by_batch($batch_list, $id, $field_name)
  320. {
  321. foreach ($batch_list as $info) {
  322. if ($info[$field_name] == $id) {
  323. $found = $info;
  324. break; // 找到后退出循环
  325. }
  326. }
  327. return $found;
  328. }
  329. /**
  330. * uploader 对应到付费类型
  331. * @param $uploader
  332. * @return string
  333. */
  334. public function uploader_map_to_pay_type($uploader)
  335. {
  336. //$uploader= $_POST['uploader'];
  337. $map = array(
  338. //'亚洲'=>'免费',
  339. // '欧美'=>'免费',
  340. // '动漫'=>'免费',
  341. // '吃瓜'=>'免费',
  342. '同城' => '金币',
  343. '网曝门' => '金币',
  344. '另类猎奇' => '金币',
  345. '女子SPA' => '金币',
  346. '经典AV' => '金币',
  347. '厕所偷拍' => '金币',
  348. '抄底偷拍' => '金币',
  349. '色情聊天' => '金币',
  350. '黑料吃瓜' => '金币',
  351. '粉嫩少女' => '金币',
  352. '顶臀街射' => '金币',
  353. '漫画' => '金币',
  354. '素人反差' => '金币',
  355. '色情小说' => '金币',
  356. );
  357. $rs = empty($map[$uploader]) ? '会员' : $map[$uploader];
  358. return $rs;
  359. }
  360. /**
  361. * 注册用户数统计
  362. * @param $invitation_code
  363. * @return void
  364. */
  365. protected function proxy_reg_count($invitation_code, $sub_uid, $sub_name, $sub_reg_time)
  366. {
  367. if (empty($invitation_code) || "" == trim($invitation_code)) {
  368. return;
  369. }
  370. // 使用 preg_match 函数进行匹配
  371. if (!preg_match('/^[A-Z]{4}\d{4}$/', $invitation_code)) {
  372. return;
  373. }
  374. //验证码是否有效
  375. $user_info_check = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  376. if (empty($user_info_check)) {
  377. return;
  378. }
  379. //汇总表
  380. $huizong_inof = M("user_proxy_huizong")->where("invitation_code='$invitation_code'")->find();
  381. if (empty($huizong_inof)) {
  382. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  383. $Add_info['uid'] = $user_info['id'];
  384. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  385. $Add_info['renshu_all'] = 1;
  386. $Add_info['last_update'] = date('Y-m-d H:i:s');
  387. M("user_proxy_huizong")->add($Add_info);
  388. }
  389. if (!empty($huizong_inof)) {
  390. $id = $huizong_inof["id"];
  391. $Add_info['renshu_all'] = $huizong_inof['renshu_all'] + 1;
  392. $Add_info['last_update'] = date('Y-m-d H:i:s');
  393. M("user_proxy_huizong")->where("id='$id'")->save($Add_info);
  394. }
  395. //月度表
  396. $current_month = date('Y') . '-' . date('m');
  397. $month_inof = M("user_proxy_month")->where("date_month='$current_month' AND invitation_code='$invitation_code'")->find();
  398. if (empty($month_inof)) {
  399. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  400. $Add_info['uid'] = $user_info['id'];
  401. $Add_info['date_month'] = $current_month;
  402. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  403. $Add_info['renshu_all'] = 1;
  404. $Add_info['last_update'] = date('Y-m-d H:i:s');
  405. M("user_proxy_month")->add($Add_info);
  406. }
  407. if (!empty($month_inof)) {
  408. $id = $month_inof["id"];
  409. $Add_info['renshu_all'] = $month_inof['renshu_all'] + 1;
  410. $Add_info['last_update'] = date('Y-m-d H:i:s');
  411. M("user_proxy_month")->where("id='$id'")->save($Add_info);
  412. }
  413. //推荐子表汇总
  414. $sub_inof = M("user_proxy_sub")->where("invitation_code='$invitation_code' AND sub_uid='$sub_uid'")->find();
  415. if (empty($sub_inof)) {
  416. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  417. $Add_info['uid'] = $user_info['id'];
  418. $Add_info['date_month'] = $current_month;
  419. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  420. $Add_info['sub_uid'] = $sub_uid;
  421. $Add_info['sub_name'] = $sub_name;
  422. $Add_info['renshu_all'] = 1;
  423. $Add_info['sub_reg_time'] = date('Y-m-d h:i:s', $sub_reg_time);
  424. $Add_info['last_update'] = date('Y-m-d H:i:s');
  425. M("user_proxy_sub")->add($Add_info);
  426. }
  427. if (!empty($sub_inof)) {
  428. $id = $sub_inof["id"];
  429. $Add_info['renshu_all'] = $month_inof['renshu_all'] + 1;
  430. $Add_info['last_update'] = date('Y-m-d H:i:s');
  431. M("user_proxy_sub")->where("id='$id'")->save($Add_info);
  432. }
  433. }
  434. /**
  435. *
  436. * 统计用户充值
  437. * @param $uid 充值用户id
  438. * @param $money
  439. * @return void
  440. */
  441. protected function proxy_pay_count($uid, $money)
  442. {
  443. $user_info_tmp = M("user_info")->where("id = '$uid'")->find();
  444. $invitation_code = $user_info_tmp['register_invitation_code'];
  445. if (empty($invitation_code) || "" == trim($invitation_code)) {
  446. return;
  447. }
  448. // 使用 preg_match 函数进行匹配
  449. if (!preg_match('/^[A-Z]{4}\d{4}$/', $invitation_code)) {
  450. return;
  451. }
  452. //验证码是否有效
  453. $user_info_check = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  454. if (empty($user_info_check)) {
  455. return;
  456. }
  457. $choucheng = 0.5;
  458. //汇总表
  459. $huizong_inof = M("user_proxy_huizong")->where("invitation_code='$invitation_code'")->find();
  460. if (empty($huizong_inof)) {
  461. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  462. $Add_info['uid'] = $user_info['id'];
  463. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  464. $Add_info['chognzhi_all'] = $money;
  465. $Add_info['yongjin_all'] = $money * $choucheng;
  466. $Add_info['last_update'] = date('Y-m-d H:i:s');
  467. M("user_proxy_huizong")->add($Add_info);
  468. }
  469. if (!empty($huizong_inof)) {
  470. $id = $huizong_inof["id"];
  471. $Add_info['chognzhi_all'] = $huizong_inof['chognzhi_all'] + $money;
  472. $Add_info['yongjin_all'] = $huizong_inof['yongjin_all'] + $money * $choucheng;
  473. $Add_info['last_update'] = date('Y-m-d H:i:s');
  474. M("user_proxy_huizong")->where("id='$id'")->save($Add_info);
  475. }
  476. //月度表
  477. $current_month = date('Y') . '-' . date('m');
  478. $month_inof = M("user_proxy_month")->where("date_month='$current_month' AND invitation_code='$invitation_code'")->find();
  479. if (empty($month_inof)) {
  480. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  481. $Add_info['uid'] = $user_info['id'];
  482. $Add_info['date_month'] = $current_month;
  483. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  484. $Add_info['chognzhi_all'] = $money;
  485. $Add_info['yongjin_all'] = $money * $choucheng;
  486. $Add_info['last_update'] = date('Y-m-d H:i:s');
  487. M("user_proxy_month")->add($Add_info);
  488. }
  489. if (!empty($month_inof)) {
  490. $id = $month_inof["id"];
  491. $Add_info['chognzhi_all'] = $month_inof['chognzhi_all'] + $money;
  492. $Add_info['yongjin_all'] = $month_inof['yongjin_all'] + $money * $choucheng;
  493. $Add_info['last_update'] = date('Y-m-d H:i:s');
  494. M("user_proxy_month")->where("id='$id'")->save($Add_info);
  495. }
  496. //推荐子表汇总
  497. $sub_uid = $user_info_tmp['id'];
  498. $sub_inof = M("user_proxy_sub")->where("date_month='$current_month' AND invitation_code='$invitation_code' AND sub_uid='$sub_uid'")->find();
  499. if (empty($sub_inof)) {
  500. $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
  501. $Add_info['uid'] = $user_info['id'];
  502. $Add_info['date_month'] = $current_month;
  503. $Add_info['invitation_code'] = $user_info['my_invitation_code'];
  504. $Add_info['sub_uid'] = $user_info_tmp['id'];
  505. $Add_info['sub_name'] = $user_info_tmp['name'];
  506. $Add_info['sub_reg_time'] = $user_info_tmp['add_date'];
  507. $Add_info['chognzhi_all'] = $money;
  508. $Add_info['yongjin_all'] = $money * $choucheng;
  509. $Add_info['last_update'] = date('Y-m-d H:i:s');
  510. M("user_proxy_sub")->add($Add_info);
  511. }
  512. if (!empty($sub_inof)) {
  513. $id = $sub_inof["id"];
  514. $Add_info['chognzhi_all'] = $sub_inof['chognzhi_all'] + $money;
  515. $Add_info['yongjin_all'] = $sub_inof['yongjin_all'] + $money * $choucheng;
  516. $Add_info['last_update'] = date('Y-m-d H:i:s');
  517. M("user_proxy_sub")->where("id='$id'")->save($Add_info);
  518. }
  519. }
  520. /**
  521. * 统计充值数
  522. * @param $uid
  523. * @param $jinbi
  524. * @return void
  525. */
  526. protected function count_chongzhi($uid, $jinbi)
  527. {
  528. $sun_info = M("user_xf_cz_sum")->field("id")->where("uid='$uid'")->find();
  529. if (empty($sun_info)) {
  530. //插入
  531. $save_info["uid"] = $uid;
  532. $save_info["chongzhi_count"] = $jinbi;
  533. $save_info["start_time"] = date('Y-m-d H:i:s');
  534. $save_info["last_update_time"] = date('Y-m-d H:i:s');
  535. M("user_xf_cz_sum")->add($save_info);
  536. return;
  537. }
  538. //更新
  539. M("user_xf_cz_sum")->where("uid='$uid'")->setInc("chongzhi_count", $jinbi);
  540. $save_info["last_update_time"] = date('Y-m-d H:i:s');
  541. M("user_xf_cz_sum")->where("uid='$uid'")->save($save_info);
  542. }
  543. /**
  544. *
  545. * 记录消费明细,并添加消费统计
  546. * @param $uid
  547. * @param $item_name
  548. * @param $item_desc
  549. * @param $take_coins
  550. * @return void
  551. */
  552. protected function xiaofei_detail($uid, $item_name, $item_desc, $take_coins)
  553. {
  554. //打印统计数据
  555. $sun_info = M("user_xf_cz_sum")->field("id")->where("uid='$uid'")->find();
  556. if (empty($sun_info)) {
  557. //插入
  558. $save_info["uid"] = $uid;
  559. $save_info["xiaofei_count"] = $take_coins;
  560. $save_info["start_time"] = date('Y-m-d H:i:s');
  561. $save_info["last_update_time"] = date('Y-m-d H:i:s');
  562. M("user_xf_cz_sum")->add($save_info);
  563. } else {
  564. //更新
  565. M("user_xf_cz_sum")->where("uid='$uid'")->setInc("xiaofei_count", $take_coins);
  566. $save_info["last_update_time"] = date('Y-m-d H:i:s');
  567. M("user_xf_cz_sum")->where("uid='$uid'")->save($save_info);
  568. }
  569. //保存消费流水
  570. $xiaofei_info["uid"] = $uid;
  571. $xiaofei_info["item_name"] = $item_name;
  572. $xiaofei_info["item_desc"] = $item_desc;
  573. $xiaofei_info["take_coins"] = $take_coins;
  574. $xiaofei_info["creater_at"] = date('Y-m-d H:i:s');
  575. M("user_xf_detail")->add($xiaofei_info);
  576. }
  577. /**
  578. * 生成uuid
  579. * @return string
  580. * @throws \Exception
  581. */
  582. protected function generateUUIDv4()
  583. {
  584. $data = random_bytes(16);
  585. $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100
  586. $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10
  587. return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
  588. }
  589. protected function generateUUIDv4Nodash()
  590. {
  591. $data = random_bytes(16);
  592. $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100
  593. $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10
  594. return vsprintf('%s%s%s%s%s%s%s%s', str_split(bin2hex($data), 4));
  595. }
  596. /**
  597. * 统一拦截器
  598. * @return void
  599. */
  600. public function _initialize()
  601. {
  602. //需要跳过的接口请求
  603. $jump_urls = array(
  604. '/bibidd/Jiajin/jia',
  605. '/bibidd/Mediaonenine/twotwoone_list',
  606. '/bibidd/MediaPayonenine/call_back_coins',
  607. '/bibidd/Index/get_gonggao_url',
  608. '/bibidd/Advert/get_index_Advert',
  609. '/bibidd/GameBet/get_pre_result',
  610. '/bibidd/GameLuck100/get_pre_result',
  611. '/home/FileUpload/file_upload',
  612. '/bibidd/Mediaonenine/yuepao_xiafang_tuijian_list',
  613. '/bibidd/Mediaonenine/woman_detail',
  614. '/bibidd/Mediaonenine/yuepao_women_list_show',
  615. '/bibidd/Mediaonenine/yuepao_city_show',
  616. '/bibidd/Mediaonenine/jingping_video_list',
  617. '/bibidd/Teacher/query_teacher',
  618. '/bibidd/Teacher/query_three_rand_teacher',
  619. '/bibidd/Index/get_game_url',
  620. '/bibidd/Mediaonenine/game_jump_link_list',
  621. '/bibidd/Index/get_gonggao_url',
  622. '/bibidd/user/slUserLogin',
  623. '/bibidd/user/slUserRegister',
  624. '/bibidd/Mediaonenine/cowb_list_show',
  625. '/bibidd/TaskManager/get_sai_dan',
  626. '/bibidd/GameLuck100/get_luck_users',
  627. '/bibidd/WebsiteMoniter/websit_speed',
  628. '/bibidd/WebsiteMoniter/clearGt3h',
  629. '/bibidd/WebsiteMoniter/zhaleme_speed_call_back',
  630. '/bibidd/GetVedioForFreeOf10/getVedioForFreeOf10',
  631. '/bibidd/Mediaonesevenfive/shouye_lianjei',
  632. '/bibidd/ShopIndex/query_list',
  633. '/bibidd/LinghangPay/call_back_coins',
  634. '/bibidd/YiyunPay/call_back_coins',
  635. '/bibidd/TmplTokenForDay/getToken',
  636. '/bibidd/Mediatime/one_free_video_test',
  637. '/bibidd/Mediatime/last_month_commission',
  638. '/bibidd/Mediatime/two_button_close',
  639. '/bibidd/Mediatime/last_month_agent_add_amount',
  640. '/bibidd/Mediatime/pop_user_commission_close',
  641. '/bibidd/Mediatime/two_two_one',
  642. '/bibidd/Mediatime/suiji_shoucang_six',
  643. '/bibidd/Mediaonefivetest/get_agent_record',
  644. '/bibidd/Mediatime/twelve_update_num',
  645. '/bibidd/Mediatime/twotwoone_list',
  646. '/bibidd/Mediatime/Mediaonenine/jingping_video_list',
  647. '/bibidd/Mediaonenine/chezhen_list_show',
  648. '/bibidd/Mediaonenine/video_info_list',
  649. '/bibidd/Mediaonenine/swag_list_show',
  650. '/bibidd/Mediaonenine/last_login_jilu',
  651. '/bibidd/Mediaonenine/fuliji_list_show',
  652. '/bibidd/Mediaonenine/chaoshuang_list_show',
  653. '/bibidd/Mediaonenine/gangtai_sanji_list_show',
  654. '/bibidd/Mediaonenine/nantong_gay_list_show'
  655. );
  656. $path = $_SERVER['PHP_SELF'];
  657. // $path = $_SERVER['PHP_SELF'];
  658. if(strpos($path,'/bibidd/Mediatime')){
  659. return;
  660. }else{
  661. $path = str_replace("/index.php", "", $path);
  662. if (in_array($path, $jump_urls)) {
  663. //跳过用户检查,并检查用户段是否有传token如有还需要继续转换用户
  664. $uid = $this->checkToken();
  665. if (!empty($uid)) {
  666. $_POST['uid'] = $uid;
  667. }
  668. return;
  669. }
  670. }
  671. $uid = $this->checkToken();
  672. if (empty($uid)) {
  673. $this->returnDataAndSendMsg("无效请求a");
  674. die();
  675. }
  676. //检查
  677. $http_url = $_SERVER["HTTP_REFERER"];
  678. $http_lg = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
  679. if (empty($http_url) || empty($http_lg)) {
  680. $this->returnDataAndSendMsg("无效请求a");
  681. die();
  682. }
  683. $doman = $this->matchurl($http_url);
  684. //$today= date("Y-m-d");
  685. $today_url = M("huoyue_list")->where("uid='$uid'")->order("id DESC")->getField("url");
  686. if (empty($today_url)) {
  687. $this->returnDataAndSendMsg("无效请求a");
  688. die();
  689. }
  690. if (strpos($today_url, $doman) === false) {
  691. $this->returnDataAndSendMsg("无效请求a");
  692. die();
  693. }
  694. $_POST['uid'] = $uid;
  695. }
  696. private function checkToken()
  697. {
  698. $token = $_SERVER['HTTP_TOKEN'];
  699. if (empty($token)) {
  700. $token = $_POST['token'];
  701. }
  702. if (empty($token)) {
  703. return null;
  704. }
  705. //验证token是否有效
  706. $current_time = date('Y-m-d H:i:s');
  707. $uid = M("user_info")->where("token='$token' AND token_time_out>='$current_time'")->getField("id");
  708. if (empty($uid)) {
  709. return null;
  710. }
  711. return $uid;
  712. }
  713. /**
  714. * 下发token
  715. * @param $uid
  716. * @return void
  717. */
  718. protected function genToken($uid)
  719. {
  720. $token = $this->generateUUIDv4Nodash();
  721. $current_time = date('Y-m-d H:i:s');
  722. $out_time = date('Y-m-d H:i:s', strtotime('+7 days', strtotime($current_time)));
  723. $update_info['token'] = $token;
  724. $update_info['token_time_out'] = $out_time;
  725. M("user_info")->where("id='$uid'")->save($update_info);
  726. return $token;
  727. }
  728. /**
  729. * 更新token时间
  730. * @param $uid
  731. * @return bool|float|int|string
  732. */
  733. protected function updateToken($uid)
  734. {
  735. $current_time = date('Y-m-d H:i:s');
  736. $out_time = date('Y-m-d H:i:s', strtotime('+7 days', strtotime($current_time)));
  737. $update_info['token_time_out'] = $out_time;
  738. return M("user_info")->where("id='$uid'")->save($update_info);
  739. }
  740. /**
  741. * 获取域名
  742. * @param $param
  743. * @return array|string|string[]
  744. */
  745. private function matchurl($param)
  746. {
  747. preg_match('/^http(s)?:\/\/(.*)\//U', $param, $url);
  748. $value = str_replace(array('http://', 'https://', '/'), "", $url[2]);
  749. return $value;
  750. }
  751. protected function SHA256Hex($str)
  752. {
  753. $re = hash('sha256', $str, true);
  754. return base64_encode(bin2hex($re));
  755. }
  756. /**
  757. * 投注统计
  758. * @param $uid
  759. * @param $tz_jin
  760. * @return void
  761. */
  762. protected function touzhu_tongji_for_day($uid, $tz_jin, $game_type)
  763. {
  764. $day = date('Y-m-d');//日期
  765. $count_info = M("game_user_tongji")->field("id,tz_jin,tz_count")->where("uid='$uid' AND tz_day='$day' AND game_type='$game_type'")->find();
  766. if (empty($count_info)) {
  767. //插入
  768. $add_info['tz_day'] = $day;
  769. $add_info['uid'] = $uid;
  770. $add_info['tz_jin'] = $tz_jin;
  771. $add_info['tz_count'] = 1;
  772. $add_info['game_type'] = $game_type;
  773. M("game_user_tongji")->add($add_info);
  774. return;
  775. }
  776. $id = $count_info['id'];
  777. $add_info['tz_jin'] = $count_info['tz_jin'] + $tz_jin;
  778. $add_info['tz_count'] = $count_info['tz_count'] + 1;
  779. M("game_user_tongji")->where("id='$id'")->save($add_info);
  780. }
  781. /**
  782. * 游戏提现统计
  783. * @param $uid
  784. * @param $tx_jin
  785. * @return void
  786. */
  787. protected function tx_tongji_for_day($uid, $tx_jin)
  788. {
  789. $day = date('Y-m-d');//日期
  790. $count_info = M("game_user_tongji")->field("id,tx_jin,tx_count")->where("uid='$uid' AND tz_day='$day'")->find();
  791. if (empty($count_info)) {
  792. //插入
  793. $add_info['tz_day'] = $day;
  794. $add_info['uid'] = $uid;
  795. $add_info['tx_jin'] = $tx_jin;
  796. $add_info['tx_count'] = 1;
  797. M("game_user_tongji")->add($add_info);
  798. return;
  799. }
  800. $id = $count_info['id'];
  801. $add_info['tx_jin'] = $count_info['tx_jin'] + $tx_jin;
  802. $add_info['tx_count'] = $count_info['tx_count'] + 1;
  803. M("game_user_tongji")->where("id = '$id'")->save($add_info);
  804. }
  805. }