AccountController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\AccountService;
  5. use App\Services\Api\BalanceLogService;
  6. /**
  7. * 账单明细
  8. * Class AccountController
  9. * @package App\Http\Controllers\Api
  10. */
  11. class AccountController extends webApp
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. */
  17. public function index()
  18. {
  19. $params = request()->post();
  20. $pageSize = request()->post('pageSize', 15);
  21. $params['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  22. $datas = AccountService::make()->getDataList($params, $pageSize);
  23. if ($datas) {
  24. return message(1010, true, $datas);
  25. } else {
  26. return message(1009, false);
  27. }
  28. }
  29. /**
  30. * 明细
  31. * @return array
  32. */
  33. public function info()
  34. {
  35. $id = request()->post('id', 0);
  36. $info = AccountService::make()->getInfo($id);
  37. if ($info) {
  38. return showJson(1010, true, $info);
  39. } else {
  40. return showJson(1004, false);
  41. }
  42. }
  43. /**
  44. * 余额明细
  45. * @return array
  46. */
  47. public function balance()
  48. {
  49. $params = request()->post();
  50. $pageSize = request()->post('pageSize', 15);
  51. $params['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  52. $datas = BalanceLogService::make()->getDataList($params, $pageSize);
  53. return message(1010, true, $datas);
  54. }
  55. /**
  56. * 提现
  57. * @return array
  58. */
  59. public function withdraw()
  60. {
  61. try {
  62. $params = request()->all();
  63. if (!$result = BalanceLogService::make()->withdraw($this->userId, $params)) {
  64. return showJson(BalanceLogService::make()->getError(), false);
  65. } else {
  66. return showJson(BalanceLogService::make()->getError(), true, $result);
  67. }
  68. } catch (\Exception $exception) {
  69. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  70. return showJson(1046, false, $error);
  71. }
  72. }
  73. /**
  74. * 转账
  75. * @return array
  76. */
  77. public function transfer()
  78. {
  79. try {
  80. $params = request()->all();
  81. if (!$result = BalanceLogService::make()->transfer($this->userId, $params)) {
  82. return showJson(BalanceLogService::make()->getError(), false);
  83. } else {
  84. return showJson(BalanceLogService::make()->getError(), true, $result);
  85. }
  86. } catch (\Exception $exception) {
  87. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  88. return showJson(1046, false, $error);
  89. }
  90. }
  91. }