Ledger.php 11 KB

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