where('status',0)->select(); foreach ($list as &$v){ $cancel_time = strtotime($v['create_at'])+($CancelTime*60); if ($cancel_timewhere('id',$v['id'])->update(['status'=>2,'cancel_at'=>date('Y-m-d H:i:s'),'cancel_state'=>1]); //增加数据库库存 Db::name('store_collection')->where('id',$v['c_id'])->setInc('now_inventory',$v['num']); //增加用户抢购卡数量 Db::name('store_member')->where('id',$v['mid'])->setInc('snap_card'); //加上库存 addCollectionInventory($v['c_id'],$v['num']); //减少用户购买数量 DecrByCount($v['mid'],$v['c_id'],$v['num']); //加上抢购卡数量 addMembercard($v['mid']); } } } /** * 藏品铸造hash 定时任务 * @url /api/Timedtask/castingHash */ public function castingHash(){ set_time_limit(0); $redis = new Redis(); $list = Db::name('store_collection')->where('is_deleted',0)->select(); $id = 0; $set_count = 0; foreach ($list as &$v){ // $info = Db::name('hash')->where('goods_id',$v['id'])->where('success',0)->count(); // if ($info){ // break; // } $count = $redis->get('castingHash_'.$v['id']); if ($count && $count>0){ $id = $v['id']; $set_count = $count; break; } } if ($id){ $address = '0xc472ec30ec813784b19872565e045c7153ea3f17'; for ($i=0;$i<$set_count;$i++){ $url2='http://192.144.219.204:8083/ddc/getNonce'; $nonce=curlRequest($url2); $str=$id.'-'.rand(100000000,999999999); $url='http://192.144.219.204:8083/ddc/createHash?address='.$address.'&ddcURI='.$str.'&nonce='.$nonce; $res=curlRequest($url); $result=json_decode($res,true); if($result['code']){ continue; }else{ $data['goods_id']=$id; $data['hash']=$res; $data['nonce'] = $nonce; $data['ddcURI'] = $str; if (Db::name('hash')->insert($data)){ $redis->Decr('castingHash_'.$id); //减一 } } } } } /** * 铸造hash判断回执 定时任务 * @url /api/Timedtask/transactionReceipt */ public function transactionReceipt(){ set_time_limit(0); Db::name('hash')->where('success',0)->where('id','neq','9748')->chunk(50,function ($list){ $redis = new Redis(); foreach ($list as &$v){ echo $v['id']."
"; $url = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash='.$v['hash']; $res=curlRequest($url); Db::name('hash')->where('id',$v['id'])->update(['result'=>$res]); $result3=json_decode($res,true); dump($result3); if (isset($result3['status']) && $result3['status']=='0x1'){ $update_data['success'] = 1; $url4='http://192.144.219.204:8083/ddc/createDdcid?hash='.$v['hash']; $ddcid=curlRequest($url4); echo $ddcid."
"; $result4=json_decode($ddcid,true); if($result4['code']){ }else{ $update_data['ddcid'] = $ddcid; } if (Db::name('hash')->where('id',$v['id'])->update($update_data)){ //存入reids list $redis_data = ['hash'=>$v['hash'],'create_at'=>date('Y-m-d H:i:s')]; $redis->rPush('collectionHash_'.$v['goods_id'],json_encode($redis_data)); } } } },'id', 'asc'); } /** * 铸造失败的再次生成hash * @url /api/Timedtask/castingHashAgain */ public function castingHashAgain(){ set_time_limit(0); Db::name('hash') ->where('success',0) ->where('id','neq','9748') ->whereNotNull('result') ->chunk(50,function ($list){ $redis = new Redis(); foreach ($list as &$v){ $info = json_decode($v['result'],true); echo $v['id']."
"; dump($info); if ($info['code']=='500'){ $url = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash='.$v['hash']; $res=curlRequest($url); Db::name('hash')->where('id',$v['id'])->update(['result'=>$res]); $result3=json_decode($res,true); if (isset($result3['status']) && $result3['status']=='0x1'){ $update_data['success'] = 1; $url4='http://192.144.219.204:8083/ddc/createDdcid?hash='.$v['hash']; $ddcid=curlRequest($url4); $result4=json_decode($ddcid,true); if($result4['code']){ }else{ $update_data['ddcid'] = $ddcid; } if (Db::name('hash')->where('id',$v['id'])->update($update_data)){ //存入reids list $redis_data = ['hash'=>$v['hash'],'create_at'=>date('Y-m-d H:i:s')]; $redis->rPush('collectionHash_'.$v['goods_id'],json_encode($redis_data)); } } } } },'id', 'asc'); } /** * 发放hash * @url /api/Timedtask/sendHash */ public function sendHash(){ set_time_limit(0); Db::name('store_order_info') ->whereNotNull('company_hash') ->whereIn('status','1,3') ->where('company_hash','neq','') ->where('collectors_hash','eq','') ->chunk('20',function ($list){ $from = '0xc472ec30ec813784b19872565e045c7153ea3f17'; foreach ($list as &$v){ echo $v['id']."
"; $url2='http://192.144.219.204:8083/ddc/getNonce'; $nonce=curlRequest($url2); if ($v['status']==1){ $mid = $v['mid']; }elseif ($v['status']==3){ $from = Db::name('store_member')->where('id',$v['to_mid'])->value('wallet_address'); $mid = $v['to_mid']; } $to = Db::name('store_member')->where('id',$mid)->value('wallet_address'); if (empty($to) || $to == ''){ continue; } $ddcid =Db::name('hash')->where('hash',$v['company_hash'])->value('ddcid'); $url = "http://192.144.219.204:8083/ddc/transfer?from=$from&to=$to&ddcid=$ddcid&nonce=".$nonce; $res=curlRequest($url); echo $res.'
'; $result=json_decode($res,true); if($result['code']){ continue; }else{ Db::name('store_order_info')->where('id',$v['id'])->update(['collectors_hash'=>$res,'collectors_hash_time'=>date('Y-m-d H:i:s')]); } } },'id','asc'); } /** * 终端账号充值业务费用及能量 * /api/Timedtask/recharge */ public function recharge(){ set_time_limit(0); Db::name('store_order_info') ->whereIn('status','1,3') ->whereRaw("is_business=0 or is_gas=0") ->field('id,is_gas,is_business,gas,business,mid') ->chunk('20',function ($list){ foreach ($list as &$v){ $data = []; $address = Db::name('store_member')->where('id',$v['mid'])->value('wallet_address'); // echo $address;die; if ($v['is_business']==0){ $rand = get_order_sn(); $money = '30'; $url = "http://192.144.219.204:8083/ddc/rechargeBusiness?money=$money&address=$address&transSn=".$rand; $res=curlRequest($url); $result = json_decode($res,true); echo $address."
"; // dump($result).'
'; if (isset($result['code']) && $result['code']==0){ $data['is_business'] = 1; $data['business'] = $money; } } if ($v['is_gas']==0){ $rand2 = get_order_sn(); $money2 = '40'; $url2 = "http://192.144.219.204:8083/ddc/rechargeGas?money=$money2&address=$address&transSn=".$rand2; $res2=curlRequest($url2); $result2 = json_decode($res2,true); //print_r($result2)."
"; if (isset($result2['code']) && $result2['code']==0){ $data['is_gas'] = 1; $data['gas'] = $money2; } } if ($data){ Db::name('store_order_info')->where('id',$v['id'])->update($data); } } },'id','asc'); } /** * @title 创建链账户 * @desc 创建链账户 * @author Gavin * @url /api/Timedtask/createAddress * @method GET */ public function createAddress(){ set_time_limit(0); Db::name('store_member')->whereNull('wallet_address')->chunk(30,function ($member){ //dump($member);die; foreach ($member as &$v){ //if (empty($v['offline_account']) || $v['offline_account']==''){ $offline_accounts = getOfflineAccount(); $v['offline_account'] =$offline_accounts; //} $offline_account = json_decode($v['offline_account'],true); $address = $offline_account['address']; $laddress = getWalletAddress($v['phone'].$v['id'],$address); dump($laddress); if ($laddress['code']==0){ $wallet_address = $laddress['data']['opbChainClientAddress']; Db::name('store_member')->where('id',$v['id'])->update(['wallet_address'=>$wallet_address]); } } },'id','asc'); } /** * 创建ddcid * @url /api/Timedtask/ddcid */ public function ddcid() { set_time_limit(0); Db::name('hash')->where('ddcid',NULL)->chunk('30',function ($list){ foreach($list as $k=>$v){ $url='http://192.144.219.204:8083/ddc/createDdcid?hash='.$v['hash']; $res=curlRequest($url); $result=json_decode($res,true); if($result['code']){ continue; }else{ Db::table('hash')->where('id',$v['id'])->update(['ddcid'=>$res]); } } },'id','asc'); } /** * 开通官方ddc * @url /api/Timedtask/openOfficialDDc */ public function openOfficialDDc(){ set_time_limit(0); Db::name('store_member') ->where('is_open_official_DDC',0) ->whereNotNull('wallet_address') ->field('id,wallet_address,is_open_official_DDC') ->chunk(50,function ($list){ foreach ($list as &$v){ $url = 'http://192.144.219.204:8083/ddc/status?address='.$v['wallet_address']; $res=curlRequest($url); $result = json_decode($res,true); if (isset($result) && $result['data']['platformSetState']!=2 && $result['data']['opsPlatformState']!=2){ $url2 = 'http://192.144.219.204:8083/ddc/official?address='.$v['wallet_address']; $res2=curlRequest($url2); $result2 = json_decode($res2,true); if ($result2['code']==0){ Db::name('store_member')->where('id',$v['id'])->update(['is_open_official_DDC'=>1]); } }else{ Db::name('store_member')->where('id',$v['id'])->update(['is_open_official_DDC'=>1]); } } },'id','asc'); } }