hkeys('buyUserInfo'); if ($users){ foreach ($users as &$value){ $key = 'order_not_pay_'.$value; $len = $redis->hGetLen($key); if ($len){ $list = $redis->hGetvals($key); foreach ($list as &$a){ $info = json_decode($a,true); $cancel_time = strtotime($info['create_at'])+($CancelTime*60); if ($cancel_timeinsert($info); //加上库存 addCollectionInventory($info['c_id'],$info['num']); //减少用户购买数量 DecrByCount($info['mid'],$info['c_id'],$info['num']); //删除数据 $redis->hdel($key,$info['order_no']); } } }else{ $redis->hdel('buyUserInfo',$value); } } } } /** * @title 二级市场未支付的自动取消 * @desc 二级市场未支付的自动取消 * @author Gavin * @url /api/Timedtask/SecondaryancelGoodsOrder * @method GET */ public function SecondaryancelGoodsOrder(){ $CancelTime = getConfigValue('secondary_cancel_time'); if ($CancelTime<=0){ die; } $list = Db::name('store_order_info_order')->where('status',0)->select(); foreach ($list as &$v){ $cancel_time = strtotime($v['create_at'])+($CancelTime*60); if ($cancel_timewhere('id',$v['id'])->update($info); $cancle = [ 'mid'=>$v['mid'], 'order_id'=>$v['id'] ]; Db::name('store_order_info_cancel_log')->insert($cancle); $time = date('Y-m-d H:i:s',time()-(60*60)); $count = Db::name('store_order_info_cancel_log')->where('mid',$v['mid'])->where('create_at','gt',$time)->count(); if ($count>2){ $buy_time = date('Y-m-d H:i:s',time()+(24*60*60)); Db::name('store_member')->where('id',$v['mid'])->update(['buy_time'=>$buy_time]); } } } } /** * @title 创建链账户 * @desc 创建链账户 * @author Gavin * @url /api/Timedtask/createAddress * @method GET */ public function createAddress(){ set_time_limit(0); $member = Db::name('store_member') ->where('wallet_address','eq','') //->whereNull('wallet_address') ->field('id,offline_account,phone,wallet_address') ->order('id asc') ->limit(30) ->select(); foreach ($member as &$v){ $name = $v['phone']; $operationId = $v['phone']; $operationId .= rand(10000,99999); $url = getIpAddress()."customNFT/createAccount?name=".$name."&operationId=".$operationId; $offlineaccount = file_get_contents($url); $offline_account = json_decode($offlineaccount,true); if (isset($offline_account) && isset($offline_account['account'])){ Db::name('store_member')->where('id',$v['id']) ->update(['accountName'=>$operationId,'wallet_address'=>$offline_account['account'],'offline_account'=>$offlineaccount]); } } } /** * 查询链上架回执 * @url /api/Timedtask/setNftCheck */ public function setNftCheck(){ Db::name('hash2')->where('success',0)->chunk(30,function ($list){ foreach ($list as &$v){ $result =$this->checkhashSuccess($v['operationId']); $data['result'] = json_encode($result,true); if (isset($result) && $result['status']==1){ $data['success'] = 1; $data['class_id'] =$result['class_id']; } Db::name('hash2')->where('id',$v['id'])->update($data); } },'id','asc'); } /** * 创建nft * @url /api/Timedtask/createNft */ public function createNft(){ Db::name('store_order_info') ->whereIn('status','1,4,5') ->where('collectors_hash','eq','') ->whereNull('collectors_hash2') ->chunk(30,function ($list){ foreach ($list as &$v){ $name = get32Str(10); $operationId = $v['id']; $operationId .= rand(1000000,9999999); $to = Db::name('store_member')->where('id',$v['mid'])->value('wallet_address'); $url = getIpAddress().'customNFT/createNft?classId='.$v['tokenid'].'&name='.$name.'&operationId='.$operationId.'&recipient='.$to; $res=curlRequest($url); $result=json_decode($res,true); if (isset($result) && isset($result['task_id'])){ Db::name('store_order_info')->where('id',$v['id'])->update(['collectors_hash2'=>$result['task_id'],'nfttype'=>$operationId]); } } },'id','asc'); } /** * 判断创建的nft是否成功 * @url /api/Timedtask/checkcreateNft */ public function checkcreateNft(){ Db::name('store_order_info') ->whereIn('status','1,4,5') ->where('collectors_hash','eq','') ->whereNotNull('collectors_hash2') ->chunk(30,function ($list){ foreach ($list as &$v){ $result = $this->checkhashSuccess($v['collectors_hash2']); $data['result'] = json_encode($result,true); if (isset($result) && $result['status']==1){ $data['tokenid'] = $result['class_id']; $data['collectors_hash'] = $result['tx_hash']; $data['nftid'] = $result['nft_id']; $data['collectors_hash_time'] = date('Y-m-d H:i:s'); } Db::name('store_order_info')->where('id',$v['id'])->update($data); } },'id','asc'); } /** * * @url /api/Timedtask/checkrepetition */ public function checkrepetition(){ $list = Db::query('select count(collectors_hash) as count,collectors_hash from store_order_info group by collectors_hash having count(*)>1'); foreach ($list as &$v){ $list2 = Db::name('store_order_info')->where('collectors_hash',$v['collectors_hash'])->select(); foreach ($list2 as &$a){ $result = json_decode($a['result'],true); if ($result['status']!=1){ Db::name('store_order_info')->where('id',$a['id'])->update(['collectors_hash'=>'']); } } } } /** * 转移nft * @url /api/Timedtask/judgeHash */ public function judgeHash(){ Db::name('store_order_info') ->where('status',3) ->where('collectors_hash','eq','') ->whereNull('collectors_hash2') ->chunk(30,function ($list){ foreach ($list as &$v){ $operationId = $v['id']; $operationId .= rand(10000000,99999999); $add = Db::name('store_member')->where('id',$v['to_mid'])->value('wallet_address'); $to = Db::name('store_member')->where('id',$v['mid'])->value('wallet_address'); $url = getIpAddress().'customNFT/transfer?classId='.$v['tokenid'].'&NFTId='.$v['nftid'].'&operationId='.$operationId.'&owner='.$add.'&recipient='.$to; echo $url; $res=curlRequest($url); $result=json_decode($res,true); dump($result); if (isset($result) && isset($result['task_id'])){ Db::name('store_order_info')->where('id',$v['id'])->update(['collectors_hash2'=>$result['task_id'],'nfttype'=>$operationId]); } } },'id','asc'); } /** * 判断转移的nft是否成功 * @url /api/Timedtask/checkjudgeNft */ public function checkjudgeNft(){ Db::name('store_order_info') ->where('status',3) ->where('collectors_hash','eq','') ->whereNotNull('collectors_hash2') ->chunk(30,function ($list){ foreach ($list as &$v){ $result = $this->checkhashSuccess($v['collectors_hash2']); $data['result'] = json_encode($result,true); if (isset($result) && $result['status']==1){ $data['tokenid'] = $result['class_id']; $data['collectors_hash'] = $result['tx_hash']; $data['nftid'] = $result['nft_id']; } Db::name('store_order_info')->where('id',$v['id'])->update($data); } },'id','asc'); } /** * 查询交易是否成功 * @url /api/Timedtask/checkhashSuccess */ public function checkhashSuccess($operationId){ $url = getIpAddress().'customNFT/queryDealResult?operationId='.$operationId; $res=curlRequest($url); $result=json_decode($res,true); return $result; } /** * 判断转移的数据是否属于当前转移用户 * @url /api/Timedtask/checkjudgeHashOwer */ public function checkjudgeHashOwer(){ $list = Db::name('store_order_info') ->where('status',3) ->where('collectors_hash','eq','') ->whereNull('collectors_hash2') ->order('id asc') ->limit(30) ->select(); foreach ($list as &$v){ if (time()>strtotime($v['collectors_hash_time'])+(1*60*60)){ $url = getIpAddress().'customNFT/sNFT?classId='.$v['tokenid'].'&NFTId='.$v['nftid']; $res=json_decode(curlRequest($url),true); if (isset($res)){ dump($res); $add = Db::name('store_member')->where('id',$v['to_mid'])->value('wallet_address'); echo $add."
"; if ($add != $res['owner']){ $operationId = $v['id']; $operationId .= rand(10000000,99999999); $adds = $res['owner']; $tos = $add; $url = getIpAddress().'customNFT/transfer?classId='.$v['tokenid'].'&NFTId='.$v['nftid'].'&operationId='.$operationId.'&owner='.$adds.'&recipient='.$tos; $ress = json_decode(curlRequest($url),true); dump($ress); } } } } } /** * redis 加锁 */ function redisCreateSetNx($id){ $redis = new Redis(); $key = 'hash_'.$id; $exptime = 450; $is_lock = $redis->setnx($key,time()+$exptime); if ($is_lock){ return true; }else{ //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁 $val = $redis->get($key); if ($val && $valdel($key); } return $redis->setnx($key,time()+$exptime); } } /** * redis nonce加锁 */ function redisNonceSetNx(){ $redis = new Redis(); $key = 'noncenx'; $exptime = 10; $is_lock = $redis->setnx($key,time()+$exptime); if ($is_lock){ return true; }else{ //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁 $val = $redis->get($key); if ($val && $valdel($key); } return $redis->setnx($key,time()+$exptime); } } /** * 预约藏品前十五分钟发送短信 * /api/Timedtask/sendSms */ public function sendSms(){ Db::name('store_collection_remind')->where('is_send',0)->chunk(50,function ($list){ foreach ($list as &$v){ $sell_time = Db::name('store_collection')->where('id',$v['c_id'])->value('sell_time'); $t = (strtotime($sell_time)-time())/60; if ($t<=15 && $t>0){ $result = $this->accessKeyClient($v['mobile'],$v['mid'],$v['c_id']); if ($result['Code'] === 'OK') { Db::name('store_collection_remind')->where('id',$v['id'])->update(['is_send'=>1]); } } } },'id','asc'); } function accessKeyClient($mobile,$mid,$cid) { $ali_accesskey = 'LTAI5tSTBuRP5AnPBHDz8gTF'; $ali_accesskey_secret = '7RVjRKv8cCaKW4hMMVZ1SFPkqeIbn4'; $templateCode = 'SMS_243370550'; AlibabaCloud::accessKeyClient($ali_accesskey, $ali_accesskey_secret) ->regionId('cn-hangzhou') ->asDefaultClient(); $user = getMemberInfoHash($mid); //获取用户信息 $coll_info = getCollectionInfoHash($cid); $post = [ 'name'=>$user['name'], 'goodname'=>$coll_info['name'], 'pubtime'=>$coll_info['sell_time'] ]; $TemplateParam = json_encode($post,true); try { $result = AlibabaCloud::rpc() ->product('Dysmsapi') // ->scheme('https') // https | http ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host('dysmsapi.aliyuncs.com') ->options([ 'query' => [ 'PhoneNumbers' => $mobile, 'SignName' => '同质科技', 'TemplateCode' => $templateCode, 'TemplateParam' => $TemplateParam ], ]) ->request(); $info = $result->toArray(); return $info; } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL; } } }