common.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. use think\Db;
  12. // 应用公共文件
  13. function makeSalt(){
  14. $str =rand(100000,999999);
  15. return $str;
  16. }
  17. /**
  18. * @param $file
  19. * @return string
  20. */
  21. function uplaod_avatar($file){
  22. // 移动到框架应用根目录/public/uploads/ 目录下
  23. $info = $file->validate(['size'=>15678,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads/avatar');
  24. if($info){
  25. return $info->getSaveName();
  26. }else{
  27. return "";
  28. }
  29. }
  30. /**
  31. * 日志记录
  32. * @param $log
  33. * @param $id
  34. */
  35. function write_log($log,$userinfo,$module="",$action="",$role=0){
  36. $data=[
  37. "action_id"=>isset($userinfo['id'])? $userinfo['id']:"",
  38. "msg"=>$log,
  39. "addtime"=>date("y-m-d H:i:s"),
  40. "action_name"=>isset($userinfo['nickname'])? $userinfo['nickname']:"sys",
  41. "module"=>$module,
  42. "action"=>$action,
  43. "username"=>isset($userinfo['username'])? $userinfo['username']:"sys",
  44. "role"=>$role==0?(isset($userinfo['role_id'])&&$userinfo['role_id']!=0?$userinfo['role_id']:0):3,
  45. ];
  46. Db::name("system_log")->insert($data);
  47. }
  48. /**
  49. * @param $code
  50. * @param $msg
  51. */
  52. function error_show($code,$msg=""){
  53. $data = [
  54. "code"=>$code,
  55. "msg"=>$msg
  56. ];
  57. echo json_encode($data);
  58. die();
  59. }
  60. /**
  61. * @param $code
  62. * @param string $msg
  63. * @param array $list
  64. */
  65. function app_show($code,$msg="",$list=[]){
  66. $data = [
  67. "code"=>$code,
  68. "msg"=>$msg,
  69. "data"=>$list
  70. ];
  71. echo json_encode($data);
  72. die();
  73. }
  74. function makeNo($str){
  75. $date=date("mdHis");
  76. $year = date("Y")-2000;
  77. $msec=randomkeys(4);
  78. return $str.$msec.$year.$date;
  79. }
  80. function randomkeys($length) {
  81. $returnStr='';
  82. $pattern = 'abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
  83. for($i = 0; $i < $length; $i ++) {
  84. $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
  85. }
  86. return $returnStr;
  87. }
  88. function curl($url,$param,$method="post",$header=[]){
  89. //对空格进行转义
  90. $ch = curl_init();
  91. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  92. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  93. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  94. curl_setopt($ch, CURLOPT_HEADER, 0);
  95. // POST数据
  96. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  97. if($method=="post"){
  98. //设置选项,包括URL
  99. curl_setopt($ch, CURLOPT_URL, "$url");
  100. curl_setopt($ch, CURLOPT_POST, 1);
  101. // 把post的变量加上
  102. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
  103. }else{
  104. $url.="?".http_build_query($param);
  105. curl_setopt($ch, CURLOPT_URL, "$url");
  106. #curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
  107. }
  108. //所需传的数组用http_bulid_query()函数处理一下,就ok了
  109. $output = curl_exec($ch);
  110. $errorCode = curl_errno($ch);
  111. curl_close($ch);
  112. if(0 !== $errorCode) {
  113. return false;
  114. }
  115. return $output;
  116. }
  117. /**
  118. * 物流状态
  119. * 快递状态
  120. 1 暂无记录
  121. 2 在途中
  122. 3 派送中
  123. 4 已签收 (完结状态)
  124. 5 用户拒签
  125. 6 疑难件
  126. 7 无效单 (完结状态)
  127. 8 超时单
  128. 9 签收失败
  129. 10 退回
  130. */
  131. function express_status(){
  132. return [
  133. 0=>"未发货",
  134. 1=>"暂无记录",
  135. 2=>"在途中",
  136. 3=>"派送中",
  137. 4=>"已签收",
  138. 5=>"用户拒签",
  139. 6=>"疑难件",
  140. 7=>"无效单",
  141. 8=>"超时单",
  142. 9=>"签收失败",
  143. 10=>"退回"
  144. ];
  145. }