TaskController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Services\Api\MemberService;
  4. use App\Services\Common\AdvertOrderService;
  5. use App\Services\Common\TradeOrderService;
  6. use App\Services\ConfigService;
  7. use App\Services\RedisService;
  8. use App\Services\UsdtWalletService;
  9. /**
  10. * 任务
  11. * Class TaskController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class TaskController extends webApp
  15. {
  16. /**
  17. * 监听处理用户TRC子钱包存币(转账-进账)
  18. * @return array|mixed
  19. */
  20. public function catchTrcRecharge()
  21. {
  22. $key = md5('OTC');
  23. $checkKey = request()->get('key');
  24. if($checkKey != $key){
  25. return showJson(1003, false);
  26. }
  27. $cachekey = "caches:wallet:trc_";
  28. $page = RedisService::get($cachekey."rechargePage");
  29. $page = $page? $page : 1;
  30. $members = MemberService::make()->getCatchMember($page, 500);
  31. if(empty($members)){
  32. RedisService::set($cachekey."rechargePage", 1, 600);
  33. return showJson(1019, false);
  34. }
  35. $count = 0;
  36. $failedCount = 0;
  37. foreach ($members as $v){
  38. $result = UsdtWalletService::make()->getTrc20RechargeLog($v['id'], $v['trc_address']);
  39. if($result){
  40. $count++;
  41. RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $result, 600);
  42. }else{
  43. $failedCount++;
  44. $error = lang(UsdtWalletService::make()->getError());
  45. RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $error, 600);
  46. }
  47. }
  48. RedisService::set($cachekey."rechargePage", $page+1, 600);
  49. if($count>0){
  50. return showJson(1020, true,['success'=> $count,'fail'=> $failedCount]);
  51. }else{
  52. return showJson(1021, false);
  53. }
  54. }
  55. /**
  56. * 监听处理用户ERC子钱包存币(转账-进账)
  57. * @return array|mixed
  58. */
  59. public function catchErcRecharge()
  60. {
  61. $key = md5('OTC');
  62. $checkKey = request()->get('key');
  63. if($checkKey != $key){
  64. return showJson(1003, false);
  65. }
  66. $cachekey = "caches:wallet:erc_";
  67. $page = RedisService::get($cachekey."rechargePage");
  68. $page = $page? $page : 1;
  69. $members = MemberService::make()->getCatchMember($page, 500);
  70. if(empty($members)){
  71. RedisService::set($cachekey."rechargePage", 1, 600);
  72. return showJson(1019, false);
  73. }
  74. $count = 0;
  75. $failedCount = 0;
  76. foreach ($members as $v){
  77. $result = UsdtWalletService::make()->getErc20RechargeLog($v['id'], $v['trc_address']);
  78. if($result){
  79. $count++;
  80. RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $result, 600);
  81. }else{
  82. $failedCount++;
  83. $error = lang(UsdtWalletService::make()->getError());
  84. RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $error, 600);
  85. }
  86. }
  87. RedisService::set($cachekey."rechargePage", $page+1, 600);
  88. if($count>0){
  89. return showJson(1020, true,['success'=> $count,'fail'=> $failedCount]);
  90. }else{
  91. return showJson(1021, false);
  92. }
  93. }
  94. /**
  95. * 监听平台TRC平台出账钱包交易记录(提币回调确认完成交易)
  96. * @return array|mixed
  97. */
  98. public function catchTrcTransferByOtc()
  99. {
  100. $key = md5('OTC');
  101. $checkKey = request()->get('key');
  102. if($checkKey != $key){
  103. return showJson(1003, false);
  104. }
  105. // 出账手续费钱包
  106. $otcOutAddress = ConfigService::make()->getConfigByCode('trc_out_address');
  107. if(empty($otcOutAddress)){
  108. return showJson(2210, false);
  109. }
  110. $cacheKey = "caches:wallets:listen:trc_{$otcOutAddress}";
  111. if(RedisService::get($cacheKey.'_lock')){
  112. return showJson(1025, false);
  113. }
  114. $result = UsdtWalletService::make()->getTrc20TransferLogByOtc($otcOutAddress, 500);
  115. RedisService::set($cacheKey.'_lock', 1, rand(5, 10));
  116. if($result){
  117. RedisService::set($cacheKey, $result, 3600);
  118. return showJson(1020, true,['success'=> count($result)]);
  119. }else{
  120. return showJson(1021, false);
  121. }
  122. }
  123. /**
  124. * 监听平台ERC平台出账钱包交易记录(提币回调确认完成交易)
  125. * @return array|mixed
  126. */
  127. public function catchErcTransferByOtc()
  128. {
  129. $key = md5('OTC');
  130. $checkKey = request()->get('key');
  131. if($checkKey != $key){
  132. return showJson(1003, false);
  133. }
  134. // 出账手续费钱包
  135. $otcOutAddress = ConfigService::make()->getConfigByCode('erc_out_address');
  136. if(empty($otcOutAddress)){
  137. return showJson(2210, false);
  138. }
  139. $cacheKey = "caches:wallets:listen:erc_{$otcOutAddress}";
  140. if(RedisService::get($cacheKey.'_lock')){
  141. return showJson(1025, false);
  142. }
  143. $result = UsdtWalletService::make()->getErc20TransferLogByOtc($otcOutAddress, 500);
  144. RedisService::set($cacheKey.'_lock', 1, rand(5, 10));
  145. if($result){
  146. RedisService::set($cacheKey, $result, 3600);
  147. return showJson(1020, true,['success'=> count($result)]);
  148. }else{
  149. return showJson(1021, false);
  150. }
  151. }
  152. /**
  153. * 自动归集TRC总钱包
  154. * @return array
  155. * @throws \Tron\Exceptions\TransactionException
  156. * @throws \Tron\Exceptions\TronErrorException
  157. */
  158. public function catchTrcTruggerByOtc()
  159. {
  160. $key = md5('OTC');
  161. $checkKey = request()->get('key');
  162. if($checkKey != $key){
  163. return showJson(1003, false);
  164. }
  165. if($result = UsdtWalletService::make()->usdtTrcTrigger()){
  166. return showJson(1002, true, $result);
  167. }else{
  168. return showJson(UsdtWalletService::make()->getError(), false);
  169. }
  170. }
  171. /**
  172. * 自动归集ERC总钱包
  173. * @return array
  174. * @throws \Tron\Exceptions\TransactionException
  175. * @throws \Tron\Exceptions\TronErrorException
  176. */
  177. public function catchErcTruggerByOtc()
  178. {
  179. $key = md5('OTC');
  180. $checkKey = request()->get('key');
  181. if($checkKey != $key){
  182. return showJson(1003, false);
  183. }
  184. if($result = UsdtWalletService::make()->usdtErcTrigger()){
  185. return showJson(1002, true, $result);
  186. }else{
  187. return showJson(UsdtWalletService::make()->getError(), false);
  188. }
  189. }
  190. /**
  191. * 自动取消派单订单任务
  192. * @return array|mixed
  193. */
  194. public function catchTradeOrderCancel()
  195. {
  196. $key = md5('OTC');
  197. $checkKey = request()->get('key');
  198. if ($checkKey != $key) {
  199. return showJson(1003, false);
  200. }
  201. if($result = TradeOrderService::make()->catchInvalidOrder()){
  202. return showJson(1002, true, $result);
  203. }else{
  204. return showJson(TradeOrderService::make()->getError(), false);
  205. }
  206. }
  207. /**
  208. * 自动取消派单订单任务
  209. * @return array|mixed
  210. */
  211. public function catchAdvertOrderCancel()
  212. {
  213. $key = md5('OTC');
  214. $checkKey = request()->get('key');
  215. if ($checkKey != $key) {
  216. return showJson(1003, false);
  217. }
  218. if($result = AdvertOrderService::make()->catchInvalidOrder()){
  219. return showJson(1002, true, $result);
  220. }else{
  221. return showJson(AdvertOrderService::make()->getError(), false);
  222. }
  223. }
  224. }