AccountController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  53. $datas = AccountService::make()->getPayLog($params, $pageSize);
  54. if ($datas) {
  55. return message(1010, true, $datas);
  56. } else {
  57. return message(1009, false);
  58. }
  59. }
  60. /**
  61. * 余额明细
  62. * @return array
  63. */
  64. public function balance()
  65. {
  66. $params = request()->post();
  67. $pageSize = request()->post('pageSize', 15);
  68. $params['user_id'] = isset($params['user_id']) ? $params['user_id'] : $this->userId;
  69. $datas = BalanceLogService::make()->getDataList($params, $pageSize);
  70. return message(1010, true, $datas);
  71. }
  72. /**
  73. * 生活充值
  74. * @return array
  75. */
  76. public function pay()
  77. {
  78. $params = request()->all();
  79. try {
  80. if (!$result = AccountService::make()->recharge($this->userId, $params)) {
  81. return showJson(AccountService::make()->getError(), false);
  82. } else {
  83. return showJson(AccountService::make()->getError(), true, $result);
  84. }
  85. } catch (\Exception $exception) {
  86. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  87. return showJson(1046, false, $error);
  88. }
  89. }
  90. /**
  91. * 收入提现
  92. * @return array
  93. */
  94. public function withdraw()
  95. {
  96. try {
  97. $params = request()->all();
  98. if (!$result = BalanceLogService::make()->withdraw($this->userId, $params)) {
  99. return showJson(BalanceLogService::make()->getError(), false);
  100. } else {
  101. return showJson(BalanceLogService::make()->getError(), true, $result);
  102. }
  103. } catch (\Exception $exception) {
  104. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  105. return showJson(1046, false, $error);
  106. }
  107. }
  108. }