Ledger.php 12 KB

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