AccountController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 payMeal()
  34. {
  35. $params = request()->post();
  36. $type = isset($params['type']) ? $params['type'] : 1;
  37. $datas = AccountService::make()->getPayMealList($type);
  38. if ($datas) {
  39. return message(1010, true, $datas);
  40. } else {
  41. return message(1009, false);
  42. }
  43. }
  44. /**
  45. * 充值记录
  46. * @return array
  47. */
  48. public function payLog()
  49. {
  50. $params = request()->post();
  51. $pageSize = request()->post('pageSize', 15);
  52. $params['type'] = 2;
  53. $params['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  54. $datas = AccountService::make()->getDataList($params, $pageSize);
  55. if ($datas) {
  56. return message(1010, true, $datas);
  57. } else {
  58. return message(1009, false);
  59. }
  60. }
  61. /**
  62. * 余额明细
  63. * @return array
  64. */
  65. public function balance()
  66. {
  67. $params = request()->post();
  68. $pageSize = request()->post('pageSize', 15);
  69. $params['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  70. $datas = BalanceLogService::make()->getDataList($params, $pageSize);
  71. return message(1010, true, $datas);
  72. }
  73. /**
  74. * 生活充值
  75. * @return array
  76. */
  77. public function pay()
  78. {
  79. $params = request()->all();
  80. try {
  81. if (!$result = AccountService::make()->recharge($this->userId, $params)) {
  82. return showJson(AccountService::make()->getError(), false);
  83. } else {
  84. return showJson(AccountService::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. /**
  92. * 收入提现
  93. * @return array
  94. */
  95. public function withdraw()
  96. {
  97. try {
  98. $params = request()->all();
  99. if (!$result = BalanceLogService::make()->withdraw($this->userId, $params)) {
  100. return showJson(BalanceLogService::make()->getError(), false);
  101. } else {
  102. return showJson(BalanceLogService::make()->getError(), true, $result);
  103. }
  104. } catch (\Exception $exception) {
  105. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  106. return showJson(1046, false, $error);
  107. }
  108. }
  109. }