123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- use think\Db;
- // 应用公共文件
- function makeSalt(){
- $str =rand(100000,999999);
- return $str;
- }
- /**
- * @param $file
- * @return string
- */
- function uplaod_avatar($file){
- // 移动到框架应用根目录/public/uploads/ 目录下
- $info = $file->validate(['size'=>15678,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads/avatar');
- if($info){
- return $info->getSaveName();
- }else{
- return "";
- }
- }
- /**
- * 日志记录
- * @param $log
- * @param $id
- */
- function write_log($log,$userinfo,$module="",$action="",$role=0){
- $data=[
- "action_id"=>isset($userinfo['id'])? $userinfo['id']:"",
- "msg"=>$log,
- "addtime"=>date("y-m-d H:i:s"),
- "action_name"=>isset($userinfo['nickname'])? $userinfo['nickname']:"sys",
- "module"=>$module,
- "action"=>$action,
- "username"=>isset($userinfo['username'])? $userinfo['username']:"sys",
- "role"=>$role==0?(isset($userinfo['role_id'])&&$userinfo['role_id']!=0?$userinfo['role_id']:0):3,
- ];
- Db::name("system_log")->insert($data);
- }
- /**
- * @param $code
- * @param $msg
- */
- function error_show($code,$msg=""){
- $data = [
- "code"=>$code,
- "msg"=>$msg
- ];
- echo json_encode($data);
- die();
- }
- /**
- * @param $code
- * @param string $msg
- * @param array $list
- */
- function app_show($code,$msg="",$list=[]){
- $data = [
- "code"=>$code,
- "msg"=>$msg,
- "data"=>$list
- ];
- echo json_encode($data);
- die();
- }
- function makeNo($str){
- $date=date("mdHis");
- $year = date("Y")-2000;
- $msec=randomkeys(4);
- return $str.$msec.$year.$date;
- }
- function randomkeys($length) {
- $returnStr='';
- $pattern = 'abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
- for($i = 0; $i < $length; $i ++) {
- $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
- }
- return $returnStr;
- }
- function curl($url,$param,$method="post",$header=[]){
- //对空格进行转义
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // POST数据
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- if($method=="post"){
- //设置选项,包括URL
- curl_setopt($ch, CURLOPT_URL, "$url");
- curl_setopt($ch, CURLOPT_POST, 1);
- // 把post的变量加上
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
- }else{
- $url.="?".http_build_query($param);
- curl_setopt($ch, CURLOPT_URL, "$url");
- #curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
- }
- //所需传的数组用http_bulid_query()函数处理一下,就ok了
- $output = curl_exec($ch);
- $errorCode = curl_errno($ch);
- curl_close($ch);
- if(0 !== $errorCode) {
- return false;
- }
- return $output;
- }
- /**
- * 物流状态
- * 快递状态
- 1 暂无记录
- 2 在途中
- 3 派送中
- 4 已签收 (完结状态)
- 5 用户拒签
- 6 疑难件
- 7 无效单 (完结状态)
- 8 超时单
- 9 签收失败
- 10 退回
- */
- function express_status(){
- return [
- 0=>"未发货",
- 1=>"暂无记录",
- 2=>"在途中",
- 3=>"派送中",
- 4=>"已签收",
- 5=>"用户拒签",
- 6=>"疑难件",
- 7=>"无效单",
- 8=>"超时单",
- 9=>"签收失败",
- 10=>"退回"
- ];
- }
|