Ledger.php 12 KB

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