HandleEnergyOrder.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. <?php
  2. namespace App\Task;
  3. use App\Model\Energy\EnergyWalletTradeList;
  4. use App\Model\Energy\EnergyPlatformPackage;
  5. use App\Model\Energy\EnergyPlatformOrder;
  6. use App\Model\Energy\EnergyPlatform;
  7. use App\Model\Energy\EnergyAiBishu;
  8. use App\Model\Energy\EnergyThirdPart;
  9. use App\Model\Energy\EnergyQuickOrder;
  10. use App\Service\RsaServices;
  11. use App\Library\Log;
  12. class HandleEnergyOrder
  13. {
  14. public function execute()
  15. {
  16. //trx闪租能量
  17. try {
  18. $data = EnergyWalletTradeList::from('energy_wallet_trade_list as a')
  19. ->join('energy_platform_bot as b','a.transferto_address','b.receive_wallet')
  20. ->where('a.process_status',1)
  21. ->where('a.coin_name','trx')
  22. ->select('a.rid','a.transferfrom_address','a.amount','b.poll_group','b.status','b.bot_rid','b.rid as energy_platform_bot_rid')
  23. ->limit(100)
  24. ->get();
  25. if($data->count() > 0){
  26. $time = nowDate();
  27. foreach ($data as $k => $v) {
  28. if($v->status == 1){
  29. $save_data = [];
  30. $save_data['process_status'] = 6; //能量钱包未启用
  31. $save_data['process_comments'] = '能量钱包未启用'; //处理备注
  32. $save_data['process_time'] = $time; //处理时间
  33. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  34. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  35. continue;
  36. }
  37. //匹配金额
  38. $res = EnergyPlatformPackage::where('bot_rid',$v->bot_rid)->where('trx_price',$v->amount)->first();
  39. if(empty($res)){
  40. $save_data = [];
  41. $save_data['process_status'] = 7; //金额无对应套餐
  42. $save_data['process_comments'] = '金额无对应套餐'; //处理备注
  43. $save_data['process_time'] = $time; //处理时间
  44. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  45. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  46. continue;
  47. }
  48. $energy_amount = $res->energy_amount;
  49. //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
  50. $model = EnergyPlatform::where('poll_group',$v->poll_group)
  51. ->where('status',0)
  52. ->whereNotNull('platform_apikey')
  53. ->where(function ($query) use($energy_amount) {
  54. $query->where(function ($query1) use($energy_amount){
  55. $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
  56. });
  57. $query->orwhere(function ($query2) {
  58. $query2->orwhereIn('platform_name', [1,2,4,5])->where('platform_balance', '>', '0');
  59. });
  60. })
  61. ->orderBy('seq_sn','desc')
  62. ->get();
  63. if($model->count() > 0){
  64. $errorMessage = '';
  65. $rsa_services = new RsaServices();
  66. foreach ($model as $k1 => $v1){
  67. $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
  68. if(empty($signstr)){
  69. // $save_data = [];
  70. // $save_data['process_status'] = 5; //能量钱包未配置私钥
  71. // $save_data['process_comments'] = '能量钱包未配置私钥2'; //处理备注
  72. // $save_data['process_time'] = $time; //处理时间
  73. // $save_data['energy_platform_rid'] = $v1->rid;
  74. // $save_data['energy_package_rid'] = $res['rid'];
  75. // $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  76. // EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  77. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
  78. $save_data = [];
  79. $save_data['process_status'] = 5; //下单失败
  80. $save_data['process_comments'] = $errorMessage; //处理备注
  81. $save_data['process_time'] = $time; //处理时间
  82. $save_data['energy_platform_rid'] = $v1->rid;
  83. $save_data['energy_package_rid'] = $res['rid'];
  84. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  85. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  86. continue;
  87. }
  88. $save_data = [];
  89. $save_data['process_status'] = 8; //下单中
  90. $save_data['process_comments'] = '下单中'; //处理备注
  91. $save_data['process_time'] = $time; //处理时间
  92. $save_data['energy_platform_rid'] = $v1->rid;
  93. $save_data['energy_package_rid'] = $res['rid'];
  94. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  95. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  96. $energy_day = $res['energy_day'];
  97. //neee.cc平台
  98. if($v1->platform_name == 1){
  99. $header = [
  100. "Content-Type:application/json"
  101. ];
  102. $param = [
  103. "uid" => strval($v1->platform_uid),
  104. "resource_type" => "0", //0能量
  105. "receive_address" => $v->transferfrom_address,
  106. "amount" => strval($energy_amount),
  107. "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
  108. "time" => strval(time())
  109. ];
  110. ksort($param);
  111. reset($param);
  112. foreach($param as $ka => $va){
  113. if($ka != "sign" && $ka != "sign_type" && $va!=''){
  114. $signstr .= $ka.$va;
  115. }
  116. }
  117. $sign = md5($signstr);
  118. $param['sign'] = $sign;
  119. $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
  120. $dlres = Get_Pay($balance_url,json_encode($param),$header);
  121. }
  122. //RentEnergysBot平台
  123. elseif($v1->platform_name == 2){
  124. //0:一小时,1:一天,3:三天
  125. switch ($energy_day) {
  126. case 1:
  127. $type = 'day';
  128. break;
  129. case 3:
  130. $type = '3day';
  131. break;
  132. default:
  133. $type = 'hour';
  134. break;
  135. }
  136. //该平台最低33000
  137. $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
  138. $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->transferfrom_address.'&amount='.$energy_amount.'&type='.$type;
  139. $dlres = Get_Pay($balance_url);
  140. }
  141. //自己质押代理
  142. elseif($v1->platform_name == 3){
  143. $params = [
  144. 'pri' => $signstr,
  145. 'fromaddress' => $v1->platform_uid,
  146. 'receiveaddress' => $v->transferfrom_address,
  147. 'resourcename' => 'ENERGY',
  148. 'resourceamount' => $energy_amount,
  149. 'resourcetype' => 1,
  150. 'permissionid' => $v1->permission_id
  151. ];
  152. $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
  153. //trongas.io平台
  154. }elseif($v1->platform_name == 4){
  155. //0:一小时,1:一天,3:三天
  156. switch ($energy_day) {
  157. case 1:
  158. $rentTime = 24;
  159. break;
  160. case 3:
  161. $rentTime = 72;
  162. break;
  163. default:
  164. $rentTime = 1;
  165. break;
  166. }
  167. $param = [
  168. "username" => $v1->platform_uid, // 用户名
  169. "password" => $signstr, // 用户密码
  170. "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
  171. "payNums" => $energy_amount, // 租用数量
  172. "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
  173. "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
  174. "receiveAddress" => $v->transferfrom_address // 接收资源地址(请勿输入合约地址或没激活地址)
  175. ];
  176. $balance_url = 'https://trongas.io/api/pay';
  177. $dlres = Get_Pay($balance_url,$param);
  178. //机器人开发代理
  179. }elseif($v1->platform_name == 5){
  180. $balance_url = env('THIRD_URL');
  181. if(empty($balance_url)){
  182. $errorMessage = $errorMessage."使用开发者能量代理时,env中url为空";
  183. $save_data = [];
  184. $save_data['process_status'] = 4; //下单失败
  185. $save_data['process_time'] = $time; //处理时间
  186. $save_data['process_comments'] = $time.$errorMessage; //处理备注
  187. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  188. continue;
  189. }
  190. //0:一小时,1:一天,3:三天
  191. switch ($energy_day) {
  192. case 1:
  193. $rentTime = 24;
  194. break;
  195. case 3:
  196. $rentTime = 72;
  197. break;
  198. default:
  199. $rentTime = 1;
  200. break;
  201. }
  202. //使用开发者能量代理,仅支持32000 65000能量代理1小时
  203. if($rentTime != 1){
  204. $errorMessage = $errorMessage."使用开发者能量代理时,时长只能为1小时";
  205. $save_data = [];
  206. $save_data['process_status'] = 4; //下单失败
  207. $save_data['process_time'] = $time; //处理时间
  208. $save_data['process_comments'] = $time.$errorMessage; //处理备注
  209. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  210. continue;
  211. }
  212. $param = [
  213. "tg_uid" => $v1->platform_uid, // 用户名,此处是tg的uid,因为是机器人能量代理模式
  214. "payNums" => $energy_amount, // 租用数量
  215. "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
  216. "receiveAddress" => $v->transferfrom_address // 接收资源地址(请勿输入合约地址或没激活地址)
  217. ];
  218. $balance_url = $balance_url.'/api/thirdpart/shanzuorder';
  219. $dlres = Get_Pay($balance_url,$param);
  220. }
  221. if(empty($dlres)){
  222. // $save_data = [];
  223. // $save_data['process_status'] = 4; //下单失败
  224. // $save_data['process_comments'] = '下单失败,接口请求空'; //处理备注
  225. // $save_data['process_time'] = $time; //处理时间
  226. // $save_data['energy_platform_rid'] = $v1->rid;
  227. // $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  228. // EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  229. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
  230. $save_data = [];
  231. $save_data['process_status'] = 4; //下单失败
  232. $save_data['process_comments'] = $errorMessage; //处理备注
  233. $save_data['process_time'] = $time; //处理时间
  234. $save_data['energy_platform_rid'] = $v1->rid;
  235. $save_data['energy_package_rid'] = $res['rid'];
  236. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  237. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  238. continue;
  239. }else{
  240. $dlres = json_decode($dlres,true);
  241. 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)){
  242. if($v1->platform_name == 1){
  243. $orderNo = $dlres['data']['order_no'];
  244. $use_trx = 0;
  245. }elseif($v1->platform_name == 2){
  246. $orderNo = $dlres['txid'];
  247. $use_trx = 0;
  248. }elseif($v1->platform_name == 3){
  249. $orderNo = $dlres['data']['txid'];
  250. $use_trx = $dlres['data']['use_trx'];
  251. }elseif($v1->platform_name == 4){
  252. $orderNo = $dlres['data']['orderId'];
  253. $use_trx = $dlres['data']['orderMoney'];
  254. }elseif($v1->platform_name == 5){
  255. $orderNo = $dlres['data']['orderId'];
  256. $use_trx = $dlres['data']['orderMoney'];
  257. }
  258. $insert_data = [];
  259. $insert_data['energy_platform_rid'] = $v1->rid;
  260. $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  261. $insert_data['platform_name'] = $v1->platform_name;
  262. $insert_data['platform_uid'] = $v1->platform_uid;
  263. $insert_data['receive_address'] = $v->transferfrom_address;
  264. $insert_data['platform_order_id'] = $orderNo;
  265. $insert_data['energy_amount'] = $energy_amount;
  266. $insert_data['energy_day'] = $energy_day;
  267. $insert_data['energy_time'] = $time;
  268. $insert_data['source_type'] = 2; //自动下单
  269. $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
  270. $insert_data['use_trx'] = $use_trx;
  271. $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
  272. $save_data = [];
  273. $save_data['process_status'] = 9; //下单成功
  274. $save_data['process_comments'] = 'SUCCESS'; //处理备注
  275. $save_data['platform_order_rid'] = $platform_order_rid; //能量订单表ID
  276. $save_data['process_time'] = $time; //处理时间
  277. $save_data['energy_platform_rid'] = $v1->rid;
  278. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  279. $save_data['tg_notice_status_send'] = 'N'; //重新通知
  280. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  281. break; //跳出不轮询了
  282. }else{
  283. if($v1->platform_name == 1){
  284. $msg = '下单失败,接口返回:'.$dlres['msg'];
  285. }elseif($v1->platform_name == 2){
  286. $msg = '下单失败,接口返回:'.json_encode($dlres);
  287. }elseif($v1->platform_name == 3){
  288. $msg = '下单失败,检查质押是否足够';
  289. }elseif($v1->platform_name == 4){
  290. $msg = ' 下单失败,接口返回:'.json_encode($dlres);
  291. }elseif($v1->platform_name == 5){
  292. $msg = ' 下单失败,接口返回:'.json_encode($dlres);
  293. }
  294. $errorMessage = $errorMessage."能量平台:".$v1->platform_name.$msg;
  295. $save_data = [];
  296. $save_data['process_status'] = 4; //下单失败
  297. $save_data['process_comments'] = $errorMessage; //处理备注
  298. $save_data['process_time'] = $time; //处理时间
  299. $save_data['energy_platform_rid'] = $v1->rid;
  300. $save_data['energy_package_rid'] = $res['rid'];
  301. $save_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  302. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  303. continue;
  304. }
  305. }
  306. }
  307. }else{
  308. $save_data = [];
  309. $save_data['process_status'] = 4; //下单失败
  310. $save_data['process_comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
  311. $save_data['process_time'] = $time; //处理时间
  312. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  313. }
  314. }
  315. }else{
  316. // $this->log('shanduibonus','----------没有数据----------');
  317. }
  318. }catch (\Exception $e){
  319. // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  320. }
  321. //能量快捷余额购买
  322. try {
  323. $data = EnergyQuickOrder::from('energy_quick_order as a')
  324. ->join('energy_platform_bot as b','a.bot_rid','b.bot_rid')
  325. ->where('a.status',1)
  326. ->where('a.energy_amount','>',0)
  327. ->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')
  328. ->limit(100)
  329. ->get();
  330. if($data->count() > 0){
  331. $time = nowDate();
  332. foreach ($data as $k => $v) {
  333. if($v->status == 1){
  334. $save_data = [];
  335. $save_data['status'] = 6; //能量钱包未启用
  336. $save_data['comments'] = '能量钱包未启用'; //处理备注
  337. $save_data['process_time'] = $time; //处理时间
  338. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  339. continue;
  340. }
  341. $energy_amount = $v->energy_amount;
  342. //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
  343. $model = EnergyPlatform::where('poll_group',$v->poll_group)
  344. ->where('status',0)
  345. ->whereNotNull('platform_apikey')
  346. ->where(function ($query) use($energy_amount) {
  347. $query->where(function ($query1) use($energy_amount){
  348. $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
  349. });
  350. $query->orwhere(function ($query2) {
  351. $query2->orwhereIn('platform_name', [1,2,4,5])->where('platform_balance', '>', '0');
  352. });
  353. })
  354. ->orderBy('seq_sn','desc')
  355. ->get();
  356. if($model->count() > 0){
  357. $errorMessage = '';
  358. $rsa_services = new RsaServices();
  359. foreach ($model as $k1 => $v1){
  360. $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
  361. if(empty($signstr)){
  362. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
  363. $save_data = [];
  364. $save_data['status'] = 5; //下单失败
  365. $save_data['comments'] = $errorMessage; //处理备注
  366. $save_data['process_time'] = $time; //处理时间
  367. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  368. continue;
  369. }
  370. $save_data = [];
  371. $save_data['status'] = 8; //下单中
  372. $save_data['comments'] = '下单中'; //处理备注
  373. $save_data['process_time'] = $time; //处理时间
  374. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  375. $energy_day = $v->energy_day;
  376. //neee.cc平台
  377. if($v1->platform_name == 1){
  378. $header = [
  379. "Content-Type:application/json"
  380. ];
  381. $param = [
  382. "uid" => strval($v1->platform_uid),
  383. "resource_type" => "0", //0能量
  384. "receive_address" => $v->wallet_addr,
  385. "amount" => strval($energy_amount),
  386. "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
  387. "time" => strval(time())
  388. ];
  389. ksort($param);
  390. reset($param);
  391. foreach($param as $ka => $va){
  392. if($ka != "sign" && $ka != "sign_type" && $va!=''){
  393. $signstr .= $ka.$va;
  394. }
  395. }
  396. $sign = md5($signstr);
  397. $param['sign'] = $sign;
  398. $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
  399. $dlres = Get_Pay($balance_url,json_encode($param),$header);
  400. }
  401. //RentEnergysBot平台
  402. elseif($v1->platform_name == 2){
  403. //0:一小时,1:一天,3:三天
  404. switch ($energy_day) {
  405. case 1:
  406. $type = 'day';
  407. break;
  408. case 3:
  409. $type = '3day';
  410. break;
  411. default:
  412. $type = 'hour';
  413. break;
  414. }
  415. //该平台最低33000
  416. $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
  417. $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->wallet_addr.'&amount='.$energy_amount.'&type='.$type;
  418. $dlres = Get_Pay($balance_url);
  419. }
  420. //自己质押代理
  421. elseif($v1->platform_name == 3){
  422. $params = [
  423. 'pri' => $signstr,
  424. 'fromaddress' => $v1->platform_uid,
  425. 'receiveaddress' => $v->wallet_addr,
  426. 'resourcename' => 'ENERGY',
  427. 'resourceamount' => $energy_amount,
  428. 'resourcetype' => 1,
  429. 'permissionid' => $v1->permission_id
  430. ];
  431. $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
  432. //trongas.io平台
  433. }elseif($v1->platform_name == 4){
  434. //0:一小时,1:一天,3:三天
  435. switch ($energy_day) {
  436. case 1:
  437. $rentTime = 24;
  438. break;
  439. case 3:
  440. $rentTime = 72;
  441. break;
  442. default:
  443. $rentTime = 1;
  444. break;
  445. }
  446. $param = [
  447. "username" => $v1->platform_uid, // 用户名
  448. "password" => $signstr, // 用户密码
  449. "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
  450. "payNums" => $energy_amount, // 租用数量
  451. "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
  452. "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
  453. "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
  454. ];
  455. $balance_url = 'https://trongas.io/api/pay';
  456. $dlres = Get_Pay($balance_url,$param);
  457. //机器人开发代理
  458. }elseif($v1->platform_name == 5){
  459. $balance_url = env('THIRD_URL');
  460. if(empty($balance_url)){
  461. $errorMessage = $errorMessage."使用开发者能量代理时,env中url为空";
  462. $save_data = [];
  463. $save_data['status'] = 4; //下单失败
  464. $save_data['process_time'] = $time; //处理时间
  465. $save_data['comments'] = $time.$errorMessage; //处理备注
  466. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  467. continue;
  468. }
  469. //0:一小时,1:一天,3:三天
  470. switch ($energy_day) {
  471. case 1:
  472. $rentTime = 24;
  473. break;
  474. case 3:
  475. $rentTime = 72;
  476. break;
  477. default:
  478. $rentTime = 1;
  479. break;
  480. }
  481. //使用开发者能量代理,仅支持32000 65000能量代理1小时
  482. if($rentTime != 1){
  483. $errorMessage = $errorMessage."使用开发者能量代理时,时长只能为1小时";
  484. $save_data = [];
  485. $save_data['status'] = 4; //下单失败
  486. $save_data['process_time'] = $time; //处理时间
  487. $save_data['comments'] = $time.$errorMessage; //处理备注
  488. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  489. continue;
  490. }
  491. $param = [
  492. "tg_uid" => $v1->platform_uid, // 用户名,此处是tg的uid,因为是机器人能量代理模式
  493. "payNums" => $energy_amount, // 租用数量
  494. "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
  495. "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
  496. ];
  497. $balance_url = $balance_url.'/api/thirdpart/shanzuorder';
  498. $dlres = Get_Pay($balance_url,$param);
  499. }
  500. if(empty($dlres)){
  501. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
  502. $save_data = [];
  503. $save_data['status'] = 4; //下单失败
  504. $save_data['comments'] = $errorMessage; //处理备注
  505. $save_data['process_time'] = $time; //处理时间
  506. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  507. continue;
  508. }else{
  509. $dlres = json_decode($dlres,true);
  510. 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)){
  511. if($v1->platform_name == 1){
  512. $orderNo = $dlres['data']['order_no'];
  513. $use_trx = 0;
  514. }elseif($v1->platform_name == 2){
  515. $orderNo = $dlres['txid'];
  516. $use_trx = 0;
  517. }elseif($v1->platform_name == 3){
  518. $orderNo = $dlres['data']['txid'];
  519. $use_trx = $dlres['data']['use_trx'];
  520. }elseif($v1->platform_name == 4){
  521. $orderNo = $dlres['data']['orderId'];
  522. $use_trx = $dlres['data']['orderMoney'];
  523. }elseif($v1->platform_name == 5){
  524. $orderNo = $dlres['data']['orderId'];
  525. $use_trx = $dlres['data']['orderMoney'];
  526. }
  527. $insert_data = [];
  528. $insert_data['energy_platform_rid'] = $v1->rid;
  529. $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  530. $insert_data['platform_name'] = $v1->platform_name;
  531. $insert_data['platform_uid'] = $v1->platform_uid;
  532. $insert_data['receive_address'] = $v->wallet_addr;
  533. $insert_data['platform_order_id'] = $orderNo;
  534. $insert_data['energy_amount'] = $energy_amount;
  535. $insert_data['energy_day'] = $energy_day;
  536. $insert_data['energy_time'] = $time;
  537. $insert_data['source_type'] = 2; //自动下单
  538. $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
  539. $insert_data['use_trx'] = $use_trx;
  540. $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
  541. $save_data = [];
  542. $save_data['status'] = 9; //下单成功
  543. $save_data['comments'] = 'SUCCESS'; //处理备注
  544. $save_data['process_time'] = $time; //处理时间
  545. $save_data['daili_time'] = $time; //代理时间
  546. $save_data['is_notice'] = 'Y'; //重新通知
  547. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  548. break; //跳出不轮询了
  549. }else{
  550. if($v1->platform_name == 1){
  551. $msg = '下单失败,接口返回:'.$dlres['msg'];
  552. }elseif($v1->platform_name == 2){
  553. $msg = '下单失败,接口返回:'.json_encode($dlres);
  554. }elseif($v1->platform_name == 3){
  555. $msg = '下单失败,检查质押是否足够';
  556. }elseif($v1->platform_name == 4){
  557. $msg = ' 下单失败,接口返回:'.json_encode($dlres);
  558. }elseif($v1->platform_name == 5){
  559. $msg = ' 下单失败,接口返回:'.json_encode($dlres);
  560. }
  561. $errorMessage = $errorMessage."能量平台:".$v1->platform_name.$msg;
  562. $save_data = [];
  563. $save_data['status'] = 4; //下单失败
  564. $save_data['comments'] = $errorMessage; //处理备注
  565. $save_data['process_time'] = $time; //处理时间
  566. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  567. continue;
  568. }
  569. }
  570. }
  571. }else{
  572. $save_data = [];
  573. $save_data['status'] = 4; //下单失败
  574. $save_data['comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
  575. $save_data['process_time'] = $time; //处理时间
  576. EnergyQuickOrder::where('rid',$v->rid)->update($save_data);
  577. }
  578. }
  579. }else{
  580. // $this->log('shanduibonus','----------没有数据----------');
  581. }
  582. }catch (\Exception $e){
  583. // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  584. }
  585. //机器人开发代理-闪租下单
  586. try {
  587. $data = EnergyThirdPart::from('energy_third_part as a')
  588. ->join('energy_platform_bot as b','a.bot_rid','b.bot_rid')
  589. ->where('a.process_status',1)
  590. ->where('a.order_type',2)
  591. ->select('a.rid','a.wallet_addr','a.cishu_energy','b.poll_group','b.status','b.bot_rid','b.rid as energy_platform_bot_rid')
  592. ->limit(100)
  593. ->get();
  594. if($data->count() > 0){
  595. $time = nowDate();
  596. foreach ($data as $k => $v) {
  597. if($v->status == 1){
  598. $save_data = [];
  599. $save_data['process_status'] = 6; //能量钱包未启用
  600. $save_data['process_comments'] = '能量钱包未启用'; //处理备注
  601. $save_data['process_time'] = $time; //处理时间
  602. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  603. continue;
  604. }
  605. $energy_amount = $v->cishu_energy;
  606. //轮询,自己质押时判断能量是否足够,用平台则判断平台的trx
  607. $model = EnergyPlatform::where('poll_group',$v->poll_group)
  608. ->where('status',0)
  609. ->whereNotNull('platform_apikey')
  610. ->where(function ($query) use($energy_amount) {
  611. $query->where(function ($query1) use($energy_amount){
  612. $query1->where('platform_name', 3)->where('platform_balance', '>=', $energy_amount);
  613. });
  614. $query->orwhere(function ($query2) {
  615. $query2->orwhereIn('platform_name', [1,2,4])->where('platform_balance', '>', '0'); //这里不能有5这个平台
  616. });
  617. })
  618. ->orderBy('seq_sn','desc')
  619. ->get();
  620. if($model->count() > 0){
  621. $errorMessage = '';
  622. $rsa_services = new RsaServices();
  623. foreach ($model as $k1 => $v1){
  624. $signstr = $rsa_services->privateDecrypt($v1->platform_apikey);
  625. if(empty($signstr)){
  626. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 平台私钥为空。";
  627. $save_data = [];
  628. $save_data['process_status'] = 5; //下单失败
  629. $save_data['process_comments'] = $errorMessage; //处理备注
  630. $save_data['process_time'] = $time; //处理时间
  631. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  632. continue;
  633. }
  634. $save_data = [];
  635. $save_data['process_status'] = 8; //下单中
  636. $save_data['process_comments'] = '下单中'; //处理备注
  637. $save_data['process_time'] = $time; //处理时间
  638. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  639. $energy_day = 0; //该方式下单只能是1小时
  640. //neee.cc平台
  641. if($v1->platform_name == 1){
  642. $header = [
  643. "Content-Type:application/json"
  644. ];
  645. $param = [
  646. "uid" => strval($v1->platform_uid),
  647. "resource_type" => "0", //0能量
  648. "receive_address" => $v->wallet_addr,
  649. "amount" => strval($energy_amount),
  650. "freeze_day" => strval($energy_day), //0:一小时,1:一天,3:三天
  651. "time" => strval(time())
  652. ];
  653. ksort($param);
  654. reset($param);
  655. foreach($param as $ka => $va){
  656. if($ka != "sign" && $ka != "sign_type" && $va!=''){
  657. $signstr .= $ka.$va;
  658. }
  659. }
  660. $sign = md5($signstr);
  661. $param['sign'] = $sign;
  662. $balance_url = 'https://api.tronqq.com/openapi/v2/order/submit';
  663. $dlres = Get_Pay($balance_url,json_encode($param),$header);
  664. }
  665. //RentEnergysBot平台
  666. elseif($v1->platform_name == 2){
  667. //0:一小时,1:一天,3:三天
  668. switch ($energy_day) {
  669. case 1:
  670. $type = 'day';
  671. break;
  672. case 3:
  673. $type = '3day';
  674. break;
  675. default:
  676. $type = 'hour';
  677. break;
  678. }
  679. //该平台最低33000
  680. $energy_amount = $energy_amount < 33000 ?33000:$energy_amount;
  681. $balance_url = 'https://api.wallet.buzz?api=getEnergy&apikey='.$signstr.'&address='.$v->wallet_addr.'&amount='.$energy_amount.'&type='.$type;
  682. $dlres = Get_Pay($balance_url);
  683. }
  684. //自己质押代理
  685. elseif($v1->platform_name == 3){
  686. $params = [
  687. 'pri' => $signstr,
  688. 'fromaddress' => $v1->platform_uid,
  689. 'receiveaddress' => $v->wallet_addr,
  690. 'resourcename' => 'ENERGY',
  691. 'resourceamount' => $energy_amount,
  692. 'resourcetype' => 1,
  693. 'permissionid' => $v1->permission_id
  694. ];
  695. $dlres = Get_Pay(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9kZWxlZ2VhbmR1bmRlbGV0ZQ=='),$params);
  696. //trongas.io平台
  697. }elseif($v1->platform_name == 4){
  698. //0:一小时,1:一天,3:三天
  699. switch ($energy_day) {
  700. case 1:
  701. $rentTime = 24;
  702. break;
  703. case 3:
  704. $rentTime = 72;
  705. break;
  706. default:
  707. $rentTime = 1;
  708. break;
  709. }
  710. $param = [
  711. "username" => $v1->platform_uid, // 用户名
  712. "password" => $signstr, // 用户密码
  713. "resType" => "ENERGY", // 资源类型,ENERGY:能量,BANDWIDTH:带宽
  714. "payNums" => $energy_amount, // 租用数量
  715. "rentTime" => $rentTime, // 单位小时,只能1时或1到30天按天租用其中不能租用2天
  716. "resLock" => 0, // 租用锁定,0:不锁定,1:锁定。能量租用数量不小于500万且租用时间不小于3天才能锁定。带宽租用数量不小于30万租用时间不小于3天才能锁定
  717. "receiveAddress" => $v->wallet_addr // 接收资源地址(请勿输入合约地址或没激活地址)
  718. ];
  719. $balance_url = 'https://trongas.io/api/pay';
  720. $dlres = Get_Pay($balance_url,$param);
  721. }
  722. if(empty($dlres)){
  723. $errorMessage = $errorMessage."能量平台:".$v1->platform_name." 能量平台接口返回为空。";
  724. $save_data = [];
  725. $save_data['process_status'] = 4; //下单失败
  726. $save_data['process_comments'] = $errorMessage; //处理备注
  727. $save_data['process_time'] = $time; //处理时间
  728. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  729. continue;
  730. }else{
  731. $dlres = json_decode($dlres,true);
  732. 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)){
  733. if($v1->platform_name == 1){
  734. $orderNo = $dlres['data']['order_no'];
  735. $use_trx = 0;
  736. }elseif($v1->platform_name == 2){
  737. $orderNo = $dlres['txid'];
  738. $use_trx = 0;
  739. }elseif($v1->platform_name == 3){
  740. $orderNo = $dlres['data']['txid'];
  741. $use_trx = $dlres['data']['use_trx'];
  742. }elseif($v1->platform_name == 4){
  743. $orderNo = $dlres['data']['orderId'];
  744. $use_trx = $dlres['data']['orderMoney'];
  745. }
  746. $insert_data = [];
  747. $insert_data['energy_platform_rid'] = $v1->rid;
  748. $insert_data['energy_platform_bot_rid'] = $v->energy_platform_bot_rid;
  749. $insert_data['platform_name'] = $v1->platform_name;
  750. $insert_data['platform_uid'] = $v1->platform_uid;
  751. $insert_data['receive_address'] = $v->wallet_addr;
  752. $insert_data['platform_order_id'] = $orderNo;
  753. $insert_data['energy_amount'] = $energy_amount;
  754. $insert_data['energy_day'] = $energy_day;
  755. $insert_data['energy_time'] = $time;
  756. $insert_data['source_type'] = 2; //自动下单
  757. $insert_data['recovery_status'] = $v1->platform_name == 3 ?2:1; //回收状态:1不用回收,2待回收,3已回收
  758. $insert_data['use_trx'] = $use_trx;
  759. $platform_order_rid = EnergyPlatformOrder::insertGetId($insert_data);
  760. $save_data = [];
  761. $save_data['process_status'] = 9; //下单成功
  762. $save_data['process_comments'] = 'SUCCESS'; //处理备注
  763. $save_data['process_time'] = $time; //处理时间
  764. // $save_data['tg_notice_status_send'] = 'N'; //重新通知
  765. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  766. break; //跳出不轮询了
  767. }else{
  768. if($v1->platform_name == 1){
  769. $msg = '下单失败,接口返回:'.$dlres['msg'];
  770. }elseif($v1->platform_name == 2){
  771. $msg = '下单失败,接口返回:'.json_encode($dlres);
  772. }elseif($v1->platform_name == 3){
  773. $msg = '下单失败,检查质押是否足够';
  774. }elseif($v1->platform_name == 4){
  775. $msg = ' 下单失败,接口返回:'.json_encode($dlres);
  776. }
  777. $errorMessage = $errorMessage."能量平台:".$v1->platform_name.$msg;
  778. $save_data = [];
  779. $save_data['process_status'] = 4; //下单失败
  780. $save_data['process_comments'] = $errorMessage; //处理备注
  781. $save_data['process_time'] = $time; //处理时间
  782. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  783. continue;
  784. }
  785. }
  786. }
  787. }else{
  788. $save_data = [];
  789. $save_data['process_status'] = 4; //下单失败
  790. $save_data['process_comments'] = "机器人无可用能量平台,请质押或者充值平台"; //处理备注
  791. $save_data['process_time'] = $time; //处理时间
  792. EnergyThirdPart::where('rid',$v->rid)->update($save_data);
  793. }
  794. }
  795. }else{
  796. // $this->log('shanduibonus','----------没有数据----------');
  797. }
  798. }catch (\Exception $e){
  799. // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  800. }
  801. //usdt笔数套餐
  802. try {
  803. $data = EnergyWalletTradeList::from('energy_wallet_trade_list as a')
  804. ->join('energy_platform_bot as b','a.transferto_address','b.receive_wallet')
  805. ->leftJoin('telegram_bot as c','b.bot_rid','c.rid')
  806. ->where('a.process_status',1)
  807. ->where('a.coin_name','usdt')
  808. ->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')
  809. ->limit(100)
  810. ->get();
  811. if($data->count() > 0){
  812. $time = nowDate();
  813. foreach ($data as $k => $v) {
  814. //查询笔数套餐钱包是否存在
  815. $energyAiBishu = EnergyAiBishu::where('wallet_addr',$v->transferfrom_address)->first();
  816. if($energyAiBishu){
  817. $save_data = [];
  818. $save_data['total_buy_usdt'] = $energyAiBishu->total_buy_usdt + $v->amount;
  819. $save_data['max_buy_quantity'] = $energyAiBishu->max_buy_quantity + floor($v->amount / $v->per_bishu_usdt_price);
  820. EnergyAiBishu::where('rid',$energyAiBishu->rid)->update($save_data);
  821. }else{
  822. $insert_data = [];
  823. $insert_data['bot_rid'] = $v->bot_rid;
  824. $insert_data['wallet_addr'] = $v->transferfrom_address;
  825. $insert_data['status'] = 0;
  826. $insert_data['total_buy_usdt'] = $v->amount;
  827. $insert_data['max_buy_quantity'] = floor($v->amount / $v->per_bishu_usdt_price);
  828. $insert_data['create_time'] = $time;
  829. EnergyAiBishu::insert($insert_data);
  830. }
  831. $save_data = [];
  832. $save_data['process_status'] = 9; //下单成功
  833. $save_data['process_comments'] = "成功,笔数套餐增加:".floor($v->amount / $v->per_bishu_usdt_price); //处理备注
  834. $save_data['process_time'] = $time; //处理时间
  835. EnergyWalletTradeList::where('rid',$v->rid)->update($save_data);
  836. //通知到群
  837. if(!empty($v->tg_notice_obj_send) && $v->tg_notice_obj_send != ''){
  838. $replytext = "<b>✳️笔数套餐购买成功</b> \n"
  839. ."➖➖➖➖➖➖➖➖\n"
  840. ."<b>下单模式</b>:笔数套餐\n"
  841. ."<b>免费转账</b>:". floor($v->amount / $v->per_bishu_usdt_price) ." 次\n"
  842. ."<b>下单地址</b>:".mb_substr($v->transferfrom_address,0,8).'****'.mb_substr($v->transferfrom_address,-8,8) ."\n\n"
  843. ."<b>笔数套餐转账不扣TRX,智能监控地址补足能量</b>\n"
  844. ."发送 /buyenergy 继续购买能量!\n"
  845. ."➖➖➖➖➖➖➖➖";
  846. //内联按钮
  847. $keyboard = [
  848. 'inline_keyboard' => [
  849. [
  850. ['text' => '能量闪租', 'url' => 'https://t.me/'.$v->bot_username],
  851. ['text' => '笔数套餐', 'url' => 'https://t.me/'.$v->bot_username]
  852. ],
  853. [
  854. ['text' => '联系客服', 'url' => 'https://t.me/'.mb_substr($v->bot_admin_username,1)],
  855. ['text' => 'TRX闪兑', 'url' => 'https://t.me/'.$v->bot_username]
  856. ]
  857. ]
  858. ];
  859. $encodedKeyboard = json_encode($keyboard);
  860. $sendlist = explode(',',$v->tg_notice_obj_send);
  861. foreach ($sendlist as $x => $y) {
  862. $sendmessageurl = 'https://api.telegram.org/bot'.$v->bot_token.'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML&reply_markup='.urlencode($encodedKeyboard);
  863. Get_Pay($sendmessageurl);
  864. }
  865. }
  866. }
  867. }else{
  868. // $this->log('shanduibonus','----------没有数据----------');
  869. }
  870. }catch (\Exception $e){
  871. // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  872. }
  873. }
  874. /**
  875. * 记入日志
  876. * @param $log_title [日志路径]
  877. * @param $message [内容,不支持数组]
  878. * @param $remarks [备注]
  879. */
  880. protected function log($log_title,$message,$remarks='info'){
  881. Log::get($remarks,$log_title)->info($message);
  882. }
  883. }