common.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. // 应用公共文件
  3. use think\facade\Config;
  4. use think\facade\Db;
  5. // 应用公共文件
  6. function app_show($code=0,$message="",$data=[]){
  7. $result = ['code'=>$code,"message"=>$message,"data"=>$data];
  8. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  9. die();
  10. }
  11. // 应用公共文件
  12. function error_show($code=0,$message=""){
  13. $result = ['code'=>$code,"message"=>$message];
  14. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  15. die();
  16. }
  17. function GetUserInfo($token){
  18. $host = Config::get("app");
  19. $url = $host["api_host"]."/Api/userinfo";
  20. $data=[
  21. "token"=>$token
  22. ];
  23. $response=curl_request($url,$data);
  24. return json_decode($response,true);
  25. }
  26. //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
  27. function curl_request($url,$post=''){
  28. $curl = curl_init();
  29. curl_setopt($curl, CURLOPT_URL, $url);
  30. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
  31. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  32. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  33. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  34. if($post) {
  35. curl_setopt($curl, CURLOPT_POST, 1);
  36. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
  37. }
  38. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  39. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  40. $data = curl_exec($curl);
  41. if (curl_errno($curl)) {
  42. return curl_error($curl);
  43. }
  44. curl_close($curl);
  45. return $data;
  46. }
  47. /**手机号验证
  48. * @param $mobile
  49. * @return bool
  50. */
  51. function checkMobile($mobile){
  52. if (!is_numeric($mobile)) {
  53. return false;
  54. }
  55. return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
  56. }
  57. function checkTel($tel){
  58. if (!$tel) {
  59. return false;
  60. }
  61. return preg_match('/^(0[0-9]{2,3}\-)([0-9]{7,8})+(\-[0-9]{1,4})?$/', $tel) ? true : false;
  62. }
  63. /**邮箱验证
  64. * @param $email
  65. * @return bool
  66. */
  67. function checkEmail($email){
  68. if (!$email) {
  69. return false;
  70. }
  71. return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
  72. }
  73. /**
  74. * @param
  75. * @return int
  76. */
  77. function makeSalt(){
  78. $salt = rand(10000000,99999999);
  79. return $salt;
  80. }
  81. /**
  82. * @param $token
  83. * @return array
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\DbException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. * @throws \think\exception\DbException
  88. */
  89. function VerifyTokens($token){
  90. $host = Config::get("app");
  91. $url = $host["api_host"]."/Api/verify_token";
  92. $data=[
  93. "token"=>$token
  94. ];
  95. $response=curl_request($url,$data);
  96. return json_decode($response,true);
  97. }
  98. /**
  99. * @param $token
  100. * @param $condition
  101. * @return mixed
  102. */
  103. function GetUserlist($token,$condition){
  104. $host = Config::get("app");
  105. $url = $host["api_host"]."/Api/getuserlist";
  106. $condition['token']=$token;
  107. $response=curl_request($url,$condition);
  108. return json_decode($response,true);
  109. }
  110. /**
  111. * @param $token
  112. * @param $condition
  113. * @return mixed
  114. */
  115. function GetAccountall($token, $condition){
  116. $host = Config::get("app");
  117. $url = $host["api_host"]."/Api/userall";
  118. $condition['token']=$token;
  119. $response=curl_request($url,$condition);
  120. return json_decode($response,true);
  121. }
  122. function GetList($token,$condition){
  123. $host = Config::get("app");
  124. $url = $host["api_host"]."/Api/userlist";
  125. $condition['token']=$token;
  126. $response=curl_request($url,$condition);
  127. return json_decode($response,true);
  128. }
  129. /**
  130. * @param $token
  131. * @param $condition ['id'=>1]
  132. * @return mixed
  133. */
  134. function GetInfoById($token,$condition){
  135. $host = Config::get("app");
  136. $url = $host["api_host"]."/Api/userinfobyid";
  137. $condition['token']=$token;
  138. $response=curl_request($url,$condition);
  139. return json_decode($response,true);
  140. }
  141. function makeNo($str){
  142. $date=date("mdHis");
  143. $year = date("Y")-2000;
  144. $msec=randomkeys(4);
  145. return $str.$msec.$year.$date;
  146. }
  147. function randomkeys($length) {
  148. $returnStr='';
  149. $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
  150. for($i = 0; $i < $length; $i ++) {
  151. $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
  152. }
  153. return $returnStr;
  154. }
  155. function tree(){
  156. }
  157. /**
  158. * @param $files
  159. * @return array
  160. */
  161. function UploadImg($files)
  162. {
  163. $savename = [];
  164. $files = !is_array($files) ? [$files] : $files;
  165. try {
  166. //验证
  167. validate(['imgFile' => ['fileSize' => 10240000, 'fileExt' => 'jpg,jpeg,png,bmp,gif', 'fileMime' => 'image/jpeg,image/png,image/gif']])->check(['imgFile' => $files]);
  168. foreach ($files as $file) {
  169. $url = Filesystem::disk('public')->putFile('topic/' . date("Ymd"), $file, function () use ($file) {
  170. return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis'));
  171. });
  172. $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
  173. $temp = ["url" => $url, "name" => $name];
  174. $savename[] = $temp;
  175. }
  176. return $savename;
  177. } catch (\think\exception\ValidateException $e) {
  178. return $e->getMessage();
  179. }
  180. }
  181. /**
  182. * @param $token
  183. * @param $condition
  184. * @return mixed
  185. */
  186. function resetpwd($token,$condition){
  187. $host = Config::get("app");
  188. $url = $host["api_host"]."/Api/passset";
  189. $condition['token']=$token;
  190. $response=curl_request($url,$condition);
  191. return json_decode($response,true);
  192. }
  193. function resetpasswd($token,$condition){
  194. $host = Config::get("app");
  195. $url = $host["api_host"]."/Api/passsave";
  196. $condition['token']=$token;
  197. $response=curl_request($url,$condition);
  198. return json_decode($response,true);
  199. }
  200. /**
  201. * @param $token
  202. * @param $condition
  203. * @return mixed
  204. */
  205. function resetinfo($token,$condition){
  206. $host = Config::get("app");
  207. $url = $host["api_host"]."/Api/passset";
  208. $condition['token']=$token;
  209. $response=curl_request($url,$condition);
  210. return json_decode($response,true);
  211. }
  212. /**
  213. * @param $token
  214. * @param $condition
  215. * @return mixed
  216. */
  217. function resetstatus($token,$condition){
  218. $host = Config::get("app");
  219. $url = $host["api_host"]."/Api/userstatus";
  220. $condition['token']=$token;
  221. $response=curl_request($url,$condition);
  222. return json_decode($response,true);
  223. }
  224. /**
  225. * @param $data
  226. * @throws \think\db\exception\DataNotFoundException
  227. * @throws \think\db\exception\DbException
  228. * @throws \think\db\exception\ModelNotFoundException
  229. */
  230. function crea($data)
  231. {
  232. $db = Db::name("company_item")->where(['pid'=>$data['id'],'is_del'=>0])->select()->toArray();
  233. $d = Db::name("depart_user")->where(['itemid'=>$data['id'],'is_del'=>0])->select()->toArray();
  234. if(empty($d)){
  235. $data['item']=[];
  236. }else{
  237. $data['item']=$d;
  238. }
  239. if(empty($db)){
  240. $data['child']=[];
  241. return $data;
  242. }
  243. //var_dump($db);
  244. foreach ($db as $p){
  245. $data['child'][]=crea($p);
  246. }
  247. return $data;
  248. }