0 ? $day.'天' : ''; $hour = floor(($remain_time % (3600*24)) / 3600); $hour = $hour > 0 ? $hour.'小时' : ''; if($is_hour && $is_minutes) { $minutes = floor((($remain_time % (3600*24)) % 3600) / 60); $minutes = $minutes > 0 ? $minutes.'分钟' : ''; return $day.$hour.$minutes; } if($hour) { return $day.$hour; } return $day; } //获取全图片地址 $image_data function image_path($image_data){ if(empty($image_data)){ return $image_data; } if (strpos($image_data,'|')!==false){ $image_res = explode('|',$image_data); }elseif(strpos($image_data,',')!==false){ $image_res = explode(',',$image_data); }else{ $image_res = array($image_data); } return $image_res; } function get_order_sn(){ $order_id_main = date('YmdHis') . rand(10000000,99999999); $order_id_len = strlen($order_id_main); $order_id_sum = 0; for($i=0; $i<$order_id_len; $i++){ $order_id_sum += (int)(substr($order_id_main,$i,1)); } $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT); return $osn; } /** * 更新会员积分 * @param $user_id * @param $integral * @param $desc * @param int $rel_id * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ function update_user_integral($user_id,$integral,$type,$desc,$rel_id = 0) { $user = Db::table('store_member')->find($user_id); $integral_info=[ 'user_id'=> $user_id, 'create_at'=> date("Y-m-d H:i:s"), 'integral'=> $integral, 'before'=> $user['integral'], 'after'=> $user['integral'] + $integral, 'type'=>$type, 'desc'=> $desc, 'rel_id'=> $rel_id, ]; Db::table('integral_info')->insert($integral_info); Db::table('store_member')->where(['id'=>$user_id])->update(['integral'=>$integral_info['after']]); } /** * 更新会员成长值 * @param $user_id * @param $growth * @param $desc * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ function update_user_growth($user_id,$growth,$type,$desc,$data = []) { $growth_info=[ 'user_id'=> $user_id, 'create_at'=> date("Y-m-d H:i:s"), 'growth'=> $growth, 'type'=>$type, 'desc'=> $desc, 'detail'=> json_encode($data), ]; Db::table('member_level_growth')->insert($growth_info); Db::table('store_member')->where('id',$user_id)->setInc('growth',$growth); $user = Db::table('store_member')->field('level_id,growth')->find($user_id); $lev_set = Db::table('member_level')->select(); $lev_set = array_column($lev_set,null,'id'); if(isset($lev_set[$user['level_id']+1]) && $user['growth'] >= $lev_set[$user['level_id']+1]['growth']) { $level_log = [ 'user_id' => $user_id , 'create_at' => date("Y-m-d H:i:s") , 'before_lev' => $user['level_id'] , 'after_lev' => $user['level_id']+1 , 'desc' => '恭喜亲成功晋级成为'.$lev_set[$user['level_id']+1]['name'].'会员!' , ]; Db::table('member_level_log')->insert($level_log); Db::table('store_member')->where('id',$user_id)->setInc('level_id',1); } } /** * 获取access_token */ function get_access_token(){ $app_id = 'wx4ccfaf737dd24004'; $app_secret ='a7a7e0e7e3ce132f751e85202a09e0dc'; $session = new Session(); $over_time = $session->get('token_over_time'); if($over_time < time()) { $url= "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$app_id}&secret={$app_secret}"; $ret = http_curl($url); $session->set('access_token',$ret['access_token']); $session->set('token_over_time',time() +$ret['expires_in'] ); } return $session->get('access_token'); } /** * 发放模板消息 */ function send_message($access_token,$openid,$jump_url,$data=[]){ // $url='https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token; $url='https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token='.$access_token; $data=[ 'touser'=>$openid, 'mp_template_msg'=>[ "appid"=>"wx8e881917d7c4c283",// 公众号 "template_id"=>"k36NAugBdarjBkMJQgMJqdpgIXtV4S89U7LQfPc9BAM", "url"=>$jump_url, 'miniprogram'=>[ //"appid"=>"wx4ccfaf737dd24004",// 小程序 ], 'data'=>[ 'first'=>[ "value"=>$data[0], "color"=>"#173177" ], 'keyword1'=>[ "value"=>$data[1], "color"=>"#173177" ], 'keyword2'=>[ "value"=>$data[2], "color"=>"#173177" ], 'keyword3'=>[ "value"=>$data[3], "color"=>"#173177" ], 'remark'=>[ "value"=>$data[4], "color"=>"#173177" ] ] ], ]; $res = http_curl($url,'post',$data); } // 获取模板区域 function get_city_area() { $field=['id','pid','name']; $list=Db::table('store_area')->where('pid',0)->field($field)->select(); foreach ($list as $k=>&$v){ $v['children']= Db::table('store_area')->where('pid',$v['id'])->field($field)->select(); } return $list; } function http_curl($url,$type='get',$arr=''){ //1.初始化curl $ch = curl_init(); //2.设置curl的参数 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($type == 'post'){ curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr)); curl_setopt($ch, CURLOPT_HEADER, 0); } //3.采集 $output = curl_exec($ch); //4.关闭 curl_close($ch); return json_decode($output,true); } // 获取物流信息 function get_delivery($send_no = 'JD0053309649641',$express_code=''){ error_reporting(E_ALL || ~E_NOTICE); $AppKey = 204002714; $AppSecret ='q4MgT64XnevYnpZYrRBjYvmBE9dl7jXb'; $AppCode ='386afbaa66574df7b843f758d86c02be';//开通服务后 买家中心-查看AppCode $host = "https://wuliu.market.alicloudapi.com";//api访问链接 $path = "/kdi";//API访问后缀 $method = "GET"; $body =''; $headers = array(); array_push($headers, "Authorization:APPCODE " . $AppCode); $querys = "no={$send_no}&type={$express_code}"; //参数写在这里 $url = $host . $path . "?" . $querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); if (1 == strpos("$" . $host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $out_put = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); list($header, $body) = explode("\r\n\r\n", $out_put, 2); if ($httpCode == 200) { return json_decode($body,true)['result']; } else { return []; /* if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) { print("参数错误"); } elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) { print("AppCode错误"); } elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) { print("请求的 Method、Path 或者环境错误"); } elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) { print("服务未被授权(或URL和Path不正确)"); } elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) { print("套餐包次数用完"); } elseif ($httpCode == 500) { print("API网关错误"); } elseif ($httpCode == 0) { print("URL错误"); } else { print("参数名错误 或 其他错误"); print($httpCode); $headers = explode("\r\n", $header); $headList = array(); foreach ($headers as $head) { $value = explode(':', $head); $headList[$value[0]] = $value[1]; } print($headList['x-ca-error-message']); }*/ } } function draw_lottery ($data = [],$field='',$num = 1) { $draw_data = []; foreach ($data as $k=>$v) { if($v[$field] > 0) { for($i=1;$i<=$v[$field];$i++) { $draw_data[] = $k.'_key_'.$i; } } } $rand_key = array_rand($draw_data,$num); $draw_key = []; for ($a=0;$a<$num;$a++) { $draw_key[] = explode( '_key_',$draw_data[$rand_key[$a]])[0]; } var_dump($draw_key); } function reload_url() { if(input('reloaded') !=1) { echo ""; } }