Ledger.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\LedgerDeclarationChange;
  4. use app\common\controller\Api;
  5. use app\common\model\LedgerPowerChangeModel;
  6. use app\common\model\LedgerQubicChangeModel;
  7. use app\common\model\LedgerServersPowerChangeModel;
  8. use app\common\model\LedgerSmhChangeModel;
  9. use app\common\model\LedgerTokenChangeModel;
  10. use app\common\model\LedgerUsdtChangeModel;
  11. use app\common\model\LedgerWalletModel;
  12. use app\common\model\OfflineWithdrawRecordModel;
  13. use fast\Action;
  14. use think\Log;
  15. use think\Env;
  16. /**
  17. * 首页接口
  18. */
  19. class Ledger extends Api
  20. {
  21. protected array $noNeedLogin = ['withdrawCallback'];
  22. /**
  23. * 资产首页
  24. */
  25. public function assets()
  26. {
  27. $res['assets'] = $this->auth->balance;
  28. $res['chabao_rate'] = getConfig('chabao_rate'); //茶宝汇率
  29. $res['withdrawal_fee']= getConfig('withdrawal_fee'); //提现收费
  30. $res['transfes_fee'] = getConfig('transfer_fee'); //转让手续费比例
  31. $res['transfes_txt'] = config('transfes_txt'); //转让文字表述
  32. $res['coin_list'] = [
  33. [
  34. 'coin_name' => 'USDT',
  35. 'coin_key' => 'usdt',
  36. 'amount' => LedgerWalletModel::getWalletChaBao($this->auth->getTokenUserID()),
  37. 'frozen_amount' => $this->auth->frozen_amount //冻结金额
  38. ]
  39. ];
  40. $this->success('', $res);
  41. }
  42. /**
  43. * 资产变动明细
  44. * @return void
  45. */
  46. public function coinList()
  47. {
  48. $type_id = $this->request->post('query.action'); // 账变类型
  49. $coin_type = $this->request->post('query.coin_type'); // 資金类型
  50. $where = [
  51. 'user_id' => $this->auth->getTokenUserID(),
  52. ];
  53. if ($type_id > 0) {
  54. $where['action'] = $type_id;
  55. }
  56. switch ($coin_type){
  57. case 'usdt':
  58. $paginator = (new LedgerUsdtChangeModel());
  59. break;
  60. case 'power':
  61. $paginator = (new LedgerPowerChangeModel());
  62. break;
  63. // case 'server':
  64. // $paginator = (new LedgerServersPowerChangeModel());
  65. // break;
  66. case 'declaration':
  67. $paginator = (new LedgerDeclarationChange());
  68. break;
  69. case 'etc':
  70. $paginator = (new LedgerTokenChangeModel());
  71. break;
  72. case 'aleo':
  73. $paginator = (new LedgerTokenChangeModel());
  74. break;
  75. case 'smh':
  76. $paginator = (new LedgerSmhChangeModel());
  77. break;
  78. case 'qubic':
  79. $paginator = (new LedgerQubicChangeModel());
  80. break;
  81. default:
  82. $this->error("参数有误");
  83. break;
  84. }
  85. $paginator = $paginator->where($where)->order('id DESC')->paginate($this->pageSize);
  86. foreach ($paginator as $key => $item){
  87. $paginator[$key]['change_amount'] = round($item['change_amount'], 4);
  88. $paginator[$key]['present_amount'] = round($item['present_amount'], 4);
  89. if($coin_type == 'smh'){
  90. $paginator[$key]['action_name'] = (new LedgerSmhChangeModel())->pay_status[$item['action']];
  91. }elseif($coin_type == 'qubic'){
  92. $paginator[$key]['action_name'] = (new LedgerQubicChangeModel())->aciton_name[$item['action']];
  93. }elseif($coin_type == 'aleo'){
  94. $paginator[$key]['action_name'] = (new LedgerTokenChangeModel())->aciton_name[$item['action']];
  95. }else{
  96. $paginator[$key]['action_name'] = Action::getText($item['action']);
  97. }
  98. }
  99. $res = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
  100. $this->success('',$res);
  101. }
  102. /**
  103. * 资产变动类型
  104. * @return void
  105. */
  106. public function coinAction()
  107. {
  108. $coin_type = $this->request->post('coin_type'); // 資金类型
  109. switch ($coin_type){
  110. case 'smh':
  111. $res = (new LedgerSmhChangeModel())->pay_status;//资金变动类型列表
  112. break;
  113. case 'qubic':
  114. $res = (new LedgerQubicChangeModel())->aciton_name;//资金变动类型列表
  115. break;
  116. case 'aleo':
  117. $res = (new LedgerTokenChangeModel())->aciton_name;//资金变动类型列表
  118. break;
  119. default:
  120. $res = Action::getAll($coin_type);//资金变动类型列表
  121. break;
  122. }
  123. $this->success('',$res);
  124. }
  125. public function actionGet()
  126. {
  127. $asset = $this->request->post('type'); // 资产类型
  128. $resp = [];
  129. switch ($asset) {
  130. case 1:
  131. $resp = [
  132. $this->getActionValueText(Action::All),
  133. $this->getActionValueText(Action::PowerRentalPower),
  134. $this->getActionValueText(Action::PowerDirectAward),
  135. $this->getActionValueText(Action::PowerTeamAward),
  136. $this->getActionValueText(Action::PowerEqualAward),
  137. $this->getActionValueText(Action::PowerBonusAward),
  138. $this->getActionValueText(Action::PowerCommunityBonusAward),
  139. ];
  140. break;
  141. case 2:
  142. $resp = [
  143. $this->getActionValueText(Action::All),
  144. $this->getActionValueText(Action::UsdtRentalPower),
  145. $this->getActionValueText(Action::UsdtGenerateProfit),
  146. $this->getActionValueText(Action::UsdtWeightDividend),
  147. $this->getActionValueText(Action::UsdtWithdrawCash),
  148. $this->getActionValueText(Action::UsdtWithdrawReturn),
  149. $this->getActionValueText(Action::UsdtRegBonus),
  150. $this->getActionValueText(Action::UsdtCmmunityBonus),
  151. ];
  152. break;
  153. case 3:
  154. $resp = [
  155. $this->getActionValueText(Action::All),
  156. $this->getActionValueText(Action::TokenAllocateEtc),
  157. ];
  158. break;
  159. default:
  160. $this->error('资产类型错误');
  161. break;
  162. }
  163. $this->success('', $resp);
  164. }
  165. private function getActionValueText(int $action): array
  166. {
  167. return ['value' => $action, 'text' => Action::getText($action)];
  168. }
  169. /**
  170. * 算力明细
  171. * @return void
  172. */
  173. public function powerList()
  174. {
  175. $type = $this->request->post('query.action'); // 账变类型
  176. $where = [
  177. 'user_id' => $this->auth->getTokenUserID(),
  178. ];
  179. if ($type != Action::All) {
  180. $where['action'] = $type;
  181. }
  182. $paginator = (new LedgerPowerChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
  183. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  184. }
  185. /**
  186. * USDT明细
  187. * @return void
  188. */
  189. public function usdtList()
  190. {
  191. $type = $this->request->post('query.action'); // 账变类型
  192. $where = [
  193. 'user_id' => $this->auth->getTokenUserID(),
  194. ];
  195. if ($type != Action::All) {
  196. $where['action'] = $type;
  197. }
  198. $paginator = (new LedgerUsdtChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
  199. foreach ($paginator as $key => $item){
  200. $paginator[$key]['action_name'] = Action::getText($item['action']);
  201. }
  202. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  203. }
  204. /**
  205. * 虚拟币明细
  206. * @return void
  207. */
  208. public function tokenList()
  209. {
  210. $type = $this->request->post('query.action'); // 账变类型
  211. $where = [
  212. 'user_id' => $this->auth->getTokenUserID(),
  213. ];
  214. if ($type != Action::All) {
  215. $where['action'] = $type;
  216. }
  217. $paginator = (new LedgerTokenChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
  218. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  219. }
  220. /**
  221. * 提现自动打款回调
  222. * 接口回调信息格式:
  223. *
  224. * @return void
  225. */
  226. public function withdrawCallback_my()
  227. {
  228. //post 获取过来的数据格式为:{"code":"1","data":{"orderNo":"1768","tx_hash":"xx4545"}}
  229. $parems = $this->request->post();
  230. Log::write('提现自动打款回调参数:','info');
  231. Log::info(json_encode($parems));
  232. if(empty($parems)){
  233. $this->error("回调参数为空");
  234. }
  235. if($parems['code'] != 1){
  236. $this->error("本次提现失败");
  237. }
  238. $rs_data = $parems['data'];
  239. $info = (new OfflineWithdrawRecordModel())
  240. ->where('id', $rs_data['orderNo'])
  241. ->find();
  242. if(empty($info)){
  243. $this->error("当前提现信息不存在");
  244. }
  245. if($info['status'] == 2){
  246. $this->success("更新成功");
  247. }
  248. if($info['status'] == 5){
  249. $is_update = (new OfflineWithdrawRecordModel())
  250. ->where('id', $info['id'])
  251. ->update([
  252. 'tx_hash' => $rs_data['tx_hash'],
  253. 'status' => 2,
  254. 'update_time' => time(),
  255. ]);
  256. if($is_update){
  257. $this->success("更新成功");
  258. }else{
  259. $this->error("更新失败");
  260. }
  261. }
  262. }
  263. /**
  264. * 提现自动打款回调
  265. * 接口回调信息格式:
  266. * companyWithdrawId=126&sign=8e3c6aee53e3ea4ff974c1d80f4e8beb&status=1&txId=0x39ce05a0698ff2b7459ca707703fd48937dd958422d98ebade6b4f5188b70995
  267. * @return void
  268. */
  269. public function withdrawCallback()
  270. {
  271. // $body1 = file_get_contents("php://input");
  272. // Log::write('提现自动打款回调1:' . $body1, 'info');
  273. //
  274. // $body = $this->request->post();
  275. $body = file_get_contents("php://input");
  276. //$body = 'companyWithdrawId=126&sign=8e3c6aee53e3ea4ff974c1d80f4e8beb&status=1&txId=0x39ce05a0698ff2b7459ca707703fd48937dd958422d98ebade6b4f5188b70995';
  277. Log::write('提现自动打款回调:' . $body, 'info');
  278. if(empty($body)){
  279. return;
  280. }
  281. $parems = explode('&', $body);
  282. $req_arr = [];
  283. foreach ($parems as $item){
  284. $temp = explode('=', $item);
  285. $req_arr[$temp[0]] = $temp[1];
  286. }
  287. Log::write('提现自动打款回调参数:','info');
  288. Log::info(json_encode($req_arr));
  289. $info = (new OfflineWithdrawRecordModel())
  290. ->where('id', $req_arr['companyWithdrawId'])
  291. ->find();
  292. if(empty($info)){
  293. $this->error("当前提现信息不存在");
  294. }
  295. if($info['status'] == OfflineWithdrawRecordModel::StatusSuccessAuto){
  296. $this->success("更新成功");
  297. }
  298. if($info['status'] == OfflineWithdrawRecordModel::StatusConfirm){
  299. $is_update = (new OfflineWithdrawRecordModel())
  300. ->where('id', $req_arr['companyWithdrawId'])
  301. ->update([
  302. 'tx_hash' => $req_arr['txId'],
  303. 'status' => OfflineWithdrawRecordModel::StatusSuccessAuto,
  304. 'update_time' => time(),
  305. ]);
  306. if($is_update){
  307. $this->success("更新成功");
  308. }else{
  309. $this->error("更新失败");
  310. }
  311. }
  312. }
  313. // 获取充值地址
  314. public function getAddress()
  315. {
  316. return $this->success('', ['value'=> Env::get('rental.pay_address'), 'name'=>getConfig('recharge_txt')]);
  317. }
  318. }