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