123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- use think\facade\Db;
- // 应用公共文件
- //返回json格式的响应信息,方便中间件记录,目前在abutmenu应用中有用到
- if (!function_exists('json_show')) {
- function json_show(int $code = 0, string $message = '请求成功', array $data = [])
- {
- return json(['code' => $code, 'message' => $message, 'data' => $data]);
- }
- }
- function made($var,$data=[]){
- $str = Db::name('cat')->where(['id'=>$var])->find();
- if($str==false){
- return [];
- }
- $vmn =[];
- $vmn['id'] =$str['id'];
- $vmn['name'] =$str['cat_name'];
- array_unshift($data,$vmn);
- // $var['id']=made();
- if($str['pid']==0){
- // krsort($data);
- return $data;
- }else{
- return made($str['pid'],$data);
- }
- }
- //获取有赞分类信息
- function made_youzan(int $yz_cat_id=0,$data=[]){
- $rs = get_yz_cat_info($yz_cat_id);
- if(empty($rs)) return [];
- $vmn =[];
- $vmn['yz_cat_id'] =$rs['id'];
- $vmn['yz_cat_name'] =$rs['yz_cat_name'];
- array_unshift($data,$vmn);
- if($rs['parent_cid']==0) return $data;
- else return made_youzan($rs['parent_cid'],$data);
- }
- function makeExcluse($var,$data=[]){
- $str = Db::name('exclusive')->where(['id'=>$var])->find();
- if($str==false){
- return [];
- }
- $vmn =[];
- $vmn['id'] =$str['id'];
- $vmn['name'] =$str['name'];
- array_unshift($data,$vmn);
- // $var['id']=made();
- if($str['pid']==0){
- // krsort($data);
- return $data;
- }else{
- return makeExcluse($str['pid'],$data);
- }
- }
- function makeNo($str){
- $date=date("mdHis");
- $year = date("Y")-2000;
- $msec=rand(1000,9999);
- return $str.$year.$date.$msec;
- }
- function randomkeys($length) {
- $returnStr='';
- $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
- for($i = 0; $i < $length; $i ++) {
- $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
- }
- return $returnStr;
- }
|