123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830 |
- <?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 = "0077fde8e0474401b8e090b780da1a97";
- $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 user_certification($id_card,$name){
- $host = "http://checkone.market.alicloudapi.com";
- $path = "/chinadatapay/1882";
- $method = "POST";
- $appcode = "30be8bdcc65842919980a8276ffc4995";
- $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);
- dump($res);die;
- if($res){
- $res = json_decode($res,true);
- if($res['data']['result'] == 1){
- return 1;
- }else{
- return 0;
- }
- }else{
- return 0;
- }
- }
- function idcardlingyu1($id_card,$name)
- {
- $data = array(
- 'appId' => 'QYeloNCb',
- 'appKey' => 'Q0PR2wle',
- 'name' => $name,
- 'idNum'=>$id_card
- );
- $data_string = json_encode($data,JSON_UNESCAPED_UNICODE);
- // $data_string = $data;
- $curl_con = curl_init();
- curl_setopt($curl_con, CURLOPT_URL,$url);
- curl_setopt($curl_con, CURLOPT_HEADER, false);
- curl_setopt($curl_con, CURLOPT_POST, true);
- curl_setopt($curl_con, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($curl_con, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($curl_con, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data_string))
- );
- curl_setopt($curl_con, CURLOPT_POSTFIELDS, $data_string);
- $res = curl_exec($curl_con);
- $status = curl_getinfo($curl_con);
- curl_close($curl_con);
- if (isset($status['http_code']) && $status['http_code'] == 200) {
- return $res;
- } else {
- return FALSE;
- }
- }
- function idcardlingyu($id_card,$name){
- $url = 'http://139.224.206.237:3333/user/api/id-card-auth';
- $header = array(
- 'Content-Type:application/x-www-form-urlencoded;boundary=ebf9f03029db4c2799ae16b5428b06bd1',
- );
- $data = array(
- 'appId' => 'QYeloNCb',
- 'appKey' => 'Q0PR2wle',
- 'name' => $name,
- 'idNum'=>$id_card
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $sResult = curl_exec($ch);
- if($sError=curl_error($ch)){
- die($sError);
- }
- curl_close($ch);
- $res = json_decode($sResult,true);
- // dump($res);
- if (isset($res) && $res['code']=='200000'){
- return true;
- }
- return false;
- }
- //四要素
- function idcardlingyufour($id_card,$name,$bank_card,$bank_mobile){
- $url = 'http://139.224.206.237:3333/user/api/cardAuth';
- $header = array(
- 'Content-Type:application/x-www-form-urlencoded;boundary=ebf9f03029db4c2799ae16b5428b06bd1',
- );
- $data = array(
- 'appId' => 'QYeloNCb',
- 'appKey' => 'Q0PR2wle',
- 'name' => $name,
- 'idNum'=>$id_card,
- 'cardNo'=>$bank_card,
- 'mobile'=>$bank_mobile
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $sResult = curl_exec($ch);
- if($sError=curl_error($ch)){
- die($sError);
- }
- curl_close($ch);
- $res = json_decode($sResult,true);
- //dump($res);die;
- $array['success'] = 0;
- if (isset($res) && $res['code']=='200000'){
- if (isset($res['data']['result']) && $res['data']['result']=='01'){
- $array['success']=1;
- $array['remark'] ='验证成功';
- }else{
- $array['remark'] = $res['data']['remark'];
- }
- }else{
- $array['remark'] ='认证失败';
- }
- return $array;
- }
- function shoucang(){
- $host = "http://180.76.141.31:8888/cz/call";
- $method = "POST";
- $headers = array();
- array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
- $bodys = array(
- 'key' => 'test2',
- 'userkey' => '12344',
- 'product' => json_encode(array('name'=>'test','count'=>7))
- );
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $host);
- 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, json_encode($bodys));
- $res = curl_exec($curl);
- var_dump($res);exit();
- }
- /**
- * 大师提前分钟数存入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;
- }
- /**
- * 用户抢购卡数量存入redis 字符串
- */
- function setMembercard($member_id){
- $snap_card = Db::name('store_member')->where('id',$member_id)->value('snap_card');
- $redis = new \think\cache\driver\Redis();
- $redis->set('membercard_'.$member_id,$snap_card);
- }
- /**
- * 获取用户抢购卡数量
- */
- function getMembercard($member_id){
- $redis = new \think\cache\driver\Redis();
- $count = $redis->get('membercard_'.$member_id);
- if (empty($count)){
- $count = Db::name('store_member')->where('id',$member_id)->value('snap_card');
- $redis->set('membercard_'.$member_id,$count);
- }
- return $count;
- }
- /**
- * 减掉用户抢购卡数量(减1)
- */
- function loseMembercard($id){
- $redis = new \think\cache\driver\Redis();
- $redis->Decr('membercard_'.$id);
- }
- /**
- * 增加用户抢购卡数量(加1)
- */
- function addMembercard($id){
- $redis = new \think\cache\driver\Redis();
- $redis->Incr('membercard_'.$id);
- }
- /**
- * 获取藏品库存
- */
- function getCollectionInventory($id){
- $redis = new \think\cache\driver\Redis();
- $count = $redis->get('collection_count_'.$id);
- 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){
- $redis = new \think\cache\driver\Redis();
- $redis->Incr('ranking'.$id);
- }
- /**
- * 获取用户购买藏品排名更新
- */
- function getRanking($id){
- $redis = new \think\cache\driver\Redis();
- $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 = Db::name('store_order')
- // ->where('mid',$mid)
- // ->where('c_id',$id)
- // ->whereIn('status','0,1')
- // ->sum('num');
- // $count = $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' => 'wxa6980453638c9c78',
- 'mch_id' =>'1623128602',
- 'key' =>'qwertyuiopASDFGHJKLZXCVBNM123456',
- ];
- return $config;
- }
- /**
- * 获取离线账户
- */
- function getOfflineAccount(){
- $url = 'http://192.144.219.204:8083/ddc/createAccount';
- return file_get_contents($url);
- }
- /**
- * 获取链账户
- */
- function getWalletAddress($phone){
- $url = 'http://39.107.12.194:8088/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')
- ->limit(1)
- ->find();
- }else{
- $hash = json_decode($hash,true);
- }
- return $hash;
- }
- /**
- * 获取排名
- */
- function getTag($id,$now,$num){
- $len = strlen($num);
- $re = getConfigValue('tag_prefix').$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;
- case 7:
- if ($now<10){
- $re = $re.'000000'.$now;
- }elseif ($now>=10 && $now<100){
- $re = $re.'00000'.$now;
- }elseif ($now>=100 && $now<1000){
- $re = $re.'0000'.$now;
- }elseif ($now>=1000 && $now<10000){
- $re = $re.'000'.$now;
- }elseif ($now>=10000 && $now<100000){
- $re = $re.'00'.$now;
- }elseif ($now>=100000 && $now<1000000){
- $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)
- {
- $member = Db::name('store_member')->where('id',$m_id)->find();
- switch ($type){
- case 1: //积分
- $before = $member['integral'];
- if ($pm==1)
- $after = $member['integral']+$num;
- else
- $after = $member['integral']-$num;
- $update_data = ['integral'=>$after];
- 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'=>$after];
- break;
- case 3: //余额
- $before = $member['money'];
- if ($pm==1)
- $after = $member['money']+$num;
- else
- $after = $member['money']-$num;
- $update_data = ['money'=>$after];
- break;
- }
- Db::startTrans();
- 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
- ];
- Db::name('store_member_log')->insert($data);
- Db::commit();
- return true;
- }catch (\Exception $e){
- Db::rollback();
- return false;
- }
- }
- /**
- * 获取单个系统配置信息
- */
- function getConfigValue($name){
- return Db::name('system_config')->where('name',$name)->value('value');
- }
- /**
- * 判断藏品状态
- */
- function checkCollectionState($id=''){
- if ($id){
- $info = Db::name('store_collection')->where('id',$id)->find();
- $now_inventory = getCollectionInventory($id);
- if (!empty($v['endtime']) && strtotime($info['endtime'])<time()){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>4]);
- }else{
- 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 if($info['state']==4){
- if ($now_inventory>0){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
- }elseif (strtotime($info['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
- }elseif ($now_inventory<=0){
- //Db::name('store_collection')->where('id',$info['id'])->update(['state'=>3]);
- }
- }
- }
- setCollectionInfoHash($id);
- }else{
- $list = Db::name('store_collection')
- ->whereIn('state','1,2,3,4')
- ->where('status',1)
- ->where('is_deleted',0)
- ->select();
- foreach ($list as &$v){
- $now_inventory = getCollectionInventory($v['id']);
- if (!empty($v['endtime']) && strtotime($v['endtime'])<time()){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>4]);
- }else{
- if ($v['state']==1){
- if ($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]);
- }
- }else if($v['state']==4){
- if ($now_inventory>0){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
- }elseif (strtotime($v['sell_time'])<=time()){
- Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
- }elseif ($now_inventory<=0){
- // Db::name('store_collection')->where('id',$v['id'])->update(['state'=>3]);
- }
- }
- }
- setCollectionInfoHash($v['id']);
- }
- }
- }
- /**
- * 判断藏品状态
- */
- 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(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($key,$exptime){
- $redis = new \think\cache\driver\Redis(['select'=>2]);
- $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($key){
- $redis = new \think\cache\driver\Redis(['select'=>2]);
- $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;
- }
- /**
- * 生成32位随机数
- */
- function get32Str($length='32'){
- $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
- /**
- * 盲盒藏品库存和藏品状态判断
- * @param $proArr
- * @return int|string
- */
- function checkBoxCollection($coll_id){
- $list = Db::name('store_box')
- ->where('status',1)
- ->where('coll_id',$coll_id)
- ->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();
- $now_inventory = getCollectionInventory($info['id']);
- if ($now_inventory<=0 || $info['status']==0 || $info['is_deleted']==1){
- Db::name('store_box')->where('id',$v['id'])->update(['status'=>0]);
- }
- }
- }
- }
- 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);
- $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['SERVER_NAME']."/user/".$name.'.png';
- }
- return $url;
- }
- //生成邀请二维码
- function setintivecode($user_id){
- $name = $user_id."_".time();
- $address = 'https://'.$_SERVER['SERVER_NAME'].'/pages/mine/zhuce?invite_code='.$user_id;
- $url = setqrcode($address,$name);
- return $url;
- }
- //邀请地址
- function getintiveaddress($user_id){
- $address = 'https://'.$_SERVER['SERVER_NAME'].'/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;
- }
- /**
- * 获取链上ip
- */
- function getIpAddress(){
- $address = 'http://120.27.21.5:8083/';
- return $address;
- }
- /**
- * 调试函数
- */
- 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");
- }
- function getAge($id){
- # 1.从身份证中获取出生日期
- $id = $id;//身份证
- $birth_Date = strtotime(substr($id, 6, 8));//截取日期并转为时间戳
- # 2.格式化[出生日期]
- $Year = date('Y', $birth_Date);//yyyy
- $Month = date('m', $birth_Date);//mm
- $Day = date('d', $birth_Date);//dd
- # 3.格式化[当前日期]
- $current_Y = date('Y');//yyyy
- $current_M = date('m');//mm
- $current_D = date('d');//dd
- # 4.计算年龄()
- $age = $current_Y - $Year;//今年减去生日年
- if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
- $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
- }
- # 返回
- return $age;
- }
- /**
- * 金额校验函数
- * @param $value
- * @param bool $isZero
- * @param bool $negative
- * @return bool
- */
- function isAmount($value, $isZero=false, $negative=false){
- // 必须是整数或浮点数,且允许为负
- if (!preg_match("/^[-]?\d+(.\d{1,2})?$/", $value)){
- return false;
- }
- // 不为 0
- if (!$isZero && empty((int)($value*100))){
- return false;
- }
- // 不为负数
- if (!$negative && (int)($value * 100) < 0){
- return false;
- }
- return true;
- }
- //注册邀请奖励
- function pull_new($mid){
- checkactivity();
- //判断有没有正在进行的活动
- $act = Db::name('store_activity')
- ->where('is_del',1)
- ->where('state',1)
- ->where('status',2)
- ->find();
- if ($act){
- $user1 = getMemberInfoHash($mid); //获取用户信息
- if ($user1['pid']){
- //先判断有没有单人拉新奖励活动
- $info = Db::name('store_activities')
- ->where('ac_id',$act['id'])
- ->where('is_del',1)
- ->where('type',2)
- ->where('state',1)
- ->find();
- if ($info){
- $pro_info = getCollectionInfoHash($info['c_id2']);
- $now_inventory = getCollectionInventory($info['c_id2']);
- if ($now_inventory>0){
- $is_nft = Db::name('hash2')->where('goods_id',$info['c_id2'])->find();
- if (!$is_nft || !$is_nft['success']){
- }else{
- //获取排名
- $rank = getRanking($info['c_id2'])+1;
- $tag = getTag($info['c_id2'],$rank,$pro_info['inventory']);
- saveRanking($info['c_id2']);
- $collectors_hash = '';
- $date = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$mid,
- 'c_id'=>$info['c_id2'],
- 'name'=>$pro_info['name'],
- 'cover'=>$pro_info['cover'],
- 'pro_info'=>json_encode($pro_info,true),
- 'type'=>$pro_info['type'],
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'新人被邀请奖励'
- ];
- if (Db::name('store_order_info')->insert($date)){
- loseCollectionInventory($info['c_id2'],1);
- }
- }
- }
- }
- //判断邀请人邀请的人数
- $count = Db::name('store_activities_invite_log')
- ->where('mid',$user1['pid'])
- ->where('create_at','egt',$act['start_at'])
- ->where('create_at','elt',$act['end_at'])
- ->count();
- if ($count){
- if ($count==1){
- if ($info){
- $pro_info = getCollectionInfoHash($info['c_id']);
- $now_inventory = getCollectionInventory($info['c_id']);
- if ($now_inventory>0){
- $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
- if (!$is_nft || !$is_nft['success']){
- }else{
- //获取排名
- $rank = getRanking($info['c_id'])+1;
- $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
- saveRanking($info['c_id']);
- $collectors_hash = '';
- $dates = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$user1['pid'],
- 'c_id'=>$info['c_id'],
- 'name'=>$pro_info['name'],
- 'cover'=>$pro_info['cover'],
- 'pro_info'=>json_encode($pro_info,true),
- 'type'=>$pro_info['type'],
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'邀请单人奖励'
- ];
- if (Db::name('store_order_info')->insert($dates)){
- loseCollectionInventory($info['c_id'],1);
- }
- }
- }
- }
- }else{
- //查询有没有当前人数的活动
- $info = Db::name('store_activities')
- ->where('ac_id',$act['id'])
- ->where('is_del',1)
- ->where('type',3)
- ->where('state',1)
- ->where('num',$count)
- ->find();
- if ($info){
- $pro_info = getCollectionInfoHash($info['c_id']);
- $now_inventory = getCollectionInventory($info['c_id']);
- if ($now_inventory>0){
- $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
- if (!$is_nft || !$is_nft['success']){
- }else{
- //获取排名
- $rank = getRanking($info['c_id'])+1;
- $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
- saveRanking($info['c_id']);
- $collectors_hash = '';
- $dates = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$user1['pid'],
- 'c_id'=>$info['c_id'],
- 'name'=>$pro_info['name'],
- 'cover'=>$pro_info['cover'],
- 'pro_info'=>json_encode($pro_info,true),
- 'type'=>$pro_info['type'],
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'邀请'.$count.'人奖励'
- ];
- if (Db::name('store_order_info')->insert($dates)){
- loseCollectionInventory($info['c_id'],1);
- }
- }
- }
- }
- }
- }
- }else{
- //判断新人注册是否有活动
- $info = Db::name('store_activities')
- ->where('ac_id',$act['id'])
- ->where('is_del',1)
- ->where('state',1)
- ->where('type',1)
- ->find();
- if ($info){
- $pro_info = getCollectionInfoHash($info['c_id']);
- $now_inventory = getCollectionInventory($info['c_id']);
- if ($now_inventory>0){
- $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
- if (!$is_nft || !$is_nft['success']){
- }else{
- //获取排名
- $rank = getRanking($info['c_id'])+1;
- $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
- saveRanking($info['c_id']);
- $collectors_hash = '';
- $date = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$mid,
- 'c_id'=>$info['c_id'],
- 'name'=>$pro_info['name'],
- 'cover'=>$pro_info['cover'],
- 'pro_info'=>json_encode($pro_info,true),
- 'type'=>$pro_info['type'],
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'新人注册奖励'
- ];
- if (Db::name('store_order_info')->insert($date)){
- loseCollectionInventory($info['c_id'],1);
- }
- }
- }
- }
- }
- }
- return true;
- }
- function pullNew($mid){
- //判断给拉新奖励
- $user1 = getMemberInfoHash($mid); //获取用户信息
- if ($user1['pid']){
- //获取奖励列表
- $ids = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('pull_new',1)
- ->column('id');
- if ($ids){
- $array = [];
- foreach ($ids as &$v){
- $now_inventory = getCollectionInventory($v);
- if ($now_inventory>1){
- array_push($array,$v);
- }
- }
- if ($array){
- $vaule = array_rand($array);
- $id = $array[$vaule];
- $info = getCollectionInfoHash($id);
- $is_nft = Db::name('hash2')->where('goods_id',$id)->where('success',1)->find();
- //获取排名
- $rank = getRanking($id)+1;
- $tag = getTag($id,$rank,$info['inventory']);
- saveRanking($id);
- $collectors_hash = '';
- $date = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$user1['pid'],
- 'c_id'=>$id,
- 'name'=>$info['name'],
- 'cover'=>$info['cover'],
- 'pro_info'=>json_encode($info,true),
- 'type'=>$info['type'],
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'拉新奖励'
- ];
- Db::name('store_order_info')->insert($date);
- // //获取排名
- // $rank = getRanking($id)+1;
- // $tag = getTag($id,$rank,$info['inventory']);
- // saveRanking($id);
- // $collectors_hash = '';
- // $data = [
- // 'order_no'=>get_order_sn(),
- // 'tag'=>$tag,
- // 'mid'=>$mid,
- // 'c_id'=>$id,
- // 'name'=>$info['name'],
- // 'cover'=>$info['cover'],
- // 'pro_info'=>json_encode($info,true),
- // 'type'=>$info['type'],
- // 'tokenid'=>$is_nft['class_id'],
- // 'nfttype'=>$is_nft['operationId'],
- // 'collectors_hash'=>$collectors_hash,
- // 'collectors_hash_time'=>'',
- // 'remark'=>'被拉新奖励'
- // ];
- // Db::name('store_order_info')->insert($data);
- }
- }
- //获取奖励列表
- $ids2 = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('pull_new2',1)
- ->column('id');
- if ($ids2){
- $array2 = [];
- foreach ($ids2 as &$v){
- $now_inventory2 = getCollectionInventory($v);
- if ($now_inventory2>1){
- array_push($array,$v);
- }
- }
- if ($array2){
- $vaule = array_rand($array2);
- $id2 = $array2[$vaule];
- $info2 = getCollectionInfoHash($id2);
- $is_nft2 = Db::name('hash2')->where('goods_id',$id2)->where('success',1)->find();
- //获取排名
- $rank = getRanking($id2)+1;
- $tag = getTag($id2,$rank,$info2['inventory']);
- saveRanking($id2);
- $collectors_hash = '';
- $data2 = [
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$mid,
- 'c_id'=>$id2,
- 'name'=>$info2['name'],
- 'cover'=>$info2['cover'],
- 'pro_info'=>json_encode($info2,true),
- 'type'=>$info2['type'],
- 'tokenid'=>$is_nft2['class_id'],
- 'nfttype'=>$is_nft2['operationId'],
- 'collectors_hash'=>$collectors_hash,
- 'remark'=>'被拉新奖励'
- ];
- Db::name('store_order_info')->insert($data2);
- }
- }
- }
- }
- /**
- * 判断邀请人活动
- * @param $proArr
- * @return int|string
- */
- function checkactivity($id=''){
- if ($id){
- $info = Db::name('store_activity')->where('id',$id)->find();
- if (time()<strtotime($info['start_at'])){
- Db::name('store_activity')->where('id',$id)->update(['status'=>1]);
- }elseif (time()>strtotime($info['start_at']) && time()<strtotime($info['end_at'])){
- Db::name('store_activity')->where('id',$id)->update(['status'=>2]);
- }elseif (time()>strtotime($info['end_at'])){
- Db::name('store_activity')->where('id',$id)->update(['status'=>3]);
- }
- }else{
- $list = Db::name('store_activity')->where('is_del',1)->select();
- foreach ($list as &$v){
- if (time()<strtotime($v['start_at'])){
- Db::name('store_activity')->where('id',$v['id'])->update(['status'=>1]);
- }elseif (time()>strtotime($v['start_at']) && time()<strtotime($v['end_at'])){
- Db::name('store_activity')->where('id',$v['id'])->update(['status'=>2]);
- }elseif (time()>strtotime($v['end_at'])){
- Db::name('store_activity')->where('id',$v['id'])->update(['status'=>3]);
- }
- }
- }
- }
- /**
- * 登录日志
- */
- function LoginLog($mid){
- $data = [
- 'mid'=>$mid,
- 'ip'=>request()->ip()
- ];
- Db::name('store_login_log')->insert($data);
- }
- /**
- * 判断银行卡号格式
- */
- function checkbank($no=""){
- if(empty($no)) return false;
- $arr_no = str_split($no);
- $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;
- $x = 10 - ($total % 10);
- if($x == $last_n){
- return true;
- }else{
- return false;
- }
- }
|