1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411 |
- <?php
- use app\common\library\QRcode;
- use think\Db;
- use OSS\OssClient;
- function IntToChr($index, $start = 65) {
- $str = '';
- if (floor($index / 26) > 0) {
- $str .= IntToChr(floor($index / 26)-1);
- }
- return $str . chr($index % 26 + $start);
- }
- /**
- * 秒转换为天
- */
- function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
- {
- $day = floor($remain_time / (3600*24));
- $day = $day > 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_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',$res='json',$arr=''){
- $headers = array();
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
- 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, false);
- $output = curl_exec($curl);
- curl_close($curl);
- if($res=='json'){
- if($output === false){
- //请求失败,返回错误信息
- return curl_error($curl);
- }else{
- //请求成功,返回信息
- return json_decode($output,true);
- }
- }
- }
- // 获取物流信息
- function get_delivery($send_no = 'JD0053309649641',$express_code=''){
- error_reporting(E_ALL || ~E_NOTICE);
- $AppKey = 204008273;
- $AppSecret ='t9PavvfCeK5v2XidwyK5pWDp8b0hzMq4';
- $AppCode ='47f640e3529d43e28365311a530db2b7';//开通服务后 买家中心-查看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 [];
- }
- }
- // 元石日志
- function crystal_log($user_id,$crystal,$desc,$type,$rel_id=0)
- {
- $log_data = [
- 'user_id' => $user_id,
- 'create_at' => date('Y-m-d H:i:s'),
- 'crystal' => $crystal,
- 'desc' => $desc,
- 'type' => $type,
- 'rel_id' => $rel_id,
- ];
- Db::table('crystal_info')->insert($log_data);
- }
- /**
- * 判断是否为合法的身份证号码
- * @param $mobile
- * @return int
- */
- function isCreditNo($vStr){
- $vCity = array(
- '11','12','13','14','15','21','22',
- '23','31','32','33','34','35','36',
- '37','41','42','43','44','45','46',
- '50','51','52','53','54','61','62',
- '63','64','65','71','81','82','91'
- );
- if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
- if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
- $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
- $vLength = strlen($vStr);
- if ($vLength == 18) {
- $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
- } else {
- $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
- }
- if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
- if ($vLength == 18) {
- $vSum = 0;
- for ($i = 17 ; $i >= 0 ; $i--) {
- $vSubStr = substr($vStr, 17 - $i, 1);
- $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
- }
- if($vSum % 11 != 1) return false;
- }
- return true;
- }
- //实名认证(云盾身份认证(身份证二要素核验)
- function identifyCertification($id_card,$name){
- $host = "https://safrvcert.market.alicloudapi.com";
- $path = "/safrv_2meta_id_name/";
- $method = "GET";
- $appcode = "95ec5cd8c54d4ced9220caebdaa5d750";
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $appcode);
- $querys = "__userId=__userId&identifyNum=$id_card&userName=$name&verifyKey=verifyKey";
- $bodys = "";
- $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, false);
- if (1 == strpos("$".$host, "https://"))
- {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
- $res = curl_exec($curl);
- if($res){
- $res = json_decode($res,true);
- if($res['code'] == 200 && $res['message']=='success'){
- return 1;
- }else{
- return 0;
- }
- }else{
- return 0;
- }
- }
- //实名认证姓名、身份证、手机号
- function threeElementCertification($id_card,$name,$phone)
- {
- $host = "http://sjsys.market.alicloudapi.com";
- $path = "/communication/personal/1979";
- $method = "POST";
- $appcode = "你自己的AppCode";
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $appcode);
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
- $querys = "";
- $bodys = "idcard=$id_card****&mobile=$phone****&name=$name";
- $url = $host . $path;
- $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);
- }
- curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
- var_dump(curl_exec($curl));
- }
- // 实名认证
- function user_certification($id_card,$name){
- $host = "http://checkone.market.alicloudapi.com";
- $path = "/chinadatapay/1882";
- $method = "POST";
- $appcode = "c8fd88cc95dd46fa8c50b05d219824ed";
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $appcode);
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
- $bodys = "idcard=".$id_card."&name=".$name;
- $url = $host . $path;
- $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, false);
- if (1 == strpos("$".$host, "https://"))
- {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
- $res = curl_exec($curl);
- if($res){
- $res = json_decode($res,true);
- if($res['data']['result'] == 1){
- return 1;
- }else{
- return 0;
- }
- }else{
- return 0;
- }
- }
- /**
- * 大师提前分钟数存入redis
- */
- function setAdvanceMinutes(){
- $redis = new \think\cache\driver\Redis();
- $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
- $redis->set('advance_minutes',$value);
- }
- /**
- * 获取大师提前分钟数
- */
- function getAdvanceMinutes(){
- $redis = new \think\cache\driver\Redis();
- $value = $redis->get('advance_minutes');
- if (empty($value)){
- $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
- $redis->set('advance_minutes',$value);
- }
- return $value;
- }
- /**
- * 获取自动取消分钟数
- */
- function getCancelTime(){
- return Db::name('system_config')->where('name','cancel_time')->value('value');
- }
- /**
- * 用户信息存入redis hash
- */
- function setMemberInfoHash($member_id){
- $info = Db::name('store_member')->where('id',$member_id)->find();
- $redis = new \think\cache\driver\Redis();
- $array = ['member'.$member_id=>json_encode($info)];
- $redis->hMSet('memberInfo',$array);
- }
- /**
- * redis获取用户信息
- */
- function getMemberInfoHash($member_id){
- $redis = new \think\cache\driver\Redis();
- $info = $redis->hGet('memberInfo','member'.$member_id);
- if (!$info){
- $info = Db::name('store_member')->where('id',$member_id)->find();
- $array = ['member'.$member_id=>json_encode($info)];
- $redis->hMSet('memberInfo',$array);
- }else{
- $info = json_decode($info,true);
- }
- return $info;
- }
- /**
- * 获取藏品库存
- */
- function getCollectionInventory($id){
- $redis = new \think\cache\driver\Redis();
- $count = $redis->get('collection_count_'.$id);
- // if (empty($count)){
- // $redis->set('collection_count_'.$id,0);
- // }
- return $count ? $count : 0;
- }
- /**
- * 减掉藏品库存
- */
- function loseCollectionInventory($id,$num){
- $redis = new \think\cache\driver\Redis();
- $redis->Decrby('collection_count_'.$id,$num);
- }
- /**
- * 加藏品库存
- */
- function addCollectionInventory($id,$num){
- $redis = new \think\cache\driver\Redis();
- $redis->Incrby('collection_count_'.$id,$num);
- }
- /**
- * 用户购买藏品排名更新
- */
- function saveRanking($id){
- }
- function getRanking($id,$inc= 1){
- $redis = new \think\cache\driver\Redis();
- if($inc == 1) {
- $count = $redis->Incr('ranking'.$id);
- }else{
- $count = $redis->get('ranking'.$id);
- if (empty($count)) $redis->set('ranking'.$id,0);
- $count = empty($count) ? 0 : $count;
- }
- return $count;
- }
- /**
- * 藏品信息存入redis hash
- */
- function setCollectionInfoHash($id){
- $info = Db::name('store_collection')->where('id',$id)->find();
- $redis = new \think\cache\driver\Redis();
- $array = ['collection'.$id=>json_encode($info)];
- $redis->hMSet('collectionInfo',$array);
- }
- /**
- * 获取用户购买数量
- */
- function getByCount($mid,$id){
- $redis = new \think\cache\driver\Redis();
- $count = $redis->get('UserByCount_'.$mid.$id);
- if (empty($count) && $count!=0){
- $count = 0;
- $redis->Incrby('UserByCount_'.$mid.$id,$count);
- }
- return $count;
- }
- /**
- * 用户购买数量增加
- */
- function IncrByCount($mid,$id,$number){
- $redis = new \think\cache\driver\Redis();
- $redis->Incrby('UserByCount_'.$mid.$id,$number);
- }
- /**
- * 用户购买数量减少
- */
- function DecrByCount($mid,$id,$number){
- $redis = new \think\cache\driver\Redis();
- $redis->Decrby('UserByCount_'.$mid.$id,$number);
- }
- /**
- * 获取藏品hash redis长度
- */
- function getLenCollection($id){
- $redis = new \think\cache\driver\Redis();
- $count = $redis->Llen('collectionHash_'.$id);
- if (!$count){
- $count = Db::name('hash')
- ->where('goods_id',$id)
- ->where('status',0)
- ->count();
- }
- return $count;
- }
- /**
- * 获取藏品信息
- */
- function getCollectionInfoHash($id)
- {
- $redis = new \think\cache\driver\Redis();
- $info = $redis->hGet('collectionInfo','collection'.$id);
- if (!$info){
- $info = Db::name('store_collection')->where('id',$id)->find();
- $array = ['collection'.$id=>json_encode($info)];
- $redis->hMSet('collectionInfo',$array);
- }else{
- $info = json_decode($info,true);
- }
- return $info;
- }
- /**
- * 收集下单用户id
- */
- function setCollectionBuyUser($mid){
- $redis = new \think\cache\driver\Redis();
- $array = [$mid=>1];
- $redis->hMSet('buyUserInfo',$array);
- }
- /*
- * 微信支付账户
- */
- function retrunWxConfig(){
- $config = [
- 'app_id' => 'wx8e47a12d0a1c007f',
- 'mch_id' =>'1627327076',
- 'key' =>'dguiadak46574hbfkjshfns55f87s5sd',
- ];
- return $config;
- }
- /**
- * 获取离线账户
- */
- function getOfflineAccount(){
- $url = 'http://192.144.219.204:8083/ddc/createAccount';
- return file_get_contents($url);
- }
- /**
- * 获取链账户
- */
- function getWalletAddress($phone){
- $url = getIpAddress().'register?accountName='.$phone;
- $res=curlRequest($url);
- if ($res){
- $res = json_decode($res,true);
- if ($res['code']=='200'){
- return $res['result']['userAddressStr'];
- }
- }
- return false;
- }
- /**
- * 获取公司生成的hash
- */
- function getCompanyHash($id){
- $redis = new \think\cache\driver\Redis();
- $hash = $redis->lPop('collectionHash_'.$id);
- if (!$hash){
- $hash = Db::name('hash')->where('goods_id',$id)
- ->where('status',0)
- ->order('id asc')
- ->field('hash,create_at,tokenid')
- ->limit(1)
- ->find();
- }else{
- $hash = json_decode($hash,true);
- }
- return $hash;
- }
- /**
- * 获取排名
- */
- function getTag($id,$now,$num){
- $len = strlen($num);
- $re = 'XL'.$id.'#';
- switch ($len){
- case 1:
- $re = $re.'0'.$now;
- break;
- case 2:
- if ($now<10){
- $re = $re.'0'.$now;
- }else{
- $re = $re.$now;
- }
- break;
- case 3:
- if ($now<10){
- $re = $re.'00'.$now;
- }elseif ($now>=10 && $now<100){
- $re = $re.'0'.$now;
- }else{
- $re = $re.$now;
- }
- break;
- case 4:
- if ($now<10){
- $re = $re.'000'.$now;
- }elseif ($now>=10 && $now<100){
- $re = $re.'00'.$now;
- }elseif ($now>=100 && $now<1000){
- $re = $re.'0'.$now;
- }else{
- $re = $re.$now;
- }
- break;
- case 5:
- if ($now<10){
- $re = $re.'0000'.$now;
- }elseif ($now>=10 && $now<100){
- $re = $re.'000'.$now;
- }elseif ($now>=100 && $now<1000){
- $re = $re.'00'.$now;
- }elseif ($now>=1000 && $now<10000){
- $re = $re.'0'.$now;
- }else{
- $re = $re.$now;
- }
- break;
- case 6:
- if ($now<10){
- $re = $re.'00000'.$now;
- }elseif ($now>=10 && $now<100){
- $re = $re.'0000'.$now;
- }elseif ($now>=100 && $now<1000){
- $re = $re.'000'.$now;
- }elseif ($now>=1000 && $now<10000){
- $re = $re.'00'.$now;
- }elseif ($now>=10000 && $now<100000){
- $re = $re.'0'.$now;
- }else{
- $re = $re.$now;
- }
- break;
- }
- $re = $re.'/'.$num;
- return $re;
- }
- /**
- * 判断藏品是否设置过提醒
- */
- function getRemind($mid,$c_id){
- return Db::name('store_collection_remind')->where('mid',$mid)->where('c_id',$c_id)->count();
- }
- /**
- * 变更会员积分等
- * @param int $money 余额
- * @param int $user_id 会员ID
- * @param string $memo 备注
- */
- function memberMoneyChange($num, $type , $m_id, $title, $pm = 0,$link_id=0,$change_type = 0)
- {
- $member = Db::name('store_member')->where('id',$m_id)->find();
- $is_inc = $pm == 1 ? 1 : -1;
- switch ($type){
- case 1: //积分
- $before = $member['integral'];
- if ($pm==1)
- $after = $member['integral']+$num;
- else
- $after = $member['integral']-$num;
- $update_data = ['integral'=>Db::raw('integral +'.$num*$is_inc)];
- break;
- case 2: //抢购卡
- $before = $member['snap_card'];
- if ($pm==1)
- $after = $member['snap_card']+$num;
- else
- $after = $member['snap_card']-$num;
- $update_data = ['snap_card'=>Db::raw('snap_card +'.$num*$is_inc)];
- break;
- case 3: //余额
- $before = $member['money'];
- if ($pm==1)
- $after = $member['money']+$num;
- else
- $after = $member['money']-$num;
- $update_data = ['money'=>Db::raw('money +'.$num*$is_inc)];
- break;
- }
- try {
- Db::name('store_member')->where('id',$m_id)->update($update_data);
- $data = [
- 'm_id'=>$m_id,
- 'type'=>$type,
- 'pm'=>$pm,
- 'title'=>$title,
- 'change'=>$num,
- 'before'=>$before,
- 'after'=>$after,
- 'link_id'=>$link_id,
- 'change_type'=>$change_type
- ];
- Db::name('store_member_log')->insert($data);
- return true;
- }catch (\Exception $e){
- return false;
- }
- }
- /**
- * 变更会员等级
- * @param int $vid 等级
- * @param int $user_id 会员ID
- * @param array $other 其他
- */
- function memberVipChange($vid, $user_id, $other = [])
- {
- return true;// 象链没有会员等级
- $member = Db::name('store_member')->where('id',$user_id)->find();
- //数据
- $before = $member['vip'];
- $after = $vid;
- //新等级小于等级 则不升级
- if($after <= $before && $other['status'] == 1){
- return false;
- }
- //等级相同 不操作
- if($after == $before){
- return false;
- }
- $update_data['vip'] = $vid;
- Db::startTrans();
- try {
- Db::name('store_member')->where('id',$user_id)->update($update_data);
- $data = [
- 'mid' => $user_id,
- 'oldvid' => $before,
- 'vid' => $after,
- 'type' => $other['type'],
- 'status' => $other['status'],
- 'desc' => $other['desc'],
- 'order_table' => $other['order_table'],
- 'order_id' => $other['order_id'],
- ];
- Db::name('store_vipuser')->insert($data);
- Db::commit();
- return true;
- }catch (\Exception $e){
- Db::rollback();
- return false;
- }
- }
- /**
- * 获取会员等级
- */
- function getMemberVipInfo($uid, $field = '' )
- {
- $memberVip = Db::name('store_member')->where('id',$uid)->value('vip');
- if(!$field){
- $vipInfo = Db::name('store_vip')
- ->where('id',$memberVip)
- ->where('is_del',0)
- ->where('status',1)
- ->value('discount');
- }else{
- $vipInfo = Db::name('store_vip')->field($field)
- ->where('id',$memberVip)
- ->where('is_del',0)
- ->where('status',1)
- ->find();
- }
- return $vipInfo;
- }
- /**
- * 优先购匹配藏品会员等级
- * @param int $user_id 会员Id
- * @param int $memberVip 会员等级
- * @param string $vids 藏品配置等级
- * @param array $other 其他
- */
- function memberBuyGoodsVip($user_id,$memberVip, $vids = '', $other = [])
- {
- $vidData = explode(',',$vids);
- if(!in_array($memberVip,$vidData)){
- return [];
- }
- //获取等级详情
- $vipInfo = Db::name('store_vip')->field('id,name,advance_minutes,advance_count')
- ->where('id',$memberVip)
- ->where('is_del',0)
- ->where('status',1)
- ->find();
- //获取用户已经购买数量
- $userByCount = getByCount($user_id,$other['gid']);
- if($userByCount >= $vipInfo['advance_count'] ){
- return [];
- }
- return $vipInfo;
- }
- /**
- * 验证会员优先购
- * @param int $user_id 会员Id
- * @param int $goods_id 藏品id
- */
- function checkMemberPriority($user_id,$goods_id)
- {
- $import_user = Db::name('store_collection_first')->where('c_id',$goods_id)->cache(300)->column('num','uid');
- if(isset($import_user[$user_id]) && $import_user[$user_id] > 0) return $import_user[$user_id];// 导入设置优先购
- $power_coll = Db::name('collection_power')->where('before_id',$goods_id)->cache(300)->column('coll_id'); // 藏品拥有者优先购
- if(empty($power_coll)) return false;
- $has_collect = Db::name('store_order_info')
- ->where('mid',$user_id)
- ->where('c_id','in',implode(',',$power_coll))
- ->where('status','neq','2')
- ->where('is_destruction',1)
- ->where('resale_status',1)
- ->cache(300)
- ->count();
- return $has_collect ? true : false;
- }
- /**
- * 手续费折扣
- * @param int $user_id 会员Id
- * @param array $other 其他
- */
- function getMemberServiceCharge($user_id)
- {
- // 设置
- $power_coll = Db::name('collection_power')->where('discount','>',0)
- ->order('discount desc ,id desc')
- ->cache(300)->column('discount','coll_id');
- if(empty($power_coll)) return 1;
- $has_collect = Db::name('store_order_info')
- ->field('c_id')
- ->whereIn('c_id',implode(',',array_keys($power_coll)))
- ->where('mid',$user_id)
- ->where('status','neq','2')
- ->where('is_destruction',1)
- ->where('resale_status',1)
- ->group('c_id')
- ->cache(300)
- ->select();
- $discount = 100;
- // var_dump($power_coll,$has_collect);
- foreach ($has_collect as $v) {
- if( isset($power_coll[$v['c_id']])) $discount = $power_coll[$v['c_id']];
- }
- return bcdiv($discount,100,2);
- }
- /**
- * 获取单个系统配置信息
- */
- function getConfigValue($name){
- return Db::name('system_config')->where('name',$name)->cache(300)->value('value');
- }
- /**
- * 判断藏品状态
- */
- function checkCollectionState($id=''){
- if ($id){
- $info = Db::name('store_collection')->field('id,sell_time,state,now_inventory')->where('id',$id)->find();
- $now_inventory = getCollectionInventory($id);
- if ($info['state']==1){
- if ($now_inventory<=0){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>3]);
- }
- }else if($info['state']==2){
- if (strtotime($info['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
- }
- }else if($info['state']==3){
- if ($now_inventory>0){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
- }
- }
- }else{
- $list = Db::name('store_collection')
- ->field('id,sell_time,state,now_inventory')
- ->where('is_deleted',0)
- ->select();
- foreach ($list as &$v){
- $now_inventory = getCollectionInventory($v['id']);
- if ($v['state']==1){
- if ($now_inventory<=0 || $v['now_inventory'] == 0){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>3]);
- }
- }elseif ($v['state']==2){
- if (strtotime($v['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
- }
- }elseif ($v['state']==3){
- if ($now_inventory>0){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
- }
- }
- }
- }
- }
- /**
- * 判断藏品状态
- */
- function checkSynCollectionState($id=''){
- if ($id){
- $info = Db::name('store_collection')->where('id',$id)->find();
- $now_inventory = getCollectionInventory($id);
- if ($info['sy_state']==1){
- if ($now_inventory<=0){
- Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
- }elseif(strtotime($info['end_time'])<time()){
- Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>3]);
- }
- }elseif ($info['sy_state']==2){
- if (strtotime($info['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>1]);
- }elseif ($now_inventory<=0){
- Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
- }
- }
- }else{
- $list = Db::name('store_collection')
- ->where('type',2)
- ->whereIn('sy_state','1,2')
- ->where('is_deleted',0)
- ->select();
- foreach ($list as &$v){
- $now_inventory = getCollectionInventory($v['id']);
- if ($v['sy_state']==1){
- if ($now_inventory<=0){
- Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
- }elseif($v['end_time'] && strtotime($v['end_time'])<time()){
- Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>3]);
- }
- }elseif ($v['sy_state']==2){
- if (strtotime($v['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>1]);
- }elseif ($now_inventory<=0){
- Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
- }
- }
- }
- }
- }
- /**
- * redis加锁
- */
- function redisSetNx($id,$exptime=3){
- $redis = new \think\cache\driver\Redis();
- $key = 'stock_'.$id;
- $is_lock = $redis->setnx($key,time()+$exptime);
- if ($is_lock){
- return true;
- }else{
- //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁
- $val = $redis->get($key);
- if ($val && $val<time()){
- $redis->del($key);
- }
- return $redis->setnx($key,time()+$exptime);
- }
- }
- /**
- * 删除锁
- */
- function DelRedisSetNx($id){
- $redis = new \think\cache\driver\Redis();
- $key = 'stock_'.$id;
- $redis->del($key);
- }
- /**
- * 盲盒信息存入redis hash
- */
- function setBoxInfoHash($id){
- $info = Db::name('store_collection')->where('id',$id)->find();
- $redis = new \think\cache\driver\Redis();
- $array = ['collection'.$id=>json_encode($info)];
- $redis->hMSet('collectionInfo',$array);
- }
- /**
- * 获取0的数量
- */
- function get0number($n){
- if ($n==1){
- return '00000000000';
- }elseif ($n==2){
- return '0000000000';
- }elseif ($n==3){
- return '000000000';
- }elseif ($n==4){
- return '00000000';
- }elseif ($n==5){
- return '0000000';
- }elseif ($n==6){
- return '000000';
- }elseif ($n==7){
- return '00000';
- }elseif ($n==8){
- return '0000';
- }elseif ($n==9){
- return '000';
- }elseif ($n==10){
- return '00';
- }elseif ($n==11){
- return '0';
- }
- }
- /***********************************************人脸识别*****************************************************************/
- /**
- * 获取accesstoken
- * @return mixed
- */
- function getAccessToken(){
- $appid_id =getFaceInfo()['appid'];
- $secret = getFaceInfo()['secret'];
- $grant_type = 'client_credential';
- $version = '1.0.0';
- $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id=".$appid_id."&secret=".$secret."&grant_type=".$grant_type."&version=".$version;
- $result = curlRequest($url);
- $result = json_decode($result,true);
- if ($result['code']==0){
- return $result;
- }
- echo $result['msg'];die;
- }
- /**
- * 获取api_ticket
- */
- function getApiTicket($type,$userId=''){
- $appid_id =getFaceInfo()['appid'];
- $access_token = getAccessToken()['access_token'];
- $version = '1.0.0';
- $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id=".$appid_id."&access_token=".$access_token."&type=".$type."&version=".$version;
- if ($type=='NONCE'){
- $url .= "&user_id=".$userId;
- }
- $result = curlRequest($url);
- $result = json_decode($result,true);
- if ($result['code']==0){
- return $result;
- }
- echo $result['msg'];die;
- }
- /**
- * 生成签名
- */
- function generateSign($userId){
- $wbappid = getFaceInfo()['appid'];
- $version = '1.0.0';
- $ticket = getApiTicket('SIGN')['tickets'][0]['value'];
- $nonce = get32Str();
- // $array = ['wbappid'=>$wbappid, 'userId'=>"$userId",'nonce'=>$nonce, 'version'=>$version, 'ticket'=>$ticket];
- $array = [$wbappid, "$userId",$nonce, $version, $ticket];
- file_put_contents("signLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
- sort($array);
- $str='';
- foreach ($array as $kk=>$vv){
- $str .=$vv;
- }
- // echo $str;die;
- $result = strtoupper(sha1($str));
- $res['sign'] = $result;
- $res['nonce'] = $nonce;
- $res['appid'] = $wbappid;
- return $res;
- }
- /**
- * 合作方后台上送身份信息
- */
- function getfaceid($name,$idNo,$userId){
- $webankAppId = getFaceInfo()['appid'];
- $orderNo = get32Str();
- $sign = generateSign($userId);
- $data = [
- 'webankAppId'=>$webankAppId,
- 'orderNo'=>$orderNo,
- 'name'=>$name,
- 'idNo'=>$idNo,
- 'userId'=>"$userId",
- 'version'=>'1.0.0',
- 'sign'=>$sign['sign'],
- 'nonce'=>$sign['nonce']
- ];
- $headers = [];
- array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
- $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getfaceid?orderNo='.$orderNo;
- $result = curlRequest($url,$headers,json_encode($data),'POST');
- $result = json_decode($result,true);
- if ($result['code']==0){
- $data = [
- 'appid'=>$sign['appid'],
- 'userID'=>"$userId",
- 'sign'=>$sign['sign'],
- 'nonce'=>$sign['nonce'],
- 'sdksign'=>SdkSign($userId,$sign['nonce']),
- 'result'=>$result['result'],
- ];
- return $data;
- }
- echo $result['msg'];die;
- }
- /**
- * 生成 SDK 接口调用步骤使用签名
- */
- function SdkSign($userId,$nonce){
- $wbappid = getFaceInfo()['appid'];
- $version = '1.0.0';
- $ticket = getApiTicket('NONCE',$userId)['tickets'][0]['value'];
- //$nonce = get32Str();
- $array = [$wbappid, "$userId",$nonce, $version, $ticket];
- file_put_contents("sdksignLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
- sort($array);
- $str='';
- foreach ($array as $kk=>$vv){
- $str .=$vv;
- }
- $result = strtoupper(sha1($str));
- return $result;
- }
- function getFaceInfo(){
- //正式
- $date = [
- 'appid'=>'IDAKcvCn',
- 'secret'=>'L1id3z5zROK8SVXg72ZyZXc8ziniYLKpOnIzN1gecrBaEMaKIlKrreyRGCLU2z4l'
- ];
- //测试
- // $date = [
- // 'appid'=>'TIDA3uGO',
- // 'secret'=>'z41IysbEhRy5oR4Qs2kFfVkrufXIJMtsJOQ3eulkWwXwdKG772LSSiZsKKwfsv9n'
- // ];
- return $date;
- }
- //将数组转成uri字符串
- function formatBizQueryParaMap($paraMap, $urlencode)
- {
- $buff = "";
- ksort($paraMap);
- foreach ($paraMap as $k => $v)
- {
- if($urlencode)
- {
- $v = urlencode($v);
- }
- // $buff .= strtolower($k) . "=" . $v . "&";
- $buff .= $v;
- }
- if (strlen($buff) > 0)
- {
- $reqPar = substr($buff, 0, strlen($buff)-1);
- }
- return $reqPar;
- }
- /**
- * 生成??位随机数
- */
- function get32Str($length='32'){
- // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
- 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;
- }
- ///**
- // * 生成二维码
- // */
- //function setqrcode($value,$name){
- // $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
- // if(!file_exists($dir)){
- // //检查是否有该文件夹,如果没有就创建,并给予最高权限
- // mkdir($dir, 0700,true);
- // }
- // $filename = $dir.'/'.$name.'.png';
- // QRcode::png($value,$filename,QR_ECLEVEL_L,7);
- // return 'http://'.$_SERVER['HTTP_HOST']."/user/".$name.'.png';
- //}
- /**
- * 生成二维码
- */
- function setqrcode($value,$name){
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
- if(!file_exists($dir)){
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($dir, 0700,true);
- }
- $filename = $dir.'/'.$name.'.png';
- QRcode::png($value,$filename,QR_ECLEVEL_L,7);
- $storage_type = getConfigValue('storage_type');
- if ($storage_type == 'oss'){
- $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint'));
- $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/user/".$name.".png";
- $newName = date('Ymd').'/'.get_order_sn().'.png';
- $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path);
- $url = $result['info']['url'];
- unlink($file_path);
- }else{
- $url = 'http://'.$_SERVER['HTTP_HOST']."/user/".$name.'.png';
- }
- return $url;
- }
- //生成邀请二维码
- function setintivecode($user_id){
- $name = $user_id."_".time();
- $address = 'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/zhuce?invite_code='.$user_id;
- $url = setqrcode($address,$name);
- return $url;
- }
- //邀请地址
- function getintiveaddress($user_id){
- $address = 'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/zhuce?invite_code='.$user_id;
- return $address;
- }
- /**
- * @param $url
- * @param array $headers
- * @param array $body
- * @param string $method
- * @return bool|string
- */
- function curlRequest($url, $headers = [], $body = [], $method = "GET")
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置请求头
- curl_setopt($ch, CURLOPT_POSTFIELDS, $body);//设置请求体
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //定义请求类型
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- /**
- * 盲盒藏品库存和藏品状态判断
- * @param $proArr
- * @return int|string
- */
- function checkBox(){
- $list = Db::name('store_blind_box')
- ->where('status',1)
- ->where('is_del',1)
- ->field('id,is_prize,prize')
- ->select();
- foreach ($list as &$v){
- if ($v['is_prize']==1){
- $info = Db::name('store_collection')->where('id',$v['prize'])->find();
- if ($info['now_inventory']<=0 || $info['status']==0 || $info['is_deleted']==1){
- Db::name('store_blind_box')->where('id',$v['id'])->update(['status'=>0]);
- }
- }
- }
- }
- //计算中奖概率
- function get_rand($proArr) {
- $result = '';
- //概率数组的总概率精度
- $proSum = array_sum($proArr);
- // var_dump($proSum);
- //概率数组循环
- foreach ($proArr as $key => $proCur) {
- $randNum = mt_rand(1, $proSum); //返回随机整数
- if ($randNum <= $proCur) {
- $result = $key;
- break;
- } else {
- $proSum -= $proCur;
- }
- }
- unset ($proArr);
- return $result;
- }
- /**
- * 调试函数
- */
- function debug($str){
- $str = var_export($str,true).PHP_EOL;
- $str.= date('Y-m-d H:i:s').' ';
- $str.= $_SERVER['REMOTE_ADDR'].' ';
- $str.= $_SERVER['REQUEST_METHOD'].': ';
- // $str.=$_SERVER['HTTP_HOST'];
- $str.= $_SERVER['REQUEST_URI'].''.PHP_EOL.PHP_EOL;
- $str='<?php exit();?>'.PHP_EOL.$str;
- error_log($str,3,"debug.log");
- }
- /**
- * 获取链上ip
- */
- function getIpAddress(){
- $address = 'http://8.136.12.232:8088/';
- return $address;
- }
- function arrayToXml($arr)
- {
- $xml = "<xml>";
- foreach ($arr as $key => $val) {
- if (is_numeric($val)) {
- $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
- } else
- $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
- }
- $xml .= "</xml>";
- return $xml;
- }
- /**
- * 验证银行卡号
- * @param string $bankCardNo 银行卡号
- * @return bool 是否合法(true:合法,false:不合法)
- */
- function check_bankCard($bankCardNo){
- $arr_no = str_split($bankCardNo);
- $last_n = $arr_no[count($arr_no)-1];
- krsort($arr_no);
- $i = 1;
- $total = 0;
- foreach ($arr_no as $n){
- if($i%2==0){
- $ix = $n*2;
- if($ix>=10){
- $nx = 1 + ($ix % 10);
- $total += $nx;
- }else{
- $total += $ix;
- }
- }else{
- $total += $n;
- }
- $i++;
- }
- $total -= $last_n;
- $total *= 9;
- if($last_n == ($total%10)){
- return 1;
- }
- return 0;
- }
- /*
- *收银台接口:三个都要
- *银行卡快捷支付接口:三个都要
- *余额支付接口:基础+API
- *提现接口:基础
- **/
- function risk_item($user_info,$goods_name,$frms_client_chnl =16 )
- {
- return [
- //基本参数中的
- 'frms_ware_category' => 4007 ,
- 'goods_name' => $goods_name ,
- 'user_info_mercht_userno' => $user_info['id'] ,
- 'user_info_dt_register' => date('YmdHis',strtotime($user_info['create_at'])) ,
- 'user_info_bind_phone' => $user_info['phone'] ,
- //实名类参数中的
- 'user_info_full_name' => $user_info['true_name'],
- 'user_info_id_no' => $user_info['id_card'],
- 'user_info_identify_state' => 1,
- 'user_info_identify_type' => 2,
- 'user_info_id_type' => 0,
- //API调用必传参数中的
- 'frms_client_chnl'=>$frms_client_chnl,//业务来源
- 'frms_ip_addr'=> request()->ip(),
- 'user_auth_flag'=>1,
- ];
- }
- function checkAuth($str){
- return true;
- }
|