functions.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. use App\AdminConfig;
  3. use Maatwebsite\Excel\Facades\Excel;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Http\helper\NumConfig;
  6. function validateURL($URL)
  7. {
  8. $pattern = "/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/";
  9. if (preg_match($pattern, $URL)) {
  10. return true;
  11. } else {
  12. return false;
  13. }
  14. }
  15. /**
  16. * @Desc: 获取配置值
  17. * @Author: woann <304550409@qq.com>
  18. * @param $key
  19. * @return array
  20. */
  21. function getConfig($key)
  22. {
  23. return AdminConfig::getValue($key);
  24. }
  25. //导出Excel
  26. function downloadExcel($cellData, $title, $name)
  27. {
  28. array_unshift($cellData, $title);
  29. Excel::create($name, function ($excel) use ($cellData) {
  30. $excel->sheet('score', function ($sheet) use ($cellData) {
  31. $sheet->rows($cellData);
  32. $sheet->setWidth(array('A' => 15, 'B' => 15, 'C' => 15, 'D' => 15, 'E' => 15, 'F' => 15, 'G' => 15, 'H' => 15, 'I' => 15, 'J' => 15, 'K' => 15, 'L' => 15, 'M' => 15, 'N' => 15, 'O' => 15, 'P' => 15, 'Q' => 15));
  33. });
  34. })->export('xls');
  35. }
  36. // 失败返回数据
  37. function apiReturnFail($msg = '', $data = [], $code = 301)
  38. {
  39. if(is_array($msg)){
  40. if(empty($data))$data=array_slice($msg,0,count($msg));
  41. $tryLang=__($msg[0]);
  42. if($tryLang!=$msg[0]){
  43. $msg=$tryLang;
  44. }else{
  45. // $msg=$msg[1];
  46. }
  47. }
  48. $data = ['data' => $data, 'msg' => $msg, 'code' => $code];
  49. return $data;
  50. }
  51. // 成功返回数据
  52. function apiReturnSuc($data = [], $result = '', $msg = 'success', $code = 200)
  53. {
  54. $data = ['data' => $data, 'result' => $result, 'msg' => $msg, 'code' => $code];
  55. return $data;
  56. }
  57. function number_float($val = null, $decimals = 2)
  58. {
  59. return number_format($val, $decimals, '.', '');
  60. }
  61. // 返回角色类型
  62. function hidden($value = 'hidden')
  63. {
  64. $hidden = session($value)['is_hidden'] ?? '';
  65. return $hidden;
  66. }
  67. // 判断值在不在数组里面
  68. function exist_array($need, $data)
  69. {
  70. if (in_array($need, $data)) {
  71. return true;
  72. } else {
  73. return false;
  74. }
  75. }
  76. function getGameID($UserID, $InvitationUserIDs)
  77. {
  78. $GameIDArr = explode(',', $InvitationUserIDs);
  79. $GameIDs = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  80. ->whereIn('UserID', $GameIDArr)
  81. ->select('GameID', 'UserID')
  82. ->pluck('GameID', 'UserID')->toArray();
  83. $str = '';
  84. foreach ($GameIDs as $k => $val) {
  85. $str .= "<a href='/admin/global/id_find?UserID={$k}'>{$val},</a>";
  86. }
  87. return $str;
  88. return implode(',', $GameIDs);
  89. }
  90. // 裂变 -- 获取用户的充值 - 提现 -对局
  91. function getUserInfo($InvitationUserIDs)
  92. {
  93. $GameIDArr = explode(',', $InvitationUserIDs);
  94. $info = DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  95. ->whereIn('UserID', $GameIDArr)
  96. ->selectRaw('IsNull(sum(WinInning+LostInning),0) gameNum,IsNull(sum(Withdraw) / 100,0)Withdraw,IsNull(sum(Recharge),0) Recharge')
  97. ->first();
  98. return $info;
  99. }
  100. function CollectableScore($UserID, $Type = 1)
  101. {
  102. // 注册
  103. $upperLimit = $info = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  104. ->where('StatusName', 'UpperLimit')
  105. ->first();
  106. // 1.判断可领额度
  107. $StatusValue = $upperLimit->StatusValue;
  108. $Score = (new \App\Services\Extension())->register($UserID, $Type)['Register'];
  109. // 剩余额度
  110. $Surplus = $Score % $StatusValue;
  111. // 要提的额度
  112. $addScore = $Score - $Surplus;
  113. return number_float($addScore / NumConfig::NUM_VALUE);
  114. }
  115. // 排序Html
  116. function sortHtml($func)
  117. {
  118. return "<svg t=\"1611284352657\" class=\"icon2\" onclick=\"$func(this,'asc')\"
  119. viewBox=\"0 0 1024 1024\" version=\"1.1\"
  120. xmlns=\"http://www.w3.org/2000/svg\" p-id=\"4118\" width=\"14\">
  121. <path
  122. d=\"M541.866667 285.866667l345.6 345.6c17.066667 17.066667 17.066667 42.666667 0 59.733333-8.533333 8.533333-19.2 12.8-29.866667 12.8H168.533333c-23.466667 0-42.666667-19.2-42.666666-42.666667 0-10.666667 4.266667-21.333333 12.8-29.866666l343.466666-345.6c17.066667-17.066667 42.666667-17.066667 59.733334 0z\"
  123. p-id=\"4119\" fill=\"#707072\">
  124. </path>
  125. </svg>
  126. <svg t=\"1611283709864\" class=\"icon1\" onclick=\"$func(this,'desc')\"
  127. viewBox=\"0 0 1024 1024\" version=\"1.1\"
  128. xmlns=\"http://www.w3.org/2000/svg\" p-id=\"3148\" width=\"14\">
  129. <path
  130. d=\"M482.133333 738.133333L136.533333 392.533333c-17.066667-17.066667-17.066667-42.666667 0-59.733333 8.533333-8.533333 19.2-12.8 29.866667-12.8h689.066667c23.466667 0 42.666667 19.2 42.666666 42.666667 0 10.666667-4.266667 21.333333-12.8 29.866666L541.866667 738.133333c-17.066667 17.066667-42.666667 17.066667-59.733334 0z\"
  131. p-id=\"3149\" fill=\"#707071\">
  132. </path>
  133. </svg>";
  134. }
  135. // 房间搜索
  136. function gamesButton($url = '/admin/group_control/room')
  137. {
  138. $ControlModel = new \App\Models\Control();
  139. $GameData = $ControlModel->GameData;
  140. foreach ($GameData as $key => $val) {
  141. if (in_array($val, config('games.openKGame'))) {
  142. $href = $url . '?gameType=' . $val;
  143. $gameName = $ControlModel->GameDataText[$key];
  144. echo '<a href="' . $href . '" class="btn-sm btn btn-gradient-dark">' . $gameName . '</a> &nbsp;';
  145. }
  146. }
  147. }
  148. // 日期转换北京时间
  149. function dateConvert($date)
  150. {
  151. return \Carbon\Carbon::parse($date,env('APP_TIMEZONE','America/Argentina/Buenos_Aires'))->setTimezone('Asia/Shanghai');
  152. }
  153. function ipAddress($ip){
  154. return \App\IpLocation::getAddressByIP($ip);
  155. }
  156. function opensslVerify( $pubkey, $data, $sign, $signType = 'RSA' ) {
  157. $res = "-----BEGIN PUBLIC KEY-----\n" . wordwrap( $pubkey, 64, "\n", true ) . "\n-----END PUBLIC KEY-----";
  158. if ( "RSA2" == $signType ) {
  159. $result = (bool)openssl_verify( $data, base64_decode( $sign ), $res, OPENSSL_ALGO_SHA256 );
  160. } else {
  161. $result = (bool)openssl_verify( $data, base64_decode( $sign ), $res );
  162. }
  163. // $public_key = '-----BEGIN PUBLIC KEY-----'."\n".$public_key."\n".'-----END PUBLIC KEY-----';
  164. // $data = base64_decode($data);
  165. // $pu_key = openssl_pkey_get_public($public_key);
  166. // $crypto = '';
  167. // foreach (str_split($data, 128) as $chunk) {
  168. // openssl_public_decrypt($chunk, $decryptData, $pu_key);
  169. // $crypto .= $decryptData;
  170. // }
  171. //
  172. // return $crypto;
  173. return $result;
  174. }
  175. function opensslSign( $prikey, $data, $signType = "RSA" ) {
  176. // $res = "-----BEGIN PRIVATE KEY-----\n" . wordwrap( $prikey, 64, "\n", true ) . "\n-----END PRIVATE KEY-----";
  177. $prikey = '-----BEGIN PRIVATE KEY-----'."\n".$prikey."\n".'-----END PRIVATE KEY-----';
  178. $pi_key = openssl_pkey_get_private($prikey);
  179. $crypto = '';
  180. foreach (str_split($data, 117) as $chunk) {
  181. openssl_private_encrypt($chunk, $encryptData, $pi_key);
  182. $crypto .= $encryptData;
  183. }
  184. return base64_encode($crypto);
  185. }
  186. function opensslSignNew( $prikey, $data, $signType = "RSA" ) {
  187. // $res = "-----BEGIN PRIVATE KEY-----\n" . wordwrap( $prikey, 64, "\n", true ) . "\n-----END PRIVATE KEY-----";
  188. $prikey = '-----BEGIN PRIVATE KEY-----'."\n".$prikey."\n".'-----END PRIVATE KEY-----';
  189. // $pi_key = openssl_pkey_get_private($prikey);
  190. // $crypto = '';
  191. // foreach (str_split($data, 117) as $chunk) {
  192. // openssl_private_encrypt($chunk, $encryptData, $pi_key);
  193. // $crypto .= $encryptData;
  194. // }
  195. //
  196. // return base64_encode($crypto);
  197. $merchant_private_key = openssl_get_privatekey($prikey);
  198. openssl_sign($data, $sign_info, $merchant_private_key, OPENSSL_ALGO_MD5);
  199. return base64_encode($sign_info);
  200. }